From 807e71e5664c06d113eefd59d4da7fee2677c203 Mon Sep 17 00:00:00 2001 From: Tux Date: Wed, 22 Apr 2015 18:34:23 -0400 Subject: [PATCH] Allow specifying ServerPlayers PLAYERS to get players and default to just count. --- .../minecraft/redisbungee/RedisBungeeListener.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeListener.java b/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeListener.java index 9c2145e..7d6ac8e 100644 --- a/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeListener.java +++ b/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeListener.java @@ -176,13 +176,17 @@ public class RedisBungeeListener implements Listener { out.writeLong(RedisBungee.getApi().getLastOnline(plugin.getUuidTranslator().getTranslatedUuid(user, true))); break; case "ServerPlayers": + String type1 = "COUNT"; + try { + type1 = in.readUTF(); + } catch (Exception e) {} 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); + serializeMultimap(human, type1.equals("PLAYERS"), out); break; case "Proxy": out.writeUTF("Proxy"); @@ -198,11 +202,15 @@ public class RedisBungeeListener implements Listener { } } - private void serializeMultimap(Multimap collection, ByteArrayDataOutput output) { + private void serializeMultimap(Multimap collection, boolean includeNames, ByteArrayDataOutput output) { output.writeInt(collection.size()); for (Map.Entry> entry : collection.asMap().entrySet()) { output.writeUTF(entry.getKey()); - serializeCollection(entry.getValue(), output); + if (includeNames) { + serializeCollection(entry.getValue(), output); + } else { + output.writeInt(entry.getValue().size()); + } } }