Search in sources :

Example 16 with CommandSender

use of org.bukkit.command.CommandSender in project MagicPlugin by elBukkit.

the class MageCommandExecutor method onTabComplete.

@Override
public Collection<String> onTabComplete(CommandSender sender, String commandName, String[] args) {
    List<String> options = new ArrayList<>();
    if (args.length == 1) {
        addIfPermissible(sender, options, "Magic.commands.mage.", "add");
        addIfPermissible(sender, options, "Magic.commands.mage.", "remove");
        addIfPermissible(sender, options, "Magic.commands.mage.", "configure");
        addIfPermissible(sender, options, "Magic.commands.mage.", "describe");
        addIfPermissible(sender, options, "Magic.commands.mage.", "upgrade");
        addIfPermissible(sender, options, "Magic.commands.mage.", "getdata");
        addIfPermissible(sender, options, "Magic.commands.mage.", "setdata");
        addIfPermissible(sender, options, "Magic.commands.mage.", "check");
        addIfPermissible(sender, options, "Magic.commands.mage.", "debug");
        addIfPermissible(sender, options, "Magic.commands.mage.", "reset");
        addIfPermissible(sender, options, "Magic.commands.mage.", "unbind");
        addIfPermissible(sender, options, "Magic.commands.mage.", "activate");
        addIfPermissible(sender, options, "Magic.commands.mage.", "unlock");
        addIfPermissible(sender, options, "Magic.commands.mage.", "lock");
        addIfPermissible(sender, options, "Magic.commands.mage.", "levelspells");
        addIfPermissible(sender, options, "Magic.commands.mage.", "attribute");
    } else if (args.length == 2 && sender.hasPermission("Magic.commands.mage.others")) {
        options.addAll(api.getPlayerNames());
    }
    if (args.length == 3 || args.length == 2) {
        CommandSender target = args.length == 2 ? sender : DeprecatedUtils.getPlayer(args[1]);
        String subCommand = args[0];
        String subCommandPNode = "Magic.commands.mage." + subCommand;
        if (subCommand.equalsIgnoreCase("setdata") || subCommand.equalsIgnoreCase("getdata")) {
            if (target != null) {
                Mage mage = controller.getMage(target);
                ConfigurationSection data = mage.getData();
                options.addAll(data.getKeys(false));
            }
        }
        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("remove")) {
            if (target != null) {
                Mage mage = controller.getMage(target);
                MageClass mageClass = mage.getActiveClass();
                if (mageClass != null) {
                    options.addAll(mageClass.getSpells());
                }
            }
            options.add("brush");
        }
        if (subCommand.equalsIgnoreCase("configure") || subCommand.equalsIgnoreCase("describe") || subCommand.equalsIgnoreCase("upgrade")) {
            for (String key : BaseMagicProperties.PROPERTY_KEYS) {
                options.add(key);
            }
            for (String protection : api.getController().getDamageTypes()) {
                options.add("protection." + protection);
            }
        }
        if (subCommand.equalsIgnoreCase("attribute")) {
            for (String attribute : api.getController().getAttributes()) {
                options.add(attribute);
            }
        }
        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 (args[0].equalsIgnoreCase("lock") || args[0].equalsIgnoreCase("unlock") || args[0].equalsIgnoreCase("activate")) {
            options.addAll(api.getController().getMageClassKeys());
        }
    }
    return options;
}
Also used : MageClass(com.elmakers.mine.bukkit.api.magic.MageClass) Mage(com.elmakers.mine.bukkit.api.magic.Mage) ArrayList(java.util.ArrayList) CommandSender(org.bukkit.command.CommandSender) ConfigurationSection(org.bukkit.configuration.ConfigurationSection) SpellTemplate(com.elmakers.mine.bukkit.api.spell.SpellTemplate)

Example 17 with CommandSender

use of org.bukkit.command.CommandSender in project MagicPlugin by elBukkit.

the class HeroesSkillSpell method onCast.

@Override
public SpellResult onCast(ConfigurationSection parameters) {
    CommandSender sender = mage.getCommandSender();
    controller.getPlugin().getServer().dispatchCommand(sender, "skill " + skillKey);
    return SpellResult.CAST;
}
Also used : CommandSender(org.bukkit.command.CommandSender)

Example 18 with CommandSender

use of org.bukkit.command.CommandSender in project MagicPlugin by elBukkit.

the class RecallAction method tryTeleport.

