com.mojang.brigadier.arguments.StringArgumentType Java Examples
The following examples show how to use
com.mojang.brigadier.arguments.StringArgumentType.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ForgeSparkPlugin.java From spark with GNU General Public License v3.0 | 7 votes |
public static <T> void registerCommands(CommandDispatcher<T> dispatcher, Command<T> executor, SuggestionProvider<T> suggestor, String... aliases) { if (aliases.length == 0) { return; } String mainName = aliases[0]; LiteralArgumentBuilder<T> command = LiteralArgumentBuilder.<T>literal(mainName) .executes(executor) .then(RequiredArgumentBuilder.<T, String>argument("args", StringArgumentType.greedyString()) .suggests(suggestor) .executes(executor) ); LiteralCommandNode<T> node = dispatcher.register(command); for (int i = 1; i < aliases.length; i++) { dispatcher.register(LiteralArgumentBuilder.<T>literal(aliases[i]).redirect(node)); } }
Example #2
Source File: MobAICommand.java From fabric-carpet with MIT License | 7 votes |
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) { LiteralArgumentBuilder<ServerCommandSource> command = literal("track"). requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandTrackAI)). then(argument("entity type", EntitySummonArgumentType.entitySummon()). suggests( (c, b) -> suggestMatching(MobAI.availbleTypes(), b)). then(literal("clear").executes( (c) -> { MobAI.clearTracking(Registry.ENTITY_TYPE.get(EntitySummonArgumentType.getEntitySummon(c, "entity type"))); return 1; } )). then(argument("aspect", StringArgumentType.word()). suggests( (c, b) -> suggestMatching(MobAI.availableFor(Registry.ENTITY_TYPE.get(EntitySummonArgumentType.getEntitySummon(c, "entity type"))),b)). executes( (c) -> { MobAI.startTracking( Registry.ENTITY_TYPE.get(EntitySummonArgumentType.getEntitySummon(c, "entity type")), MobAI.TrackingType.byName(StringArgumentType.getString(c, "aspect")) ); return 1; }))); dispatcher.register(command); }
Example #3
Source File: VRCommandHandler.java From ViaFabric with MIT License | 6 votes |
public CompletableFuture<Suggestions> suggestion(CommandContext<? extends CommandSource> ctx, SuggestionsBuilder builder) { String[] args; try { args = StringArgumentType.getString(ctx, "args").split(" ", -1); } catch (IllegalArgumentException ignored) { args = new String[]{""}; } String[] pref = args.clone(); pref[pref.length - 1] = ""; String prefix = String.join(" ", pref); onTabComplete(new NMSCommandSender(ctx.getSource()), args) .stream() .map(it -> { SuggestionsBuilder b = new SuggestionsBuilder(builder.getInput(), prefix.length() + builder.getStart()); b.suggest(it); return b; }) .forEach(builder::add); return builder.buildFuture(); }
Example #4
Source File: BackendPlaySessionHandler.java From Velocity with MIT License | 6 votes |
@Override public boolean handle(AvailableCommands commands) { // Inject commands from the proxy. for (String command : server.getCommandManager().getAllRegisteredCommands()) { if (!server.getCommandManager().hasPermission(serverConn.getPlayer(), command)) { continue; } LiteralCommandNode<Object> root = LiteralArgumentBuilder.literal(command) .then(RequiredArgumentBuilder.argument("args", StringArgumentType.greedyString()) .suggests(new ProtocolSuggestionProvider("minecraft:ask_server")) .build()) .executes((ctx) -> 0) .build(); commands.getRootNode().addChild(root); } return false; }
Example #5
Source File: StringArgumentPropertySerializer.java From Velocity with MIT License | 6 votes |
@Override public void serialize(StringArgumentType object, ByteBuf buf) { switch (object.getType()) { case SINGLE_WORD: ProtocolUtils.writeVarInt(buf, 0); break; case QUOTABLE_PHRASE: ProtocolUtils.writeVarInt(buf, 1); break; case GREEDY_PHRASE: ProtocolUtils.writeVarInt(buf, 2); break; default: throw new IllegalArgumentException("Invalid string argument type " + object.getType()); } }
Example #6
Source File: PlayerCommand.java From fabric-carpet with MIT License | 6 votes |
private static boolean cantSpawn(CommandContext<ServerCommandSource> context) { String playerName = StringArgumentType.getString(context, "player"); MinecraftServer server = context.getSource().getMinecraftServer(); PlayerManager manager = server.getPlayerManager(); PlayerEntity player = manager.getPlayer(playerName); if (player != null) { Messenger.m(context.getSource(), "r Player ", "rb " + playerName, "r is already logged on"); return true; } GameProfile profile = server.getUserCache().findByName(playerName); if (manager.getUserBanList().contains(profile)) { Messenger.m(context.getSource(), "r Player ", "rb " + playerName, "r is banned"); return true; } if (manager.isWhitelistEnabled() && profile != null && manager.isWhitelisted(profile) && !context.getSource().hasPermissionLevel(2)) { Messenger.m(context.getSource(), "r Whitelisted players can only be spawned by operators"); return true; } return false; }
Example #7
Source File: FabricSparkPlugin.java From spark with GNU General Public License v3.0 | 6 votes |
public static <T> void registerCommands(CommandDispatcher<T> dispatcher, Command<T> executor, SuggestionProvider<T> suggestor, String... aliases) { if (aliases.length == 0) { return; } String mainName = aliases[0]; LiteralArgumentBuilder<T> command = LiteralArgumentBuilder.<T>literal(mainName) .executes(executor) .then(RequiredArgumentBuilder.<T, String>argument("args", StringArgumentType.greedyString()) .suggests(suggestor) .executes(executor) ); LiteralCommandNode<T> node = dispatcher.register(command); for (int i = 1; i < aliases.length; i++) { dispatcher.register(LiteralArgumentBuilder.<T>literal(aliases[i]).redirect(node)); } }
Example #8
Source File: ScriptCommand.java From fabric-carpet with MIT License | 6 votes |
private static CarpetScriptHost getHost(CommandContext<ServerCommandSource> context) { CarpetScriptHost host; try { String name = StringArgumentType.getString(context, "app").toLowerCase(Locale.ROOT); CarpetScriptHost parentHost = CarpetServer.scriptServer.modules.getOrDefault(name, CarpetServer.scriptServer.globalHost); host = parentHost.retrieveForExecution(context.getSource()); } catch (IllegalArgumentException ignored) { host = CarpetServer.scriptServer.globalHost; } host.setChatErrorSnooper(context.getSource()); return host; }
Example #9
Source File: SettingsManager.java From fabric-carpet with MIT License | 5 votes |
private ParsedRule<?> contextRule(CommandContext<ServerCommandSource> ctx) throws CommandSyntaxException { String ruleName = StringArgumentType.getString(ctx, "rule"); ParsedRule<?> rule = getRule(ruleName); if (rule == null) throw new SimpleCommandExceptionType(Messenger.c("rb "+ tr("ui.unknown_rule","Unknown rule")+": "+ruleName)).create(); return rule; }
Example #10
Source File: MutableTest.java From Chimera with MIT License | 5 votes |
static Stream<Mutable<CommandSender>> mutables() { var optional = Literal.of("optional").then(Literal.of("optional child")); return Stream.of( Literal.of("literal").alias("literal alias").alias("a", "b").executes((s, val) -> {val.getSource().getName();}).optionally(optional).build(), Argument.of("argument", StringArgumentType.word()).executes((s, val) -> {val.getSource().getName();}).optionally(optional).build() ); }
Example #11
Source File: ArgumentTest.java From Chimera with MIT License | 5 votes |
@Test void constructors() { var command = new Argument<>("name", StringArgumentType.string(), (context) -> 1, null, null); var execution = new Argument<>("name", StringArgumentType.string(), (source, context) -> {}, null, null); assertEquals("name", command.getName()); assertEquals(StringArgumentType.string().getClass(), command.getType().getClass()); assertEquals("name", execution.getName()); assertEquals(StringArgumentType.string().getClass(), execution.getType().getClass()); }
Example #12
Source File: MapperTest.java From Chimera with MIT License | 5 votes |
@Test void map_argument() { var unmapped = Argument.<String, String>builder("b", StringArgumentType.word()).build(); var argument = (ArgumentCommandNode<String, String>) mapper.map(unmapped); assertEquals("b", argument.getName()); assertSame(unmapped.getType(), argument.getType()); assertSame(Mapper.NONE, argument.getCommand()); assertSame(Mapper.TRUE, argument.getRequirement()); assertNull(argument.getCustomSuggestions()); }
Example #13
Source File: StringArgumentPropertySerializer.java From Velocity with MIT License | 5 votes |
@Override public StringArgumentType deserialize(ByteBuf buf) { int type = ProtocolUtils.readVarInt(buf); switch (type) { case 0: return StringArgumentType.word(); case 1: return StringArgumentType.string(); case 2: return StringArgumentType.greedyString(); default: throw new IllegalArgumentException("Invalid string argument type " + type); } }
Example #14
Source File: AbstractSuggestionProvider.java From BlueMap with MIT License | 5 votes |
@Override public CompletableFuture<Suggestions> getSuggestions(CommandContext<S> context, SuggestionsBuilder builder) throws CommandSyntaxException { Collection<String> possibleValues = getPossibleValues(); if(possibleValues.isEmpty()) return Suggestions.empty(); String remaining = builder.getRemaining().toLowerCase(); for (String str : possibleValues) { if (str.toLowerCase().startsWith(remaining)) { builder.suggest(str = StringArgumentType.escapeIfRequired(str)); } } return builder.buildFuture(); }
Example #15
Source File: LogCommand.java From fabric-carpet with MIT License | 5 votes |
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) { LiteralArgumentBuilder<ServerCommandSource> literalargumentbuilder = CommandManager.literal("log"). requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandLog)). executes((context) -> listLogs(context.getSource())). then(CommandManager.literal("clear"). executes( (c) -> unsubFromAll(c.getSource(), c.getSource().getName())). then(CommandManager.argument("player", StringArgumentType.word()). suggests( (c, b)-> suggestMatching(c.getSource().getPlayerNames(),b)). executes( (c) -> unsubFromAll(c.getSource(), getString(c, "player"))))); literalargumentbuilder.then(CommandManager.argument("log name",StringArgumentType.word()). suggests( (c, b)-> suggestMatching(LoggerRegistry.getLoggerNames(),b)). executes( (c)-> toggleSubscription(c.getSource(), c.getSource().getName(), getString(c, "log name"))). then(CommandManager.literal("clear"). executes( (c) -> unsubFromLogger( c.getSource(), c.getSource().getName(), getString(c, "log name")))). then(CommandManager.argument("option", StringArgumentType.greedyString()). suggests( (c, b) -> suggestMatching( (LoggerRegistry.getLogger(getString(c, "log name"))==null ?new String[]{} :LoggerRegistry.getLogger(getString(c, "log name")).getOptions()), b)). executes( (c) -> subscribePlayer( c.getSource(), c.getSource().getName(), getString(c, "log name"), getString(c, "option"))). then(CommandManager.argument("player", StringArgumentType.word()). suggests( (c, b) -> suggestMatching(c.getSource().getPlayerNames(),b)). executes( (c) -> subscribePlayer( c.getSource(), getString(c, "player"), getString(c, "log name"), getString(c, "option")))))); dispatcher.register(literalargumentbuilder); }
Example #16
Source File: ViaFabric.java From ViaFabric with MIT License | 5 votes |
public static <S extends CommandSource> LiteralArgumentBuilder<S> command(String commandName) { return LiteralArgumentBuilder.<S>literal(commandName) .then( RequiredArgumentBuilder .<S, String>argument("args", StringArgumentType.greedyString()) .executes(((VRCommandHandler) Via.getManager().getCommandHandler())::execute) .suggests(((VRCommandHandler) Via.getManager().getCommandHandler())::suggestion) ) .executes(((VRCommandHandler) Via.getManager().getCommandHandler())::execute); }
Example #17
Source File: VRCommandHandler.java From ViaFabric with MIT License | 5 votes |
public int execute(CommandContext<? extends CommandSource> ctx) { String[] args = new String[0]; try { args = StringArgumentType.getString(ctx, "args").split(" "); } catch (IllegalArgumentException ignored) { } onCommand( new NMSCommandSender(ctx.getSource()), args ); return 1; }
Example #18
Source File: Commands_1_12_2.java From multiconnect with MIT License | 5 votes |
public static void registerAll(CommandDispatcher<CommandSource> dispatcher, Set<String> serverCommands) { ((Protocol_1_12_2) ConnectionInfo.protocol).registerCommands(dispatcher, serverCommands); if (serverCommands != null) { for (String command : serverCommands) { if (dispatcher.getRoot().getChild(command) == null) { dispatcher.register(literal(command) .executes(ctx -> 0) .then(argument("args", StringArgumentType.greedyString()) .suggests(SuggestionProviders.ASK_SERVER) .executes(ctx -> 0))); } } } }
Example #19
Source File: SettingsManager.java From fabric-carpet with MIT License | 4 votes |
private void registerCommand(CommandDispatcher<ServerCommandSource> dispatcher) { if (dispatcher.getRoot().getChildren().stream().anyMatch(node -> node.getName().equalsIgnoreCase(identifier))) { CarpetSettings.LOG.error("Failed to add settings command for " + identifier + ". It is masking previous command."); return; } LiteralArgumentBuilder<ServerCommandSource> literalargumentbuilder = literal(identifier).requires((player) -> player.hasPermissionLevel(2) && !locked); literalargumentbuilder.executes((context)-> listAllSettings(context.getSource())). then(literal("list"). executes( (c) -> listSettings(c.getSource(), String.format(tr("ui.all_%(mod)s_settings","All %s Settings"), fancyName), getRules())). then(literal("defaults"). executes( (c)-> listSettings(c.getSource(), String.format(tr("ui.current_%(mod)s_startup_settings_from_%(conf)s","Current %s Startup Settings from %s"), fancyName, (identifier+".conf")), findStartupOverrides()))). then(argument("tag",StringArgumentType.word()). suggests( (c, b)->suggestMatching(getCategories(), b)). executes( (c) -> listSettings(c.getSource(), String.format(tr("ui.%(mod)s_settings_matching_'%(query)s'","%s Settings matching \"%s\""), fancyName, tr("category." + StringArgumentType.getString(c, "tag"),StringArgumentType.getString(c, "tag"))), getRulesMatching(StringArgumentType.getString(c, "tag")))))). then(literal("removeDefault"). requires(s -> !locked). then(argument("rule", StringArgumentType.word()). suggests( (c, b) -> suggestMatching(getRules().stream().map(r -> r.name), b)). executes((c) -> removeDefault(c.getSource(), contextRule(c))))). then(literal("setDefault"). requires(s -> !locked). then(argument("rule", StringArgumentType.word()). suggests( (c, b) -> suggestMatching(getRules().stream().map(r -> r.name), b)). then(argument("value", StringArgumentType.greedyString()). suggests((c, b)-> suggestMatching(contextRule(c).options, b)). executes((c) -> setDefault(c.getSource(), contextRule(c), StringArgumentType.getString(c, "value")))))). then(argument("rule", StringArgumentType.word()). suggests( (c, b) -> suggestMatching(getRules().stream().map(r -> r.name), b)). requires(s -> !locked ). executes( (c) -> displayRuleMenu(c.getSource(), contextRule(c))). then(argument("value", StringArgumentType.greedyString()). suggests((c, b)-> suggestMatching(contextRule(c).options,b)). executes((c) -> setRule(c.getSource(), contextRule(c), StringArgumentType.getString(c, "value"))))); dispatcher.register(literalargumentbuilder); }
Example #20
Source File: DrawCommand.java From fabric-carpet with MIT License | 4 votes |
private static int drawPrism(CommandContext<ServerCommandSource> ctx, String base){ BlockPos pos; double radius; int height; String orientation; BlockStateArgument block; Predicate<CachedBlockPosition> replacement; try { pos = getArg(ctx, BlockPosArgumentType::getBlockPos, "center"); radius = getArg(ctx, IntegerArgumentType::getInteger, "radius")+0.5D; height = getArg(ctx, IntegerArgumentType::getInteger, "height"); orientation = getArg(ctx, StringArgumentType::getString,"orientation"); block = getArg(ctx, BlockStateArgumentType::getBlockState, "block"); replacement = getArg(ctx, BlockPredicateArgumentType::getBlockPredicate, "filter", true); } catch (ErrorHandled | CommandSyntaxException ignored) { return 0; } ServerCommandSource source = ctx.getSource(); int affected = 0; BlockPos.Mutable mbpos = new BlockPos.Mutable(pos); List<BlockPos> list = Lists.newArrayList(); ServerWorld world = source.getWorld(); CarpetSettings.impendingFillSkipUpdates = !CarpetSettings.fillUpdates; boolean isSquare = base.equalsIgnoreCase("square"); for(int i =0; i<height;++i) { affected+= fillFlat(world, pos, i, radius, isSquare, orientation, block, replacement, list, mbpos); } CarpetSettings.impendingFillSkipUpdates = false; if (CarpetSettings.fillUpdates) { for (BlockPos blockpos1 : list) { Block blokc = world.getBlockState(blockpos1).getBlock(); world.updateNeighbors(blockpos1, blokc); } } Messenger.m(source, "gi Filled " + affected + " blocks"); return affected; }
Example #21
Source File: DrawCommand.java From fabric-carpet with MIT License | 4 votes |
private static int drawPyramid(CommandContext<ServerCommandSource> ctx, String base, boolean solid) throws CommandSyntaxException { BlockPos pos; double radius; int height; boolean pointup; String orientation; BlockStateArgument block; Predicate<CachedBlockPosition> replacement; try { pos = getArg(ctx, BlockPosArgumentType::getBlockPos, "center"); radius = getArg(ctx, IntegerArgumentType::getInteger, "radius")+0.5D; height = getArg(ctx, IntegerArgumentType::getInteger, "height"); pointup = getArg(ctx, StringArgumentType::getString, "pointing").equalsIgnoreCase("up"); orientation = getArg(ctx, StringArgumentType::getString,"orientation"); block = getArg(ctx, BlockStateArgumentType::getBlockState, "block"); replacement = getArg(ctx, BlockPredicateArgumentType::getBlockPredicate, "filter", true); } catch (ErrorHandled ignored) { return 0; } ServerCommandSource source = ctx.getSource(); int affected = 0; BlockPos.Mutable mbpos = new BlockPos.Mutable(pos); List<BlockPos> list = Lists.newArrayList(); ServerWorld world = source.getWorld(); CarpetSettings.impendingFillSkipUpdates = !CarpetSettings.fillUpdates; boolean isSquare = base.equalsIgnoreCase("square"); for(int i =0; i<height;++i) { double r = pointup ? radius - radius * i / height - 1 : radius * i / height; affected+= fillFlat(world, pos, i, r, isSquare, orientation, block, replacement, list, mbpos); } CarpetSettings.impendingFillSkipUpdates = false; if (CarpetSettings.fillUpdates) { for (BlockPos blockpos1 : list) { Block blokc = world.getBlockState(blockpos1).getBlock(); world.updateNeighbors(blockpos1, blokc); } } Messenger.m(source, "gi Filled " + affected + " blocks"); return affected; }
Example #22
Source File: TextArgument.java From 1.13-Command-API with Apache License 2.0 | 4 votes |
/** * A string argument for one word, or multiple words encased in quotes */ public TextArgument() { super(StringArgumentType.string()); }
Example #23
Source File: StringArgument.java From 1.13-Command-API with Apache License 2.0 | 4 votes |
/** * A string argument for one word */ public StringArgument() { super(StringArgumentType.word()); }
Example #24
Source File: GreedyStringArgument.java From 1.13-Command-API with Apache License 2.0 | 4 votes |
/** * A string argument for a string of any length */ public GreedyStringArgument() { super(StringArgumentType.greedyString()); }
Example #25
Source File: DrawCommand.java From fabric-carpet with MIT License | 4 votes |
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) { LiteralArgumentBuilder<ServerCommandSource> command = literal("draw"). requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandDraw)). then(literal("sphere"). then(argument("center", BlockPosArgumentType.blockPos()). then(argument("radius", IntegerArgumentType.integer(1)). then(drawShape(c -> DrawCommand.drawSphere(c, false)))))). then(literal("ball"). then(argument("center", BlockPosArgumentType.blockPos()). then(argument("radius", IntegerArgumentType.integer(1)). then(drawShape(c -> DrawCommand.drawSphere(c, true)))))). then(literal("diamond"). then(argument("center", BlockPosArgumentType.blockPos()). then(argument("radius", IntegerArgumentType.integer(1)). then(drawShape(c -> DrawCommand.drawDiamond(c, true)))))). then(literal("pyramid"). then(argument("center", BlockPosArgumentType.blockPos()). then(argument("radius", IntegerArgumentType.integer(1)). then(argument("height",IntegerArgumentType.integer(1)). then(argument("pointing",StringArgumentType.word()).suggests( (c, b) -> suggestMatching(new String[]{"up","down"},b)). then(argument("orientation",StringArgumentType.word()).suggests( (c, b) -> suggestMatching(new String[]{"y","x","z"},b)). then(drawShape(c -> DrawCommand.drawPyramid(c, "square", true))))))))). then(literal("cone"). then(argument("center", BlockPosArgumentType.blockPos()). then(argument("radius", IntegerArgumentType.integer(1)). then(argument("height",IntegerArgumentType.integer(1)). then(argument("pointing",StringArgumentType.word()).suggests( (c, b) -> suggestMatching(new String[]{"up","down"},b)). then(argument("orientation",StringArgumentType.word()).suggests( (c, b) -> suggestMatching(new String[]{"y","x","z"},b)) .then(drawShape(c -> DrawCommand.drawPyramid(c, "circle", true))))))))). then(literal("cylinder"). then(argument("center", BlockPosArgumentType.blockPos()). then(argument("radius", IntegerArgumentType.integer(1)). then(argument("height",IntegerArgumentType.integer(1)). then(argument("orientation",StringArgumentType.word()).suggests( (c, b) -> suggestMatching(new String[]{"y","x","z"},b)) .then(drawShape(c -> DrawCommand.drawPrism(c, "circle")))))))). then(literal("cuboid"). then(argument("center", BlockPosArgumentType.blockPos()). then(argument("radius", IntegerArgumentType.integer(1)). then(argument("height",IntegerArgumentType.integer(1)). then(argument("orientation",StringArgumentType.word()).suggests( (c, b) -> suggestMatching(new String[]{"y","x","z"},b)) .then(drawShape(c -> DrawCommand.drawPrism(c, "square")))))))); dispatcher.register(command); }
Example #26
Source File: PlayerCommand.java From fabric-carpet with MIT License | 4 votes |
private static ServerPlayerEntity getPlayer(CommandContext<ServerCommandSource> context) { String playerName = StringArgumentType.getString(context, "player"); MinecraftServer server = context.getSource().getMinecraftServer(); return server.getPlayerManager().getPlayer(playerName); }
Example #27
Source File: PlayerCommand.java From fabric-carpet with MIT License | 4 votes |
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) { LiteralArgumentBuilder<ServerCommandSource> literalargumentbuilder = literal("player") .requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandPlayer)) .then(argument("player", StringArgumentType.word()) .suggests( (c, b) -> suggestMatching(getPlayers(c.getSource()), b)) .then(literal("stop").executes(PlayerCommand::stop)) .then(makeActionCommand("use", EntityPlayerActionPack.ActionType.USE)) .then(makeActionCommand("jump", EntityPlayerActionPack.ActionType.JUMP)) .then(makeActionCommand("attack", EntityPlayerActionPack.ActionType.ATTACK)) .then(makeActionCommand("drop", EntityPlayerActionPack.ActionType.DROP_ITEM)) .then(makeDropCommand("drop", false)) .then(makeActionCommand("dropStack", EntityPlayerActionPack.ActionType.DROP_STACK)) .then(makeDropCommand("dropStack", true)) .then(makeActionCommand("swapHands", EntityPlayerActionPack.ActionType.SWAP_HANDS)) .then(literal("kill").executes(PlayerCommand::kill)) .then(literal("shadow"). executes(PlayerCommand::shadow)) .then(literal("mount").executes(manipulation(ap -> ap.mount(true))) .then(literal("anything").executes(manipulation(ap -> ap.mount(false))))) .then(literal("dismount").executes(manipulation(EntityPlayerActionPack::dismount))) .then(literal("sneak").executes(manipulation(ap -> ap.setSneaking(true)))) .then(literal("unsneak").executes(manipulation(ap -> ap.setSneaking(false)))) .then(literal("sprint").executes(manipulation(ap -> ap.setSprinting(true)))) .then(literal("unsprint").executes(manipulation(ap -> ap.setSprinting(false)))) .then(literal("look") .then(literal("north").executes(manipulation(ap -> ap.look(Direction.NORTH)))) .then(literal("south").executes(manipulation(ap -> ap.look(Direction.SOUTH)))) .then(literal("east").executes(manipulation(ap -> ap.look(Direction.EAST)))) .then(literal("west").executes(manipulation(ap -> ap.look(Direction.WEST)))) .then(literal("up").executes(manipulation(ap -> ap.look(Direction.UP)))) .then(literal("down").executes(manipulation(ap -> ap.look(Direction.DOWN)))) .then(argument("direction", RotationArgumentType.rotation()) .executes(c -> manipulate(c, ap -> ap.look(RotationArgumentType.getRotation(c, "direction").toAbsoluteRotation(c.getSource()))))) ).then(literal("turn") .then(literal("left").executes(c -> manipulate(c, ap -> ap.turn(-90, 0)))) .then(literal("right").executes(c -> manipulate(c, ap -> ap.turn(90, 0)))) .then(literal("back").executes(c -> manipulate(c, ap -> ap.turn(180, 0)))) .then(argument("rotation", RotationArgumentType.rotation()) .executes(c -> manipulate(c, ap -> ap.turn(RotationArgumentType.getRotation(c, "rotation").toAbsoluteRotation(c.getSource()))))) ).then(literal("move").executes(c -> manipulate(c, EntityPlayerActionPack::stopMovement)) .then(literal("forward").executes(c -> manipulate(c, ap -> ap.setForward(1)))) .then(literal("backward").executes(c -> manipulate(c, ap -> ap.setForward(-1)))) .then(literal("left").executes(c -> manipulate(c, ap -> ap.setStrafing(1)))) .then(literal("right").executes(c -> manipulate(c, ap -> ap.setStrafing(-1)))) ).then(literal("spawn").executes(PlayerCommand::spawn) .then(literal("at").then(argument("position", Vec3ArgumentType.vec3()).executes(PlayerCommand::spawn) .then(literal("facing").then(argument("direction", RotationArgumentType.rotation()).executes(PlayerCommand::spawn) .then(literal("in").then(argument("dimension", DimensionArgumentType.dimension()).executes(PlayerCommand::spawn))) )) )) ) ); dispatcher.register(literalargumentbuilder); }
Example #28
Source File: MapperTest.java From Chimera with MIT License | 4 votes |
@Test void type() { var argument = Argument.<String, String>builder("", StringArgumentType.word()).build(); assertEquals(argument.getType(), mapper.type(argument)); }
Example #29
Source File: CustomArgument.java From 1.13-Command-API with Apache License 2.0 | 2 votes |
/** * Creates a CustomArgument with a valid parser * * @param parser * A CustomArgumentParser that maps a String to the object of your choice. * The String input is the text that the CommandSender inputs for * this argument * @param keyed Whether this argument can accept Minecraft's <code>NamespacedKey</code> as * valid arguments */ public CustomArgument(CustomArgumentParser<T> parser, boolean keyed) { super(keyed ? CommandAPIHandler.getNMS()._ArgumentMinecraftKeyRegistered() : StringArgumentType.string()); this.parser = parser; }