Command Listener improvements

This commit is contained in:
4drian3d 2022-02-01 11:41:22 -05:00
parent 5c4a9777ad
commit cbea29583e
2 changed files with 25 additions and 6 deletions

View File

@ -3,6 +3,7 @@ package com.glyart.authmevelocity.proxy.listener;
import com.glyart.authmevelocity.proxy.AuthmeVelocityAPI; import com.glyart.authmevelocity.proxy.AuthmeVelocityAPI;
import com.glyart.authmevelocity.proxy.config.AuthMeConfig; import com.glyart.authmevelocity.proxy.config.AuthMeConfig;
import com.glyart.authmevelocity.proxy.config.ConfigUtils; 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.EventTask;
import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.command.CommandExecuteEvent; import com.velocitypowered.api.event.command.CommandExecuteEvent;
@ -32,12 +33,8 @@ public class ProxyListener {
return; return;
if(AuthmeVelocityAPI.isInAuthServer(player)){ if(AuthmeVelocityAPI.isInAuthServer(player)){
var commandconfig = config.getCommandsConfig(); String command = AuthmeUtils.getFirstArgument(event.getCommand());
String command = event.getCommand(); if(!config.getCommandsConfig().getAllowedCommands().contains(command)){
if(command.contains(" ")){
command = command.split(" ")[0];
}
if(!commandconfig.getAllowedCommands().contains(command)){
ConfigUtils.sendBlockedMessage(player); ConfigUtils.sendBlockedMessage(player);
event.setResult(CommandExecuteEvent.CommandResult.denied()); event.setResult(CommandExecuteEvent.CommandResult.denied());
} }

View File

@ -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(){}
}