diff --git a/src/main/java/net/md_5/bungee/UserConnection.java b/src/main/java/net/md_5/bungee/UserConnection.java index 5eb58e6b..df7b4abf 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 16fcf368..a14656c3 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 a8192405..5cd6afb3 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 00000000..009120ff --- /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; +}