diff --git a/proxy/src/main/java/com/glyart/authmevelocity/proxy/listener/ProxyListener.java b/proxy/src/main/java/com/glyart/authmevelocity/proxy/listener/ProxyListener.java index 8694eaf..a3b6e34 100644 --- a/proxy/src/main/java/com/glyart/authmevelocity/proxy/listener/ProxyListener.java +++ b/proxy/src/main/java/com/glyart/authmevelocity/proxy/listener/ProxyListener.java @@ -3,6 +3,7 @@ package com.glyart.authmevelocity.proxy.listener; import com.glyart.authmevelocity.proxy.AuthmeVelocityAPI; import com.glyart.authmevelocity.proxy.config.AuthMeConfig; import com.glyart.authmevelocity.proxy.config.ConfigUtils; +import com.glyart.authmevelocity.proxy.utils.AuthmeUtils; import com.velocitypowered.api.event.EventTask; import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.command.CommandExecuteEvent; @@ -32,12 +33,8 @@ public class ProxyListener { return; if(AuthmeVelocityAPI.isInAuthServer(player)){ - var commandconfig = config.getCommandsConfig(); - String command = event.getCommand(); - if(command.contains(" ")){ - command = command.split(" ")[0]; - } - if(!commandconfig.getAllowedCommands().contains(command)){ + String command = AuthmeUtils.getFirstArgument(event.getCommand()); + if(!config.getCommandsConfig().getAllowedCommands().contains(command)){ ConfigUtils.sendBlockedMessage(player); event.setResult(CommandExecuteEvent.CommandResult.denied()); } diff --git a/proxy/src/main/java/com/glyart/authmevelocity/proxy/utils/AuthmeUtils.java b/proxy/src/main/java/com/glyart/authmevelocity/proxy/utils/AuthmeUtils.java new file mode 100644 index 0000000..2f329ad --- /dev/null +++ b/proxy/src/main/java/com/glyart/authmevelocity/proxy/utils/AuthmeUtils.java @@ -0,0 +1,22 @@ +package com.glyart.authmevelocity.proxy.utils; + +import java.util.Objects; + +import org.jetbrains.annotations.NotNull; + +public class AuthmeUtils { + //Origin: https://github.com/4drian3d/ChatRegulator/blob/main/src/main/java/me/dreamerzero/chatregulator/utils/CommandUtils.java#L71 + /** + * Get the first argument of a string + * @param string the string + * @return the first argument + */ + public static @NotNull String getFirstArgument(@NotNull String string){ + int index = Objects.requireNonNull(string).indexOf(" "); + if (index == -1) { + return string; + } + return string.substring(0, index); + } + private AuthmeUtils(){} +}