Allow turning nodes back into builders without children
This commit is contained in:
@@ -162,4 +162,8 @@ public class CommandDispatcher<S> {
|
||||
|
||||
return nodes.toArray(new String[nodes.size()]);
|
||||
}
|
||||
|
||||
public RootCommandNode<S> getRoot() {
|
||||
return root;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ public abstract class ArgumentBuilder<S, T extends ArgumentBuilder<S, T>> {
|
||||
return getThis();
|
||||
}
|
||||
|
||||
protected Command<S> getCommand() {
|
||||
public Command<S> getCommand() {
|
||||
return command;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ public class LiteralArgumentBuilder<S> extends ArgumentBuilder<S, LiteralArgumen
|
||||
return this;
|
||||
}
|
||||
|
||||
private String getLiteral() {
|
||||
public String getLiteral() {
|
||||
return literal;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,11 +22,11 @@ public class RequiredArgumentBuilder<S, T> extends ArgumentBuilder<S, RequiredAr
|
||||
return this;
|
||||
}
|
||||
|
||||
private CommandArgumentType<T> getType() {
|
||||
public CommandArgumentType<T> getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
private String getName() {
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.mojang.brigadier.tree;
|
||||
|
||||
import com.mojang.brigadier.Command;
|
||||
import com.mojang.brigadier.arguments.CommandArgumentType;
|
||||
import com.mojang.brigadier.builder.ArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
import com.mojang.brigadier.context.CommandContextBuilder;
|
||||
import com.mojang.brigadier.context.ParsedArgument;
|
||||
import com.mojang.brigadier.exceptions.CommandException;
|
||||
@@ -60,6 +62,16 @@ public class ArgumentCommandNode<S, T> extends CommandNode<S> {
|
||||
type.listSuggestions(command, output);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequiredArgumentBuilder<S, T> createBuilder() {
|
||||
final RequiredArgumentBuilder<S, T> builder = RequiredArgumentBuilder.argument(name, type);
|
||||
builder.requires(getRequirement());
|
||||
if (getCommand() != null) {
|
||||
builder.executes(getCommand());
|
||||
}
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.mojang.brigadier.tree;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.mojang.brigadier.Command;
|
||||
import com.mojang.brigadier.builder.ArgumentBuilder;
|
||||
import com.mojang.brigadier.context.CommandContextBuilder;
|
||||
import com.mojang.brigadier.exceptions.CommandException;
|
||||
|
||||
@@ -65,6 +66,10 @@ public abstract class CommandNode<S> {
|
||||
return 31 * children.hashCode() + (command != null ? command.hashCode() : 0);
|
||||
}
|
||||
|
||||
public Predicate<S> getRequirement() {
|
||||
return requirement;
|
||||
}
|
||||
|
||||
protected abstract Object getMergeKey();
|
||||
|
||||
public abstract String getUsageText();
|
||||
@@ -72,4 +77,6 @@ public abstract class CommandNode<S> {
|
||||
public abstract String parse(String command, CommandContextBuilder<S> contextBuilder) throws CommandException;
|
||||
|
||||
public abstract void listSuggestions(String command, Set<String> output);
|
||||
|
||||
public abstract ArgumentBuilder<S, ?> createBuilder();
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.mojang.brigadier.tree;
|
||||
|
||||
import com.mojang.brigadier.Command;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.builder.ArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.context.CommandContextBuilder;
|
||||
import com.mojang.brigadier.exceptions.CommandException;
|
||||
import com.mojang.brigadier.exceptions.ParameterizedCommandExceptionType;
|
||||
@@ -70,4 +72,14 @@ public class LiteralCommandNode<S> extends CommandNode<S> {
|
||||
result = 31 * result + super.hashCode();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LiteralArgumentBuilder<S> createBuilder() {
|
||||
final LiteralArgumentBuilder<S> builder = LiteralArgumentBuilder.literal(this.literal);
|
||||
builder.requires(getRequirement());
|
||||
if (getCommand() != null) {
|
||||
builder.executes(getCommand());
|
||||
}
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.mojang.brigadier.tree;
|
||||
|
||||
import com.mojang.brigadier.builder.ArgumentBuilder;
|
||||
import com.mojang.brigadier.context.CommandContextBuilder;
|
||||
import com.mojang.brigadier.exceptions.CommandException;
|
||||
|
||||
@@ -35,4 +36,9 @@ public class RootCommandNode<S> extends CommandNode<S> {
|
||||
if (!(o instanceof RootCommandNode)) return false;
|
||||
return super.equals(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArgumentBuilder<S, ?> createBuilder() {
|
||||
throw new IllegalStateException("Cannot convert root into a builder");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user