From 6c71b666af464dba2d86e56d904eb0bc1c286d02 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Sun, 11 Jun 2023 20:33:13 +0700 Subject: [PATCH] add descriptions.,,. --- .../mojang/brigadier/builder/ArgumentBuilder.java | 11 +++++++++++ .../brigadier/builder/LiteralArgumentBuilder.java | 2 +- .../builder/RequiredArgumentBuilder.java | 2 +- .../brigadier/tree/ArgumentCommandNode.java | 7 ++++++- .../com/mojang/brigadier/tree/CommandNode.java | 15 +++++++++++---- .../mojang/brigadier/tree/LiteralCommandNode.java | 7 ++++++- .../mojang/brigadier/tree/RootCommandNode.java | 2 +- 7 files changed, 37 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/mojang/brigadier/builder/ArgumentBuilder.java b/src/main/java/com/mojang/brigadier/builder/ArgumentBuilder.java index 899008b..d1988f5 100644 --- a/src/main/java/com/mojang/brigadier/builder/ArgumentBuilder.java +++ b/src/main/java/com/mojang/brigadier/builder/ArgumentBuilder.java @@ -4,6 +4,7 @@ package com.mojang.brigadier.builder; import com.mojang.brigadier.Command; +import com.mojang.brigadier.Message; import com.mojang.brigadier.RedirectModifier; import com.mojang.brigadier.SingleRedirectModifier; import com.mojang.brigadier.tree.CommandNode; @@ -20,6 +21,7 @@ public abstract class ArgumentBuilder> { private CommandNode target; private RedirectModifier modifier = null; private boolean forks; + private Message description; protected abstract T getThis(); @@ -52,6 +54,15 @@ public abstract class ArgumentBuilder> { return command; } + public T describe(final Message description) { + this.description = description; + return getThis(); + } + + public Message getDescription() { + return description; + } + public T requires(final Predicate requirement) { this.requirement = requirement; return getThis(); diff --git a/src/main/java/com/mojang/brigadier/builder/LiteralArgumentBuilder.java b/src/main/java/com/mojang/brigadier/builder/LiteralArgumentBuilder.java index 779f760..ef86dee 100644 --- a/src/main/java/com/mojang/brigadier/builder/LiteralArgumentBuilder.java +++ b/src/main/java/com/mojang/brigadier/builder/LiteralArgumentBuilder.java @@ -28,7 +28,7 @@ public class LiteralArgumentBuilder extends ArgumentBuilder build() { - final LiteralCommandNode result = new LiteralCommandNode<>(getLiteral(), getCommand(), getRequirement(), getRedirect(), getRedirectModifier(), isFork()); + final LiteralCommandNode result = new LiteralCommandNode<>(getLiteral(), getCommand(), getRequirement(), getRedirect(), getRedirectModifier(), isFork(), getDescription()); for (final CommandNode argument : getArguments()) { result.addChild(argument); diff --git a/src/main/java/com/mojang/brigadier/builder/RequiredArgumentBuilder.java b/src/main/java/com/mojang/brigadier/builder/RequiredArgumentBuilder.java index a09b9e1..adf1cc1 100644 --- a/src/main/java/com/mojang/brigadier/builder/RequiredArgumentBuilder.java +++ b/src/main/java/com/mojang/brigadier/builder/RequiredArgumentBuilder.java @@ -45,7 +45,7 @@ public class RequiredArgumentBuilder extends ArgumentBuilder build() { - final ArgumentCommandNode result = new ArgumentCommandNode<>(getName(), getType(), getCommand(), getRequirement(), getRedirect(), getRedirectModifier(), isFork(), getSuggestionsProvider()); + final ArgumentCommandNode result = new ArgumentCommandNode<>(getName(), getType(), getCommand(), getRequirement(), getRedirect(), getRedirectModifier(), isFork(), getSuggestionsProvider(), getDescription()); for (final CommandNode argument : getArguments()) { result.addChild(argument); diff --git a/src/main/java/com/mojang/brigadier/tree/ArgumentCommandNode.java b/src/main/java/com/mojang/brigadier/tree/ArgumentCommandNode.java index 6018eb0..adb64a2 100644 --- a/src/main/java/com/mojang/brigadier/tree/ArgumentCommandNode.java +++ b/src/main/java/com/mojang/brigadier/tree/ArgumentCommandNode.java @@ -4,6 +4,7 @@ package com.mojang.brigadier.tree; import com.mojang.brigadier.Command; +import com.mojang.brigadier.Message; import com.mojang.brigadier.RedirectModifier; import com.mojang.brigadier.StringReader; import com.mojang.brigadier.arguments.ArgumentType; @@ -29,7 +30,11 @@ public class ArgumentCommandNode extends CommandNode { private final SuggestionProvider customSuggestions; public ArgumentCommandNode(final String name, final ArgumentType type, final Command command, final Predicate requirement, final CommandNode redirect, final RedirectModifier modifier, final boolean forks, final SuggestionProvider customSuggestions) { - super(command, requirement, redirect, modifier, forks); + this(name, type, command, requirement, redirect, modifier, forks, customSuggestions, null); + } + + public ArgumentCommandNode(final String name, final ArgumentType type, final Command command, final Predicate requirement, final CommandNode redirect, final RedirectModifier modifier, final boolean forks, final SuggestionProvider customSuggestions, final Message description) { + super(command, requirement, redirect, modifier, forks, description); this.name = name; this.type = type; this.customSuggestions = customSuggestions; diff --git a/src/main/java/com/mojang/brigadier/tree/CommandNode.java b/src/main/java/com/mojang/brigadier/tree/CommandNode.java index 47f8e3d..60c9262 100644 --- a/src/main/java/com/mojang/brigadier/tree/CommandNode.java +++ b/src/main/java/com/mojang/brigadier/tree/CommandNode.java @@ -3,10 +3,7 @@ package com.mojang.brigadier.tree; -import com.mojang.brigadier.AmbiguityConsumer; -import com.mojang.brigadier.Command; -import com.mojang.brigadier.RedirectModifier; -import com.mojang.brigadier.StringReader; +import com.mojang.brigadier.*; import com.mojang.brigadier.builder.ArgumentBuilder; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.context.CommandContextBuilder; @@ -32,19 +29,29 @@ public abstract class CommandNode implements Comparable> { private final RedirectModifier modifier; private final boolean forks; private Command command; + private Message description; protected CommandNode(final Command command, final Predicate requirement, final CommandNode redirect, final RedirectModifier modifier, final boolean forks) { + this(command, requirement, redirect, modifier, forks, null); + } + + protected CommandNode(final Command command, final Predicate requirement, final CommandNode redirect, final RedirectModifier modifier, final boolean forks, final Message description) { this.command = command; this.requirement = requirement; this.redirect = redirect; this.modifier = modifier; this.forks = forks; + this.description = description; } public Command getCommand() { return command; } + public Message getDescription() { + return description; + } + public Collection> getChildren() { return children.values(); } diff --git a/src/main/java/com/mojang/brigadier/tree/LiteralCommandNode.java b/src/main/java/com/mojang/brigadier/tree/LiteralCommandNode.java index 85a8904..bfec3bb 100644 --- a/src/main/java/com/mojang/brigadier/tree/LiteralCommandNode.java +++ b/src/main/java/com/mojang/brigadier/tree/LiteralCommandNode.java @@ -4,6 +4,7 @@ package com.mojang.brigadier.tree; import com.mojang.brigadier.Command; +import com.mojang.brigadier.Message; import com.mojang.brigadier.RedirectModifier; import com.mojang.brigadier.StringReader; import com.mojang.brigadier.builder.LiteralArgumentBuilder; @@ -25,7 +26,11 @@ public class LiteralCommandNode extends CommandNode { private final String literalLowerCase; public LiteralCommandNode(final String literal, final Command command, final Predicate requirement, final CommandNode redirect, final RedirectModifier modifier, final boolean forks) { - super(command, requirement, redirect, modifier, forks); + this(literal, command, requirement, redirect, modifier, forks, null); + } + + public LiteralCommandNode(final String literal, final Command command, final Predicate requirement, final CommandNode redirect, final RedirectModifier modifier, final boolean forks, final Message description) { + super(command, requirement, redirect, modifier, forks, description); this.literal = literal; this.literalLowerCase = literal.toLowerCase(Locale.ROOT); } diff --git a/src/main/java/com/mojang/brigadier/tree/RootCommandNode.java b/src/main/java/com/mojang/brigadier/tree/RootCommandNode.java index d2b25aa..b23ae5b 100644 --- a/src/main/java/com/mojang/brigadier/tree/RootCommandNode.java +++ b/src/main/java/com/mojang/brigadier/tree/RootCommandNode.java @@ -17,7 +17,7 @@ import java.util.concurrent.CompletableFuture; public class RootCommandNode extends CommandNode { public RootCommandNode() { - super(null, c -> true, null, s -> Collections.singleton(s.getSource()), false); + super(null, c -> true, null, s -> Collections.singleton(s.getSource()), false, null); } @Override