Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added static methods to create ArgumentBuilders directly in the BrigadierCommand class #1161

Merged
merged 1 commit into from
Dec 27, 2023

Conversation

4drian3d
Copy link
Contributor

Until now, to create a command with several brigadier nodes required a lot of boilerplate, otherwise, a compilation error arises

final LiteralCommandNode<CommandSource> rootNode = LiteralArgumentBuilder.<CommandSource>literal("command")
  .then(RequiredArgumentBuilder.<CommandSource, String>argument("argument", StringArgumentType.word())
    .executes(context -> {
      // command execution
      return Command.SINGLE_SUCCESS;
   })
  ).build();

With this pull request, the creation of a brigadier command would be significantly simplified, eliminating the unnecessary use of generics

final LiteralCommandNode<CommandSource> rootNode = BrigadierCommand.literalArgumentBuilder("command")
  .then(BrigadierCommand.requiredArgumentBuilder("argument", StringArgumentType.word())
    .executes(context -> {
      // command execution
      return Command.SINGLE_SUCCESS;
   })
  ).build();

In addition, it adds extra validations that Brigadier does not perform, such as improper use of spaces in the name of a LiteralCommandNode.

These methods may seem unnecessary, but for a complex node with several subnodes, it would be quite useful since normally one would do a static method doing exactly the same thing.

@astei astei merged commit 6fd03d6 into PaperMC:dev/3.0.0 Dec 27, 2023
1 check passed
@4drian3d 4drian3d deleted the feat/brigadier/static-factory branch December 27, 2023 18:35
pull bot pushed a commit to WiIIiam278/Velocity that referenced this pull request Jan 6, 2024
skbeh pushed a commit to skbeh/Velocity that referenced this pull request Jan 17, 2024
@4drian3d 4drian3d added this to the Velocity 3.3.0 milestone Feb 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants