Search in sources :

Example 1 with ItemAddon

use of mc.dragons.core.addon.ItemAddon in project DragonsOnline by UniverseCraft.

the class ItemCommand method manageAddons.

private void manageAddons(CommandSender sender, String[] args) {
    ItemClass itemClass = lookupItemClass(sender, args[0]);
    if (itemClass == null)
        return;
    User user = user(sender);
    if (args.length == 2) {
        sender.sendMessage(ChatColor.GREEN + "Listing addons for item class " + itemClass.getClassName() + ":");
        for (ItemAddon addon : itemClass.getAddons()) {
            sender.sendMessage(ChatColor.GRAY + "- " + addon.getName());
        }
    } else if (args.length == 3) {
        sender.sendMessage(ChatColor.RED + "Specify an addon name! For a list of addons, do /addon -l");
    } else {
        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 instanceof ItemAddon)) {
            sender.sendMessage(ChatColor.RED + "Invalid addon type! Only Item Addons can be applied to items.");
        } else if (args[2].equalsIgnoreCase("add")) {
            Document base = Document.parse(itemClass.getData().toJson());
            itemClass.addAddon((ItemAddon) addon);
            sender.sendMessage(ChatColor.GREEN + "Added addon " + addon.getName() + " to item class " + itemClass.getClassName() + ".");
            AUDIT_LOG.saveEntry(itemClass, user, base, "Added addon " + addon.getName());
        } else if (args[2].equalsIgnoreCase("remove")) {
            Document base = Document.parse(itemClass.getData().toJson());
            itemClass.removeAddon((ItemAddon) addon);
            sender.sendMessage(ChatColor.GREEN + "Removed addon " + addon.getName() + " from item class " + itemClass.getClassName() + ".");
            AUDIT_LOG.saveEntry(itemClass, user, base, "Removed addon " + addon.getName());
        } else {
            sender.sendMessage(ChatColor.RED + "Invalid arguments! /item <ClassName> addon [<add|remove> <AddonName>]");
        }
    }
}
Also used : ItemClass(mc.dragons.core.gameobject.item.ItemClass) Addon(mc.dragons.core.addon.Addon) ItemAddon(mc.dragons.core.addon.ItemAddon) User(mc.dragons.core.gameobject.user.User) ItemAddon(mc.dragons.core.addon.ItemAddon) Document(org.bson.Document)

Aggregations

Addon (mc.dragons.core.addon.Addon)1 ItemAddon (mc.dragons.core.addon.ItemAddon)1 ItemClass (mc.dragons.core.gameobject.item.ItemClass)1 User (mc.dragons.core.gameobject.user.User)1 Document (org.bson.Document)1