Search in sources :

Example 1 with CommandPermissionsException

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

the class BukkitDebugHandler method testEvent.

/**
 * Simulate an event and print its report.
 *
 * @param receiver The receiver of the messages
 * @param target The target
 * @param event The event
 * @param stacktraceMode Whether stack traces should be generated and posted
 * @param <T> The type of event
 */
private <T extends Event & CancelLogging> void testEvent(CommandSender receiver, Player target, T event, boolean stacktraceMode) throws CommandPermissionsException {
    boolean isConsole = receiver instanceof ConsoleCommandSender;
    if (!receiver.equals(target)) {
        if (!isConsole) {
            log.info(receiver.getName() + " is simulating an event on " + target.getName());
        }
        target.sendMessage(ChatColor.RED + "(Please ignore any messages that may immediately follow.)");
    }
    Bukkit.getPluginManager().callEvent(event);
    int start = new Exception().getStackTrace().length;
    CancelReport report = new CancelReport(event, event.getCancels(), start);
    report.setDetectingPlugin(!stacktraceMode);
    String result = report.toString();
    if (stacktraceMode) {
        receiver.sendMessage(ChatColor.GRAY + "The report was printed to console.");
        log.info("Event report for " + receiver.getName() + ":\n\n" + result);
        plugin.checkPermission(receiver, "worldguard.debug.pastebin");
        ActorCallbackPaste.pastebin(WorldGuard.getInstance().getSupervisor(), plugin.wrapCommandSender(receiver), result, "Event debugging report: %s.txt");
    } else {
        receiver.sendMessage(result.replaceAll("(?m)^", ChatColor.AQUA.toString()));
        if (result.length() >= 500 && !isConsole) {
            receiver.sendMessage(ChatColor.GRAY + "The report was also printed to console.");
            log.info("Event report for " + receiver.getName() + ":\n\n" + result);
        }
    }
}
Also used : CancelReport(com.sk89q.worldguard.bukkit.util.report.CancelReport) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender) CommandPermissionsException(com.sk89q.minecraft.util.commands.CommandPermissionsException) CommandException(com.sk89q.minecraft.util.commands.CommandException)

Example 2 with CommandPermissionsException

use of com.sk89q.minecraft.util.commands.CommandPermissionsException 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 CommandPermissionsException

use of com.sk89q.minecraft.util.commands.CommandPermissionsException 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 CommandPermissionsException

use of com.sk89q.minecraft.util.commands.CommandPermissionsException 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 CommandPermissionsException

use of com.sk89q.minecraft.util.commands.CommandPermissionsException 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

CommandPermissionsException (com.sk89q.minecraft.util.commands.CommandPermissionsException)23 Command (com.sk89q.minecraft.util.commands.Command)22 World (com.sk89q.worldedit.world.World)18 RegionManager (com.sk89q.worldguard.protection.managers.RegionManager)18 CommandException (com.sk89q.minecraft.util.commands.CommandException)16 ProtectedRegion (com.sk89q.worldguard.protection.regions.ProtectedRegion)16 GlobalProtectedRegion (com.sk89q.worldguard.protection.regions.GlobalProtectedRegion)12 LocalPlayer (com.sk89q.worldguard.LocalPlayer)9 RegionPermissionModel (com.sk89q.worldguard.internal.permission.RegionPermissionModel)4 RegionContainer (com.sk89q.worldguard.protection.regions.RegionContainer)4 DomainInputResolver (com.sk89q.worldguard.protection.util.DomainInputResolver)4 RegionAdder (com.sk89q.worldguard.commands.task.RegionAdder)3 MigrationException (com.sk89q.worldguard.protection.managers.migration.MigrationException)3 RegionDriver (com.sk89q.worldguard.protection.managers.storage.RegionDriver)3 LoggerToChatHandler (com.sk89q.worldguard.util.logging.LoggerToChatHandler)3 Logger (java.util.logging.Logger)3 ConfigurationManager (com.sk89q.worldguard.config.ConfigurationManager)2 DefaultDomain (com.sk89q.worldguard.domains.DefaultDomain)2 ProtectedPolygonalRegion (com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion)2 CircularInheritanceException (com.sk89q.worldguard.protection.regions.ProtectedRegion.CircularInheritanceException)2