com.mojang.brigadier.builder.LiteralArgumentBuilder Java Examples

The following examples show how to use com.mojang.brigadier.builder.LiteralArgumentBuilder. 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 vote down vote up
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 vote down vote up
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: ConfigCommand.java    From BoundingBoxOutlineReloaded with MIT License 6 votes vote down vote up
private static LiteralArgumentBuilder<CommandSource> setCommandForSetting(Setting<?> setting) {
    LiteralArgumentBuilder<CommandSource> command = Commands.literal(setting.getName());
    switch (setting.getType()) {
        case 'B':
            buildSetSettingCommand(command, (Setting<Boolean>) setting, Arguments.bool(), Boolean.class);
            break;
        case 'I':
            buildSetSettingCommand(command, (Setting<Integer>) setting, Arguments.integer(), Integer.class);
            break;
        case 'S':
            buildSetSettingCommand(command, (Setting<String>) setting, Arguments.string(), String.class);
            break;
        case 'H':
            buildSetSettingCommand(command, (Setting<HexColor>) setting, Arguments.hexColor(), HexColor.class);
            break;
    }
    return command;
}
 
Example #4
Source File: ConfigCommand.java    From BoundingBoxOutlineReloaded with MIT License 6 votes vote down vote up
public static void register(CommandDispatcher<ISuggestionProvider> commandDispatcher) {
    LiteralArgumentBuilder command = Commands.literal(COMMAND)
            .then(buildCommands(GET, ConfigCommand::getCommandForSetting))
            .then(buildCommands(ArgumentNames.SET, ConfigCommand::setCommandForSetting))
            .then(buildCommands(RESET, ConfigCommand::resetCommandForSetting)
                    .executes(context1 -> {
                        ConfigManager.getSettings().forEach(Setting::reset);
                        ConfigManager.saveConfig();
                        return 0;
                    }))
            .then(Commands.literal(SAVE)
                    .executes(context -> {
                        ConfigManager.saveConfig();
                        return 0;
                    }))
            .then(Commands.literal(SHOW_GUI)
                    .executes(context -> {
                        SettingsScreen.show();
                        return 0;
                    }));

    commandDispatcher.register(command);
}
 
Example #5
Source File: BackendPlaySessionHandler.java    From Velocity with MIT License 6 votes vote down vote up
@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 #6
Source File: AvailableCommands.java    From Velocity with MIT License 6 votes vote down vote up
@Override
public String toString() {
  MoreObjects.ToStringHelper helper = MoreObjects.toStringHelper(this)
      .add("idx", idx)
      .add("flags", flags)
      .add("children", children)
      .add("redirectTo", redirectTo);

  if (args != null) {
    if (args instanceof LiteralArgumentBuilder) {
      helper.add("argsLabel", ((LiteralArgumentBuilder) args).getLiteral());
    } else if (args instanceof RequiredArgumentBuilder) {
      helper.add("argsName", ((RequiredArgumentBuilder) args).getName());
    }
  }

  return helper.toString();
}
 
Example #7
Source File: FabricSparkPlugin.java    From spark with GNU General Public License v3.0 6 votes vote down vote up
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: CounterCommand.java    From fabric-carpet with MIT License 6 votes vote down vote up
public static void register(CommandDispatcher<ServerCommandSource> dispatcher)
{
    LiteralArgumentBuilder<ServerCommandSource> literalargumentbuilder = CommandManager.literal("counter").executes((context)
     -> listAllCounters(context.getSource(), false)).requires((player) ->
            CarpetSettings.hopperCounters);

    literalargumentbuilder.
            then((CommandManager.literal("reset").executes( (p_198489_1_)->
                    resetCounter(p_198489_1_.getSource(), null))));
    for (DyeColor enumDyeColor: DyeColor.values())
    {
        String color = enumDyeColor.toString();
        literalargumentbuilder.
                then((CommandManager.literal(color).executes( (p_198489_1_)-> displayCounter(p_198489_1_.getSource(), color, false))));
        literalargumentbuilder.then(CommandManager.literal(color).
                then(CommandManager.literal("reset").executes((context) ->
                        resetCounter(context.getSource(), color))));
        literalargumentbuilder.then(CommandManager.literal(color).
                then(CommandManager.literal("realtime").executes((context) ->
                        displayCounter(context.getSource(), color, true))));
    }
    dispatcher.register(literalargumentbuilder);
}
 
