Search in sources :

Example 1 with RegionLister

use of com.sk89q.worldguard.commands.task.RegionLister in project WorldGuard by EngineHub.

the class RegionCommands method list.

/**
 * List regions.
 *
 * @param args the arguments
 * @param sender the sender
 * @throws CommandException any error
 */
@Command(aliases = { "list" }, usage = "[-w world] [-p owner [-n]] [-s] [-i filter] [page]", desc = "Get a list of regions", flags = "np:w:i:s", max = 1)
public void list(CommandContext args, Actor sender) throws CommandException {
    warnAboutSaveFailures(sender);
    // Get the world
    World world = checkWorld(args, sender, 'w');
    String ownedBy;
    // Get page
    int page = args.getInteger(0, 1);
    if (page < 1) {
        page = 1;
    }
    // -p flag to lookup a player's regions
    if (args.hasFlag('p')) {
        ownedBy = args.getFlag('p');
    } else {
        // List all regions
        ownedBy = null;
    }
    // Check permissions
    if (!getPermissionModel(sender).mayList(ownedBy)) {
        // assume they only want their own
        ownedBy = sender.getName();
        if (!getPermissionModel(sender).mayList(ownedBy)) {
            throw new CommandPermissionsException();
        }
    }
    RegionManager manager = checkRegionManager(world);
    RegionLister task = new RegionLister(manager, sender, world.getName());
    task.setPage(page);
    if (ownedBy != null) {
        task.filterOwnedByName(ownedBy, args.hasFlag('n'));
    }
    if (args.hasFlag('s')) {
        ProtectedRegion existing = checkRegionFromSelection(sender, "tmp");
        task.filterByIntersecting(existing);
    }
    // -i string is in region id
    if (args.hasFlag('i')) {
        task.filterIdByMatch(args.getFlag('i'));
    }
    AsyncCommandBuilder.wrap(task, sender).registerWithSupervisor(WorldGuard.getInstance().getSupervisor(), "Getting region list").sendMessageAfterDelay("(Please wait... fetching region list...)").onFailure("Failed to fetch region list", WorldGuard.getInstance().getExceptionConverter()).buildAndExec(WorldGuard.getInstance().getExecutorService());
}
Also used : RegionLister(com.sk89q.worldguard.commands.task.RegionLister) 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)

Aggregations

Command (com.sk89q.minecraft.util.commands.Command)1 CommandPermissionsException (com.sk89q.minecraft.util.commands.CommandPermissionsException)1 World (com.sk89q.worldedit.world.World)1 RegionLister (com.sk89q.worldguard.commands.task.RegionLister)1 RegionManager (com.sk89q.worldguard.protection.managers.RegionManager)1 GlobalProtectedRegion (com.sk89q.worldguard.protection.regions.GlobalProtectedRegion)1 ProtectedRegion (com.sk89q.worldguard.protection.regions.ProtectedRegion)1