From a48ef137bd62a4849c00a3d48f3a992a891a1668 Mon Sep 17 00:00:00 2001 From: md_5 Date: Wed, 15 May 2013 19:04:22 +1000 Subject: [PATCH] Make connect event implement cancellable, closes #338 --- .../md_5/bungee/api/event/ServerConnectEvent.java | 14 ++++++++++++-- .../main/java/net/md_5/bungee/UserConnection.java | 5 ++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/api/src/main/java/net/md_5/bungee/api/event/ServerConnectEvent.java b/api/src/main/java/net/md_5/bungee/api/event/ServerConnectEvent.java index 8a7b8cfe..b075e59c 100644 --- a/api/src/main/java/net/md_5/bungee/api/event/ServerConnectEvent.java +++ b/api/src/main/java/net/md_5/bungee/api/event/ServerConnectEvent.java @@ -6,13 +6,13 @@ import lombok.EqualsAndHashCode; import lombok.ToString; import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.md_5.bungee.api.plugin.Cancellable; import net.md_5.bungee.api.plugin.Event; @Data -@AllArgsConstructor @ToString(callSuper = false) @EqualsAndHashCode(callSuper = false) -public class ServerConnectEvent extends Event +public class ServerConnectEvent extends Event implements Cancellable { /** @@ -23,4 +23,14 @@ public class ServerConnectEvent extends Event * Server the player will be connected to. */ private ServerInfo target; + /** + * Cancelled state. + */ + private boolean cancelled; + + public ServerConnectEvent(ProxiedPlayer player, ServerInfo target) + { + this.player = player; + this.target = target; + } } diff --git a/proxy/src/main/java/net/md_5/bungee/UserConnection.java b/proxy/src/main/java/net/md_5/bungee/UserConnection.java index 98d00eca..dd015166 100644 --- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java @@ -143,7 +143,10 @@ public final class UserConnection implements ProxiedPlayer public void connect(ServerInfo info, final boolean retry) { ServerConnectEvent event = new ServerConnectEvent( this, info ); - ProxyServer.getInstance().getPluginManager().callEvent( event ); + if ( bungee.getPluginManager().callEvent( event ).isCancelled() ) + { + return; + } Preconditions.checkArgument( event.getTarget() instanceof BungeeServerInfo, "BungeeCord can only connect to BungeeServerInfo instances" ); final BungeeServerInfo target = (BungeeServerInfo) event.getTarget(); // Update in case the event changed target