Search in sources :

Example 1 with WandAction

use of com.elmakers.mine.bukkit.api.wand.WandAction in project MagicPlugin by elBukkit.

the class WandCommandExecutor method onTabComplete.

@Override
public Collection<String> onTabComplete(CommandSender sender, String commandName, String[] args) {
    List<String> options = new ArrayList<>();
    Player player = (sender instanceof Player) ? (Player) sender : null;
    String permissionKey = "wand";
    if (commandName.contains("wandp")) {
        permissionKey = "wandp";
        if (args.length > 0) {
            player = DeprecatedUtils.getPlayer(args[0]);
        }
        if (args.length == 1) {
            options.addAll(api.getPlayerNames());
            return options;
        } else if (args.length > 1) {
            args = Arrays.copyOfRange(args, 1, args.length);
        }
    }
    if (args.length == 1) {
        addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "add");
        addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "remove");
        addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "name");
        addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "fill");
        addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "configure");
        addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "override");
        addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "organize");
        addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "alphabetize");
        addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "combine");
        addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "upgrade");
        addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "describe");
        addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "enchant");
        addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "create");
        addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "destroy");
        addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "duplicate");
        addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "restore");
        addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "unlock");
        addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "bind");
        addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "unbind");
        addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "save");
        addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "delete");
        addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "levelspells");
        Collection<String> allWands = api.getWandKeys();
        for (String wandKey : allWands) {
            addIfPermissible(sender, options, "Magic.create.", wandKey);
        }
    }
    if (args.length == 2) {
        String subCommand = args[0];
        String subCommandPNode = "Magic.commands." + permissionKey + "." + subCommand;
        if (!api.hasPermission(sender, subCommandPNode)) {
            return options;
        }
        subCommandPNode += ".";
        if (subCommand.equalsIgnoreCase("add")) {
            Collection<SpellTemplate> spellList = api.getSpellTemplates(sender.hasPermission("Magic.bypass_hidden"));
            for (SpellTemplate spell : spellList) {
                addIfPermissible(sender, options, subCommandPNode, spell.getKey(), true);
            }
            addIfPermissible(sender, options, subCommandPNode, "brush", true);
        }
        if (subCommand.equalsIgnoreCase("configure") || subCommand.equalsIgnoreCase("describe") || subCommand.equalsIgnoreCase("upgrade")) {
            for (String key : BaseMagicProperties.PROPERTY_KEYS) {
                options.add(key);
            }
            for (String damageType : api.getController().getDamageTypes()) {
                options.add("protection." + damageType);
                options.add("strength." + damageType);
                options.add("weakness." + damageType);
            }
        }
        if (subCommand.equalsIgnoreCase("override")) {
            Collection<SpellTemplate> spellList = api.getController().getSpellTemplates(true);
            String partial = args[1];
            if (partial.indexOf('.') > 0) {
                String[] pieces = StringUtils.split(partial, '.');
                String spellKey = pieces[0];
                SpellTemplate spell = api.getController().getSpellTemplate(spellKey);
                if (spell != null) {
                    List<String> spellOptions = new ArrayList<>();
                    spell.getParameters(spellOptions);
                    for (String option : spellOptions) {
                        options.add(spellKey + "." + option);
                    }
                }
            } else {
                for (SpellTemplate spell : spellList) {
                    String spellKey = spell.getKey();
                    if (api.hasPermission(sender, subCommandPNode + spellKey)) {
                        options.add(spellKey + ".");
                    }
                }
            }
        }
        if (subCommand.equalsIgnoreCase("remove")) {
            Wand activeWand = null;
            if (player != null) {
                Mage mage = controller.getMage(player);
                activeWand = mage.getActiveWand();
            }
            if (activeWand != null) {
                Collection<String> spellNames = activeWand.getSpells();
                for (String spellName : spellNames) {
                    options.add(spellName);
                }
                options.add("brush");
            }
        }
        if (subCommand.equalsIgnoreCase("combine")) {
            Collection<String> allWands = api.getWandKeys();
            for (String wandKey : allWands) {
                addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".combine.", wandKey, true);
            }
        }
        if (subCommand.equalsIgnoreCase("delete")) {
            File wandFolder = new File(api.getController().getConfigFolder(), "wands");
            if (wandFolder.exists()) {
                File[] files = wandFolder.listFiles();
                for (File file : files) {
                    if (file.getName().endsWith(".yml")) {
                        options.add(file.getName().replace(".yml", ""));
                    }
                }
            }
        }
    }
    if (args.length == 3) {
        String subCommand = args[0];
        String subCommand2 = args[1];
        String commandPNode = "Magic.commands." + permissionKey + "." + subCommand;
        if (!api.hasPermission(sender, commandPNode)) {
            return options;
        }
        if (subCommand.equalsIgnoreCase("override")) {
            String[] pieces = StringUtils.split(subCommand2, '.');
            if (pieces.length > 1) {
                String spellKey = pieces[0];
                String argument = pieces[1];
                SpellTemplate spell = api.getSpellTemplate(spellKey);
                if (spell != null) {
                    spell.getParameterOptions(options, argument);
                }
            }
        }
        if (subCommand.equalsIgnoreCase("configure") || subCommand.equalsIgnoreCase("upgrade")) {
            if (subCommand2.equals("effect_sound")) {
                Sound[] sounds = Sound.values();
                for (Sound sound : sounds) {
                    options.add(sound.name().toLowerCase());
                }
            } else if (subCommand2.equals("effect_particle")) {
                ParticleEffect[] particleTypes = ParticleEffect.values();
                for (ParticleEffect particleType : particleTypes) {
                    options.add(particleType.name().toLowerCase());
                }
            } else if (subCommand2.equals("mode")) {
                for (WandMode mode : WandMode.values()) {
                    options.add(mode.name().toLowerCase());
                }
            } else if (subCommand2.equals("left_click") || subCommand2.equals("right_click") || subCommand2.equals("drop") || subCommand2.equals("swap")) {
                for (WandAction action : WandAction.values()) {
                    options.add(action.name().toLowerCase());
                }
            }
        }
        String subCommandPNode = "Magic.commands." + permissionKey + "." + subCommand + "." + subCommand2;
        if (!api.hasPermission(sender, subCommandPNode)) {
            return options;
        }
        boolean isBrushCommand = subCommand2.equalsIgnoreCase("material") || subCommand2.equalsIgnoreCase("brush");
        if (subCommand.equalsIgnoreCase("remove") && isBrushCommand) {
            Wand activeWand = null;
            if (player != null) {
                Mage mage = controller.getMage(player);
                activeWand = mage.getActiveWand();
            }
            if (activeWand != null) {
                Collection<String> materialNames = activeWand.getBrushes();
                for (String materialName : materialNames) {
                    options.add(materialName);
                }
            }
        }
        if (subCommand.equalsIgnoreCase("add") && isBrushCommand) {
            options.addAll(api.getBrushes());
        }
    }
    return options;
}
Also used : Player(org.bukkit.entity.Player) ArrayList(java.util.ArrayList) Wand(com.elmakers.mine.bukkit.api.wand.Wand) Sound(org.bukkit.Sound) ParticleEffect(de.slikey.effectlib.util.ParticleEffect) Mage(com.elmakers.mine.bukkit.api.magic.Mage) File(java.io.File) WandMode(com.elmakers.mine.bukkit.wand.WandMode) WandAction(com.elmakers.mine.bukkit.api.wand.WandAction) SpellTemplate(com.elmakers.mine.bukkit.api.spell.SpellTemplate)

Aggregations

Mage (com.elmakers.mine.bukkit.api.magic.Mage)1 SpellTemplate (com.elmakers.mine.bukkit.api.spell.SpellTemplate)1 Wand (com.elmakers.mine.bukkit.api.wand.Wand)1 WandAction (com.elmakers.mine.bukkit.api.wand.WandAction)1 WandMode (com.elmakers.mine.bukkit.wand.WandMode)1 ParticleEffect (de.slikey.effectlib.util.ParticleEffect)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Sound (org.bukkit.Sound)1 Player (org.bukkit.entity.Player)1