diff --git a/src/main/java/io/github/znetworkw/znpcservers/commands/list/DefaultCommand.java b/src/main/java/io/github/znetworkw/znpcservers/commands/list/DefaultCommand.java index 352cb11..ef45a7f 100644 --- a/src/main/java/io/github/znetworkw/znpcservers/commands/list/DefaultCommand.java +++ b/src/main/java/io/github/znetworkw/znpcservers/commands/list/DefaultCommand.java @@ -368,10 +368,6 @@ public class DefaultCommand extends Command { @CommandInformation(arguments = {"id", "customizeValues"}, name = "customize", permission = "znpcs.cmd.customize", help = {" &f&l* &e/znpcs customize "}) public void customize(CommandSender sender, Map args) { - if (args.size() < 2) { - Configuration.MESSAGES.sendMessage(sender.getCommandSender(), ConfigurationValue.INCORRECT_USAGE); - return; - } Integer id = Ints.tryParse(args.get("id")); if (id == null) { Configuration.MESSAGES.sendMessage(sender.getCommandSender(), ConfigurationValue.INVALID_NUMBER); @@ -383,6 +379,12 @@ public class DefaultCommand extends Command { return; } NPCType npcType = foundNPC.getNpcPojo().getNpcType(); + if (args.get("customizeValues") == null) { + Configuration.MESSAGES.sendMessage(sender.getCommandSender(), ConfigurationValue.INCORRECT_USAGE); + for (Map.Entry method : npcType.getCustomizationLoader().getMethods().entrySet()) + sender.sendMessage(ChatColor.YELLOW + method.getKey() + " " + SPACE_JOINER.join(method.getValue().getParameterTypes())); + return; + } List customizeOptions = SPACE_SPLITTER.splitToList(args.get("customizeValues")); String methodName = customizeOptions.get(0); if (npcType.getCustomizationLoader().contains(methodName)) { @@ -392,10 +394,18 @@ public class DefaultCommand extends Command { Configuration.MESSAGES.sendMessage(sender.getCommandSender(), ConfigurationValue.TOO_FEW_ARGUMENTS); return; } + split = Iterables.transform(split, String::toUpperCase); String[] values = Iterables.toArray(split, String.class); - npcType.updateCustomization(foundNPC, methodName, values); - foundNPC.getNpcPojo().getCustomizationMap().put(methodName, values); - Configuration.MESSAGES.sendMessage(sender.getCommandSender(), ConfigurationValue.SUCCESS); + try { + npcType.updateCustomization(foundNPC, methodName, values); + foundNPC.getNpcPojo().getCustomizationMap().put(methodName, values); + Configuration.MESSAGES.sendMessage(sender.getCommandSender(), ConfigurationValue.SUCCESS); + }catch (Exception e) { + Configuration.MESSAGES.sendMessage(sender.getCommandSender(), ConfigurationValue.INVALID_CUSTOMIZE_ARGUMENTS); + if (ConfigurationConstants.DEBUG_ENABLED) { + e.printStackTrace(); + } + } } else { Configuration.MESSAGES.sendMessage(sender.getCommandSender(), ConfigurationValue.METHOD_NOT_FOUND); for (Map.Entry method : npcType.getCustomizationLoader().getMethods().entrySet()) 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 f9b67bf..e865d5f 100644 --- a/src/main/java/io/github/znetworkw/znpcservers/configuration/ConfigurationValue.java +++ b/src/main/java/io/github/znetworkw/znpcservers/configuration/ConfigurationValue.java @@ -52,6 +52,7 @@ public enum ConfigurationValue { CANT_GET_SKIN("messages", "&cCould not fetch skin for name: %s.", String.class), GET_SKIN("messages", "&aSkin successfully fetched!", String.class), NOT_SUPPORTED_NPC_TYPE("messages", "&cThis NPC type doesn't exists or is not supported in your current server version.", String.class), + INVALID_CUSTOMIZE_ARGUMENTS("messages", "&cThe argument(s) you have specified is/are invalid. Type &f/znpcs&c or view our documentation for a list/examples of existing arguments.", String.class), CONVERSATION_LIST("conversations" /* Leave this lowercase or it will break */, new ArrayList<>(), Conversation.class); public static final Map> VALUES_BY_NAME;