mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2024-11-22 20:28:00 +00:00
move PlayerUtils code from platforms to the api
This commit is contained in:
parent
d8c21edc7a
commit
92bb0030de
@ -3,6 +3,12 @@ package com.imaginarycode.minecraft.redisbungee.api.util.player;
|
|||||||
import com.imaginarycode.minecraft.redisbungee.AbstractRedisBungeeAPI;
|
import com.imaginarycode.minecraft.redisbungee.AbstractRedisBungeeAPI;
|
||||||
import redis.clients.jedis.UnifiedJedis;
|
import redis.clients.jedis.UnifiedJedis;
|
||||||
|
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static com.imaginarycode.minecraft.redisbungee.api.util.payload.PayloadUtils.playerJoinPayload;
|
||||||
import static com.imaginarycode.minecraft.redisbungee.api.util.payload.PayloadUtils.playerQuitPayload;
|
import static com.imaginarycode.minecraft.redisbungee.api.util.payload.PayloadUtils.playerQuitPayload;
|
||||||
|
|
||||||
public class PlayerUtils {
|
public class PlayerUtils {
|
||||||
@ -17,5 +23,22 @@ public class PlayerUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void createPlayer(UUID uuid, UnifiedJedis unifiedJedis, String currentServer, InetAddress hostname, boolean fireEvent) {
|
||||||
|
if (currentServer != null) {
|
||||||
|
unifiedJedis.hset("player:" + uuid, "server", currentServer);
|
||||||
|
}
|
||||||
|
Map<String, String> playerData = new HashMap<>(4);
|
||||||
|
playerData.put("online", "0");
|
||||||
|
playerData.put("ip", hostname.getHostName());
|
||||||
|
playerData.put("proxy", AbstractRedisBungeeAPI.getAbstractRedisBungeeAPI().getProxyId());
|
||||||
|
|
||||||
|
unifiedJedis.sadd("proxy:" + AbstractRedisBungeeAPI.getAbstractRedisBungeeAPI().getProxyId() + ":usersOnline", uuid.toString());
|
||||||
|
unifiedJedis.hmset("player:" + uuid, playerData);
|
||||||
|
|
||||||
|
if (fireEvent) {
|
||||||
|
playerJoinPayload(uuid, unifiedJedis, hostname);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,37 +10,19 @@
|
|||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee;
|
package com.imaginarycode.minecraft.redisbungee;
|
||||||
|
|
||||||
|
import com.imaginarycode.minecraft.redisbungee.api.util.player.PlayerUtils;
|
||||||
import net.md_5.bungee.api.connection.PendingConnection;
|
import net.md_5.bungee.api.connection.PendingConnection;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
import redis.clients.jedis.UnifiedJedis;
|
import redis.clients.jedis.UnifiedJedis;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import static com.imaginarycode.minecraft.redisbungee.api.util.payload.PayloadUtils.playerJoinPayload;
|
|
||||||
|
|
||||||
public class BungeePlayerUtils {
|
public class BungeePlayerUtils {
|
||||||
|
|
||||||
public static void createPlayer(ProxiedPlayer player, UnifiedJedis unifiedJedis, boolean fireEvent) {
|
public static void createBungeePlayer(ProxiedPlayer player, UnifiedJedis unifiedJedis, boolean fireEvent) {
|
||||||
createPlayer(player.getPendingConnection(), unifiedJedis, fireEvent);
|
String serverName = null;
|
||||||
if (player.getServer() != null)
|
if (player.getServer() != null) {
|
||||||
unifiedJedis.hset("player:" + player.getUniqueId().toString(), "server", player.getServer().getInfo().getName());
|
serverName = player.getServer().getInfo().getName();
|
||||||
|
}
|
||||||
|
PendingConnection pendingConnection = player.getPendingConnection();
|
||||||
|
PlayerUtils.createPlayer(player.getUniqueId(), unifiedJedis, serverName, pendingConnection.getAddress().getAddress(), fireEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void createPlayer(PendingConnection connection, UnifiedJedis unifiedJedis, boolean fireEvent) {
|
|
||||||
Map<String, String> playerData = new HashMap<>(4);
|
|
||||||
playerData.put("online", "0");
|
|
||||||
playerData.put("ip", connection.getAddress().getAddress().getHostAddress());
|
|
||||||
playerData.put("proxy", RedisBungeeAPI.getRedisBungeeApi().getProxyId());
|
|
||||||
|
|
||||||
unifiedJedis.sadd("proxy:" + RedisBungeeAPI.getRedisBungeeApi().getProxyId() + ":usersOnline", connection.getUniqueId().toString());
|
|
||||||
unifiedJedis.hmset("player:" + connection.getUniqueId().toString(), playerData);
|
|
||||||
|
|
||||||
if (fireEvent) {
|
|
||||||
playerJoinPayload(connection.getUniqueId(), unifiedJedis, connection.getAddress().getAddress());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -243,7 +243,7 @@ public class RedisBungee extends Plugin implements RedisBungeePlugin<ProxiedPlay
|
|||||||
if (proxiedPlayer == null)
|
if (proxiedPlayer == null)
|
||||||
return; // We'll deal with it later.
|
return; // We'll deal with it later.
|
||||||
|
|
||||||
BungeePlayerUtils.createPlayer(proxiedPlayer, unifiedJedis, false);
|
BungeePlayerUtils.createBungeePlayer(proxiedPlayer, unifiedJedis, false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ public class RedisBungeeBungeeListener extends AbstractRedisBungeeListener<Login
|
|||||||
@Override
|
@Override
|
||||||
public Void unifiedJedisTask(UnifiedJedis unifiedJedis) {
|
public Void unifiedJedisTask(UnifiedJedis unifiedJedis) {
|
||||||
plugin.getUuidTranslator().persistInfo(event.getPlayer().getName(), event.getPlayer().getUniqueId(), unifiedJedis);
|
plugin.getUuidTranslator().persistInfo(event.getPlayer().getName(), event.getPlayer().getUniqueId(), unifiedJedis);
|
||||||
BungeePlayerUtils.createPlayer(event.getPlayer(), unifiedJedis, true);
|
BungeePlayerUtils.createBungeePlayer(event.getPlayer(), unifiedJedis, true);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -97,7 +97,7 @@ public class RedisBungeeVelocityListener extends AbstractRedisBungeeListener<Log
|
|||||||
@Override
|
@Override
|
||||||
public Void unifiedJedisTask(UnifiedJedis unifiedJedis) {
|
public Void unifiedJedisTask(UnifiedJedis unifiedJedis) {
|
||||||
plugin.getUuidTranslator().persistInfo(event.getPlayer().getUsername(), event.getPlayer().getUniqueId(), unifiedJedis);
|
plugin.getUuidTranslator().persistInfo(event.getPlayer().getUsername(), event.getPlayer().getUniqueId(), unifiedJedis);
|
||||||
VelocityPlayerUtils.createPlayer(event.getPlayer(), unifiedJedis, true);
|
VelocityPlayerUtils.createVelocityPlayer(event.getPlayer(), unifiedJedis, true);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -259,7 +259,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player>, Con
|
|||||||
Player playerProxied = getProxy().getPlayer(UUID.fromString(player)).orElse(null);
|
Player playerProxied = getProxy().getPlayer(UUID.fromString(player)).orElse(null);
|
||||||
if (playerProxied == null)
|
if (playerProxied == null)
|
||||||
return; // We'll deal with it later.
|
return; // We'll deal with it later.
|
||||||
VelocityPlayerUtils.createPlayer(playerProxied, unifiedJedis, false);
|
VelocityPlayerUtils.createVelocityPlayer(playerProxied, unifiedJedis, false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
integrityCheck = getProxy().getScheduler().buildTask(this, integrityCheckTask::execute).repeat(30, TimeUnit.SECONDS).schedule();
|
integrityCheck = getProxy().getScheduler().buildTask(this, integrityCheckTask::execute).repeat(30, TimeUnit.SECONDS).schedule();
|
||||||
|
@ -10,31 +10,22 @@
|
|||||||
|
|
||||||
package com.imaginarycode.minecraft.redisbungee;
|
package com.imaginarycode.minecraft.redisbungee;
|
||||||
|
|
||||||
|
import com.imaginarycode.minecraft.redisbungee.api.util.player.PlayerUtils;
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
import com.velocitypowered.api.proxy.ServerConnection;
|
import com.velocitypowered.api.proxy.ServerConnection;
|
||||||
import redis.clients.jedis.UnifiedJedis;
|
import redis.clients.jedis.UnifiedJedis;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import static com.imaginarycode.minecraft.redisbungee.api.util.payload.PayloadUtils.playerJoinPayload;
|
|
||||||
|
|
||||||
public class VelocityPlayerUtils {
|
public class VelocityPlayerUtils {
|
||||||
protected static void createPlayer(Player player, UnifiedJedis unifiedJedis, boolean fireEvent) {
|
protected static void createVelocityPlayer(Player player, UnifiedJedis unifiedJedis, boolean fireEvent) {
|
||||||
Optional<ServerConnection> server = player.getCurrentServer();
|
Optional<ServerConnection> optionalServerConnection = player.getCurrentServer();
|
||||||
server.ifPresent(serverConnection -> unifiedJedis.hset("player:" + player.getUniqueId().toString(), "server", serverConnection.getServerInfo().getName()));
|
String serverName = null;
|
||||||
|
if (optionalServerConnection.isPresent()) {
|
||||||
Map<String, String> playerData = new HashMap<>(4);
|
serverName = optionalServerConnection.get().getServerInfo().getName();
|
||||||
playerData.put("online", "0");
|
|
||||||
playerData.put("ip", player.getRemoteAddress().getHostName());
|
|
||||||
playerData.put("proxy", AbstractRedisBungeeAPI.getAbstractRedisBungeeAPI().getProxyId());
|
|
||||||
|
|
||||||
unifiedJedis.sadd("proxy:" + AbstractRedisBungeeAPI.getAbstractRedisBungeeAPI().getProxyId() + ":usersOnline", player.getUniqueId().toString());
|
|
||||||
unifiedJedis.hmset("player:" + player.getUniqueId().toString(), playerData);
|
|
||||||
|
|
||||||
if (fireEvent) {
|
|
||||||
playerJoinPayload(player.getUniqueId(), unifiedJedis, player.getRemoteAddress().getAddress());
|
|
||||||
}
|
}
|
||||||
|
PlayerUtils.createPlayer(player.getUniqueId(), unifiedJedis, serverName, player.getRemoteAddress().getAddress(), fireEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user