protected boolean tryTeleport(final Player player, final Waypoint waypoint) {
    Mage mage = context.getMage();
    if (waypoint == null)
        return false;
    if (waypoint.isCommand()) {
        if (waypoint.asConsole) {
            try {
                player.getServer().dispatchCommand(Bukkit.getConsoleSender(), waypoint.command);
            } catch (Exception ex) {
                context.getLogger().log(Level.WARNING, "Error running command as console " + waypoint.command, ex);
            }
        } else {
            CommandSender sender = mage.getCommandSender();
            boolean isOp = sender.isOp();
            if (waypoint.opPlayer && !isOp) {
                sender.setOp(true);
            }
            try {
                player.getServer().dispatchCommand(sender, waypoint.command);
            } catch (Exception ex) {
                context.getLogger().log(Level.WARNING, "Error running command " + waypoint.command, ex);
            }
            if (waypoint.opPlayer && !isOp) {
                sender.setOp(false);
            }
        }
        mage.enableSuperProtection(protectionTime);
        return true;
    }
    Location targetLocation = waypoint.location;
    if (targetLocation == null) {
        String serverName = waypoint.serverName;
        String warpName = waypoint.warpName;
        if (warpName != null && serverName != null) {
            context.getController().warpPlayerToServer(player, serverName, warpName);
        } else {
            context.sendMessage(waypoint.failMessage);
        }
        return false;
    }
    if (!allowCrossWorld && !mage.getLocation().getWorld().equals(targetLocation.getWorld())) {
        context.sendMessageKey("cross_world_disallowed");
        return false;
    }
    if (waypoint.maintainDirection) {
        Location playerLocation = player.getLocation();
        targetLocation.setYaw(playerLocation.getYaw());
        targetLocation.setPitch(playerLocation.getPitch());
    }
    mage.enableSuperProtection(protectionTime);
    if (context.teleport(player, targetLocation, verticalSearchDistance, waypoint.safe, waypoint.safe)) {
        context.castMessage(waypoint.message);
    } else {
        context.castMessage(waypoint.failMessage);
    }
    return true;
}
Also used : Mage(com.elmakers.mine.bukkit.api.magic.Mage) CommandSender(org.bukkit.command.CommandSender) Location(org.bukkit.Location)

Example 19 with CommandSender

use of org.bukkit.command.CommandSender in project MagicPlugin by elBukkit.

the class CommandAction method perform.

@Override
public SpellResult perform(CastContext context) {
    Mage mage = context.getMage();
    MageController controller = context.getController();
    CommandSender sender = asConsole ? Bukkit.getConsoleSender() : mage.getCommandSender();
    if (sender == null) {
        return SpellResult.FAIL;
    }
    Queue<String> conversationCommands = new ArrayDeque<>(commands.size());
    boolean isOp = sender.isOp();
    if (opPlayer && !isOp) {
        sender.setOp(true);
    }
    for (String command : commands) {
        try {
            String converted = context.parameterize(command);
            if (converted.contains("@arg")) {
                conversationCommands.add(converted);
            } else {
                controller.getPlugin().getServer().dispatchCommand(sender, converted);
            }
        } catch (Exception ex) {
            controller.getLogger().log(Level.WARNING, "Error running command: " + command, ex);
        }
    }
    if (opPlayer && !isOp) {
        sender.setOp(false);
    }
    if (!conversationCommands.isEmpty()) {
        runConversations(context, conversationCommands, opPlayer);
    }
    return SpellResult.CAST;
}
Also used : MageController(com.elmakers.mine.bukkit.api.magic.MageController) Mage(com.elmakers.mine.bukkit.api.magic.Mage) CommandSender(org.bukkit.command.CommandSender) ArrayDeque(java.util.ArrayDeque)

Example 20 with CommandSender

use of org.bukkit.command.CommandSender in project MagicPlugin by elBukkit.

the class CountAction method finish.

@Override
public void finish(CastContext context) {
    super.finish(context);
    CommandSender sender = context.getMage().getCommandSender();
    if (sender != null) {
        sender.sendMessage(ChatColor.DARK_AQUA + "Found " + ChatColor.AQUA + totalCount + ChatColor.DARK_AQUA + " targets in the area");
        for (Map.Entry<String, Integer> entry : counts.entrySet()) {
            sender.sendMessage(ChatColor.AQUA + entry.getKey() + ChatColor.WHITE + ": " + ChatColor.GOLD + entry.getValue());
        }
    }
    totalCount = 0;
    counts.clear();
}
Also used : CommandSender(org.bukkit.command.CommandSender) TreeMap(java.util.TreeMap) Map(java.util.Map)

Aggregations

CommandSender (org.bukkit.command.CommandSender)295 Test (org.junit.Test)171 Player (org.bukkit.entity.Player)94 Matchers.containsString (org.hamcrest.Matchers.containsString)68 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)50 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)43 PlayerAuth (fr.xephi.authme.data.auth.PlayerAuth)30 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)29 PermissionNode (fr.xephi.authme.permission.PermissionNode)17 BlockCommandSender (org.bukkit.command.BlockCommandSender)16 ValidationResult (fr.xephi.authme.service.ValidationService.ValidationResult)12 Location (org.bukkit.Location)10 HashedPassword (fr.xephi.authme.security.crypts.HashedPassword)9 ArrayList (java.util.ArrayList)9 List (java.util.List)9 FoundCommandResult (fr.xephi.authme.command.FoundCommandResult)8 IOException (java.io.IOException)7 Entity (org.bukkit.entity.Entity)7 IEssentialsCommand (com.earth2me.essentials.commands.IEssentialsCommand)6 NoChargeException (com.earth2me.essentials.commands.NoChargeException)6