diff --git a/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeListener.java b/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeListener.java index 9962b94..9c2145e 100644 --- a/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeListener.java +++ b/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeListener.java @@ -7,6 +7,8 @@ package com.imaginarycode.minecraft.redisbungee; import com.google.common.base.Joiner; +import com.google.common.collect.HashMultimap; +import com.google.common.collect.Multimap; import com.google.common.io.ByteArrayDataInput; import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteStreams; @@ -173,6 +175,19 @@ public class RedisBungeeListener implements Listener { out.writeUTF(user); out.writeLong(RedisBungee.getApi().getLastOnline(plugin.getUuidTranslator().getTranslatedUuid(user, true))); break; + case "ServerPlayers": + out.writeUTF("ServerPlayers"); + Multimap multimap = RedisBungee.getApi().getServerToPlayers(); + Multimap human = HashMultimap.create(); + for (Map.Entry entry : multimap.entries()) { + human.put(entry.getKey(), plugin.getUuidTranslator().getNameFromUuid(entry.getValue(), false)); + } + serializeMultimap(human, out); + break; + case "Proxy": + out.writeUTF("Proxy"); + out.writeUTF(RedisBungee.getConfiguration().getServerId()); + break; default: break; } @@ -183,6 +198,21 @@ public class RedisBungeeListener implements Listener { } } + private void serializeMultimap(Multimap collection, ByteArrayDataOutput output) { + output.writeInt(collection.size()); + for (Map.Entry> entry : collection.asMap().entrySet()) { + output.writeUTF(entry.getKey()); + serializeCollection(entry.getValue(), output); + } + } + + private void serializeCollection(Collection collection, ByteArrayDataOutput output) { + output.writeInt(collection.size()); + for (Object o : collection) { + output.writeUTF(o.toString()); + } + } + @EventHandler public void onPubSubMessage(PubSubMessageEvent event) { if (event.getChannel().equals("redisbungee-allservers") || event.getChannel().equals("redisbungee-" + RedisBungee.getApi().getServerId())) {