protected void checkPermission(T player, Method method) throws CommandException { if (!hasPermission(method, player)) { throw new CommandPermissionsException(); } }
} else { throw new CommandPermissionsException();
@Override public Object call(String arguments, CommandLocals locals, String[] parentCommands) throws CommandException { // We have permission for this command if we have permissions for subcommands if (parentCommands.length != 0 && !testPermission(locals)) { throw new CommandPermissionsException(); } String[] split = CommandContext.split(arguments); Set<String> aliases = getPrimaryAliases(); if (aliases.isEmpty()) { throw new InvalidUsageException("This command has no sub-commands.", this); } else if (split.length > 0) { String subCommand = split[0]; String subArguments = Joiner.on(" ").join(Arrays.copyOfRange(split, 1, split.length)); String[] subParents = Arrays.copyOf(parentCommands, parentCommands.length + 1); subParents[parentCommands.length] = subCommand; CommandMapping mapping = get(subCommand); if (mapping != null) { try { return mapping.getCallable().call(subArguments, locals, subParents); } catch (CommandException e) { e.prependStack(subCommand); throw e; } catch (Throwable t) { throw new WrappedCommandException(t); } } } throw new InvalidUsageException("Please choose a sub-command.", this, true); }
@Override public Operation call(CommandArgs args, CommandLocals locals) throws CommandException { if (!testPermission(locals)) { throw new CommandPermissionsException();
@Override public Object call(CommandArgs args, CommandLocals locals) throws CommandException { if (!testPermission(locals)) { throw new CommandPermissionsException(); } RegionFactory regionFactory = regionFactoryParser.call(args, locals); int radius = radiusCommand.call(args, locals).intValue(); Contextual<? extends Operation> factory = delegate.call(args, locals); Player player = (Player) locals.get(Actor.class); LocalSession session = WorldEdit.getInstance().getSessionManager().get(player); try { WorldEdit.getInstance().checkMaxBrushRadius(radius); BrushTool tool = session.getBrushTool(player.getItemInHand(HandSide.MAIN_HAND).getType()); tool.setSize(radius); tool.setBrush(new OperationFactoryBrush(factory, regionFactory), permission); } catch (MaxBrushRadiusException | InvalidToolBindException e) { WorldEdit.getInstance().getPlatformManager().getCommandManager().getExceptionConverter().convert(e); } player.print("Set brush to " + factory); return true; }
/** * Checks permissions and throws an exception if permission is not met. * * @param sender The sender to check the permission on. * @param perm The permission to check the permission on. * @throws CommandPermissionsException if {@code sender} doesn't have {@code perm} */ public void checkPermission(CommandSender sender, String perm) throws CommandPermissionsException { if (!hasPermission(sender, perm)) { throw new CommandPermissionsException(); } }
} else { throw new CommandPermissionsException();
/** * Get a WorldEdit selection from a region. * * @param args the arguments * @param sender the sender * @throws CommandException any error */ @Command(aliases = {"select", "sel", "s"}, usage = "[id]", desc = "Load a region as a WorldEdit selection", min = 0, max = 1) public void select(CommandContext args, Actor sender) throws CommandException { LocalPlayer player = worldGuard.checkPlayer(sender); RegionManager manager = checkRegionManager(player.getWorld()); ProtectedRegion existing; // If no arguments were given, get the region that the player is inside if (args.argsLength() == 0) { existing = checkRegionStandingIn(manager, player); } else { existing = checkExistingRegion(manager, args.getString(0), false); } // Check permissions if (!getPermissionModel(player).maySelect(existing)) { throw new CommandPermissionsException(); } // Select setPlayerSelection(player, existing); }
/** * Set the priority of a region. * * @param args the arguments * @param sender the sender * @throws CommandException any error */ @Command(aliases = {"setpriority", "priority", "pri"}, usage = "<id> <priority>", flags = "w:", desc = "Set the priority of a region", min = 2, max = 2) public void setPriority(CommandContext args, Actor sender) throws CommandException { warnAboutSaveFailures(sender); World world = checkWorld(args, sender, 'w'); // Get the world int priority = args.getInteger(1); // Lookup the existing region RegionManager manager = checkRegionManager(world); ProtectedRegion existing = checkExistingRegion(manager, args.getString(0), false); // Check permissions if (!getPermissionModel(sender).maySetPriority(existing)) { throw new CommandPermissionsException(); } existing.setPriority(priority); sender.print("Priority of '" + existing.getId() + "' set to " + priority + " (higher numbers override)."); }
@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); World world = checkWorld(args, sender, 'w'); // Get the world String id = args.getString(0); RegionManager manager = checkRegionManager(world); ProtectedRegion region = checkExistingRegion(manager, id, true); id = region.getId(); // 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); // Then add it to the members ListenableFuture<DefaultDomain> future = Futures.transform( WorldGuard.getInstance().getExecutorService().submit(resolver), resolver.createAddAllFunction(region.getMembers())); AsyncCommandHelper.wrap(future, worldGuard.getSupervisor(), sender, worldGuard.getExceptionConverter()) .formatUsing(region.getId(), world.getName()) .registerWithSupervisor("Adding members to the region '%s' on '%s'") .sendMessageAfterDelay("(Please wait... querying player names...)") .thenRespondWith("Region '%s' updated with new members.", "Failed to add new members"); }