add descriptions.,,.
This commit is contained in:
parent
f20bede62a
commit
6c71b666af
7 changed files with 37 additions and 9 deletions
|
@ -4,6 +4,7 @@
|
||||||
package com.mojang.brigadier.builder;
|
package com.mojang.brigadier.builder;
|
||||||
|
|
||||||
import com.mojang.brigadier.Command;
|
import com.mojang.brigadier.Command;
|
||||||
|
import com.mojang.brigadier.Message;
|
||||||
import com.mojang.brigadier.RedirectModifier;
|
import com.mojang.brigadier.RedirectModifier;
|
||||||
import com.mojang.brigadier.SingleRedirectModifier;
|
import com.mojang.brigadier.SingleRedirectModifier;
|
||||||
import com.mojang.brigadier.tree.CommandNode;
|
import com.mojang.brigadier.tree.CommandNode;
|
||||||
|
@ -20,6 +21,7 @@ public abstract class ArgumentBuilder<S, T extends ArgumentBuilder<S, T>> {
|
||||||
private CommandNode<S> target;
|
private CommandNode<S> target;
|
||||||
private RedirectModifier<S> modifier = null;
|
private RedirectModifier<S> modifier = null;
|
||||||
private boolean forks;
|
private boolean forks;
|
||||||
|
private Message description;
|
||||||
|
|
||||||
protected abstract T getThis();
|
protected abstract T getThis();
|
||||||
|
|
||||||
|
@ -52,6 +54,15 @@ public abstract class ArgumentBuilder<S, T extends ArgumentBuilder<S, T>> {
|
||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public T describe(final Message description) {
|
||||||
|
this.description = description;
|
||||||
|
return getThis();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Message getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
public T requires(final Predicate<S> requirement) {
|
public T requires(final Predicate<S> requirement) {
|
||||||
this.requirement = requirement;
|
this.requirement = requirement;
|
||||||
return getThis();
|
return getThis();
|
||||||
|
|
|
@ -28,7 +28,7 @@ public class LiteralArgumentBuilder<S> extends ArgumentBuilder<S, LiteralArgumen
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LiteralCommandNode<S> build() {
|
public LiteralCommandNode<S> build() {
|
||||||
final LiteralCommandNode<S> result = new LiteralCommandNode<>(getLiteral(), getCommand(), getRequirement(), getRedirect(), getRedirectModifier(), isFork());
|
final LiteralCommandNode<S> result = new LiteralCommandNode<>(getLiteral(), getCommand(), getRequirement(), getRedirect(), getRedirectModifier(), isFork(), getDescription());
|
||||||
|
|
||||||
for (final CommandNode<S> argument : getArguments()) {
|
for (final CommandNode<S> argument : getArguments()) {
|
||||||
result.addChild(argument);
|
result.addChild(argument);
|
||||||
|
|
|
@ -45,7 +45,7 @@ public class RequiredArgumentBuilder<S, T> extends ArgumentBuilder<S, RequiredAr
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArgumentCommandNode<S, T> build() {
|
public ArgumentCommandNode<S, T> build() {
|
||||||
final ArgumentCommandNode<S, T> result = new ArgumentCommandNode<>(getName(), getType(), getCommand(), getRequirement(), getRedirect(), getRedirectModifier(), isFork(), getSuggestionsProvider());
|
final ArgumentCommandNode<S, T> result = new ArgumentCommandNode<>(getName(), getType(), getCommand(), getRequirement(), getRedirect(), getRedirectModifier(), isFork(), getSuggestionsProvider(), getDescription());
|
||||||
|
|
||||||
for (final CommandNode<S> argument : getArguments()) {
|
for (final CommandNode<S> argument : getArguments()) {
|
||||||
result.addChild(argument);
|
result.addChild(argument);
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
package com.mojang.brigadier.tree;
|
package com.mojang.brigadier.tree;
|
||||||
|
|
||||||
import com.mojang.brigadier.Command;
|
import com.mojang.brigadier.Command;
|
||||||
|
import com.mojang.brigadier.Message;
|
||||||
import com.mojang.brigadier.RedirectModifier;
|
import com.mojang.brigadier.RedirectModifier;
|
||||||
import com.mojang.brigadier.StringReader;
|
import com.mojang.brigadier.StringReader;
|
||||||
import com.mojang.brigadier.arguments.ArgumentType;
|
import com.mojang.brigadier.arguments.ArgumentType;
|
||||||
|
@ -29,7 +30,11 @@ public class ArgumentCommandNode<S, T> extends CommandNode<S> {
|
||||||
private final SuggestionProvider<S> customSuggestions;
|
private final SuggestionProvider<S> customSuggestions;
|
||||||
|
|
||||||
public ArgumentCommandNode(final String name, final ArgumentType<T> type, final Command<S> command, final Predicate<S> requirement, final CommandNode<S> redirect, final RedirectModifier<S> modifier, final boolean forks, final SuggestionProvider<S> customSuggestions) {
|
public ArgumentCommandNode(final String name, final ArgumentType<T> type, final Command<S> command, final Predicate<S> requirement, final CommandNode<S> redirect, final RedirectModifier<S> modifier, final boolean forks, final SuggestionProvider<S> customSuggestions) {
|
||||||
super(command, requirement, redirect, modifier, forks);
|
this(name, type, command, requirement, redirect, modifier, forks, customSuggestions, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArgumentCommandNode(final String name, final ArgumentType<T> type, final Command<S> command, final Predicate<S> requirement, final CommandNode<S> redirect, final RedirectModifier<S> modifier, final boolean forks, final SuggestionProvider<S> customSuggestions, final Message description) {
|
||||||
|
super(command, requirement, redirect, modifier, forks, description);
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.customSuggestions = customSuggestions;
|
this.customSuggestions = customSuggestions;
|
||||||
|
|
|
@ -3,10 +3,7 @@
|
||||||
|
|
||||||
package com.mojang.brigadier.tree;
|
package com.mojang.brigadier.tree;
|
||||||
|
|
||||||
import com.mojang.brigadier.AmbiguityConsumer;
|
import com.mojang.brigadier.*;
|
||||||
import com.mojang.brigadier.Command;
|
|
||||||
import com.mojang.brigadier.RedirectModifier;
|
|
||||||
import com.mojang.brigadier.StringReader;
|
|
||||||
import com.mojang.brigadier.builder.ArgumentBuilder;
|
import com.mojang.brigadier.builder.ArgumentBuilder;
|
||||||
import com.mojang.brigadier.context.CommandContext;
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
import com.mojang.brigadier.context.CommandContextBuilder;
|
import com.mojang.brigadier.context.CommandContextBuilder;
|
||||||
|
@ -32,19 +29,29 @@ public abstract class CommandNode<S> implements Comparable<CommandNode<S>> {
|
||||||
private final RedirectModifier<S> modifier;
|
private final RedirectModifier<S> modifier;
|
||||||
private final boolean forks;
|
private final boolean forks;
|
||||||
private Command<S> command;
|
private Command<S> command;
|
||||||
|
private Message description;
|
||||||
|
|
||||||
protected CommandNode(final Command<S> command, final Predicate<S> requirement, final CommandNode<S> redirect, final RedirectModifier<S> modifier, final boolean forks) {
|
protected CommandNode(final Command<S> command, final Predicate<S> requirement, final CommandNode<S> redirect, final RedirectModifier<S> modifier, final boolean forks) {
|
||||||
|
this(command, requirement, redirect, modifier, forks, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected CommandNode(final Command<S> command, final Predicate<S> requirement, final CommandNode<S> redirect, final RedirectModifier<S> modifier, final boolean forks, final Message description) {
|
||||||
this.command = command;
|
this.command = command;
|
||||||
this.requirement = requirement;
|
this.requirement = requirement;
|
||||||
this.redirect = redirect;
|
this.redirect = redirect;
|
||||||
this.modifier = modifier;
|
this.modifier = modifier;
|
||||||
this.forks = forks;
|
this.forks = forks;
|
||||||
|
this.description = description;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Command<S> getCommand() {
|
public Command<S> getCommand() {
|
||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Message getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
public Collection<CommandNode<S>> getChildren() {
|
public Collection<CommandNode<S>> getChildren() {
|
||||||
return children.values();
|
return children.values();
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
package com.mojang.brigadier.tree;
|
package com.mojang.brigadier.tree;
|
||||||
|
|
||||||
import com.mojang.brigadier.Command;
|
import com.mojang.brigadier.Command;
|
||||||
|
import com.mojang.brigadier.Message;
|
||||||
import com.mojang.brigadier.RedirectModifier;
|
import com.mojang.brigadier.RedirectModifier;
|
||||||
import com.mojang.brigadier.StringReader;
|
import com.mojang.brigadier.StringReader;
|
||||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
|
@ -25,7 +26,11 @@ public class LiteralCommandNode<S> extends CommandNode<S> {
|
||||||
private final String literalLowerCase;
|
private final String literalLowerCase;
|
||||||
|
|
||||||
public LiteralCommandNode(final String literal, final Command<S> command, final Predicate<S> requirement, final CommandNode<S> redirect, final RedirectModifier<S> modifier, final boolean forks) {
|
public LiteralCommandNode(final String literal, final Command<S> command, final Predicate<S> requirement, final CommandNode<S> redirect, final RedirectModifier<S> 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<S> command, final Predicate<S> requirement, final CommandNode<S> redirect, final RedirectModifier<S> modifier, final boolean forks, final Message description) {
|
||||||
|
super(command, requirement, redirect, modifier, forks, description);
|
||||||
this.literal = literal;
|
this.literal = literal;
|
||||||
this.literalLowerCase = literal.toLowerCase(Locale.ROOT);
|
this.literalLowerCase = literal.toLowerCase(Locale.ROOT);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
public class RootCommandNode<S> extends CommandNode<S> {
|
public class RootCommandNode<S> extends CommandNode<S> {
|
||||||
public RootCommandNode() {
|
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
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue