Add ability to block a server change and send a message on change

This commit is contained in:
mbax 2012-11-02 01:45:14 -04:00
parent cd95befbea
commit 71ab7f7c45
2 changed files with 24 additions and 1 deletions

View File

@ -40,9 +40,23 @@ public class UserConnection extends GenericConnection implements CommandSender
public void connect(String server) public void connect(String server)
{ {
ServerConnectEvent event = new ServerConnectEvent(this, server); ServerConnectEvent event = new ServerConnectEvent(this.server == null, this, server);
event.setNewServer(server); event.setNewServer(server);
BungeeCord.instance.pluginManager.onServerConnect(event); BungeeCord.instance.pluginManager.onServerConnect(event);
if (event.getMessage() != null)
{
this.sendMessage(event.getMessage());
}
if (event.getNewServer() == null)
{
if (event.isFirstTime())
{
event.setNewServer(BungeeCord.instance.config.defaultServerName);
} else
{
return;
}
}
InetSocketAddress addr = BungeeCord.instance.config.getServer(event.getNewServer()); InetSocketAddress addr = BungeeCord.instance.config.getServer(event.getNewServer());
connect(server, addr); connect(server, addr);
} }

View File

@ -10,6 +10,15 @@ import net.md_5.bungee.UserConnection;
public class ServerConnectEvent public class ServerConnectEvent
{ {
/**
* If the player currently has no server, this is true
*/
private final boolean firstTime;
/**
* Message to send just before the change.
* null for no message
*/
private String message;
/** /**
* User in question. * User in question.
*/ */