use of mc.dragons.core.addon.NPCAddon in project DragonsOnline by UniverseCraft.
the class NPCCommand method manageAddons.
private void manageAddons(CommandSender sender, String[] args) {
NPCClass npcClass = lookupNPCClass(sender, args[0]);
if (npcClass == null)
return;
User user = user(sender);
if (args.length == 2) {
sender.sendMessage(ChatColor.GREEN + "Listing addons for NPC class " + npcClass.getClassName() + ":");
for (NPCAddon addon : npcClass.getAddons()) {
sender.sendMessage(ChatColor.GRAY + "- " + addon.getName());
}
return;
} else if (args.length == 3) {
sender.sendMessage(ChatColor.RED + "Specify an addon name! For a list of addons, do /addon -l");
return;
}
Document base = Document.parse(npcClass.getData().toJson());
Addon addon = addonRegistry.getAddonByName(args[3]);
if (addon == null) {
sender.sendMessage(ChatColor.RED + "Invalid addon name! For a list of addons, do /addon -l");
} else if (addon.getType() != AddonType.NPC) {
sender.sendMessage(ChatColor.RED + "Invalid addon type! Only NPC Addons can be applied to NPCs.");
} else if (args[2].equalsIgnoreCase("add")) {
npcClass.addAddon((NPCAddon) addon);
sender.sendMessage(ChatColor.GREEN + "Added addon " + addon.getName() + " to NPC class " + npcClass.getClassName() + ".");
AUDIT_LOG.saveEntry(npcClass, user, base, "Added addon " + addon.getName());
} else if (args[2].equalsIgnoreCase("remove")) {
npcClass.removeAddon((NPCAddon) addon);
sender.sendMessage(ChatColor.GREEN + "Removed addon " + addon.getName() + " from NPC class " + npcClass.getClassName() + ".");
AUDIT_LOG.saveEntry(npcClass, user, base, "Removed addon " + addon.getName());
} else {
sender.sendMessage(ChatColor.RED + "Invalid arguments! /npc <ClassName> addon [<add|remove> <AddonName>]");
}
}