Example #9
Source File: CameraModeCommand.java    From fabric-carpet with MIT License 6 votes vote down vote up
public static void register(CommandDispatcher<ServerCommandSource> dispatcher)
{
    LiteralArgumentBuilder<ServerCommandSource> camera = literal("c").
            requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandCameramode)).
            executes((c) -> cameraMode(c.getSource(), c.getSource().getPlayer())).
            then(argument("player", EntityArgumentType.player()).
                    executes( (c) -> cameraMode(c.getSource(), EntityArgumentType.getPlayer(c, "player"))));

    LiteralArgumentBuilder<ServerCommandSource> survival = literal("s").
            requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandCameramode)).
            executes((c) -> survivalMode(
                    c.getSource(),
                    c.getSource().getPlayer())).
            then(argument("player", EntityArgumentType.player()).
                    executes( (c) -> survivalMode(c.getSource(), EntityArgumentType.getPlayer(c, "player"))));

    dispatcher.register(camera);
    dispatcher.register(survival);
}
 
Example #10
Source File: CustomCommand.java    From BoundingBoxOutlineReloaded with MIT License 6 votes vote down vote up
public static void register(CommandDispatcher<ISuggestionProvider> commandDispatcher) {
    LiteralArgumentBuilder command = Commands.literal(COMMAND)
            .then(BoxCommandBuilder.build(BOX))
            .then(BeaconCommandBuilder.build(BEACON))
            .then(LineCommandBuilder.build(LINE))
            .then(SphereCommandBuilder.build(SPHERE))
            .then(Commands.literal(ArgumentNames.CLEAR)
                    .executes(context -> {
                        CustomBoxProvider.clear();
                        CustomBeaconProvider.clear();
                        CustomLineProvider.clear();
                        CustomSphereProvider.clear();

                        CommandHelper.feedback(context, "bbor.commands.custom.cleared.all");
                        return 0;
                    }));
    commandDispatcher.register(command);
}
 
Example #11
Source File: PerimeterInfoCommand.java    From fabric-carpet with MIT License 6 votes vote down vote up
public static void register(CommandDispatcher<ServerCommandSource> dispatcher)
{
    LiteralArgumentBuilder<ServerCommandSource> command = literal("perimeterinfo").
            requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandPerimeterInfo)).
            executes( (c) -> perimeterDiagnose(
                    c.getSource(),
                    new BlockPos(c.getSource().getPosition()),
                    null)).
            then(argument("center position", BlockPosArgumentType.blockPos()).
                    executes( (c) -> perimeterDiagnose(
                            c.getSource(),
                            BlockPosArgumentType.getBlockPos(c, "center position"),
                            null)).
                    then(argument("mob",EntitySummonArgumentType.entitySummon()).
                            suggests(SuggestionProviders.SUMMONABLE_ENTITIES).
                            executes( (c) -> perimeterDiagnose(
                                    c.getSource(),
                                    BlockPosArgumentType.getBlockPos(c, "center position"),
                                    EntitySummonArgumentType.getEntitySummon(c, "mob").toString()
                            ))));
    dispatcher.register(command);
}
 
