Add player disconnect event, thanks @lazertester

This commit is contained in:
md_5 2013-02-13 18:49:08 +11:00
parent d2a919fc06
commit 379376f0fa
6 changed files with 48 additions and 16 deletions

View File

@ -11,8 +11,8 @@ import net.md_5.bungee.api.plugin.Event;
* Event called to represent a player logging in.
*/
@Data
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = false)
@EqualsAndHashCode(callSuper = false)
public class LoginEvent extends Event implements Cancellable
{

View File

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

View File

@ -13,8 +13,8 @@ import net.md_5.bungee.api.plugin.Event;
*/
@Data
@AllArgsConstructor
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = false)
@EqualsAndHashCode(callSuper = false)
public class ProxyPingEvent extends Event
{

View File

@ -10,8 +10,8 @@ import net.md_5.bungee.api.plugin.Event;
@Data
@AllArgsConstructor
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = false)
@EqualsAndHashCode(callSuper = false)
public class ServerConnectEvent extends Event
{

View File

@ -14,8 +14,8 @@ import net.md_5.bungee.api.plugin.Event;
* information to the server before the player logs in.
*/
@Data
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = false)
@EqualsAndHashCode(callSuper = false)
public class ServerConnectedEvent extends Event
{

View File

@ -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.ProxiedPlayer;
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.ServerConnectEvent;
import net.md_5.bungee.packet.*;
@ -51,6 +52,7 @@ public class UserConnection extends GenericConnection implements ProxiedPlayer
private final Object permMutex = new Object();
// Hack for connect timings
private ServerInfo nextServer;
private volatile boolean clientConnected = true;
public UserConnection(Socket socket, PendingConnection pendingConnection, PacketStream stream, Packet2Handshake handshake)
{
@ -155,16 +157,23 @@ public class UserConnection extends GenericConnection implements ProxiedPlayer
}
}
private void destroySelf(String reason)
private synchronized void destroySelf(String reason)
{
ProxyServer.getInstance().getPlayers().remove( this );
disconnect( reason );
if ( server != null )
if ( clientConnected )
{
server.getInfo().removePlayer( this );
server.disconnect( "Quitting" );
ProxyServer.getInstance().getReconnectHandler().setServer( this );
PlayerDisconnectEvent event = new PlayerDisconnectEvent( this );
ProxyServer.getInstance().getPluginManager().callEvent( event );
ProxyServer.getInstance().getPlayers().remove( this );
disconnect( reason );
if ( server != null )
{
server.getInfo().removePlayer( this );
server.disconnect( "Quitting" );
ProxyServer.getInstance().getReconnectHandler().setServer( this );
}
clientConnected = false;
}
}