Search in sources :

Example 41 with Command

use of com.sk89q.minecraft.util.commands.Command in project WorldGuard by EngineHub.

the class GeneralCommands method slay.

@Command(aliases = { "slay" }, usage = "[player]", desc = "Slay a player", flags = "s", max = 1)
public void slay(CommandContext args, Actor sender) throws CommandException, AuthorizationException {
    Iterable<? extends LocalPlayer> targets = Lists.newArrayList();
    boolean included = false;
    // Detect arguments based on the number of arguments provided
    if (args.argsLength() == 0) {
        targets = worldGuard.getPlatform().getMatcher().matchPlayers(worldGuard.checkPlayer(sender));
        // Check permissions!
        sender.checkPermission("worldguard.slay");
    } else if (args.argsLength() == 1) {
        targets = worldGuard.getPlatform().getMatcher().matchPlayers(sender, args.getString(0));
        // Check permissions!
        sender.checkPermission("worldguard.slay.other");
    }
    for (LocalPlayer player : targets) {
        player.setHealth(0);
        // Tell the user
        if (player.equals(sender)) {
            player.print("Slain!");
            // Keep track of this
            included = true;
        } else {
            player.print("Slain by " + sender.getDisplayName() + ".");
        }
    }
    // user a message so s/he know that something is indeed working
    if (!included && args.hasFlag('s')) {
        sender.print("Players slain.");
    }
}
Also used : LocalPlayer(com.sk89q.worldguard.LocalPlayer) Command(com.sk89q.minecraft.util.commands.Command)

Aggregations

Command (com.sk89q.minecraft.util.commands.Command)41 LocalPlayer (com.sk89q.worldguard.LocalPlayer)24 World (com.sk89q.worldedit.world.World)23 CommandPermissionsException (com.sk89q.minecraft.util.commands.CommandPermissionsException)22 CommandException (com.sk89q.minecraft.util.commands.CommandException)18 RegionManager (com.sk89q.worldguard.protection.managers.RegionManager)18 ProtectedRegion (com.sk89q.worldguard.protection.regions.ProtectedRegion)16 CommandPermissions (com.sk89q.minecraft.util.commands.CommandPermissions)15 GlobalProtectedRegion (com.sk89q.worldguard.protection.regions.GlobalProtectedRegion)12 NestedCommand (com.sk89q.minecraft.util.commands.NestedCommand)5 ConfigurationManager (com.sk89q.worldguard.config.ConfigurationManager)5 LoggerToChatHandler (com.sk89q.worldguard.util.logging.LoggerToChatHandler)5 Logger (java.util.logging.Logger)5 RegionPermissionModel (com.sk89q.worldguard.internal.permission.RegionPermissionModel)4 TextComponent (com.sk89q.worldedit.util.formatting.text.TextComponent)3 FutureForwardingTask (com.sk89q.worldedit.util.task.FutureForwardingTask)3 Task (com.sk89q.worldedit.util.task.Task)3 RegionAdder (com.sk89q.worldguard.commands.task.RegionAdder)3 WorldConfiguration (com.sk89q.worldguard.config.WorldConfiguration)3 RegionContainer (com.sk89q.worldguard.protection.regions.RegionContainer)3