Example #12
Source File: GalacticraftCommands.java    From Galacticraft-Rewoven with MIT License 6 votes vote down vote up
public static void register() {
    CommandRegistrationCallback.EVENT.register((commandDispatcher, b) -> {
        commandDispatcher.register(LiteralArgumentBuilder.<ServerCommandSource>literal("dimensiontp")
                .requires(serverCommandSource -> serverCommandSource.hasPermissionLevel(2))
                .then(CommandManager.argument("dimension", DimensionArgumentType.dimension())
                        .executes(GalacticraftCommands::teleport)
                        .then(CommandManager.argument("entities", EntityArgumentType.entities())
                                .executes(((GalacticraftCommands::teleportMultiple))))));
        commandDispatcher.register(LiteralArgumentBuilder.<ServerCommandSource>literal("gcr_listbodies")
                .executes(context -> {
                    StringBuilder builder = new StringBuilder();
                    CelestialBodyType.getAll().forEach(celestialBodyType -> builder.append(celestialBodyType.getTranslationKey()).append("\n"));
                    context.getSource().sendFeedback(new LiteralText(builder.toString()), true);
                    return 1;
                }));
    });
}
 
Example #13
Source File: SpawningSphereCommand.java    From BoundingBoxOutlineReloaded with MIT License 5 votes vote down vote up
public static void register(CommandDispatcher<ISuggestionProvider> commandDispatcher) {
    LiteralArgumentBuilder command = Commands.literal(COMMAND)
            .then(Commands.literal(ArgumentNames.SET)
                    .then(Commands.argument(ArgumentNames.POS, Arguments.point())
                            .executes(SpawningSphereCommand::setSphere))
                    .executes(SpawningSphereCommand::setSphere))
            .then(Commands.literal(ArgumentNames.CLEAR)
                    .executes(context -> {
                        boolean cleared = SpawningSphereProvider.clear();

                        String format = cleared ? "bbor.commands.spawningSphere.cleared" : "bbor.commands.spawningSphere.notSet";
                        CommandHelper.feedback(context, format);
                        return 0;
                    }))
            .then(Commands.literal(CALCULATE_SPAWNABLE)
                    .executes(context -> {
                        if (!SpawningSphereProvider.hasSpawningSphereInDimension(Player.getDimensionId())) {
                            CommandHelper.feedback(context, "bbor.commands.spawningSphere.notSet");
                            return 0;
                        }

                        Counts counts = new Counts();
                        World world = Minecraft.getInstance().world;
                        SpawningSphereProvider.calculateSpawnableSpacesCount(pos -> {
                            counts.spawnable++;
                            if (world.getLightFor(LightType.SKY, pos) > 7)
                                counts.nightSpawnable++;
                        });
                        SpawningSphereProvider.setSpawnableSpacesCount(counts.spawnable);

                        CommandHelper.feedback(context, "bbor.commands.spawningSphere.calculated",
                                String.format("%,d", counts.spawnable),
                                String.format("%,d", counts.nightSpawnable));
                        return 0;
                    }));
    commandDispatcher.register(command);
}
 
Example #14
Source File: ConfigCommand.java    From BoundingBoxOutlineReloaded with MIT License 5 votes vote down vote up
private static LiteralArgumentBuilder<CommandSource> getCommandForSetting(Setting<?> setting) {
    return Commands.literal(setting.getName())
            .executes(context -> {
                CommandHelper.feedback(context, "%s: %s", setting.getName(), setting.get());
                return 0;
            });
}
 
Example #15
Source File: ConfigCommand.java    From BoundingBoxOutlineReloaded with MIT License 5 votes vote down vote up
private static LiteralArgumentBuilder<CommandSource> buildCommands(String commandName, CommandBuilder commandBuilder) {
    LiteralArgumentBuilder<CommandSource> command = Commands.literal(commandName);
    for (Setting<?> setting : ConfigManager.getSettings()) {
        command.then(commandBuilder.apply(setting));
    }
    return command;
}
 
Example #16
Source File: ConfigCommand.java    From BoundingBoxOutlineReloaded with MIT License 5 votes vote down vote up
private static LiteralArgumentBuilder<CommandSource> resetCommandForSetting(Setting<?> setting) {
    return Commands.literal(setting.getName())
            .executes(context -> {
                setting.reset();
                ConfigManager.saveConfig();
                return 0;
            });
}
 
