Search in sources :

Example 1 with Command

use of com.sk89q.minecraft.util.commands.Command in project FastAsyncWorldEdit by IntellectualSites.

the class CommandsManagerRegistration method registerAll.

public boolean registerAll(List<Command> registered) {
    List<CommandInfo> toRegister = new ArrayList<>();
    for (Command command : registered) {
        List<String> permissions = null;
        Method cmdMethod = commands.getMethods().get(null).get(command.aliases()[0]);
        Map<String, Method> childMethods = commands.getMethods().get(cmdMethod);
        if (cmdMethod != null && cmdMethod.isAnnotationPresent(CommandPermissions.class)) {
            permissions = Arrays.asList(cmdMethod.getAnnotation(CommandPermissions.class).value());
        } else if (cmdMethod != null && childMethods != null && !childMethods.isEmpty()) {
            permissions = new ArrayList<>();
            for (Method m : childMethods.values()) {
                if (m.isAnnotationPresent(CommandPermissions.class)) {
                    permissions.addAll(Arrays.asList(m.getAnnotation(CommandPermissions.class).value()));
                }
            }
        }
        toRegister.add(new CommandInfo(command.usage(), command.desc(), command.aliases(), commands, permissions == null ? null : permissions.toArray(new String[permissions.size()])));
    }
    return register(toRegister);
}
Also used : Command(com.sk89q.minecraft.util.commands.Command) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) CommandPermissions(com.sk89q.minecraft.util.commands.CommandPermissions)

Example 2 with Command

use of com.sk89q.minecraft.util.commands.Command in project WorldGuard by EngineHub.

the class MemberCommands method removeMember.

@Command(aliases = { "removemember", "remmember", "removemem", "remmem", "rm" }, usage = "<id> <owners...>", flags = "naw:", desc = "Remove an owner to a region", min = 1)
public void removeMember(CommandContext args, Actor sender) throws CommandException {
    warnAboutSaveFailures(sender);
    // Get the world
    World world = checkWorld(args, sender, 'w');
    String id = args.getString(0);
    RegionManager manager = checkRegionManager(world);
    ProtectedRegion region = checkExistingRegion(manager, id, true);
    // Check permissions
    if (!getPermissionModel(sender).mayRemoveMembers(region)) {
        throw new CommandPermissionsException();
    }
    Callable<DefaultDomain> callable;
    if (args.hasFlag('a')) {
        callable = region::getMembers;
    } else {
        if (args.argsLength() < 2) {
            throw new CommandException("List some names to remove, or use -a to remove all.");
        }
        // Resolve members asynchronously
        DomainInputResolver resolver = new DomainInputResolver(WorldGuard.getInstance().getProfileService(), args.getParsedPaddedSlice(1, 0));
        resolver.setLocatorPolicy(args.hasFlag('n') ? UserLocatorPolicy.NAME_ONLY : UserLocatorPolicy.UUID_AND_NAME);
        callable = resolver;
    }
    final String description = String.format("Removing members from the region '%s' on '%s'", region.getId(), world.getName());
    AsyncCommandBuilder.wrap(callable, sender).registerWithSupervisor(worldGuard.getSupervisor(), description).sendMessageAfterDelay("(Please wait... querying player names...)").onSuccess(String.format("Region '%s' updated with members removed.", region.getId()), region.getMembers()::removeAll).onFailure("Failed to remove members", worldGuard.getExceptionConverter()).buildAndExec(worldGuard.getExecutorService());
}
Also used : DomainInputResolver(com.sk89q.worldguard.protection.util.DomainInputResolver) CommandPermissionsException(com.sk89q.minecraft.util.commands.CommandPermissionsException) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) RegionManager(com.sk89q.worldguard.protection.managers.RegionManager) CommandException(com.sk89q.minecraft.util.commands.CommandException) World(com.sk89q.worldedit.world.World) DefaultDomain(com.sk89q.worldguard.domains.DefaultDomain) Command(com.sk89q.minecraft.util.commands.Command)

Example 3 with Command

use of com.sk89q.minecraft.util.commands.Command in project WorldGuard by EngineHub.

