Search in sources :

Example 6 with Command

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

the class RegionCommands method select.

/**
 * Get a WorldEdit selection from a region.
 *
 * @param args the arguments
 * @param sender the sender
 * @throws CommandException any error
 */
@Command(aliases = { "select", "sel", "s" }, usage = "[-w <world>] [id]", desc = "Load a region as a WorldEdit selection", min = 0, max = 1, flags = "w:")
public void select(CommandContext args, Actor sender) throws CommandException {
    World world = checkWorld(args, sender, 'w');
    RegionManager manager = checkRegionManager(world);
    ProtectedRegion existing;
    // If no arguments were given, get the region that the player is inside
    if (args.argsLength() == 0) {
        LocalPlayer player = worldGuard.checkPlayer(sender);
        if (!player.getWorld().equals(world)) {
            // just don't allow that
            throw new CommandException("Please specify a region name.");
        }
        world = player.getWorld();
        existing = checkRegionStandingIn(manager, player, "/rg select -w \"" + world.getName() + "\" %id%");
    } else {
        existing = checkExistingRegion(manager, args.getString(0), false);
    }
    // Check permissions
    if (!getPermissionModel(sender).maySelect(existing)) {
        throw new CommandPermissionsException();
    }
    // Select
    setPlayerSelection(sender, existing, world);
}
Also used : CommandPermissionsException(com.sk89q.minecraft.util.commands.CommandPermissionsException) LocalPlayer(com.sk89q.worldguard.LocalPlayer) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) GlobalProtectedRegion(com.sk89q.worldguard.protection.regions.GlobalProtectedRegion) RegionManager(com.sk89q.worldguard.protection.managers.RegionManager) CommandException(com.sk89q.minecraft.util.commands.CommandException) World(com.sk89q.worldedit.world.World) Command(com.sk89q.minecraft.util.commands.Command)

Example 7 with Command

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

the class RegionCommands method flagHelper.

@Command(aliases = "flags", usage = "[-p <page>] [id]", flags = "p:w:", desc = "View region flags", min = 0, max = 2)
public void flagHelper(CommandContext args, Actor sender) throws CommandException {
    // Get the world
    World world = checkWorld(args, sender, 'w');
    // Lookup the existing region
    RegionManager manager = checkRegionManager(world);
    ProtectedRegion region;
    if (args.argsLength() == 0) {
        // Get region from where the player is
        if (!(sender instanceof LocalPlayer)) {
            throw new CommandException("Please specify the region with /region flags -w world_name region_name.");
        }
        region = checkRegionStandingIn(manager, (LocalPlayer) sender, true, "/rg flags -w \"" + world.getName() + "\" %id%");
    } else {
        // Get region from the ID
        region = checkExistingRegion(manager, args.getString(0), true);
    }
    final RegionPermissionModel perms = getPermissionModel(sender);
    if (!perms.mayLookup(region)) {
        throw new CommandPermissionsException();
    }
    int page = args.hasFlag('p') ? args.getFlagInteger('p') : 1;
    sendFlagHelper(sender, world, region, perms, page);
}
Also used : CommandPermissionsException(com.sk89q.minecraft.util.commands.CommandPermissionsException) LocalPlayer(com.sk89q.worldguard.LocalPlayer) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) GlobalProtectedRegion(com.sk89q.worldguard.protection.regions.GlobalProtectedRegion) RegionManager(com.sk89q.worldguard.protection.managers.RegionManager) RegionPermissionModel(com.sk89q.worldguard.internal.permission.RegionPermissionModel) CommandException(com.sk89q.minecraft.util.commands.CommandException) World(com.sk89q.worldedit.world.World) Command(com.sk89q.minecraft.util.commands.Command)

Example 8 with Command

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

the class RegionCommands method setPriority.

/**
 * Set the priority of a region.
 *
 * @param args the arguments
 * @param sender the sender
 * @throws CommandException any error
 */
@Command(aliases = { "setpriority", "priority", "pri" }, usage = "<id> <priority>", flags = "w:", desc = "Set the priority of a region", min = 2, max = 2)
public void setPriority(CommandContext args, Actor sender) throws CommandException {
    warnAboutSaveFailures(sender);
    // Get the world
    World world = checkWorld(args, sender, 'w');
    int priority = args.getInteger(1);
    // Lookup the existing region
    RegionManager manager = checkRegionManager(world);
    ProtectedRegion existing = checkExistingRegion(manager, args.getString(0), false);
    // Check permissions
    if (!getPermissionModel(sender).maySetPriority(existing)) {
        throw new CommandPermissionsException();
    }
    existing.setPriority(priority);
    sender.print("Priority of '" + existing.getId() + "' set to " + priority + " (higher numbers override).");
    checkSpawnOverlap(sender, world, existing);
}
Also used : CommandPermissionsException(com.sk89q.minecraft.util.commands.CommandPermissionsException) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) GlobalProtectedRegion(com.sk89q.worldguard.protection.regions.GlobalProtectedRegion) RegionManager(com.sk89q.worldguard.protection.managers.RegionManager) World(com.sk89q.worldedit.world.World) Command(com.sk89q.minecraft.util.commands.Command)

