Add getServerInfo(name) and rework plugin channel system for stupud Bukkit limitations.

This commit is contained in:
md_5 2013-01-24 14:13:27 +11:00
parent 8f32374cda
commit 8797a29761
3 changed files with 52 additions and 30 deletions

View File

@ -87,6 +87,14 @@ public abstract class ProxyServer
*/ */
public abstract Map<String, ServerInfo> getServers(); public abstract Map<String, ServerInfo> 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 * Get the {@link PluginManager} associated with loading plugins and
* dispatching events. It is recommended that implementations use the * dispatching events. It is recommended that implementations use the

View File

@ -105,9 +105,7 @@ public class BungeeCord extends ProxyServer
getPluginManager().registerCommand(new CommandAlert()); getPluginManager().registerCommand(new CommandAlert());
getPluginManager().registerCommand(new CommandBungee()); getPluginManager().registerCommand(new CommandBungee());
registerChannel("BungeeCord::Disconnect"); registerChannel("BungeeCord");
registerChannel("BungeeCord::Connect");
registerChannel("BungeeCord::Forward");
} }
public static BungeeCord getInstance() public static BungeeCord getInstance()
@ -291,6 +289,12 @@ public class BungeeCord extends ProxyServer
return config.getServers(); return config.getServers();
} }
@Override
public ServerInfo getServerInfo(String name)
{
return getServers().get(name);
}
@Override @Override
@Synchronized("pluginChannels") @Synchronized("pluginChannels")
public void registerChannel(String channel) public void registerChannel(String channel)

View File

@ -282,6 +282,13 @@ public class UserConnection extends GenericConnection implements ProxiedPlayer
case 0xFA: case 0xFA:
// Call the onPluginMessage event // Call the onPluginMessage event
PacketFAPluginMessage message = new PacketFAPluginMessage(packet); 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); PluginMessageEvent event = new PluginMessageEvent(UserConnection.this, server, message.tag, message.data);
ProxyServer.getInstance().getPluginManager().callEvent(event); ProxyServer.getInstance().getPluginManager().callEvent(event);
@ -371,39 +378,42 @@ public class UserConnection extends GenericConnection implements ProxiedPlayer
continue; continue;
} }
switch (message.tag) if (message.tag.equals("BungeeCord"))
{ {
case "BungeeCord::Disconnect": switch (in.readUTF())
break outer; {
case "BungeeCord::Forward": case "Disconnect":
String target = in.readUTF(); break outer;
String channel = in.readUTF(); case "Forward":
short len = in.readShort(); String target = in.readUTF();
byte[] data = new byte[len]; String channel = in.readUTF();
in.readFully(data); short len = in.readShort();
byte[] data = new byte[len];
in.readFully(data);
if (target.equals("ALL")) if (target.equals("ALL"))
{
for (String s : BungeeCord.getInstance().getServers().keySet())
{ {
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); server.sendData(channel, data);
} }
} else
{
Server server = BungeeCord.getInstance().getServer(target);
server.sendData(channel, data);
}
break; break;
case "BungeeCord::Connect": case "Connect":
ServerInfo server = BungeeCord.getInstance().config.getServers().get(in.readUTF()); ServerInfo server = BungeeCord.getInstance().config.getServers().get(in.readUTF());
if (server != null) if (server != null)
{ {
connect(server); connect(server);
break outer; break outer;
} }
break; break;
}
} }
} }