Search in sources :

Example 1 with DomainInputResolver

use of com.sk89q.worldguard.protection.util.DomainInputResolver 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 2 with DomainInputResolver

use of com.sk89q.worldguard.protection.util.DomainInputResolver 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 3 with DomainInputResolver

use of com.sk89q.worldguard.protection.util.DomainInputResolver 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 4 with DomainInputResolver

use of com.sk89q.worldguard.protection.util.DomainInputResolver in project WorldGuard by EngineHub.

the class MemberCommands method removeOwner.

@Command(aliases = { "removeowner", "remowner", "ro" }, usage = "<id> <owners...>", flags = "naw:", desc = "Remove an owner to a region", min = 1)
public void removeOwner(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).mayRemoveOwners(region)) {
        throw new CommandPermissionsException();
    }
    Callable<DefaultDomain> callable;
    if (args.hasFlag('a')) {
        callable = region::getOwners;
    } else {
        if (args.argsLength() < 2) {
            throw new CommandException("List some names to remove, or use -a to remove all.");
        }
        // Resolve owners 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 owners 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 owners removed.", region.getId()), region.getOwners()::removeAll).onFailure("Failed to remove 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) 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 5 with DomainInputResolver

use of com.sk89q.worldguard.protection.util.DomainInputResolver in project WorldGuard by EngineHub.

the class RegionAdder method call.

@Override
public ProtectedRegion call() throws Exception {
    if (ownersInput != null) {
        DomainInputResolver resolver = new DomainInputResolver(WorldGuard.getInstance().getProfileService(), ownersInput);
        resolver.setLocatorPolicy(locatorPolicy);
        DefaultDomain domain = resolver.call();
        region.getOwners().addAll(domain);
    }
    manager.addRegion(region);
    return region;
}
Also used : DomainInputResolver(com.sk89q.worldguard.protection.util.DomainInputResolver) DefaultDomain(com.sk89q.worldguard.domains.DefaultDomain)

Aggregations

DomainInputResolver (com.sk89q.worldguard.protection.util.DomainInputResolver)5 Command (com.sk89q.minecraft.util.commands.Command)4 CommandPermissionsException (com.sk89q.minecraft.util.commands.CommandPermissionsException)4 World (com.sk89q.worldedit.world.World)4 RegionManager (com.sk89q.worldguard.protection.managers.RegionManager)4 ProtectedRegion (com.sk89q.worldguard.protection.regions.ProtectedRegion)4 DefaultDomain (com.sk89q.worldguard.domains.DefaultDomain)3 CommandException (com.sk89q.minecraft.util.commands.CommandException)2