Hackily solve issue where Bukkit doesn't create a new Brigadier command per alias, so that command aliases get the full Brigadier treatment

This commit is contained in:
Alexander Söderberg 2020-09-19 22:49:03 +02:00
parent 1fede2b4c0
commit d83690cdcf
No known key found for this signature in database
GPG key ID: C0207FF7EA146678
14 changed files with 213 additions and 82 deletions

View file

@ -531,8 +531,17 @@ public final class CommandTree<C> {
*/
@Nullable
public Node<CommandArgument<C, ?>> getNamedNode(@Nullable final String name) {
return this.getRootNodes().stream().filter(node -> node.getValue() != null
&& node.getValue().getName().equalsIgnoreCase(name)).findAny().orElse(null);
for (final Node<CommandArgument<C, ?>> node : this.getRootNodes()) {
if (node.getValue() != null && node.getValue() instanceof StaticArgument) {
final StaticArgument<C> staticArgument = (StaticArgument<C>) node.getValue();
for (final String alias : staticArgument.getAliases()) {
if (alias.equalsIgnoreCase(name)) {
return node;
}
}
}
}
return null;
}
/**

View file

@ -165,7 +165,7 @@ public class CommandArgument<C, T> implements Comparable<CommandArgument<?, ?>>
@Nonnull
@Override
public final String toString() {
return String.format("CommandArgument{name=%s}", this.name);
return String.format("%s{name=%s}", this.getClass().getSimpleName(), this.name);
}
/**

View file

@ -214,6 +214,24 @@ public final class ByteArgument<C> extends CommandArgument<C, Byte> {
return IntegerArgument.IntegerParser.getSuggestions(this.min, this.max, input);
}
/**
* Get the max value
*
* @return Max value
*/
public byte getMax() {
return this.max;
}
/**
* Get the min value
*
* @return Min value
*/
public byte getMin() {
return this.min;
}
}

View file

@ -204,6 +204,24 @@ public final class DoubleArgument<C> extends CommandArgument<C, Double> {
return true;
}
/**
* Get the max value
*
* @return Max value
*/
public double getMax() {
return this.max;
}
/**
* Get the min value
*
* @return Min value
*/
public double getMin() {
return this.min;
}
}

View file

@ -203,6 +203,25 @@ public final class FloatArgument<C> extends CommandArgument<C, Float> {
public boolean isContextFree() {
return true;
}
/**
* Get the max value
*
* @return Max value
*/
public float getMax() {
return this.max;
}
/**
* Get the min value
*
* @return Min value
*/
public float getMin() {
return this.min;
}
}

View file

@ -212,6 +212,24 @@ public final class ShortArgument<C> extends CommandArgument<C, Short> {
return IntegerArgument.IntegerParser.getSuggestions(this.min, this.max, input);
}
/**
* Get the max value
*
* @return Max value
*/
public short getMax() {
return this.max;
}
/**
* Get the min value
*
* @return Min value
*/
public short getMin() {
return this.min;
}
}

View file

@ -268,6 +268,16 @@ public final class StringArgument<C> extends CommandArgument<C, String> {
public boolean isContextFree() {
return true;
}
/**
* Get the string mode
*
* @return String mode
*/
@Nonnull
public StringMode getStringMode() {
return this.stringMode;
}
}