From 71ab7f7c45515c24d8158d81ddbb535083be47bb Mon Sep 17 00:00:00 2001 From: mbax Date: Fri, 2 Nov 2012 01:45:14 -0400 Subject: [PATCH] Add ability to block a server change and send a message on change --- .../java/net/md_5/bungee/UserConnection.java | 16 +++++++++++++++- .../md_5/bungee/plugin/ServerConnectEvent.java | 9 +++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/md_5/bungee/UserConnection.java b/src/main/java/net/md_5/bungee/UserConnection.java index df7b4abf..95495042 100644 --- a/src/main/java/net/md_5/bungee/UserConnection.java +++ b/src/main/java/net/md_5/bungee/UserConnection.java @@ -40,9 +40,23 @@ public class UserConnection extends GenericConnection implements CommandSender public void connect(String server) { - ServerConnectEvent event = new ServerConnectEvent(this, server); + ServerConnectEvent event = new ServerConnectEvent(this.server == null, this, server); event.setNewServer(server); 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()); connect(server, addr); } diff --git a/src/main/java/net/md_5/bungee/plugin/ServerConnectEvent.java b/src/main/java/net/md_5/bungee/plugin/ServerConnectEvent.java index 009120ff..7b6a7784 100644 --- a/src/main/java/net/md_5/bungee/plugin/ServerConnectEvent.java +++ b/src/main/java/net/md_5/bungee/plugin/ServerConnectEvent.java @@ -10,6 +10,15 @@ import net.md_5.bungee.UserConnection; 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. */