From fb0446f4fcf46112c7b7331a3813c791a38a137b Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Tue, 24 Dec 2019 23:56:39 -0500 Subject: [PATCH] Add DisconnectEvent#disconnectedDuringLogin() --- .../api/event/connection/DisconnectEvent.java | 14 +++++++++++++- .../proxy/connection/client/ConnectedPlayer.java | 4 +++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/com/velocitypowered/api/event/connection/DisconnectEvent.java b/api/src/main/java/com/velocitypowered/api/event/connection/DisconnectEvent.java index dee4dd7e0..2442077a8 100644 --- a/api/src/main/java/com/velocitypowered/api/event/connection/DisconnectEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/connection/DisconnectEvent.java @@ -10,19 +10,31 @@ import com.velocitypowered.api.proxy.Player; public final class DisconnectEvent { private final Player player; + private final boolean disconnectedDuringLogin; public DisconnectEvent(Player player) { + this(player, false); + } + + public DisconnectEvent(Player player, + boolean disconnectedDuringLogin) { this.player = Preconditions.checkNotNull(player, "player"); + this.disconnectedDuringLogin = disconnectedDuringLogin; } public Player getPlayer() { return player; } + public boolean disconnectedDuringLogin() { + return this.disconnectedDuringLogin; + } + @Override public String toString() { return "DisconnectEvent{" - + "player=" + player + + "player=" + player + ", " + + "disconnectedDuringLogin=" + disconnectedDuringLogin + '}'; } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java index d90fc2054..fd6b9d71c 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java @@ -571,8 +571,10 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { if (connectedServer != null) { connectedServer.disconnect(); } + boolean isConnected = server.getPlayer(this.getUniqueId()).isPresent(); + server.unregisterConnection(this); - server.getEventManager().fire(new DisconnectEvent(this)) + server.getEventManager().fire(new DisconnectEvent(this, !isConnected)) .thenRun(() -> this.teardownFuture.complete(null)); }