Add player disconnect event, thanks @lazertester
This commit is contained in:
parent
d2a919fc06
commit
379376f0fa
@ -11,8 +11,8 @@ import net.md_5.bungee.api.plugin.Event;
|
|||||||
* Event called to represent a player logging in.
|
* Event called to represent a player logging in.
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@ToString(callSuper = true)
|
@ToString(callSuper = false)
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
public class LoginEvent extends Event implements Cancellable
|
public class LoginEvent extends Event implements Cancellable
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
package net.md_5.bungee.api.event;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.ToString;
|
||||||
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
import net.md_5.bungee.api.plugin.Event;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a player has left the proxy, it is not safe to call any methods
|
||||||
|
* that perform an action on the passed player instance.
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@ToString(callSuper = false)
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
public class PlayerDisconnectEvent extends Event
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Player disconnecting.
|
||||||
|
*/
|
||||||
|
private final ProxiedPlayer player;
|
||||||
|
}
|
@ -13,8 +13,8 @@ import net.md_5.bungee.api.plugin.Event;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@ToString(callSuper = true)
|
@ToString(callSuper = false)
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
public class ProxyPingEvent extends Event
|
public class ProxyPingEvent extends Event
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -10,8 +10,8 @@ import net.md_5.bungee.api.plugin.Event;
|
|||||||
|
|
||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@ToString(callSuper = true)
|
@ToString(callSuper = false)
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
public class ServerConnectEvent extends Event
|
public class ServerConnectEvent extends Event
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -14,8 +14,8 @@ import net.md_5.bungee.api.plugin.Event;
|
|||||||
* information to the server before the player logs in.
|
* information to the server before the player logs in.
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@ToString(callSuper = true)
|
@ToString(callSuper = false)
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
public class ServerConnectedEvent extends Event
|
public class ServerConnectedEvent extends Event
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ import net.md_5.bungee.api.config.ServerInfo;
|
|||||||
import net.md_5.bungee.api.connection.PendingConnection;
|
import net.md_5.bungee.api.connection.PendingConnection;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
import net.md_5.bungee.api.event.ChatEvent;
|
import net.md_5.bungee.api.event.ChatEvent;
|
||||||
|
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
|
||||||
import net.md_5.bungee.api.event.PluginMessageEvent;
|
import net.md_5.bungee.api.event.PluginMessageEvent;
|
||||||
import net.md_5.bungee.api.event.ServerConnectEvent;
|
import net.md_5.bungee.api.event.ServerConnectEvent;
|
||||||
import net.md_5.bungee.packet.*;
|
import net.md_5.bungee.packet.*;
|
||||||
@ -51,6 +52,7 @@ public class UserConnection extends GenericConnection implements ProxiedPlayer
|
|||||||
private final Object permMutex = new Object();
|
private final Object permMutex = new Object();
|
||||||
// Hack for connect timings
|
// Hack for connect timings
|
||||||
private ServerInfo nextServer;
|
private ServerInfo nextServer;
|
||||||
|
private volatile boolean clientConnected = true;
|
||||||
|
|
||||||
public UserConnection(Socket socket, PendingConnection pendingConnection, PacketStream stream, Packet2Handshake handshake)
|
public UserConnection(Socket socket, PendingConnection pendingConnection, PacketStream stream, Packet2Handshake handshake)
|
||||||
{
|
{
|
||||||
@ -155,8 +157,12 @@ public class UserConnection extends GenericConnection implements ProxiedPlayer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void destroySelf(String reason)
|
private synchronized void destroySelf(String reason)
|
||||||
{
|
{
|
||||||
|
if ( clientConnected )
|
||||||
|
{
|
||||||
|
PlayerDisconnectEvent event = new PlayerDisconnectEvent( this );
|
||||||
|
ProxyServer.getInstance().getPluginManager().callEvent( event );
|
||||||
ProxyServer.getInstance().getPlayers().remove( this );
|
ProxyServer.getInstance().getPlayers().remove( this );
|
||||||
|
|
||||||
disconnect( reason );
|
disconnect( reason );
|
||||||
@ -166,6 +172,9 @@ public class UserConnection extends GenericConnection implements ProxiedPlayer
|
|||||||
server.disconnect( "Quitting" );
|
server.disconnect( "Quitting" );
|
||||||
ProxyServer.getInstance().getReconnectHandler().setServer( this );
|
ProxyServer.getInstance().getReconnectHandler().setServer( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clientConnected = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user