mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2024-11-23 04:28:01 +00:00
Removed efficient per-server list fetching. It had too many issues. It will be readded when it can be fixed.
This commit is contained in:
parent
e3f84c7536
commit
ad67e1c60c
@ -117,8 +117,10 @@ public final class RedisBungee extends Plugin {
|
|||||||
|
|
||||||
final Multimap<String, UUID> serversToPlayers() {
|
final Multimap<String, UUID> serversToPlayers() {
|
||||||
ImmutableMultimap.Builder<String, UUID> multimapBuilder = ImmutableMultimap.builder();
|
ImmutableMultimap.Builder<String, UUID> multimapBuilder = ImmutableMultimap.builder();
|
||||||
for (ServerInfo info : getProxy().getServers().values()) {
|
for (UUID p : getPlayers()) {
|
||||||
multimapBuilder.putAll(info.getName(), getPlayersOnServer(info.getName()));
|
String name = dataManager.getServer(p);
|
||||||
|
if (name != null)
|
||||||
|
multimapBuilder.put(name, p);
|
||||||
}
|
}
|
||||||
return multimapBuilder.build();
|
return multimapBuilder.build();
|
||||||
}
|
}
|
||||||
@ -194,29 +196,8 @@ public final class RedisBungee extends Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final Set<UUID> getPlayersOnServer(@NonNull String server) {
|
final Set<UUID> getPlayersOnServer(@NonNull String server) {
|
||||||
ServerInfo info = getProxy().getServerInfo(server);
|
checkArgument(getProxy().getServers().containsKey(server), "server does not exist");
|
||||||
checkArgument(info != null, "server doesn't exist");
|
return ImmutableSet.copyOf(serversToPlayers().get(server));
|
||||||
|
|
||||||
ImmutableSet.Builder<UUID> setBuilder = ImmutableSet.builder();
|
|
||||||
|
|
||||||
Jedis jedis = pool.getResource();
|
|
||||||
try {
|
|
||||||
for (String s : jedis.smembers("server:" + server + ":players")) {
|
|
||||||
try {
|
|
||||||
setBuilder.add(UUID.fromString(s));
|
|
||||||
} catch (IllegalArgumentException ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (JedisConnectionException e) {
|
|
||||||
// Redis server has disappeared!
|
|
||||||
getLogger().log(Level.SEVERE, "Unable to get connection from pool - did your Redis server go away?", e);
|
|
||||||
pool.returnBrokenResource(jedis);
|
|
||||||
throw new RuntimeException("Unable to publish command", e);
|
|
||||||
} finally {
|
|
||||||
pool.returnResource(jedis);
|
|
||||||
}
|
|
||||||
|
|
||||||
return setBuilder.build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final void sendProxyCommand(@NonNull String proxyId, @NonNull String command) {
|
final void sendProxyCommand(@NonNull String proxyId, @NonNull String command) {
|
||||||
|
@ -59,10 +59,6 @@ public class RedisBungeeConsumer implements Runnable {
|
|||||||
PlayerLoggedOffConsumerEvent event1 = (PlayerLoggedOffConsumerEvent) event;
|
PlayerLoggedOffConsumerEvent event1 = (PlayerLoggedOffConsumerEvent) event;
|
||||||
Pipeline pipeline = jedis.pipelined();
|
Pipeline pipeline = jedis.pipelined();
|
||||||
jedis.hset("player:" + event1.getPlayer().getUniqueId().toString(), "online", String.valueOf(System.currentTimeMillis()));
|
jedis.hset("player:" + event1.getPlayer().getUniqueId().toString(), "online", String.valueOf(System.currentTimeMillis()));
|
||||||
|
|
||||||
if (event1.getPlayer().getServer() != null)
|
|
||||||
pipeline.srem("server:" + event1.getPlayer().getServer().getInfo().getName() + ":players", event1.getPlayer().getUniqueId().toString());
|
|
||||||
|
|
||||||
RedisUtil.cleanUpPlayer(event1.getPlayer().getUniqueId().toString(), pipeline);
|
RedisUtil.cleanUpPlayer(event1.getPlayer().getUniqueId().toString(), pipeline);
|
||||||
pipeline.publish("redisbungee-data", RedisBungee.getGson().toJson(new DataManager.DataManagerMessage(event1.getPlayer().getUniqueId(), DataManager.DataManagerMessage.Action.LEAVE)));
|
pipeline.publish("redisbungee-data", RedisBungee.getGson().toJson(new DataManager.DataManagerMessage(event1.getPlayer().getUniqueId(), DataManager.DataManagerMessage.Action.LEAVE)));
|
||||||
pipeline.sync();
|
pipeline.sync();
|
||||||
@ -70,11 +66,6 @@ public class RedisBungeeConsumer implements Runnable {
|
|||||||
PlayerChangedServerConsumerEvent event1 = (PlayerChangedServerConsumerEvent) event;
|
PlayerChangedServerConsumerEvent event1 = (PlayerChangedServerConsumerEvent) event;
|
||||||
Pipeline pipeline = jedis.pipelined();
|
Pipeline pipeline = jedis.pipelined();
|
||||||
pipeline.hset("player:" + event1.getPlayer().getUniqueId().toString(), "server", event1.getNewServer().getName());
|
pipeline.hset("player:" + event1.getPlayer().getUniqueId().toString(), "server", event1.getNewServer().getName());
|
||||||
|
|
||||||
if (event1.getOldServer() != null)
|
|
||||||
pipeline.srem("server:" + event1.getOldServer().getName() + ":players", event1.getPlayer().getUniqueId().toString());
|
|
||||||
|
|
||||||
pipeline.sadd("server:" + event1.getNewServer().getName() + ":players", event1.getPlayer().getUniqueId().toString());
|
|
||||||
pipeline.publish("redisbungee-data", RedisBungee.getGson().toJson(new DataManager.DataManagerMessage(event1.getPlayer().getUniqueId(), DataManager.DataManagerMessage.Action.SERVER_CHANGE)));
|
pipeline.publish("redisbungee-data", RedisBungee.getGson().toJson(new DataManager.DataManagerMessage(event1.getPlayer().getUniqueId(), DataManager.DataManagerMessage.Action.SERVER_CHANGE)));
|
||||||
pipeline.sync();
|
pipeline.sync();
|
||||||
}
|
}
|
||||||
|
@ -11,13 +11,7 @@ import redis.clients.jedis.Pipeline;
|
|||||||
|
|
||||||
class RedisUtil {
|
class RedisUtil {
|
||||||
public static void cleanUpPlayer(String player, Jedis rsc) {
|
public static void cleanUpPlayer(String player, Jedis rsc) {
|
||||||
String server = rsc.hget("player:" + player, "server");
|
|
||||||
|
|
||||||
Pipeline pipeline = rsc.pipelined();
|
Pipeline pipeline = rsc.pipelined();
|
||||||
|
|
||||||
if (server != null)
|
|
||||||
pipeline.srem("server:" + server + ":players", player);
|
|
||||||
|
|
||||||
cleanUpPlayer(player, pipeline);
|
cleanUpPlayer(player, pipeline);
|
||||||
pipeline.sync();
|
pipeline.sync();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user