Command Listener improvements
This commit is contained in:
parent
5c4a9777ad
commit
cbea29583e
@ -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());
|
||||
}
|
||||
|
@ -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(){}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user