From 1b3ddab1a931ce7e85f80556d2cbe6b41d55a9ca Mon Sep 17 00:00:00 2001 From: "Jos (BM)" <43651265+JosTheDude@users.noreply.github.com> Date: Thu, 20 Apr 2023 01:01:49 -0400 Subject: [PATCH] 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. --- .../znetworkw/znpcservers/commands/CommandInvoker.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/github/znetworkw/znpcservers/commands/CommandInvoker.java b/src/main/java/io/github/znetworkw/znpcservers/commands/CommandInvoker.java index 53cdab7..b7545f4 100644 --- a/src/main/java/io/github/znetworkw/znpcservers/commands/CommandInvoker.java +++ b/src/main/java/io/github/znetworkw/znpcservers/commands/CommandInvoker.java @@ -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) {