mirror of
https://github.com/SpigotMC/BungeeCord.git
synced 2024-12-25 18:17:38 +01:00
Add server kick event
This commit is contained in:
parent
ce40391717
commit
e681c8906d
@ -0,0 +1,43 @@
|
||||
package net.md_5.bungee.api.event;
|
||||
|
||||
import lombok.Data;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Represents a player getting kicked from a server.
|
||||
*/
|
||||
@Data
|
||||
@ToString(callSuper = false)
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class ServerKickEvent extends Event implements Cancellable
|
||||
{
|
||||
|
||||
/**
|
||||
* Cancelled status.
|
||||
*/
|
||||
private boolean cancelled;
|
||||
/**
|
||||
* Player being kicked.
|
||||
*/
|
||||
private final ProxiedPlayer player;
|
||||
/**
|
||||
* Kick reason.
|
||||
*/
|
||||
private String kickReason;
|
||||
/**
|
||||
* Server to send player to if this event is cancelled.
|
||||
*/
|
||||
private ServerInfo cancelServer;
|
||||
|
||||
public ServerKickEvent(ProxiedPlayer player, String kickReason, ServerInfo cancelServer)
|
||||
{
|
||||
this.player = player;
|
||||
this.kickReason = kickReason;
|
||||
this.cancelServer = cancelServer;
|
||||
}
|
||||
}
|
@ -101,6 +101,13 @@ public final class UserConnection implements ProxiedPlayer
|
||||
connect( target, false );
|
||||
}
|
||||
|
||||
public void connectNow(ServerInfo target)
|
||||
{
|
||||
ch.write( Packet9Respawn.DIM1_SWITCH );
|
||||
ch.write( Packet9Respawn.DIM2_SWITCH );
|
||||
connect( target );
|
||||
}
|
||||
|
||||
public void connect(ServerInfo info, final boolean retry)
|
||||
{
|
||||
ServerConnectEvent event = new ServerConnectEvent( this, info );
|
||||
|
@ -15,6 +15,7 @@ import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.event.ChatEvent;
|
||||
import net.md_5.bungee.api.event.PluginMessageEvent;
|
||||
import net.md_5.bungee.api.event.ServerKickEvent;
|
||||
import net.md_5.bungee.api.scoreboard.Objective;
|
||||
import net.md_5.bungee.api.scoreboard.Position;
|
||||
import net.md_5.bungee.api.scoreboard.Score;
|
||||
@ -44,9 +45,7 @@ public class DownstreamBridge extends PacketHandler
|
||||
ServerInfo def = bungee.getServerInfo( con.getPendingConnection().getListener().getDefaultServer() );
|
||||
if ( server.getInfo() != def )
|
||||
{
|
||||
con.ch.write( Packet9Respawn.DIM1_SWITCH );
|
||||
con.ch.write( Packet9Respawn.DIM2_SWITCH );
|
||||
con.connect( def );
|
||||
con.connectNow( def );
|
||||
con.sendMessage( ChatColor.RED + "The server you were previously on went down, you have been connected to the lobby" );
|
||||
} else
|
||||
{
|
||||
@ -276,7 +275,19 @@ public class DownstreamBridge extends PacketHandler
|
||||
@Override
|
||||
public void handle(PacketFFKick kick) throws Exception
|
||||
{
|
||||
con.disconnect( "[Kicked] " + kick.message );
|
||||
ServerInfo def = bungee.getServerInfo( con.getPendingConnection().getListener().getDefaultServer() );
|
||||
if ( server.getInfo() == def )
|
||||
{
|
||||
def = null;
|
||||
}
|
||||
ServerKickEvent event = bungee.getPluginManager().callEvent( new ServerKickEvent( con, kick.message, def ) );
|
||||
if ( event.isCancelled() && event.getCancelServer() != null )
|
||||
{
|
||||
con.connectNow( event.getCancelServer() );
|
||||
} else
|
||||
{
|
||||
con.disconnect( "[Kicked] " + event.getKickReason() );
|
||||
}
|
||||
throw new CancelSendSignal();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user