Make DisconnectEvent more sane
This is a step towards fixing #289 and removing some less-than-optimal behavior in plugins I maintain internally.
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
package com.velocitypowered.api.event.connection;
|
||||
|
||||
import static com.velocitypowered.api.event.connection.DisconnectEvent.LoginStatus.CANCELLED_BY_PROXY;
|
||||
import static com.velocitypowered.api.event.connection.DisconnectEvent.LoginStatus.SUCCESSFUL_LOGIN;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
|
||||
@@ -10,31 +13,50 @@ import com.velocitypowered.api.proxy.Player;
|
||||
public final class DisconnectEvent {
|
||||
|
||||
private final Player player;
|
||||
private final boolean disconnectedDuringLogin;
|
||||
private final LoginStatus loginStatus;
|
||||
|
||||
@Deprecated
|
||||
public DisconnectEvent(Player player) {
|
||||
this(player, false);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public DisconnectEvent(Player player,
|
||||
boolean disconnectedDuringLogin) {
|
||||
this(player, disconnectedDuringLogin ? CANCELLED_BY_PROXY : SUCCESSFUL_LOGIN);
|
||||
}
|
||||
|
||||
public DisconnectEvent(Player player, LoginStatus loginStatus) {
|
||||
this.player = Preconditions.checkNotNull(player, "player");
|
||||
this.disconnectedDuringLogin = disconnectedDuringLogin;
|
||||
this.loginStatus = Preconditions.checkNotNull(loginStatus, "loginStatus");
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean disconnectedDuringLogin() {
|
||||
return this.disconnectedDuringLogin;
|
||||
return this.loginStatus == CANCELLED_BY_PROXY;
|
||||
}
|
||||
|
||||
public LoginStatus getLoginStatus() {
|
||||
return loginStatus;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DisconnectEvent{"
|
||||
+ "player=" + player + ", "
|
||||
+ "disconnectedDuringLogin=" + disconnectedDuringLogin
|
||||
+ "loginStatus=" + loginStatus
|
||||
+ '}';
|
||||
}
|
||||
|
||||
public enum LoginStatus {
|
||||
|
||||
SUCCESSFUL_LOGIN,
|
||||
CONFLICTING_LOGIN,
|
||||
CANCELLED_BY_USER,
|
||||
CANCELLED_BY_PROXY
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user