From 6f005064a1949b84efd102a739229801d6f9ae91 Mon Sep 17 00:00:00 2001 From: md_5 Date: Fri, 2 Nov 2012 09:19:55 +1100 Subject: [PATCH] Add new event for @mbax --- .../java/net/md_5/bungee/UserConnection.java | 6 ++++- .../net/md_5/bungee/plugin/JavaPlugin.java | 7 ++++++ .../md_5/bungee/plugin/JavaPluginManager.java | 9 +++++++ .../bungee/plugin/ServerConnectEvent.java | 25 +++++++++++++++++++ 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 src/main/java/net/md_5/bungee/plugin/ServerConnectEvent.java diff --git a/src/main/java/net/md_5/bungee/UserConnection.java b/src/main/java/net/md_5/bungee/UserConnection.java index 5eb58e6b8..df7b4abfe 100644 --- a/src/main/java/net/md_5/bungee/UserConnection.java +++ b/src/main/java/net/md_5/bungee/UserConnection.java @@ -15,6 +15,7 @@ import net.md_5.bungee.packet.Packet3Chat; import net.md_5.bungee.packet.Packet9Respawn; import net.md_5.bungee.packet.PacketFAPluginMessage; import net.md_5.bungee.packet.PacketInputStream; +import net.md_5.bungee.plugin.ServerConnectEvent; public class UserConnection extends GenericConnection implements CommandSender { @@ -39,7 +40,10 @@ public class UserConnection extends GenericConnection implements CommandSender public void connect(String server) { - InetSocketAddress addr = BungeeCord.instance.config.getServer(server); + ServerConnectEvent event = new ServerConnectEvent(this, server); + event.setNewServer(server); + BungeeCord.instance.pluginManager.onServerConnect(event); + InetSocketAddress addr = BungeeCord.instance.config.getServer(event.getNewServer()); connect(server, addr); } diff --git a/src/main/java/net/md_5/bungee/plugin/JavaPlugin.java b/src/main/java/net/md_5/bungee/plugin/JavaPlugin.java index 16fcf368e..a14656c3e 100644 --- a/src/main/java/net/md_5/bungee/plugin/JavaPlugin.java +++ b/src/main/java/net/md_5/bungee/plugin/JavaPlugin.java @@ -44,6 +44,13 @@ public abstract class JavaPlugin { } + /** + * Called when a user is connecting to a new server. + */ + public void onServerConnect(ServerConnectEvent event) + { + } + /** * Register a command for use with the proxy. */ diff --git a/src/main/java/net/md_5/bungee/plugin/JavaPluginManager.java b/src/main/java/net/md_5/bungee/plugin/JavaPluginManager.java index a8192405b..5cd6afb3e 100644 --- a/src/main/java/net/md_5/bungee/plugin/JavaPluginManager.java +++ b/src/main/java/net/md_5/bungee/plugin/JavaPluginManager.java @@ -97,4 +97,13 @@ public class JavaPluginManager extends JavaPlugin p.onLogin(event); } } + + @Override + public void onServerConnect(ServerConnectEvent event) + { + for (JavaPlugin p : plugins) + { + p.onServerConnect(event); + } + } } diff --git a/src/main/java/net/md_5/bungee/plugin/ServerConnectEvent.java b/src/main/java/net/md_5/bungee/plugin/ServerConnectEvent.java new file mode 100644 index 000000000..009120ffc --- /dev/null +++ b/src/main/java/net/md_5/bungee/plugin/ServerConnectEvent.java @@ -0,0 +1,25 @@ +package net.md_5.bungee.plugin; + +import lombok.Data; +import net.md_5.bungee.UserConnection; + +/** + * Event called when the decision is made to decide which server to connect to. + */ +@Data +public class ServerConnectEvent +{ + + /** + * User in question. + */ + private final UserConnection connection; + /** + * Name of the server they are connecting to. + */ + private final String server; + /** + * Name of the server which they will be forwarded to instead. + */ + private String newServer; +}