@Override public boolean testPermission(CommandSender sender, Command command) { CommandMapping mapping = dispatcher.get(command.getName()); if (mapping != null) { CommandLocals locals = new CommandLocals(); locals.put(Actor.class, plugin.wrapCommandSender(sender)); return mapping.getCallable().testPermission(locals); } else { logger.warning("BukkitCommandInspector doesn't know how about the command '" + command + "'"); return false; } } }
@Override public boolean testPermission0(CommandLocals locals) { Actor sender = locals.get(Actor.class); if (sender == null) { throw new RuntimeException("Uh oh! No 'Actor' specified so that we can check permissions"); } else { return sender.hasPermission(permission); } }
LocalConfiguration config = worldEdit.getConfiguration(); CommandLocals locals = new CommandLocals(); locals.put(Actor.class, actor); locals.put("arguments", event.getArguments()); EditSession editSession = locals.get(EditSession.class);
public CommandContext(String args, Set<Character> valueFlags, boolean allowHangingFlag) throws CommandException { this(args.split(" ", -1), valueFlags, allowHangingFlag, new CommandLocals()); }
/** * Gets an {@link EditSession} from a {@link ArgumentStack}. * * @param context the context * @return an edit session * @throws ParameterException on other error */ @BindingMatch(type = EditSession.class, behavior = BindingBehavior.PROVIDES) public EditSession getEditSession(ArgumentStack context) throws ParameterException { Player sender = getPlayer(context); LocalSession session = worldEdit.getSessionManager().get(sender); EditSession editSession = session.createEditSession(sender); editSession.enableStandardMode(); context.getContext().getLocals().put(EditSession.class, editSession); session.tellVersion(sender); return editSession; }
this.locals = locals != null ? locals : new CommandLocals(); boolean isHanging = false; SuggestionContext suggestionContext = SuggestionContext.hangingValue();
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onPlayerCommand(PlayerCommandSendEvent event) { CommandLocals locals = new CommandLocals(); locals.put(Actor.class, plugin.wrapCommandSender(event.getPlayer())); Set<String> toRemove = plugin.getWorldEdit().getPlatformManager().getCommandManager().getDispatcher().getCommands().stream() .filter(commandMapping -> !commandMapping.getCallable().testPermission(locals)) .map(CommandMapping::getPrimaryAlias) .collect(Collectors.toSet()); event.getCommands().removeIf(toRemove::contains); }
this.locals = locals != null ? locals : new CommandLocals(); if(args.length < 2) completing = false;
@Override public boolean testPermission(CommandLocals locals, String permission) { Actor sender = locals.get(Actor.class); if (sender == null) { throw new RuntimeException("Uh oh! No 'Actor' specified so that we can check permissions"); } else { return sender.hasPermission(permission); } } }
@Subscribe public void handleCommandSuggestion(CommandSuggestionEvent event) { try { CommandLocals locals = new CommandLocals(); locals.put(Actor.class, event.getActor()); locals.put("arguments", event.getArguments()); event.setSuggestions(dispatcher.getSuggestions(event.getArguments(), locals)); } catch (CommandException e) { event.getActor().printError(e.getMessage()); } }
@Override protected boolean testPermission0(CommandLocals locals) { return locals.get(Actor.class).hasPermission(permission); }
/** * Gets an {@link Actor} from a {@link ArgumentStack}. * * @param context the context * @return a local player * @throws ParameterException on error */ @BindingMatch(type = Actor.class, behavior = BindingBehavior.PROVIDES) public Actor getActor(ArgumentStack context) throws ParameterException { Actor sender = context.getContext().getLocals().get(Actor.class); if (sender == null) { throw new ParameterException("Missing 'Actor'"); } else { return sender; } }
Actor sender = context.getLocals().get(Actor.class); Player player;
/** * Gets an {@link Player} from a {@link ArgumentStack}. * * @param context the context * @return a local player * @throws ParameterException on error */ @BindingMatch(type = Player.class, behavior = BindingBehavior.PROVIDES) public Player getPlayer(ArgumentStack context) throws ParameterException { Actor sender = context.getContext().getLocals().get(Actor.class); if (sender == null) { throw new ParameterException("No player to get a session for"); } else if (sender instanceof Player) { return (Player) sender; } else { throw new ParameterException("Caller is not a player"); } }
@Override public Deform call(CommandArgs args, CommandLocals locals) throws CommandException { FlagData flagData = getFlagParser().call(args, locals); String expression = expressionParser.call(args, locals); boolean rawCoords = rawCoordsFlag.get(flagData, false); boolean offset = offsetFlag.get(flagData, false); Deform deform = new Deform(expression); if (rawCoords) { deform.setMode(Mode.RAW_COORD); } else if (offset) { deform.setMode(Mode.OFFSET); Player player = (Player) locals.get(Actor.class); LocalSession session = WorldEdit.getInstance().getSessionManager().get(locals.get(Actor.class)); try { deform.setOffset(session.getPlacementPosition(player).toVector3()); } catch (IncompleteRegionException e) { throw new WrappedCommandException(e); } } else { deform.setMode(Mode.UNIT_CUBE); } return deform; }
/** * Gets an {@link BaseBlock} from a {@link ArgumentStack}. * * @param context the context * @return a pattern * @throws ParameterException on error * @throws WorldEditException on error */ @BindingMatch(type = {BaseBlock.class, BlockState.class, BlockStateHolder.class}, behavior = BindingBehavior.CONSUMES, consumedCount = 1) public BaseBlock getBaseBlock(ArgumentStack context) throws ParameterException, WorldEditException { Actor actor = context.getContext().getLocals().get(Actor.class); ParserContext parserContext = new ParserContext(); parserContext.setActor(context.getContext().getLocals().get(Actor.class)); if (actor instanceof Entity) { Extent extent = ((Entity) actor).getExtent(); if (extent instanceof World) { parserContext.setWorld((World) extent); } } parserContext.setSession(worldEdit.getSessionManager().get(actor)); try { return worldEdit.getBlockFactory().parseFromInput(context.next(), parserContext); } catch (NoMatchException e) { throw new ParameterException(e.getMessage(), e); } }
/** * Gets an {@link Pattern} from a {@link ArgumentStack}. * * @param context the context * @return a pattern * @throws ParameterException on error * @throws WorldEditException on error */ @BindingMatch(type = Pattern.class, behavior = BindingBehavior.CONSUMES, consumedCount = 1) public Pattern getPattern(ArgumentStack context) throws ParameterException, WorldEditException { Actor actor = context.getContext().getLocals().get(Actor.class); ParserContext parserContext = new ParserContext(); parserContext.setActor(context.getContext().getLocals().get(Actor.class)); if (actor instanceof Entity) { Extent extent = ((Entity) actor).getExtent(); if (extent instanceof World) { parserContext.setWorld((World) extent); } } parserContext.setSession(worldEdit.getSessionManager().get(actor)); try { return worldEdit.getPatternFactory().parseFromInput(context.next(), parserContext); } catch (NoMatchException e) { throw new ParameterException(e.getMessage(), e); } }
/** * Gets an {@link Mask} from a {@link ArgumentStack}. * * @param context the context * @return a pattern * @throws ParameterException on error * @throws WorldEditException on error */ @BindingMatch(type = Mask.class, behavior = BindingBehavior.CONSUMES, consumedCount = 1) public Mask getMask(ArgumentStack context) throws ParameterException, WorldEditException { Actor actor = context.getContext().getLocals().get(Actor.class); ParserContext parserContext = new ParserContext(); parserContext.setActor(context.getContext().getLocals().get(Actor.class)); if (actor instanceof Entity) { Extent extent = ((Entity) actor).getExtent(); if (extent instanceof World) { parserContext.setWorld((World) extent); } } parserContext.setSession(worldEdit.getSessionManager().get(actor)); try { return worldEdit.getMaskFactory().parseFromInput(context.next(), parserContext); } catch (NoMatchException e) { throw new ParameterException(e.getMessage(), e); } }
@Override public Pattern call(CommandArgs args, CommandLocals locals) throws CommandException { String patternString = stringParser.call(args, locals); Actor actor = locals.get(Actor.class); LocalSession session = WorldEdit.getInstance().getSessionManager().get(actor); ParserContext parserContext = new ParserContext(); parserContext.setActor(actor); if (actor instanceof Entity) { Extent extent = ((Entity) actor).getExtent(); if (extent instanceof World) { parserContext.setWorld((World) extent); } } parserContext.setSession(session); try { return WorldEdit.getInstance().getPatternFactory().parseFromInput(patternString, parserContext); } catch (InputParseException e) { throw new CommandException(e.getMessage(), e); } }