Example #17
Source File: StructuresCommand.java    From BoundingBoxOutlineReloaded with MIT License 5 votes vote down vote up
public static void register(CommandDispatcher<ISuggestionProvider> commandDispatcher) {
    LiteralArgumentBuilder command = Commands.literal(COMMAND)
            .then(Commands.literal(LOAD)
                    .executes(context -> {
                        LoadSavesScreen.show();
                        return 0;
                    }))
            .then(Commands.literal(ArgumentNames.CLEAR)
                    .executes(context -> {
                        ClientInterop.clearStructures();
                        return 0;
                    }));

    commandDispatcher.register(command);
}
 
Example #18
Source File: SphereCommandBuilder.java    From BoundingBoxOutlineReloaded with MIT License 5 votes vote down vote up
static LiteralArgumentBuilder<CommandSource> build(String command) {
    return Commands.literal(command)
            .then(Commands.literal(ArgumentNames.ADD)
                    .then(Commands.argument(ArgumentNames.POS, Arguments.point())
                            .then(Commands.argument(RADIUS, Arguments.integer())
                                    .executes(SphereCommandBuilder::addSphere)))
                    .then(Commands.argument(RADIUS, Arguments.integer())
                            .executes(SphereCommandBuilder::addSphere)))
            .then(Commands.literal(ArgumentNames.CLEAR)
                    .executes(context -> {
                        CustomSphereProvider.clear();

                        CommandHelper.feedback(context, "bbor.commands.sphere.cleared.all");
                        return 0;
                    })
                    .then(Commands.argument(ArgumentNames.FROM, Arguments.coords())
                            .then(Commands.argument(ArgumentNames.TO, Arguments.coords())
                                    .executes(context -> {
                                        Point pos = Arguments.getPoint(context, ArgumentNames.POS).snapXZ(0.5d);
                                        boolean removed = CustomSphereProvider.remove(pos);

                                        String format = removed ? "bbor.commands.sphere.cleared" : "bbor.commands.sphere.notFound";
                                        CommandHelper.feedback(context, format,
                                                pos.getX(), pos.getY(), pos.getZ());
                                        return 0;
                                    }))));
}
 
Example #19
Source File: ServerCommandConfig.java    From Better-Sprinting with Mozilla Public License 2.0 5 votes vote down vote up
public static void register(CommandDispatcher<CommandSource> dispatcher){
	LiteralArgumentBuilder<CommandSource> builder = literal("bettersprinting").requires(source -> source.hasPermissionLevel(3));
	
	builder.executes(ServerCommandConfig::execHelp);
	builder.then(literal("info").executes(ServerCommandConfig::execInfo));
	builder.then(literal("disablemod").then(argument(ARG_BOOLEAN, bool()).executes(ServerCommandConfig::execDisableMod)));
	builder.then(literal("setting").then(argument(ARG_SETTINGS, word()).suggests(SUGGEST_SETTING).then(argument(ARG_BOOLEAN, bool()).executes(ServerCommandConfig::execSetting))));
	
	dispatcher.register(builder);
}
 
Example #20
Source File: TreeWalkerTest.java    From Chimera with MIT License 5 votes vote down vote up
static Stream<Arguments> redirect_parameters() {
    var destination = LiteralArgumentBuilder.<String>literal("a").build();
    return Stream.of(
        of(destination, Literal.builder("a").build(), destination),
        of(destination, LiteralArgumentBuilder.<String>literal("a").build(), null),
        of(null, Literal.builder("a").build(), null),
        of(null, LiteralArgumentBuilder.<String>literal("a").build(), null)
    );
}
 
Example #21
Source File: LiteralCommandNodeTest.java    From brigadier with MIT License 5 votes vote down vote up
@Test
public void testCreateBuilder() throws Exception {
    final LiteralArgumentBuilder<Object> builder = node.createBuilder();
    assertThat(builder.getLiteral(), is(node.getLiteral()));
    assertThat(builder.getRequirement(), is(node.getRequirement()));
    assertThat(builder.getCommand(), is(node.getCommand()));
}
 
