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