Merge pull request #27 from D3v1s0m/master

Command fixes
This commit is contained in:
Pyr 2023-04-25 00:05:14 +01:00 committed by GitHub
commit bd90f80314
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 8 deletions

@ -359,7 +359,7 @@ public class DefaultCommand extends Command {
} }
NPCFunction npcFunction = FunctionFactory.findFunctionForName(args.get("type")); NPCFunction npcFunction = FunctionFactory.findFunctionForName(args.get("type"));
if (npcFunction.getName().equalsIgnoreCase("glow")) { 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 { } else {
npcFunction.doRunFunction(foundNPC, new FunctionContext.DefaultContext(foundNPC)); npcFunction.doRunFunction(foundNPC, new FunctionContext.DefaultContext(foundNPC));
} }
@ -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 <npc_id> <customization>"}) @CommandInformation(arguments = {"id", "customizeValues"}, name = "customize", permission = "znpcs.cmd.customize", help = {" &f&l* &e/znpcs customize <npc_id> <customization>"})
public void customize(CommandSender sender, Map<String, String> args) { public void customize(CommandSender sender, Map<String, String> args) {
if (args.size() < 2) {
Configuration.MESSAGES.sendMessage(sender.getCommandSender(), ConfigurationValue.INCORRECT_USAGE);
return;
}
Integer id = Ints.tryParse(args.get("id")); Integer id = Ints.tryParse(args.get("id"));
if (id == null) { if (id == null) {
Configuration.MESSAGES.sendMessage(sender.getCommandSender(), ConfigurationValue.INVALID_NUMBER); Configuration.MESSAGES.sendMessage(sender.getCommandSender(), ConfigurationValue.INVALID_NUMBER);
@ -383,6 +379,12 @@ public class DefaultCommand extends Command {
return; return;
} }
NPCType npcType = foundNPC.getNpcPojo().getNpcType(); NPCType npcType = foundNPC.getNpcPojo().getNpcType();
if (args.get("customizeValues") == null) {
Configuration.MESSAGES.sendMessage(sender.getCommandSender(), ConfigurationValue.INCORRECT_USAGE);
for (Map.Entry<String, Method> method : npcType.getCustomizationLoader().getMethods().entrySet())
sender.sendMessage(ChatColor.YELLOW + method.getKey() + " " + SPACE_JOINER.join(method.getValue().getParameterTypes()));
return;
}
List<String> customizeOptions = SPACE_SPLITTER.splitToList(args.get("customizeValues")); List<String> customizeOptions = SPACE_SPLITTER.splitToList(args.get("customizeValues"));
String methodName = customizeOptions.get(0); String methodName = customizeOptions.get(0);
if (npcType.getCustomizationLoader().contains(methodName)) { if (npcType.getCustomizationLoader().contains(methodName)) {
@ -392,10 +394,18 @@ public class DefaultCommand extends Command {
Configuration.MESSAGES.sendMessage(sender.getCommandSender(), ConfigurationValue.TOO_FEW_ARGUMENTS); Configuration.MESSAGES.sendMessage(sender.getCommandSender(), ConfigurationValue.TOO_FEW_ARGUMENTS);
return; return;
} }
split = Iterables.transform(split, String::toUpperCase);
String[] values = Iterables.toArray(split, String.class); String[] values = Iterables.toArray(split, String.class);
try {
npcType.updateCustomization(foundNPC, methodName, values); npcType.updateCustomization(foundNPC, methodName, values);
foundNPC.getNpcPojo().getCustomizationMap().put(methodName, values); foundNPC.getNpcPojo().getCustomizationMap().put(methodName, values);
Configuration.MESSAGES.sendMessage(sender.getCommandSender(), ConfigurationValue.SUCCESS); 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 { } else {
Configuration.MESSAGES.sendMessage(sender.getCommandSender(), ConfigurationValue.METHOD_NOT_FOUND); Configuration.MESSAGES.sendMessage(sender.getCommandSender(), ConfigurationValue.METHOD_NOT_FOUND);
for (Map.Entry<String, Method> method : npcType.getCustomizationLoader().getMethods().entrySet()) for (Map.Entry<String, Method> method : npcType.getCustomizationLoader().getMethods().entrySet())

@ -52,6 +52,7 @@ public enum ConfigurationValue {
CANT_GET_SKIN("messages", "&cCould not fetch skin for name: %s.", String.class), CANT_GET_SKIN("messages", "&cCould not fetch skin for name: %s.", String.class),
GET_SKIN("messages", "&aSkin successfully fetched!", 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), 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); CONVERSATION_LIST("conversations" /* Leave this lowercase or it will break */, new ArrayList<>(), Conversation.class);
public static final Map<String, ImmutableSet<ConfigurationValue>> VALUES_BY_NAME; public static final Map<String, ImmutableSet<ConfigurationValue>> VALUES_BY_NAME;