From a372720e5030bde7968810d6593f59cdb7b20fa2 Mon Sep 17 00:00:00 2001 From: Tux Date: Wed, 22 Apr 2015 18:30:04 -0400 Subject: [PATCH] Add batch server<->player mapping and current proxy plugin messages. --- .../redisbungee/RedisBungeeListener.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) 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())) {