the class MemberCommands method addMember.

@Command(aliases = { "addmember", "addmember", "addmem", "am" }, usage = "<id> <members...>", flags = "nw:", desc = "Add a member to a region", min = 2)
public void addMember(CommandContext args, Actor sender) throws CommandException {
    warnAboutSaveFailures(sender);
    // Get the world
    World world = checkWorld(args, sender, 'w');
    String id = args.getString(0);
    RegionManager manager = checkRegionManager(world);
    ProtectedRegion region = checkExistingRegion(manager, id, true);
    // Check permissions
    if (!getPermissionModel(sender).mayAddMembers(region)) {
        throw new CommandPermissionsException();
    }
    // Resolve members asynchronously
    DomainInputResolver resolver = new DomainInputResolver(WorldGuard.getInstance().getProfileService(), args.getParsedPaddedSlice(1, 0));
    resolver.setLocatorPolicy(args.hasFlag('n') ? UserLocatorPolicy.NAME_ONLY : UserLocatorPolicy.UUID_ONLY);
    final String description = String.format("Adding members to the region '%s' on '%s'", region.getId(), world.getName());
    AsyncCommandBuilder.wrap(resolver, sender).registerWithSupervisor(worldGuard.getSupervisor(), description).onSuccess(String.format("Region '%s' updated with new members.", region.getId()), region.getMembers()::addAll).onFailure("Failed to add new members", worldGuard.getExceptionConverter()).buildAndExec(worldGuard.getExecutorService());
}
Also used : DomainInputResolver(com.sk89q.worldguard.protection.util.DomainInputResolver) CommandPermissionsException(com.sk89q.minecraft.util.commands.CommandPermissionsException) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) RegionManager(com.sk89q.worldguard.protection.managers.RegionManager) World(com.sk89q.worldedit.world.World) Command(com.sk89q.minecraft.util.commands.Command)

Example 4 with Command

use of com.sk89q.minecraft.util.commands.Command in project WorldGuard by EngineHub.

the class MemberCommands method addOwner.

@Command(aliases = { "addowner", "addowner", "ao" }, usage = "<id> <owners...>", flags = "nw:", desc = "Add an owner to a region", min = 2)
public void addOwner(CommandContext args, Actor sender) throws CommandException {
    warnAboutSaveFailures(sender);
    // Get the world
    World world = checkWorld(args, sender, 'w');
    String id = args.getString(0);
    RegionManager manager = checkRegionManager(world);
    ProtectedRegion region = checkExistingRegion(manager, id, true);
    // Check permissions
    if (!getPermissionModel(sender).mayAddOwners(region)) {
        throw new CommandPermissionsException();
    }
    // Resolve owners asynchronously
    DomainInputResolver resolver = new DomainInputResolver(WorldGuard.getInstance().getProfileService(), args.getParsedPaddedSlice(1, 0));
    resolver.setLocatorPolicy(args.hasFlag('n') ? UserLocatorPolicy.NAME_ONLY : UserLocatorPolicy.UUID_ONLY);
    final String description = String.format("Adding owners to the region '%s' on '%s'", region.getId(), world.getName());
    AsyncCommandBuilder.wrap(checkedAddOwners(sender, manager, region, world, resolver), sender).registerWithSupervisor(worldGuard.getSupervisor(), description).onSuccess(String.format("Region '%s' updated with new owners.", region.getId()), region.getOwners()::addAll).onFailure("Failed to add new owners", worldGuard.getExceptionConverter()).buildAndExec(worldGuard.getExecutorService());
}
Also used : DomainInputResolver(com.sk89q.worldguard.protection.util.DomainInputResolver) CommandPermissionsException(com.sk89q.minecraft.util.commands.CommandPermissionsException) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) RegionManager(com.sk89q.worldguard.protection.managers.RegionManager) World(com.sk89q.worldedit.world.World) Command(com.sk89q.minecraft.util.commands.Command)

Example 5 with Command

use of com.sk89q.minecraft.util.commands.Command 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());
}
Also used : RegionLister(com.sk89q.worldguard.commands.task.RegionLister) 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)

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