From fd367c6efdc95562739e5603070ba454e27822d9 Mon Sep 17 00:00:00 2001 From: Leymooo Date: Wed, 4 Sep 2019 01:43:25 +0300 Subject: [PATCH] Add method to determine if player is in OnlineMode --- .../java/com/velocitypowered/api/proxy/Player.java | 7 +++++++ .../proxy/connection/client/ConnectedPlayer.java | 11 +++++++++-- .../proxy/connection/client/LoginSessionHandler.java | 2 +- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/api/src/main/java/com/velocitypowered/api/proxy/Player.java b/api/src/main/java/com/velocitypowered/api/proxy/Player.java index 54fcc8d99..b2ef61409 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/Player.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/Player.java @@ -65,6 +65,13 @@ public interface Player extends CommandSource, InboundConnection, ChannelMessage */ long getPing(); + /** + * Returns the player's connection status. + * + * @return true if the player is authenticated with Mojang servers + */ + boolean isOnlineMode(); + /** * Sends a chat message to the player's client. * 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 d1a609023..c012e8fcb 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 @@ -90,6 +90,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { private PermissionFunction permissionFunction; private int tryIndex = 0; private long ping = -1; + private final boolean onlineMode; private @Nullable VelocityServerConnection connectedServer; private @Nullable VelocityServerConnection connectionInFlight; private @Nullable PlayerSettings settings; @@ -102,8 +103,8 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { private @MonotonicNonNull List serversToTry = null; - ConnectedPlayer(VelocityServer server, GameProfile profile, - MinecraftConnection connection, @Nullable InetSocketAddress virtualHost) { + ConnectedPlayer(VelocityServer server, GameProfile profile, MinecraftConnection connection, + @Nullable InetSocketAddress virtualHost, boolean onlineMode) { this.server = server; if (connection.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { this.tabList = new VelocityTabList(connection); @@ -116,6 +117,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { this.permissionFunction = PermissionFunction.ALWAYS_UNDEFINED; this.connectionPhase = connection.getType().getInitialClientPhase(); this.knownChannels = CappedSet.create(MAX_PLUGIN_CHANNELS); + this.onlineMode = onlineMode; } @Override @@ -151,6 +153,11 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { this.ping = ping; } + @Override + public boolean isOnlineMode() { + return onlineMode; + } + @Override public PlayerSettings getPlayerSettings() { return settings == null ? ClientSettingsWrapper.DEFAULT : this.settings; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java index 444232869..05b032ce6 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java @@ -232,7 +232,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { // Initiate a regular connection and move over to it. ConnectedPlayer player = new ConnectedPlayer(server, profileEvent.getGameProfile(), mcConnection, - inbound.getVirtualHost().orElse(null)); + inbound.getVirtualHost().orElse(null), onlineMode); this.connectedPlayer = player; if (!server.canRegisterConnection(player)) { player.disconnect(VelocityMessages.ALREADY_CONNECTED);