Patch: Command Ran as Console Error Fix

When running any zNPCsPlus command in console, it throws an exception stating that the command could not be run.

This adds a check making sure that only players can run zNPCs related commands to avoid the thrown exception.
This commit is contained in:
Jos (BM) 2023-04-20 01:01:49 -04:00 committed by GitHub
parent 269a248020
commit 1b3ddab1a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -4,9 +4,7 @@ import java.lang.reflect.Method;
public class CommandInvoker {
private final Command command;
private final Method commandMethod;
private final String permission;
public CommandInvoker(Command command, Method commandMethod, String permission) {
@ -16,8 +14,12 @@ public class CommandInvoker {
}
public void execute(CommandSender sender, Object command) throws CommandPermissionException, CommandExecuteException {
if (this.permission.length() > 0 && !sender.getCommandSender().hasPermission(this.permission))
if (!(sender instanceof Player) && this.permission.length() == 0) {
throw new CommandPermissionException("Only players may execute this command.");
}
if (this.permission.length() > 0 && !sender.getCommandSender().hasPermission(this.permission)) {
throw new CommandPermissionException("Insufficient permission.");
}
try {
this.commandMethod.invoke(this.command, sender, command);
} catch (IllegalAccessException | java.lang.reflect.InvocationTargetException e) {