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:
parent
269a248020
commit
1b3ddab1a9
1 changed files with 5 additions and 3 deletions
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue