From 2fa7c8c0f660ecf44a53af586bf40e0627be278b Mon Sep 17 00:00:00 2001 From: Om Choksi Date: Mon, 24 Apr 2023 08:13:50 +0530 Subject: [PATCH 1/2] Fixed 'Name is null' error if glow color is not specified --- .../znetworkw/znpcservers/commands/list/DefaultCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 207b26a..352cb11 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 @@ -359,7 +359,7 @@ public class DefaultCommand extends Command { } NPCFunction npcFunction = FunctionFactory.findFunctionForName(args.get("type")); if (npcFunction.getName().equalsIgnoreCase("glow")) { - npcFunction.doRunFunction(foundNPC, new FunctionContext.ContextWithValue(foundNPC, args.get("value"))); + npcFunction.doRunFunction(foundNPC, new FunctionContext.ContextWithValue(foundNPC, args.get("value") != null ? args.get("value").toUpperCase() : "WHITE")); } else { npcFunction.doRunFunction(foundNPC, new FunctionContext.DefaultContext(foundNPC)); } From ae83ca1a15ab54e56e4194b325af9e7c5a66552e Mon Sep 17 00:00:00 2001 From: Om Choksi Date: Mon, 24 Apr 2023 08:46:27 +0530 Subject: [PATCH 2/2] Customization fix --- .../commands/list/DefaultCommand.java | 24 +++++++++++++------ .../configuration/ConfigurationValue.java | 1 + 2 files changed, 18 insertions(+), 7 deletions(-) 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;