com.mojang.brigadier.builder.RequiredArgumentBuilder Java Examples

The following examples show how to use com.mojang.brigadier.builder.RequiredArgumentBuilder. 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: 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 #3
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 #4
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 #5
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 #6
Source File: DrawCommand.java    From fabric-carpet with MIT License 5 votes vote down vote up
private static RequiredArgumentBuilder<ServerCommandSource, BlockStateArgument>
drawShape(OptionalBlockSelector drawer)
{
    return argument("block", BlockStateArgumentType.blockState()).
            executes(drawer::apply)
            .then(literal("replace")
                    .then(argument("filter", BlockPredicateArgumentType.blockPredicate())
                            .executes(drawer::apply)));
}
 
Example #7
Source File: CommandAPIHandler.java    From 1.13-Command-API with Apache License 2.0 5 votes vote down vote up
private <T> RequiredArgumentBuilder<?, T> getRequiredArgumentBuilderDynamic(String argumentName, Argument type,
		CommandPermission permission) {
	if(type.getOverriddenSuggestions() == null) {
		return RequiredArgumentBuilder.argument(argumentName, (ArgumentType<T>) type.getRawType()).requires(clw -> 
             permissionCheck(nms.getCommandSenderForCLW(clw), permission)
        );
	} else {
		return getRequiredArgumentBuilderWithProvider(argumentName, type.getRawType(), permission,
				(CommandContext context, SuggestionsBuilder builder) -> getSuggestionsBuilder(builder,
						type.getOverriddenSuggestions().apply(nms.getCommandSenderForCLW(context.getSource()))));
	}
}
 
Example #8
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 #9
Source File: ArgumentCommandNode.java    From brigadier with MIT License 5 votes vote down vote up
@Override
public RequiredArgumentBuilder<S, T> createBuilder() {
    final RequiredArgumentBuilder<S, T> builder = RequiredArgumentBuilder.argument(name, type);
    builder.requires(getRequirement());
    builder.forward(getRedirect(), getRedirectModifier(), isFork());
    builder.suggests(customSuggestions);
    if (getCommand() != null) {
        builder.executes(getCommand());
    }
    return builder;
}
 
Example #10
Source File: ArgumentCommandNodeTest.java    From brigadier with MIT License 5 votes vote down vote up
@Test
public void testCreateBuilder() throws Exception {
    final RequiredArgumentBuilder<Object, Integer> builder = node.createBuilder();
    assertThat(builder.getName(), is(node.getName()));
    assertThat(builder.getType(), is(node.getType()));
    assertThat(builder.getRequirement(), is(node.getRequirement()));
    assertThat(builder.getCommand(), is(node.getCommand()));
}
 
Example #11
Source File: Commands.java    From BlueMap with MIT License 4 votes vote down vote up
private <T> RequiredArgumentBuilder<S, T> argument(String name, ArgumentType<T> type){
	return RequiredArgumentBuilder.<S, T>argument(name, type);
}
 
Example #12
Source File: Commands_1_12_2.java    From multiconnect with MIT License 4 votes vote down vote up
public static <T> RequiredArgumentBuilder<CommandSource, T> argument(String name, ArgumentType<T> type) {
    return RequiredArgumentBuilder.argument(name, type);
}
 
Example #13
Source File: CommandAPIHandler.java    From 1.13-Command-API with Apache License 2.0 4 votes vote down vote up
private <T> RequiredArgumentBuilder<?, T> getRequiredArgumentBuilderWithProvider(String argumentName,
		ArgumentType<T> type, CommandPermission permission, SuggestionProvider provider) {
	return RequiredArgumentBuilder.argument(argumentName, type)
			.requires(clw -> permissionCheck(nms.getCommandSenderForCLW(clw), permission)).suggests(provider);
}