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());
}
Aggregations