2
0
mirror of https://github.com/proxiodev/RedisBungee.git synced 2024-12-23 18:48:02 +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:
Tux 2014-08-10 17:58:45 -04:00
parent e3f84c7536
commit ad67e1c60c
3 changed files with 6 additions and 40 deletions

View File

@ -117,8 +117,10 @@ public final class RedisBungee extends Plugin {
final Multimap<String, UUID> serversToPlayers() {
ImmutableMultimap.Builder<String, UUID> multimapBuilder = ImmutableMultimap.builder();
for (ServerInfo info : getProxy().getServers().values()) {
multimapBuilder.putAll(info.getName(), getPlayersOnServer(info.getName()));
for (UUID p : getPlayers()) {
String name = dataManager.getServer(p);
if (name != null)
multimapBuilder.put(name, p);
}
return multimapBuilder.build();
}
@ -194,29 +196,8 @@ public final class RedisBungee extends Plugin {
}
final Set<UUID> getPlayersOnServer(@NonNull String server) {
ServerInfo info = getProxy().getServerInfo(server);
checkArgument(info != null, "server doesn't exist");
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();
checkArgument(getProxy().getServers().containsKey(server), "server does not exist");
return ImmutableSet.copyOf(serversToPlayers().get(server));
}
final void sendProxyCommand(@NonNull String proxyId, @NonNull String command) {

View File

@ -59,10 +59,6 @@ public class RedisBungeeConsumer implements Runnable {
PlayerLoggedOffConsumerEvent event1 = (PlayerLoggedOffConsumerEvent) event;
Pipeline pipeline = jedis.pipelined();
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);
pipeline.publish("redisbungee-data", RedisBungee.getGson().toJson(new DataManager.DataManagerMessage(event1.getPlayer().getUniqueId(), DataManager.DataManagerMessage.Action.LEAVE)));
pipeline.sync();
@ -70,11 +66,6 @@ public class RedisBungeeConsumer implements Runnable {
PlayerChangedServerConsumerEvent event1 = (PlayerChangedServerConsumerEvent) event;
Pipeline pipeline = jedis.pipelined();
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.sync();
}

View File

@ -11,13 +11,7 @@ import redis.clients.jedis.Pipeline;
class RedisUtil {
public static void cleanUpPlayer(String player, Jedis rsc) {
String server = rsc.hget("player:" + player, "server");
Pipeline pipeline = rsc.pipelined();
if (server != null)
pipeline.srem("server:" + server + ":players", player);
cleanUpPlayer(player, pipeline);
pipeline.sync();
}