Make connect event implement cancellable, closes #338

This commit is contained in:
md_5 2013-05-15 19:04:22 +10:00
parent ff32d29e09
commit a48ef137bd
2 changed files with 16 additions and 3 deletions

View File

@ -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;
}
}

View File

@ -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