From 9e5b5b5fc71ce24bae69d495b6adc8765c14679d Mon Sep 17 00:00:00 2001 From: YouHaveTrouble Date: Wed, 28 Sep 2022 19:24:18 +0200 Subject: [PATCH] fix velocity weird command handling --- CommandWhitelistBukkit/pom.xml | 2 +- .../listeners/PlayerCommandPreProcessListener.java | 3 ++- CommandWhitelistCommon/pom.xml | 2 +- CommandWhitelistVelocity/pom.xml | 2 +- .../velocity/CommandWhitelistVelocity.java | 9 ++++++--- CommandWhitelistWaterfall/pom.xml | 2 +- pom.xml | 2 +- 7 files changed, 13 insertions(+), 9 deletions(-) diff --git a/CommandWhitelistBukkit/pom.xml b/CommandWhitelistBukkit/pom.xml index 7091aa7..3366061 100644 --- a/CommandWhitelistBukkit/pom.xml +++ b/CommandWhitelistBukkit/pom.xml @@ -6,7 +6,7 @@ eu.endermite.commandwhitelist CommandWhitelist - 2.5.1 + 2.5.2 Bukkit diff --git a/CommandWhitelistBukkit/src/main/java/eu/endermite/commandwhitelist/bukkit/listeners/PlayerCommandPreProcessListener.java b/CommandWhitelistBukkit/src/main/java/eu/endermite/commandwhitelist/bukkit/listeners/PlayerCommandPreProcessListener.java index 4fa5643..7953958 100644 --- a/CommandWhitelistBukkit/src/main/java/eu/endermite/commandwhitelist/bukkit/listeners/PlayerCommandPreProcessListener.java +++ b/CommandWhitelistBukkit/src/main/java/eu/endermite/commandwhitelist/bukkit/listeners/PlayerCommandPreProcessListener.java @@ -1,6 +1,7 @@ package eu.endermite.commandwhitelist.bukkit.listeners; import eu.endermite.commandwhitelist.bukkit.CommandWhitelistBukkit; +import eu.endermite.commandwhitelist.common.CWPermission; import eu.endermite.commandwhitelist.common.CommandUtil; import eu.endermite.commandwhitelist.common.ConfigCache; import eu.endermite.commandwhitelist.common.commands.CWCommand; @@ -16,7 +17,7 @@ public class PlayerCommandPreProcessListener implements Listener { @EventHandler(priority = EventPriority.HIGHEST) public void PlayerCommandSendEvent(org.bukkit.event.player.PlayerCommandPreprocessEvent event) { Player player = event.getPlayer(); - if (player.hasPermission("commandwhitelist.bypass")) return; + if (player.hasPermission(CWPermission.BYPASS.permission())) return; String caseSensitiveLabel = CommandUtil.getCommandLabel(event.getMessage()); String label = caseSensitiveLabel.toLowerCase(); event.setMessage(event.getMessage().replaceFirst(caseSensitiveLabel, label)); diff --git a/CommandWhitelistCommon/pom.xml b/CommandWhitelistCommon/pom.xml index e48c29a..99506d3 100644 --- a/CommandWhitelistCommon/pom.xml +++ b/CommandWhitelistCommon/pom.xml @@ -6,7 +6,7 @@ eu.endermite.commandwhitelist CommandWhitelist - 2.5.1 + 2.5.2 Common diff --git a/CommandWhitelistVelocity/pom.xml b/CommandWhitelistVelocity/pom.xml index b2932a3..5cf8ac3 100644 --- a/CommandWhitelistVelocity/pom.xml +++ b/CommandWhitelistVelocity/pom.xml @@ -6,7 +6,7 @@ eu.endermite.commandwhitelist CommandWhitelist - 2.5.1 + 2.5.2 Velocity diff --git a/CommandWhitelistVelocity/src/main/java/eu/endermite/commandwhitelist/velocity/CommandWhitelistVelocity.java b/CommandWhitelistVelocity/src/main/java/eu/endermite/commandwhitelist/velocity/CommandWhitelistVelocity.java index aece787..9e35f86 100644 --- a/CommandWhitelistVelocity/src/main/java/eu/endermite/commandwhitelist/velocity/CommandWhitelistVelocity.java +++ b/CommandWhitelistVelocity/src/main/java/eu/endermite/commandwhitelist/velocity/CommandWhitelistVelocity.java @@ -11,6 +11,7 @@ import com.velocitypowered.api.proxy.ProxyServer; import eu.endermite.commandwhitelist.common.CWGroup; import eu.endermite.commandwhitelist.common.CWPermission; +import eu.endermite.commandwhitelist.common.CommandUtil; import eu.endermite.commandwhitelist.common.ConfigCache; import eu.endermite.commandwhitelist.common.commands.CWCommand; import eu.endermite.commandwhitelist.velocity.command.VelocityMainCommand; @@ -87,10 +88,12 @@ public void onUserCommandExecuteEvent(com.velocitypowered.api.event.command.Comm if (player.hasPermission(CWPermission.BYPASS.permission())) return; + // Workaround for velocity executing "/ command" as valid command + String command = event.getCommand().trim(); + HashSet allowedCommands = CommandWhitelistVelocity.getCommands(player); - String command = event.getCommand().split(" ")[0]; - if (server.getCommandManager().hasCommand(command) - && !allowedCommands.contains(command)) + String label = CommandUtil.getCommandLabel(command); + if (server.getCommandManager().hasCommand(label) && !allowedCommands.contains(label)) event.setResult(CommandExecuteEvent.CommandResult.forwardToServer()); } diff --git a/CommandWhitelistWaterfall/pom.xml b/CommandWhitelistWaterfall/pom.xml index e76667e..45cbb42 100644 --- a/CommandWhitelistWaterfall/pom.xml +++ b/CommandWhitelistWaterfall/pom.xml @@ -6,7 +6,7 @@ eu.endermite.commandwhitelist CommandWhitelist - 2.5.1 + 2.5.2 Waterfall diff --git a/pom.xml b/pom.xml index 636c4f1..62b40ea 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ eu.endermite.commandwhitelist CommandWhitelist - 2.5.1 + 2.5.2 CommandWhitelistCommon CommandWhitelistBukkit