/** * Gets a type from a {@link ArgumentStack}. * * @param context the context * @return the requested type * @throws ParameterException on error */ @BindingMatch(type = { Boolean.class, boolean.class }, behavior = BindingBehavior.CONSUMES, consumedCount = 1) public Boolean getBoolean(ArgumentStack context) throws ParameterException { return context.nextBoolean(); }
if (binding.annotation.provideModifiers()) { args.add(parameter.getModifiers()); if (onlyConsume && binding.annotation.behavior() == BindingBehavior.PROVIDES) { return null; // Nothing to consume, nothing to do
if (!info.classifier().equals(Annotation.class)) { classifier = info.classifier(); types.add(classifier); for (Type t : info.type()) { Type type = null;
@Override public BindingBehavior getBehavior(ParameterData parameter) { return match(parameter).annotation.behavior(); }
@Override public int getConsumedCount(ParameterData parameter) { return match(parameter).annotation.consumedCount(); }
/** * Gets a type from a {@link ArgumentStack}. * * @param context the context * @param modifiers a list of modifiers * @return the requested type * @throws ParameterException on error */ @BindingMatch(type = { Short.class, short.class }, behavior = BindingBehavior.CONSUMES, consumedCount = 1, provideModifiers = true) public Short getShort(ArgumentStack context, Annotation[] modifiers) throws ParameterException { Integer v = getInteger(context, modifiers); if (v != null) { return v.shortValue(); } return null; }
/** * Gets a type from a {@link ArgumentStack}. * * @param context the context * @param modifiers a list of modifiers * @return the requested type * @throws ParameterException on error */ @BindingMatch(type = { Float.class, float.class }, behavior = BindingBehavior.CONSUMES, consumedCount = 1, provideModifiers = true) public Float getFloat(ArgumentStack context, Annotation[] modifiers) throws ParameterException { Double v = getDouble(context, modifiers); if (v != null) { return v.floatValue(); } return null; }
/** * Gets a {@link CommandContext} from a {@link ArgumentStack}. * * @param context the context * @return a selection */ @BindingMatch(type = CommandContext.class, behavior = BindingBehavior.PROVIDES) public CommandContext getCommandContext(ArgumentStack context) { context.markConsumed(); // Consume entire stack return context.getContext(); }
/** * Gets a type from a {@link ArgumentStack}. * * @param context the context * @param modifiers a list of modifiers * @return the requested type * @throws ParameterException on error */ @BindingMatch(type = String.class, behavior = BindingBehavior.CONSUMES, consumedCount = 1, provideModifiers = true) public String getString(ArgumentStack context, Annotation[] modifiers) throws ParameterException { String v = context.next(); validate(v, modifiers); return v; }
/** * Gets a type from a {@link ArgumentStack}. * * @param context the context * @param text the text annotation * @param modifiers a list of modifiers * @return the requested type * @throws ParameterException on error */ @BindingMatch(classifier = Text.class, type = String.class, behavior = BindingBehavior.CONSUMES, consumedCount = -1, provideModifiers = true) public String getText(ArgumentStack context, Text text, Annotation[] modifiers) throws ParameterException { String v = context.remaining(); validate(v, modifiers); return v; }
/** * Gets an {@link LocalSession} from a {@link ArgumentStack}. * * @param context the context * @return a local session * @throws ParameterException on error */ @BindingMatch(type = LocalSession.class, behavior = BindingBehavior.PROVIDES) public LocalSession getLocalSession(ArgumentStack context) throws ParameterException { Player sender = getPlayer(context); return worldEdit.getSessionManager().get(sender); }
/** * Gets a type from a {@link ArgumentStack}. * * @param context the context * @param modifiers a list of modifiers * @return the requested type * @throws ParameterException on error */ @BindingMatch(type = { Integer.class, int.class }, behavior = BindingBehavior.CONSUMES, consumedCount = 1, provideModifiers = true) public Integer getInteger(ArgumentStack context, Annotation[] modifiers) throws ParameterException { Double v = parseNumericInput(context.next()); if (v != null) { int intValue = v.intValue(); validate(intValue, modifiers); return intValue; } else { return null; } }
/** * Gets an {@link TreeType} from a {@link ArgumentStack}. * * @param context the context * @return a pattern * @throws ParameterException on error * @throws WorldEditException on error */ @BindingMatch(type = TreeType.class, behavior = BindingBehavior.CONSUMES, consumedCount = 1) public TreeType getTreeType(ArgumentStack context) throws ParameterException, WorldEditException { String input = context.next(); if (input != null) { TreeType type = TreeGenerator.lookup(input); if (type != null) { return type; } else { throw new ParameterException( String.format("Can't recognize tree type '%s' -- choose from: %s", input, Arrays.toString(TreeType.values()))); } } else { return TreeType.TREE; } }
/** * Gets a type from a {@link ArgumentStack}. * * @param context the context * @param modifiers a list of modifiers * @return the requested type * @throws ParameterException on error */ @BindingMatch(type = { Double.class, double.class }, behavior = BindingBehavior.CONSUMES, consumedCount = 1, provideModifiers = true) public Double getDouble(ArgumentStack context, Annotation[] modifiers) throws ParameterException { Double v = parseNumericInput(context.next()); if (v != null) { validate(v, modifiers); return v; } else { return null; } }
/** * 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; } }
/** * Gets a selection from a {@link ArgumentStack}. * * @param context the context * @param selection the annotation * @return a selection * @throws IncompleteRegionException if no selection is available * @throws ParameterException on other error */ @BindingMatch(classifier = Selection.class, type = Region.class, behavior = BindingBehavior.PROVIDES) public Object getSelection(ArgumentStack context, Selection selection) throws IncompleteRegionException, ParameterException { Player sender = getPlayer(context); LocalSession session = worldEdit.getSessionManager().get(sender); return session.getSelection(sender.getWorld()); }
/** * 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"); } }
/** * Get a direction from the player. * * @param context the context * @param direction the direction annotation * @return a pattern * @throws ParameterException on error * @throws UnknownDirectionException on an unknown direction */ @BindingMatch(classifier = Direction.class, type = BlockVector3.class, behavior = BindingBehavior.CONSUMES, consumedCount = 1) public BlockVector3 getDirection(ArgumentStack context, Direction direction) throws ParameterException, UnknownDirectionException { Player sender = getPlayer(context); if (direction.includeDiagonals()) { return worldEdit.getDiagonalDirection(sender, context.next()); } else { return worldEdit.getDirection(sender, context.next()); } }
/** * Gets an {@link BaseBiome} from a {@link ArgumentStack}. * * @param context the context * @return a pattern * @throws ParameterException on error * @throws WorldEditException on error */ @BindingMatch(type = BaseBiome.class, behavior = BindingBehavior.CONSUMES, consumedCount = 1) public BaseBiome getBiomeType(ArgumentStack context) throws ParameterException, WorldEditException { String input = context.next(); if (input != null) { BiomeRegistry biomeRegistry = WorldEdit.getInstance().getPlatformManager() .queryCapability(Capability.GAME_HOOKS).getRegistries().getBiomeRegistry(); List<BaseBiome> knownBiomes = biomeRegistry.getBiomes(); BaseBiome biome = Biomes.findBiomeByName(knownBiomes, input, biomeRegistry); if (biome != null) { return biome; } else { throw new ParameterException( String.format("Can't recognize biome type '%s' -- use /biomelist to list available types", input)); } } else { throw new ParameterException( "This command takes a 'default' biome if one is not set, except there is no particular " + "biome that should be 'default', so the command should not be taking a default biome"); } }
/** * 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; }