Example #22
Source File: PingCommand.java    From carpet-extra with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void register(CommandDispatcher<ServerCommandSource> dispatcher)
{
    LiteralArgumentBuilder<ServerCommandSource> command = literal("ping").
            requires( (player) -> CarpetExtraSettings.commandPing).
                    executes( c ->
                    {
                        ServerPlayerEntity playerEntity = c.getSource().getPlayer();
                        int ping = playerEntity.pingMilliseconds;
                        playerEntity.sendMessage(new LiteralText("Your ping is: " + ping + " ms"));
                        return 1;
                    });
    
    dispatcher.register(command);
}
 
Example #23
Source File: AvailableCommands.java    From Velocity with MIT License 5 votes vote down vote up
private static WireNode deserializeNode(ByteBuf buf, int idx) {
  byte flags = buf.readByte();
  int[] children = ProtocolUtils.readIntegerArray(buf);
  int redirectTo = -1;
  if ((flags & FLAG_IS_REDIRECT) > 0) {
    redirectTo = ProtocolUtils.readVarInt(buf);
  }

  switch (flags & FLAG_NODE_TYPE) {
    case NODE_TYPE_ROOT:
      return new WireNode(idx, flags, children, redirectTo, null);
    case NODE_TYPE_LITERAL:
      return new WireNode(idx, flags, children, redirectTo, LiteralArgumentBuilder
          .literal(ProtocolUtils.readString(buf)));
    case NODE_TYPE_ARGUMENT:
      String name = ProtocolUtils.readString(buf);
      ArgumentType<?> argumentType = ArgumentPropertyRegistry.deserialize(buf);

      RequiredArgumentBuilder<Object, ?> argumentBuilder = RequiredArgumentBuilder
          .argument(name, argumentType);
      if ((flags & FLAG_HAS_SUGGESTIONS) != 0) {
        argumentBuilder.suggests(new ProtocolSuggestionProvider(ProtocolUtils.readString(buf)));
      }

      return new WireNode(idx, flags, children, redirectTo, argumentBuilder);
    default:
      throw new IllegalArgumentException("Unknown node type " + (flags & FLAG_NODE_TYPE));
  }
}
 
Example #24
Source File: ConfigCommand.java    From BoundingBoxOutlineReloaded with MIT License 5 votes vote down vote up
private static <T> void buildSetSettingCommand(LiteralArgumentBuilder<CommandSource> command,
                                               Setting<T> setting, ArgumentType<T> argument, Class<T> clazz) {
    Command<CommandSource> setSettingCommand = context -> {
        setting.set(context.getArgument(VALUE, clazz));
        if (CommandHelper.lastNodeIsLiteral(context, SAVE)) {
            ConfigManager.saveConfig();
        }
        return 0;
    };
    command.then(Commands.argument(VALUE, argument)
            .executes(setSettingCommand)
            .then(Commands.literal(SAVE)
                    .executes(setSettingCommand)));
}
 
Example #25
Source File: BoxCommandBuilder.java    From BoundingBoxOutlineReloaded with MIT License 5 votes vote down vote up
static LiteralArgumentBuilder<CommandSource> build(String command) {
    return Commands.literal(command)
            .then(Commands.literal(ArgumentNames.ADD)
                    .then(Commands.argument(ArgumentNames.FROM, Arguments.coords())
                            .then(Commands.argument(ArgumentNames.TO, Arguments.coords())
                                    .executes(BoxCommandBuilder::addBox))))
            .then(Commands.literal(ArgumentNames.CLEAR)
                    .executes(context -> {
                        CustomBoxProvider.clear();

                        CommandHelper.feedback(context, "bbor.commands.box.cleared.all");
                        return 0;
                    })
                    .then(Commands.argument(ArgumentNames.FROM, Arguments.coords())
                            .then(Commands.argument(ArgumentNames.TO, Arguments.coords())
                                    .executes(context -> {
                                        Coords from = Arguments.getCoords(context, ArgumentNames.FROM);
                                        Coords to = Arguments.getCoords(context, ArgumentNames.TO);
                                        Coords minCoords = getMinCoords(from, to);
                                        Coords maxCoords = getMaxCoords(from, to);
                                        boolean removed = CustomBoxProvider.remove(minCoords, maxCoords);

                                        String format = removed ? "bbor.commands.box.cleared" : "bbor.commands.box.notFound";
                                        CommandHelper.feedback(context, format,
                                                from.getX(), from.getY(), from.getZ(),
                                                to.getX(), to.getY(), to.getZ());
                                        return 0;
                                    }))));
}
 
