mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-15 20:23:53 -07:00
Prioritize Minecraft commands in function parsing and command blocks
This commit is contained in:
@@ -52,7 +52,43 @@
|
||||
return this.requirement.test(source);
|
||||
}
|
||||
|
||||
@@ -183,4 +205,11 @@
|
||||
@@ -151,6 +173,12 @@
|
||||
protected abstract String getSortedKey();
|
||||
|
||||
public Collection<? extends CommandNode<S>> getRelevantNodes(final StringReader input) {
|
||||
+ // Paper start - prioritize mc commands in function parsing
|
||||
+ return this.getRelevantNodes(input, null);
|
||||
+ }
|
||||
+ @org.jetbrains.annotations.ApiStatus.Internal
|
||||
+ public Collection<? extends CommandNode<S>> getRelevantNodes(final StringReader input, final Object source) {
|
||||
+ // Paper end - prioritize mc commands in function parsing
|
||||
if (this.literals.size() > 0) {
|
||||
final int cursor = input.getCursor();
|
||||
while (input.canRead() && input.peek() != ' ') {
|
||||
@@ -158,7 +186,21 @@
|
||||
}
|
||||
final String text = input.getString().substring(cursor, input.getCursor());
|
||||
input.setCursor(cursor);
|
||||
- final LiteralCommandNode<S> literal = this.literals.get(text);
|
||||
+ // Paper start - prioritize mc commands in function parsing
|
||||
+ LiteralCommandNode<S> literal = null;
|
||||
+ if (source instanceof CommandSourceStack css && css.source == net.minecraft.commands.CommandSource.NULL) {
|
||||
+ if (!text.contains(":")) {
|
||||
+ literal = this.literals.get("minecraft:" + text);
|
||||
+ }
|
||||
+ } else if (source instanceof CommandSourceStack css && css.source instanceof net.minecraft.world.level.BaseCommandBlock) {
|
||||
+ if (css.getServer().server.getCommandBlockOverride(text) && !text.contains(":")) {
|
||||
+ literal = this.literals.get("minecraft:" + text);
|
||||
+ }
|
||||
+ }
|
||||
+ if (literal == null) {
|
||||
+ literal = this.literals.get(text);
|
||||
+ }
|
||||
+ // Paper end - prioritize mc commands in function parsing
|
||||
if (literal != null) {
|
||||
return Collections.singleton(literal);
|
||||
} else {
|
||||
@@ -183,4 +225,11 @@
|
||||
}
|
||||
|
||||
public abstract Collection<String> getExamples();
|
||||
|
@@ -0,0 +1,57 @@
|
||||
--- a/com/mojang/brigadier/tree/LiteralCommandNode.java
|
||||
+++ b/com/mojang/brigadier/tree/LiteralCommandNode.java
|
||||
@@ -23,11 +23,19 @@
|
||||
public class LiteralCommandNode<S> extends CommandNode<S> {
|
||||
private final String literal;
|
||||
private final String literalLowerCase;
|
||||
+ private final String nonPrefixed; // Paper - prioritize mc commands in function parsing
|
||||
|
||||
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 = literal;
|
||||
this.literalLowerCase = literal.toLowerCase(Locale.ROOT);
|
||||
+ // Paper start - prioritize mc commands in function parsing
|
||||
+ if (literal.startsWith("minecraft:")) {
|
||||
+ this.nonPrefixed = literal.substring("minecraft:".length());
|
||||
+ } else {
|
||||
+ this.nonPrefixed = null;
|
||||
+ }
|
||||
+ // Paper end - prioritize mc commands in function parsing
|
||||
}
|
||||
|
||||
public String getLiteral() {
|
||||
@@ -42,7 +50,12 @@
|
||||
@Override
|
||||
public void parse(final StringReader reader, final CommandContextBuilder<S> contextBuilder) throws CommandSyntaxException {
|
||||
final int start = reader.getCursor();
|
||||
- final int end = parse(reader);
|
||||
+ // Paper start - prioritize mc commands in function parsing
|
||||
+ int end = parse(reader, false);
|
||||
+ if (end == -1 && this.nonPrefixed != null) {
|
||||
+ end = parse(reader, true);
|
||||
+ }
|
||||
+ // Paper end - prioritize mc commands in function parsing
|
||||
if (end > -1) {
|
||||
contextBuilder.withNode(this, StringRange.between(start, end));
|
||||
return;
|
||||
@@ -51,7 +64,10 @@
|
||||
throw CommandSyntaxException.BUILT_IN_EXCEPTIONS.literalIncorrect().createWithContext(reader, literal);
|
||||
}
|
||||
|
||||
- private int parse(final StringReader reader) {
|
||||
+ // Paper start - prioritize mc commands in function parsing
|
||||
+ private int parse(final StringReader reader, final boolean secondPass) {
|
||||
+ String literal = secondPass ? this.nonPrefixed : this.literal;
|
||||
+ // Paper end - prioritize mc commands in function parsing
|
||||
final int start = reader.getCursor();
|
||||
if (reader.canRead(literal.length())) {
|
||||
final int end = start + literal.length();
|
||||
@@ -78,7 +94,7 @@
|
||||
|
||||
@Override
|
||||
public boolean isValidInput(final String input) {
|
||||
- return parse(new StringReader(input)) > -1;
|
||||
+ return parse(new StringReader(input), false) > -1; // Paper - prioritize mc commands in function parsing
|
||||
}
|
||||
|
||||
@Override
|
Reference in New Issue
Block a user