Example 9 with Command

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

the class RegionCommands method load.

/**
 * Reload the region database.
 *
 * @param args the arguments
 * @param sender the sender
 * @throws CommandException any error
 */
@Command(aliases = { "load", "reload" }, usage = "[world]", desc = "Reload regions from file", flags = "w:")
public void load(CommandContext args, final Actor sender) throws CommandException {
    warnAboutSaveFailures(sender);
    World world = null;
    try {
        // Get the world
        world = checkWorld(args, sender, 'w');
    } catch (CommandException ignored) {
    // assume the user wants to reload all worlds
    }
    // Check permissions
    if (!getPermissionModel(sender).mayForceLoadRegions()) {
        throw new CommandPermissionsException();
    }
    if (world != null) {
        RegionManager manager = checkRegionManager(world);
        if (manager == null) {
            throw new CommandException("No region manager exists for world '" + world.getName() + "'.");
        }
        final String description = String.format("Loading region data for '%s'.", world.getName());
        AsyncCommandBuilder.wrap(new RegionManagerLoader(manager), sender).registerWithSupervisor(worldGuard.getSupervisor(), description).sendMessageAfterDelay("Please wait... " + description).onSuccess(String.format("Loaded region data for '%s'", world.getName()), null).onFailure(String.format("Failed to load region data for '%s'", world.getName()), worldGuard.getExceptionConverter()).buildAndExec(worldGuard.getExecutorService());
    } else {
        // Load regions for all worlds
        List<RegionManager> managers = new ArrayList<>();
        for (World w : WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getWorlds()) {
            RegionManager manager = WorldGuard.getInstance().getPlatform().getRegionContainer().get(w);
            if (manager != null) {
                managers.add(manager);
            }
        }
        AsyncCommandBuilder.wrap(new RegionManagerLoader(managers), sender).registerWithSupervisor(worldGuard.getSupervisor(), "Loading regions for all worlds").sendMessageAfterDelay("(Please wait... loading region data for all worlds...)").onSuccess("Successfully load the region data for all worlds.", null).onFailure("Failed to load regions for all worlds", worldGuard.getExceptionConverter()).buildAndExec(worldGuard.getExecutorService());
    }
}
Also used : RegionManagerLoader(com.sk89q.worldguard.commands.task.RegionManagerLoader) CommandPermissionsException(com.sk89q.minecraft.util.commands.CommandPermissionsException) ArrayList(java.util.ArrayList) RegionManager(com.sk89q.worldguard.protection.managers.RegionManager) CommandException(com.sk89q.minecraft.util.commands.CommandException) World(com.sk89q.worldedit.world.World) Command(com.sk89q.minecraft.util.commands.Command)

Example 10 with Command

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

the class RegionCommands method toggleBypass.

@Command(aliases = { "toggle-bypass", "bypass" }, usage = "[on|off]", desc = "Toggle region bypassing, effectively ignoring bypass permissions.")
public void toggleBypass(CommandContext args, Actor sender) throws CommandException {
    LocalPlayer player = worldGuard.checkPlayer(sender);
    if (!player.hasPermission("worldguard.region.toggle-bypass")) {
        throw new CommandPermissionsException();
    }
    Session session = WorldGuard.getInstance().getPlatform().getSessionManager().get(player);
    boolean shouldEnableBypass;
    if (args.argsLength() > 0) {
        String arg1 = args.getString(0);
        if (!arg1.equalsIgnoreCase("on") && !arg1.equalsIgnoreCase("off")) {
            throw new CommandException("Allowed optional arguments are: on, off");
        }
        shouldEnableBypass = arg1.equalsIgnoreCase("on");
    } else {
        shouldEnableBypass = session.hasBypassDisabled();
    }
    if (shouldEnableBypass) {
        session.setBypassDisabled(false);
        player.print("You are now bypassing region protection (as long as you have permission).");
    } else {
        session.setBypassDisabled(true);
        player.print("You are no longer bypassing region protection.");
    }
}
Also used : CommandPermissionsException(com.sk89q.minecraft.util.commands.CommandPermissionsException) LocalPlayer(com.sk89q.worldguard.LocalPlayer) CommandException(com.sk89q.minecraft.util.commands.CommandException) Session(com.sk89q.worldguard.session.Session) 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