Search in sources :

Example 31 with Command

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());
}
Also used : RegionAdder(com.sk89q.worldguard.commands.task.RegionAdder) GlobalProtectedRegion(com.sk89q.worldguard.protection.regions.GlobalProtectedRegion) 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)

Example 32 with Command

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());
}
Also used : RegionRemover(com.sk89q.worldguard.commands.task.RegionRemover) 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) CommandException(com.sk89q.minecraft.util.commands.CommandException) World(com.sk89q.worldedit.world.World) Command(com.sk89q.minecraft.util.commands.Command)

Example 33 with Command

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);
}
Also used : CircularInheritanceException(com.sk89q.worldguard.protection.regions.ProtectedRegion.CircularInheritanceException) 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)

Example 34 with Command

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'));
}
Also used : LocalPlayer(com.sk89q.worldguard.LocalPlayer) Command(com.sk89q.minecraft.util.commands.Command) CommandPermissions(com.sk89q.minecraft.util.commands.CommandPermissions)

Example 35 with Command

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'));
}
Also used : LocalPlayer(com.sk89q.worldguard.LocalPlayer) Command(com.sk89q.minecraft.util.commands.Command) CommandPermissions(com.sk89q.minecraft.util.commands.CommandPermissions)

Aggregations

Command (com.sk89q.minecraft.util.commands.Command)41 LocalPlayer (com.sk89q.worldguard.LocalPlayer)24 World (com.sk89q.worldedit.world.World)23 CommandPermissionsException (com.sk89q.minecraft.util.commands.CommandPermissionsException)22 CommandException (com.sk89q.minecraft.util.commands.CommandException)18 RegionManager (com.sk89q.worldguard.protection.managers.RegionManager)18 ProtectedRegion (com.sk89q.worldguard.protection.regions.ProtectedRegion)16 CommandPermissions (com.sk89q.minecraft.util.commands.CommandPermissions)15 GlobalProtectedRegion (com.sk89q.worldguard.protection.regions.GlobalProtectedRegion)12 NestedCommand (com.sk89q.minecraft.util.commands.NestedCommand)5 ConfigurationManager (com.sk89q.worldguard.config.ConfigurationManager)5 LoggerToChatHandler (com.sk89q.worldguard.util.logging.LoggerToChatHandler)5 Logger (java.util.logging.Logger)5 RegionPermissionModel (com.sk89q.worldguard.internal.permission.RegionPermissionModel)4 TextComponent (com.sk89q.worldedit.util.formatting.text.TextComponent)3 FutureForwardingTask (com.sk89q.worldedit.util.task.FutureForwardingTask)3 Task (com.sk89q.worldedit.util.task.Task)3 RegionAdder (com.sk89q.worldguard.commands.task.RegionAdder)3 WorldConfiguration (com.sk89q.worldguard.config.WorldConfiguration)3 RegionContainer (com.sk89q.worldguard.protection.regions.RegionContainer)3