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 1/2] 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) { From e30d4a4d708641a822a3bf53b8cba78bb35c4d45 Mon Sep 17 00:00:00 2001 From: "Jos (BM)" <43651265+JosTheDude@users.noreply.github.com> Date: Thu, 20 Apr 2023 01:10:22 -0400 Subject: [PATCH 2/2] General Change: More User Friendly Messages These changes just make the errors, success messages, and informational messages look more user-friendly and make them easier to understand for newer users of the plugin. Also removes some of the 'slang' messages and replaces them with more professional ones. --- .../configuration/ConfigurationValue.java | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/main/java/io/github/znetworkw/znpcservers/configuration/ConfigurationValue.java b/src/main/java/io/github/znetworkw/znpcservers/configuration/ConfigurationValue.java index 025a5d1..b4b1510 100644 --- a/src/main/java/io/github/znetworkw/znpcservers/configuration/ConfigurationValue.java +++ b/src/main/java/io/github/znetworkw/znpcservers/configuration/ConfigurationValue.java @@ -22,34 +22,34 @@ public enum ConfigurationValue { LINE_SPACING("config", 0.3D, Double.class), ANIMATION_RGB("config", Boolean.FALSE, Boolean.class), NO_PERMISSION("messages", "&cYou do not have permission to execute this command.", String.class), - SUCCESS("messages", "&aDone...", String.class), - INCORRECT_USAGE("messages", "&cIncorrect use of command.", String.class), - COMMAND_NOT_FOUND("messages", "&cThis command was not found.", String.class), + SUCCESS("messages", "&aDone!", String.class), + INCORRECT_USAGE("messages", "&cThe arguements you specified are not valid, do &f/znpcs help&c for assistance and examples.", String.class), + COMMAND_NOT_FOUND("messages", "&cThe command you specified does not exist!", String.class), COMMAND_ERROR("messages", "&cThere was an error executing the command, see the console for more information.", String.class), - INVALID_NUMBER("messages", "&cHey!, The inserted number/id does not look like a number..", String.class), - NPC_NOT_FOUND("messages", "&cHey!, I couldnt find a npc with this id.", String.class), - TOO_FEW_ARGUMENTS("messages", "&cToo few arguments.", String.class), - PATH_START("messages", "&aDone, now walk where you want the npc to, when u finish type /znpcs path exit.", String.class), + INVALID_NUMBER("messages", "&cHey!, The inserted number/id does not look like a number, please use integer values only!", String.class), + NPC_NOT_FOUND("messages", "&cHey!, I couldn't find a npc with this id!", String.class), + TOO_FEW_ARGUMENTS("messages", "&cThis command does not have enough arguements, do &f/znpcs help&c for assistance and examples.", String.class), + PATH_START("messages", "&aDone, now walk where you want the npc to walk towards, when finished type &f/znpcs path exit", String.class), EXIT_PATH("messages", "&cYou have exited the waypoint creation.", String.class), PATH_FOUND("messages", "&cThere is already a path with this name.", String.class), - NPC_FOUND("messages", "&cThere is already a npc with this id.", String.class), + NPC_FOUND("messages", "&cThere is already an NPC with this id.", String.class), NO_PATH_FOUND("messages", "&cNo path found.", String.class), NO_SKIN_FOUND("messages", "&cSkin not found.", String.class), NO_NPC_FOUND("messages", "&cNo npc found.", String.class), - NO_ACTION_FOUND("messages", "&cNo action found.", String.class), - METHOD_NOT_FOUND("messages", "&cNo method found.", String.class), - INVALID_NAME_LENGTH("messages", "&cThe name is too short or long, it must be in the range of (3 to 16) characters.", String.class), - UNSUPPORTED_ENTITY("messages", "&cEntity type not available for your current version.", String.class), + NO_ACTION_FOUND("messages", "&cThis action was not valid! Check the wiki for valid action types.", String.class), + METHOD_NOT_FOUND("messages", "&cThis method was not found! Check the wiki for valid action types.", String.class), + INVALID_NAME_LENGTH("messages", "&cThe name you specified is too short or long, it must be in the range of (3 to 16) characters.", String.class), + UNSUPPORTED_ENTITY("messages", "&cThis entity type not available for your current version.", String.class), PATH_SET_INCORRECT_USAGE("messages", "&eUsage: &aset ", String.class), ACTION_ADD_INCORRECT_USAGE("messages", "&eUsage: &a ", String.class), ACTION_DELAY_INCORRECT_USAGE("messages", "&eUsage: &a ", String.class), CONVERSATION_SET_INCORRECT_USAGE("messages", "&cUsage: ", String.class), - NO_CONVERSATION_FOUND("messages", "&cNo conversation found.", String.class), + NO_CONVERSATION_FOUND("messages", "&cThis conversation was not found.", String.class), CONVERSATION_FOUND("messages", "&cThere is already a conversation with this name.", String.class), INVALID_SIZE("messages", "&cThe position cannot exceed the limit.", String.class), FETCHING_SKIN("messages", "&aFetching skin for name: &f%s&a, wait...", String.class), - CANT_GET_SKIN("messages", "&ccan't fetch skin with name: %s.", String.class), - GET_SKIN("messages", "&aSkin fetched.", String.class), + CANT_GET_SKIN("messages", "&cCould not fetch skin for name: %s.", String.class), + GET_SKIN("messages", "&aSkin fetched!", String.class), CONVERSATION_LIST("conversations", new ArrayList<>(), Conversation.class); public static final Map> VALUES_BY_NAME;