2
0
mirror of https://github.com/proxiodev/RedisBungee.git synced 2024-11-22 20:28:00 +00:00

Allow specifying ServerPlayers PLAYERS to get players and default to just count.

This commit is contained in:
Tux 2015-04-22 18:34:23 -04:00
parent a372720e50
commit 807e71e566

View File

@ -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<String, UUID> multimap = RedisBungee.getApi().getServerToPlayers();
Multimap<String, String> human = HashMultimap.create();
for (Map.Entry<String, UUID> 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<String, String> collection, ByteArrayDataOutput output) {
private void serializeMultimap(Multimap<String, String> collection, boolean includeNames, ByteArrayDataOutput output) {
output.writeInt(collection.size());
for (Map.Entry<String, Collection<String>> entry : collection.asMap().entrySet()) {
output.writeUTF(entry.getKey());
serializeCollection(entry.getValue(), output);
if (includeNames) {
serializeCollection(entry.getValue(), output);
} else {
output.writeInt(entry.getValue().size());
}
}
}