Example #26
Source File: ViaFabric.java    From ViaFabric with MIT License 5 votes vote down vote up
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 #27
Source File: InfoCommand.java    From fabric-carpet with MIT License 5 votes vote down vote up
public static void register(CommandDispatcher<ServerCommandSource> dispatcher)
{
    LiteralArgumentBuilder<ServerCommandSource> command = literal("info").
            requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandInfo)).
            then(literal("block").
                    then(argument("block position", BlockPosArgumentType.blockPos()).
                            executes( (c) -> infoBlock(
                                    c.getSource(),
                                    BlockPosArgumentType.getBlockPos(c, "block position"), null)).
                            then(literal("grep").
                                    then(argument("regexp",greedyString()).
                                            executes( (c) -> infoBlock(
                                                    c.getSource(),
                                                    BlockPosArgumentType.getBlockPos(c, "block position"),
                                                    getString(c, "regexp"))))))).
            then(literal("entity").
                    then(argument("entity selector", EntityArgumentType.entities()).
                            executes( (c) -> infoEntities(
                                    c.getSource(), EntityArgumentType.getEntities(c,"entity selector"), null)).
                            then(literal("grep").
                                    then(argument("regexp",greedyString()).
                                            executes( (c) -> infoEntities(
                                                    c.getSource(),
                                                    EntityArgumentType.getEntities(c,"entity selector"),
                                                    getString(c, "regexp")))))));

    dispatcher.register(command);
}
 
Example #28
Source File: LineCommandBuilder.java    From BoundingBoxOutlineReloaded with MIT License 5 votes vote down vote up
static LiteralArgumentBuilder<CommandSource> build(String command) {
    return Commands.literal(command)
            .then(Commands.literal(ArgumentNames.ADD)
                    .then(Commands.argument(ArgumentNames.FROM, Arguments.point())
                            .then(Commands.argument(ArgumentNames.TO, Arguments.point())
                                    .executes(LineCommandBuilder::addLine)
                                    .then(Commands.argument(WIDTH, Arguments.doubleArg())
                                            .executes(LineCommandBuilder::addLine)))))
            .then(Commands.literal(ArgumentNames.CLEAR)
                    .executes(context -> {
                        CustomLineProvider.clear();

                        CommandHelper.feedback(context, "bbor.commands.line.cleared.all");
                        return 0;
                    })
                    .then(Commands.argument(ArgumentNames.FROM, Arguments.coords())
                            .then(Commands.argument(ArgumentNames.TO, Arguments.coords())
                                    .executes(context -> {
                                        Point from = Arguments.getPoint(context, ArgumentNames.FROM).snapXZ(0.5d);
                                        Point to = Arguments.getPoint(context, ArgumentNames.TO).snapXZ(0.5d);
                                        boolean removed = CustomLineProvider.remove(from, to);

                                        String format = removed ? "bbor.commands.line.cleared" : "bbor.commands.line.notFound";
                                        CommandHelper.feedback(context, format,
                                                from.getX(), from.getY(), from.getZ(),
                                                to.getX(), to.getY(), to.getZ());
                                        return 0;
                                    }))));
}
 
Example #29
Source File: LiteralCommandNode.java    From brigadier with MIT License 5 votes vote down vote up
@Override
public LiteralArgumentBuilder<S> createBuilder() {
    final LiteralArgumentBuilder<S> builder = LiteralArgumentBuilder.literal(this.literal);
    builder.requires(getRequirement());
    builder.forward(getRedirect(), getRedirectModifier(), isFork());
    if (getCommand() != null) {
        builder.executes(getCommand());
    }
    return builder;
}
 
Example #30
Source File: LogCommand.java    From fabric-carpet with MIT License 5 votes vote down vote up
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);
}