From 8797a29761d6f243039143c78213a80f798f85ad Mon Sep 17 00:00:00 2001 From: md_5 Date: Thu, 24 Jan 2013 14:13:27 +1100 Subject: [PATCH] Add getServerInfo(name) and rework plugin channel system for stupud Bukkit limitations. --- .../java/net/md_5/bungee/api/ProxyServer.java | 8 +++ .../main/java/net/md_5/bungee/BungeeCord.java | 10 ++- .../java/net/md_5/bungee/UserConnection.java | 64 +++++++++++-------- 3 files changed, 52 insertions(+), 30 deletions(-) diff --git a/api/src/main/java/net/md_5/bungee/api/ProxyServer.java b/api/src/main/java/net/md_5/bungee/api/ProxyServer.java index 1d4522c6..6530ba43 100644 --- a/api/src/main/java/net/md_5/bungee/api/ProxyServer.java +++ b/api/src/main/java/net/md_5/bungee/api/ProxyServer.java @@ -87,6 +87,14 @@ public abstract class ProxyServer */ public abstract Map getServers(); + /** + * Gets the server info of a server. + * + * @param name the name of the configured server + * @return the server info belonging to the specified server + */ + public abstract ServerInfo getServerInfo(String name); + /** * Get the {@link PluginManager} associated with loading plugins and * dispatching events. It is recommended that implementations use the diff --git a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java index 2add6029..8966a9fd 100644 --- a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java +++ b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java @@ -105,9 +105,7 @@ public class BungeeCord extends ProxyServer getPluginManager().registerCommand(new CommandAlert()); getPluginManager().registerCommand(new CommandBungee()); - registerChannel("BungeeCord::Disconnect"); - registerChannel("BungeeCord::Connect"); - registerChannel("BungeeCord::Forward"); + registerChannel("BungeeCord"); } public static BungeeCord getInstance() @@ -291,6 +289,12 @@ public class BungeeCord extends ProxyServer return config.getServers(); } + @Override + public ServerInfo getServerInfo(String name) + { + return getServers().get(name); + } + @Override @Synchronized("pluginChannels") public void registerChannel(String channel) diff --git a/proxy/src/main/java/net/md_5/bungee/UserConnection.java b/proxy/src/main/java/net/md_5/bungee/UserConnection.java index c17447d6..aaefdc23 100644 --- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java @@ -282,6 +282,13 @@ public class UserConnection extends GenericConnection implements ProxiedPlayer case 0xFA: // Call the onPluginMessage event PacketFAPluginMessage message = new PacketFAPluginMessage(packet); + + // Might matter in the future + if (message.tag.equals("BungeeCord")) + { + continue; + } + PluginMessageEvent event = new PluginMessageEvent(UserConnection.this, server, message.tag, message.data); ProxyServer.getInstance().getPluginManager().callEvent(event); @@ -371,39 +378,42 @@ public class UserConnection extends GenericConnection implements ProxiedPlayer continue; } - switch (message.tag) + if (message.tag.equals("BungeeCord")) { - case "BungeeCord::Disconnect": - break outer; - case "BungeeCord::Forward": - String target = in.readUTF(); - String channel = in.readUTF(); - short len = in.readShort(); - byte[] data = new byte[len]; - in.readFully(data); + switch (in.readUTF()) + { + case "Disconnect": + break outer; + case "Forward": + String target = in.readUTF(); + String channel = in.readUTF(); + short len = in.readShort(); + byte[] data = new byte[len]; + in.readFully(data); - if (target.equals("ALL")) - { - for (String s : BungeeCord.getInstance().getServers().keySet()) + if (target.equals("ALL")) { - Server server = BungeeCord.getInstance().getServer(s); + for (String s : BungeeCord.getInstance().getServers().keySet()) + { + Server server = BungeeCord.getInstance().getServer(s); + server.sendData(channel, data); + } + } else + { + Server server = BungeeCord.getInstance().getServer(target); server.sendData(channel, data); } - } else - { - Server server = BungeeCord.getInstance().getServer(target); - server.sendData(channel, data); - } - break; - case "BungeeCord::Connect": - ServerInfo server = BungeeCord.getInstance().config.getServers().get(in.readUTF()); - if (server != null) - { - connect(server); - break outer; - } - break; + break; + case "Connect": + ServerInfo server = BungeeCord.getInstance().config.getServers().get(in.readUTF()); + if (server != null) + { + connect(server); + break outer; + } + break; + } } }