Customization fix
This commit is contained in:
parent
2fa7c8c0f6
commit
ae83ca1a15
2 changed files with 18 additions and 7 deletions
|
@ -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>"})
|
||||
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"));
|
||||
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<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"));
|
||||
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<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),
|
||||
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<String, ImmutableSet<ConfigurationValue>> VALUES_BY_NAME;
|
||||
|
|
Loading…
Reference in a new issue