use of com.sk89q.minecraft.util.commands.Command 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());
}
use of com.sk89q.minecraft.util.commands.Command in project WorldGuard by EngineHub.
the class RegionCommands method remove.
/**
* Remove a region.
*
* @param args the arguments
* @param sender the sender
* @throws CommandException any error
*/
@Command(aliases = { "remove", "delete", "del", "rem" }, usage = "<id>", flags = "fuw:", desc = "Remove a region", min = 1, max = 1)
public void remove(CommandContext args, Actor sender) throws CommandException {
warnAboutSaveFailures(sender);
// Get the world
World world = checkWorld(args, sender, 'w');
boolean removeChildren = args.hasFlag('f');
boolean unsetParent = args.hasFlag('u');
// Lookup the existing region
RegionManager manager = checkRegionManager(world);
ProtectedRegion existing = checkExistingRegion(manager, args.getString(0), true);
// Check permissions
if (!getPermissionModel(sender).mayDelete(existing)) {
throw new CommandPermissionsException();
}
RegionRemover task = new RegionRemover(manager, existing);
if (removeChildren && unsetParent) {
throw new CommandException("You cannot use both -u (unset parent) and -f (remove children) together.");
} else if (removeChildren) {
task.setRemovalStrategy(RemovalStrategy.REMOVE_CHILDREN);
} else if (unsetParent) {
task.setRemovalStrategy(RemovalStrategy.UNSET_PARENT_IN_CHILDREN);
}
final String description = String.format("Removing region '%s' in '%s'", existing.getId(), world.getName());
AsyncCommandBuilder.wrap(task, sender).registerWithSupervisor(WorldGuard.getInstance().getSupervisor(), description).sendMessageAfterDelay("Please wait... removing region.").onSuccess((Component) null, removed -> sender.print(TextComponent.of("Successfully removed " + removed.stream().map(ProtectedRegion::getId).collect(Collectors.joining(", ")) + ".", TextColor.LIGHT_PURPLE))).onFailure("Failed to remove region", WorldGuard.getInstance().getExceptionConverter()).buildAndExec(WorldGuard.getInstance().getExecutorService());
}
use of com.sk89q.minecraft.util.commands.Command in project WorldGuard by EngineHub.
the class RegionCommands method setParent.
/**
* Set the parent of a region.
*
* @param args the arguments
* @param sender the sender
* @throws CommandException any error
*/
@Command(aliases = { "setparent", "parent", "par" }, usage = "<id> [parent-id]", flags = "w:", desc = "Set the parent of a region", min = 1, max = 2)
public void setParent(CommandContext args, Actor sender) throws CommandException {
warnAboutSaveFailures(sender);
// Get the world
World world = checkWorld(args, sender, 'w');
ProtectedRegion parent;
ProtectedRegion child;
// Lookup the existing region
RegionManager manager = checkRegionManager(world);
// Get parent and child
child = checkExistingRegion(manager, args.getString(0), false);
if (args.argsLength() == 2) {
parent = checkExistingRegion(manager, args.getString(1), false);
} else {
parent = null;
}
// Check permissions
if (!getPermissionModel(sender).maySetParent(child, parent)) {
throw new CommandPermissionsException();
}
try {
child.setParent(parent);
} catch (CircularInheritanceException e) {
// Tell the user what's wrong
RegionPrintoutBuilder printout = new RegionPrintoutBuilder(world.getName(), parent, null, sender);
assert parent != null;
printout.append(ErrorFormat.wrap("Uh oh! Setting '", parent.getId(), "' to be the parent of '", child.getId(), "' would cause circular inheritance.")).newline();
printout.append(SubtleFormat.wrap("(Current inheritance on '", parent.getId(), "':")).newline();
printout.appendParentTree(true);
printout.append(SubtleFormat.wrap(")"));
printout.send(sender);
return;
}
// Tell the user the current inheritance
RegionPrintoutBuilder printout = new RegionPrintoutBuilder(world.getName(), child, null, sender);
printout.append(TextComponent.of("Inheritance set for region '" + child.getId() + "'.", TextColor.LIGHT_PURPLE));
if (parent != null) {
printout.newline();
printout.append(SubtleFormat.wrap("(Current inheritance:")).newline();
printout.appendParentTree(true);
printout.append(SubtleFormat.wrap(")"));
} else {
printout.append(LabelFormat.wrap(" Region is now orphaned."));
}
printout.send(sender);
}
use of com.sk89q.minecraft.util.commands.Command in project WorldGuard by EngineHub.
the class DebuggingCommands method fireInteractEvent.
@Command(aliases = { "testinteract" }, usage = "[player]", desc = "Simulate a block interact", min = 1, max = 1, flags = "ts")
@CommandPermissions("worldguard.debug.event")
public void fireInteractEvent(CommandContext args, final Actor sender) throws CommandException {
LocalPlayer target = worldGuard.getPlatform().getMatcher().matchSinglePlayer(sender, args.getString(0));
worldGuard.getPlatform().getDebugHandler().testInteract(sender, target, args.hasFlag('t'), args.hasFlag('s'));
}
use of com.sk89q.minecraft.util.commands.Command in project WorldGuard by EngineHub.
the class DebuggingCommands method fireDamageEvent.
@Command(aliases = { "testdamage" }, usage = "[player]", desc = "Simulate an entity damage", min = 1, max = 1, flags = "ts")
@CommandPermissions("worldguard.debug.event")
public void fireDamageEvent(CommandContext args, final Actor sender) throws CommandException {
LocalPlayer target = worldGuard.getPlatform().getMatcher().matchSinglePlayer(sender, args.getString(0));
worldGuard.getPlatform().getDebugHandler().testDamage(sender, target, args.hasFlag('t'), args.hasFlag('s'));
}
Aggregations