use of com.sk89q.worldguard.commands.task.RegionAdder in project WorldGuard by EngineHub.
the class RegionCommands method redefine.
/**
* Re-defines a region with a new selection.
*
* @param args the arguments
* @param sender the sender
* @throws CommandException any error
*/
@Command(aliases = { "redefine", "update", "move" }, usage = "[-w <world>] <id>", desc = "Re-defines the shape of a region", flags = "gw:", min = 1, max = 1)
public void redefine(CommandContext args, Actor sender) throws CommandException {
warnAboutSaveFailures(sender);
String id = checkRegionId(args.getString(0), false);
World world = checkWorld(args, sender, 'w');
RegionManager manager = checkRegionManager(world);
ProtectedRegion existing = checkExistingRegion(manager, id, false);
// Check permissions
if (!getPermissionModel(sender).mayRedefine(existing)) {
throw new CommandPermissionsException();
}
ProtectedRegion region;
if (args.hasFlag('g')) {
region = new GlobalProtectedRegion(id);
} else {
region = checkRegionFromSelection(sender, id);
}
region.copyFrom(existing);
RegionAdder task = new RegionAdder(manager, region);
final String description = String.format("Updating region '%s'", region.getId());
AsyncCommandBuilder.wrap(task, sender).registerWithSupervisor(worldGuard.getSupervisor(), description).sendMessageAfterDelay("(Please wait... " + description + ")").onSuccess((Component) null, t -> {
sender.print(String.format("Region '%s' has been updated with a new area.", region.getId()));
warnAboutDimensions(sender, region);
informNewUser(sender, manager, region);
checkSpawnOverlap(sender, world, region);
}).onFailure(String.format("Failed to update the region '%s'", region.getId()), worldGuard.getExceptionConverter()).buildAndExec(worldGuard.getExecutorService());
}
use of com.sk89q.worldguard.commands.task.RegionAdder in project WorldGuard by EngineHub.
the class RegionCommands method claim.
/**
* Claiming command for users.
*
* <p>This command is a joke and it needs to be rewritten. It was contributed
* code :(</p>
*
* @param args the arguments
* @param sender the sender
* @throws CommandException any error
*/
@Command(aliases = { "claim" }, usage = "<id>", desc = "Claim a region", min = 1, max = 1)
public void claim(CommandContext args, Actor sender) throws CommandException {
warnAboutSaveFailures(sender);
LocalPlayer player = worldGuard.checkPlayer(sender);
RegionPermissionModel permModel = getPermissionModel(player);
// Check permissions
if (!permModel.mayClaim()) {
throw new CommandPermissionsException();
}
String id = checkRegionId(args.getString(0), false);
RegionManager manager = checkRegionManager(player.getWorld());
checkRegionDoesNotExist(manager, id, false);
ProtectedRegion region = checkRegionFromSelection(player, id);
WorldConfiguration wcfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager().get(player.getWorld());
// Check whether the player has created too many regions
if (!permModel.mayClaimRegionsUnbounded()) {
int maxRegionCount = wcfg.getMaxRegionCount(player);
if (maxRegionCount >= 0 && manager.getRegionCountOfPlayer(player) >= maxRegionCount) {
throw new CommandException("You own too many regions, delete one first to claim a new one.");
}
}
ProtectedRegion existing = manager.getRegion(id);
// Check for an existing region
if (existing != null) {
if (!existing.getOwners().contains(player)) {
throw new CommandException("This region already exists and you don't own it.");
}
}
// We have to check whether this region violates the space of any other region
ApplicableRegionSet regions = manager.getApplicableRegions(region);
// Check if this region overlaps any other region
if (regions.size() > 0) {
if (!regions.isOwnerOfAll(player)) {
throw new CommandException("This region overlaps with someone else's region.");
}
} else {
if (wcfg.claimOnlyInsideExistingRegions) {
throw new CommandException("You may only claim regions inside " + "existing regions that you or your group own.");
}
}
if (wcfg.maxClaimVolume >= Integer.MAX_VALUE) {
throw new CommandException("The maximum claim volume get in the configuration is higher than is supported. " + "Currently, it must be " + Integer.MAX_VALUE + " or smaller. Please contact a server administrator.");
}
// Check claim volume
if (!permModel.mayClaimRegionsUnbounded()) {
if (region instanceof ProtectedPolygonalRegion) {
throw new CommandException("Polygons are currently not supported for /rg claim.");
}
if (region.volume() > wcfg.maxClaimVolume) {
player.printError("This region is too large to claim.");
player.printError("Max. volume: " + wcfg.maxClaimVolume + ", your volume: " + region.volume());
return;
}
}
// Inherit from a template region
if (!Strings.isNullOrEmpty(wcfg.setParentOnClaim)) {
ProtectedRegion templateRegion = manager.getRegion(wcfg.setParentOnClaim);
if (templateRegion != null) {
try {
region.setParent(templateRegion);
} catch (CircularInheritanceException e) {
throw new CommandException(e.getMessage());
}
}
}
RegionAdder task = new RegionAdder(manager, region);
task.setLocatorPolicy(UserLocatorPolicy.UUID_ONLY);
task.setOwnersInput(new String[] { player.getName() });
final String description = String.format("Claiming region '%s'", id);
AsyncCommandBuilder.wrap(task, sender).registerWithSupervisor(WorldGuard.getInstance().getSupervisor(), description).sendMessageAfterDelay("(Please wait... " + description + ")").onSuccess(TextComponent.of(String.format("A new region has been claimed named '%s'.", id)), null).onFailure("Failed to claim region", WorldGuard.getInstance().getExceptionConverter()).buildAndExec(WorldGuard.getInstance().getExecutorService());
}
use of com.sk89q.worldguard.commands.task.RegionAdder in project WorldGuard by EngineHub.
the class RegionCommands method define.
/**
* Defines a new region.
*
* @param args the arguments
* @param sender the sender
* @throws CommandException any error
*/
@Command(aliases = { "define", "def", "d", "create" }, usage = "[-w <world>] <id> [<owner1> [<owner2> [<owners...>]]]", flags = "ngw:", desc = "Defines a region", min = 1)
public void define(CommandContext args, Actor sender) throws CommandException {
warnAboutSaveFailures(sender);
// Check permissions
if (!getPermissionModel(sender).mayDefine()) {
throw new CommandPermissionsException();
}
String id = checkRegionId(args.getString(0), false);
World world = checkWorld(args, sender, 'w');
RegionManager manager = checkRegionManager(world);
checkRegionDoesNotExist(manager, id, true);
ProtectedRegion region;
if (args.hasFlag('g')) {
region = new GlobalProtectedRegion(id);
} else {
region = checkRegionFromSelection(sender, id);
}
RegionAdder task = new RegionAdder(manager, region);
task.addOwnersFromCommand(args, 2);
final String description = String.format("Adding region '%s'", region.getId());
AsyncCommandBuilder.wrap(task, sender).registerWithSupervisor(worldGuard.getSupervisor(), description).onSuccess((Component) null, t -> {
sender.print(String.format("A new region has been made named '%s'.", region.getId()));
warnAboutDimensions(sender, region);
informNewUser(sender, manager, region);
checkSpawnOverlap(sender, world, region);
}).onFailure(String.format("Failed to add the region '%s'", region.getId()), worldGuard.getExceptionConverter()).buildAndExec(worldGuard.getExecutorService());
}
Aggregations