From 0d8630452f3285b9280de9ac61ab10c8169dd8d9 Mon Sep 17 00:00:00 2001 From: Adrian3d04 Date: Sat, 13 Aug 2022 21:47:26 +0000 Subject: [PATCH] fix(velocity): Implement ignoreSignedPlayer configuration Workaround for #48 --- .../configuration/ProxyConfiguration.java | 22 +++++++----- .../velocity/listener/ProxyListener.java | 35 ++++++++++++++++--- 2 files changed, 44 insertions(+), 13 deletions(-) diff --git a/common/src/main/java/me/adrianed/authmevelocity/common/configuration/ProxyConfiguration.java b/common/src/main/java/me/adrianed/authmevelocity/common/configuration/ProxyConfiguration.java index 6220e08..09ae2be 100644 --- a/common/src/main/java/me/adrianed/authmevelocity/common/configuration/ProxyConfiguration.java +++ b/common/src/main/java/me/adrianed/authmevelocity/common/configuration/ProxyConfiguration.java @@ -47,8 +47,7 @@ public class ProxyConfiguration { Selection Mode of the player's initial server TO_FIRST | Send to the first valid server configured TO_EMPTIEST_SERVER | Send to the server with the lowest number of players - RANDOM | Send to a random server - """) + RANDOM | Send to a random server""") private SendMode sendMode = SendMode.RANDOM; public SendMode sendMode() { return this.sendMode; @@ -65,8 +64,7 @@ public class ProxyConfiguration { @Comment(""" List of servers to send - One of these servers will be chosen at random - """) + One of these servers will be chosen at random""") private List teleportServers = List.of("lobby1", "lobby2"); public List teleportServers() { return this.teleportServers; @@ -76,8 +74,7 @@ public class ProxyConfiguration { Selection Mode of the server to which the player will be sent TO_FIRST | Send to the first valid server configured TO_EMPTIEST_SERVER | Send to the server with the lowest number of players - RANDOM | Send to a random server - """) + RANDOM | Send to a random server""") private SendMode sendMode = SendMode.RANDOM; public SendMode sendMode() { return this.sendMode; @@ -94,8 +91,7 @@ public class ProxyConfiguration { @Comment(""" Sets the message to send in case a non-logged-in player executes an unauthorized command - To deactivate the message, leave it empty - """) + To deactivate the message, leave it empty""") private String blockedMessage = "You cannot execute commands if you are not logged in yet"; public String blockedCommandMessage() { return this.blockedMessage; @@ -115,6 +111,16 @@ public class ProxyConfiguration { public int randomAttempts() { return this.randomAttempts; } + + @Comment(""" + Ignore blocking of commands and chat messages to 1.19.1 clients with a valid signed key + When trying to block these executions, the proxy will kick the player out. + This option allows you to prevent the plugin from trying to block these executions, + avoiding the player to be kicked out""") + private boolean ignoreSignedPlayers = false; + public boolean ignoreSignedPlayers() { + return this.ignoreSignedPlayers; + } } diff --git a/velocity/src/main/java/me/adrianed/authmevelocity/velocity/listener/ProxyListener.java b/velocity/src/main/java/me/adrianed/authmevelocity/velocity/listener/ProxyListener.java index e8aa8dc..fdebbd8 100644 --- a/velocity/src/main/java/me/adrianed/authmevelocity/velocity/listener/ProxyListener.java +++ b/velocity/src/main/java/me/adrianed/authmevelocity/velocity/listener/ProxyListener.java @@ -10,6 +10,7 @@ import com.velocitypowered.api.event.command.CommandExecuteEvent; import com.velocitypowered.api.event.connection.DisconnectEvent; import com.velocitypowered.api.event.player.PlayerChatEvent; import com.velocitypowered.api.event.player.TabCompleteEvent; +import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.proxy.Player; import net.kyori.adventure.text.minimessage.MiniMessage; @@ -35,7 +36,13 @@ public final class ProxyListener { } if (plugin.isLogged(player)) { - plugin.logDebug("CommandExecuteEvent | Player is not logged"); + plugin.logDebug("CommandExecuteEvent | Player is already logged"); + continuation.resume(); + return; + } + + if (canBeIgnored(player)) { + plugin.logDebug("CommandexecuteEvent | Ignored signed player"); continuation.resume(); return; } @@ -57,11 +64,23 @@ public final class ProxyListener { } @Subscribe(order = PostOrder.FIRST) - public void onPlayerChat(final PlayerChatEvent event) { - if (plugin.isNotLogged(event.getPlayer())) { - plugin.logDebug("PlayerChatEvent | Player is not logged"); - event.setResult(PlayerChatEvent.ChatResult.denied()); + public void onPlayerChat(final PlayerChatEvent event, Continuation continuation) { + if (plugin.isLogged(event.getPlayer())) { + plugin.logDebug("PlayerChatEvent | Player is already logged"); + continuation.resume(); + return; } + + plugin.logDebug("PlayerChatEvent | Player is not logged"); + + if (canBeIgnored(event.getPlayer())) { + plugin.logDebug("PlayerChatEvent | Ignored signed player"); + continuation.resume(); + return; + } + + event.setResult(PlayerChatEvent.ChatResult.denied()); + continuation.resume(); } @Subscribe(order = PostOrder.FIRST) @@ -88,5 +107,11 @@ public final class ProxyListener { player.sendMessage(MiniMessage.miniMessage().deserialize(blockedMessage)); } } + + boolean canBeIgnored(Player player) { + return player.getIdentifiedKey() != null + && player.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_19_1) >= 0 + && plugin.config().get().advanced().ignoreSignedPlayers(); + } }