Search in sources :

Example 6 with CommandPermissionsException

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

the class RegionCommands method save.

/**
 * Re-save the region database.
 *
 * @param args the arguments
 * @param sender the sender
 * @throws CommandException any error
 */
@Command(aliases = { "save", "write" }, usage = "[world]", desc = "Re-save regions to file", flags = "w:")
public void save(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 user wants to save all worlds
    }
    // Check permissions
    if (!getPermissionModel(sender).mayForceSaveRegions()) {
        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("Saving region data for '%s'.", world.getName());
        AsyncCommandBuilder.wrap(new RegionManagerSaver(manager), sender).registerWithSupervisor(worldGuard.getSupervisor(), description).sendMessageAfterDelay("Please wait... " + description).onSuccess(String.format("Saving region data for '%s'", world.getName()), null).onFailure(String.format("Failed to save region data for '%s'", world.getName()), worldGuard.getExceptionConverter()).buildAndExec(worldGuard.getExecutorService());
    } else {
        // Save for all worlds
        List<RegionManager> managers = new ArrayList<>();
        final RegionContainer regionContainer = worldGuard.getPlatform().getRegionContainer();
        for (World w : WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getWorlds()) {
            RegionManager manager = regionContainer.get(w);
            if (manager != null) {
                managers.add(manager);
            }
        }
        AsyncCommandBuilder.wrap(new RegionManagerSaver(managers), sender).registerWithSupervisor(worldGuard.getSupervisor(), "Saving regions for all worlds").sendMessageAfterDelay("(Please wait... saving region data for all worlds...)").onSuccess("Successfully saved the region data for all worlds.", null).onFailure("Failed to save regions for all worlds", worldGuard.getExceptionConverter()).buildAndExec(worldGuard.getExecutorService());
    }
}
Also used : RegionManagerSaver(com.sk89q.worldguard.commands.task.RegionManagerSaver) CommandPermissionsException(com.sk89q.minecraft.util.commands.CommandPermissionsException) RegionContainer(com.sk89q.worldguard.protection.regions.RegionContainer) 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 7 with CommandPermissionsException

use of com.sk89q.minecraft.util.commands.CommandPermissionsException 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 8 with CommandPermissionsException

use of com.sk89q.minecraft.util.commands.CommandPermissionsException 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 9 with CommandPermissionsException

use of com.sk89q.minecraft.util.commands.CommandPermissionsException 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 10 with CommandPermissionsException

use of com.sk89q.minecraft.util.commands.CommandPermissionsException 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)

Aggregations

CommandPermissionsException (com.sk89q.minecraft.util.commands.CommandPermissionsException)23 Command (com.sk89q.minecraft.util.commands.Command)22 World (com.sk89q.worldedit.world.World)18 RegionManager (com.sk89q.worldguard.protection.managers.RegionManager)18 CommandException (com.sk89q.minecraft.util.commands.CommandException)16 ProtectedRegion (com.sk89q.worldguard.protection.regions.ProtectedRegion)16 GlobalProtectedRegion (com.sk89q.worldguard.protection.regions.GlobalProtectedRegion)12 LocalPlayer (com.sk89q.worldguard.LocalPlayer)9 RegionPermissionModel (com.sk89q.worldguard.internal.permission.RegionPermissionModel)4 RegionContainer (com.sk89q.worldguard.protection.regions.RegionContainer)4 DomainInputResolver (com.sk89q.worldguard.protection.util.DomainInputResolver)4 RegionAdder (com.sk89q.worldguard.commands.task.RegionAdder)3 MigrationException (com.sk89q.worldguard.protection.managers.migration.MigrationException)3 RegionDriver (com.sk89q.worldguard.protection.managers.storage.RegionDriver)3 LoggerToChatHandler (com.sk89q.worldguard.util.logging.LoggerToChatHandler)3 Logger (java.util.logging.Logger)3 ConfigurationManager (com.sk89q.worldguard.config.ConfigurationManager)2 DefaultDomain (com.sk89q.worldguard.domains.DefaultDomain)2 ProtectedPolygonalRegion (com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion)2 CircularInheritanceException (com.sk89q.worldguard.protection.regions.ProtectedRegion.CircularInheritanceException)2