Make connect event implement cancellable, closes #338
This commit is contained in:
parent
ff32d29e09
commit
a48ef137bd
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user