brig stuff

This commit is contained in:
Owen1212055 2024-12-13 11:02:13 -05:00
parent f2ff5966a6
commit 8324be321a
No known key found for this signature in database
GPG key ID: 2133292072886A30
4 changed files with 29 additions and 29 deletions

View file

@ -1,6 +1,6 @@
--- a/com/mojang/brigadier/CommandDispatcher.java --- a/com/mojang/brigadier/CommandDispatcher.java
+++ b/com/mojang/brigadier/CommandDispatcher.java +++ b/com/mojang/brigadier/CommandDispatcher.java
@@ -3,6 +3,7 @@ @@ -3,6 +_,7 @@
package com.mojang.brigadier; package com.mojang.brigadier;
@ -8,7 +8,7 @@
import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.context.CommandContextBuilder; import com.mojang.brigadier.context.CommandContextBuilder;
@@ -297,15 +298,21 @@ @@ -297,15 +_,21 @@
List<ParseResults<S>> potentials = null; List<ParseResults<S>> potentials = null;
final int cursor = originalReader.getCursor(); final int cursor = originalReader.getCursor();
@ -31,7 +31,7 @@
} catch (final RuntimeException ex) { } catch (final RuntimeException ex) {
throw CommandSyntaxException.BUILT_IN_EXCEPTIONS.dispatcherParseException().createWithContext(reader, ex.getMessage()); throw CommandSyntaxException.BUILT_IN_EXCEPTIONS.dispatcherParseException().createWithContext(reader, ex.getMessage());
} }
@@ -320,6 +327,7 @@ @@ -320,6 +_,7 @@
} }
errors.put(child, ex); errors.put(child, ex);
reader.setCursor(cursor); reader.setCursor(cursor);
@ -39,7 +39,7 @@
continue; continue;
} }
@@ -451,7 +459,7 @@ @@ -451,7 +_,7 @@
} }
private String getSmartUsage(final CommandNode<S> node, final S source, final boolean optional, final boolean deep) { private String getSmartUsage(final CommandNode<S> node, final S source, final boolean optional, final boolean deep) {
@ -48,16 +48,16 @@
return null; return null;
} }
@@ -465,7 +473,7 @@ @@ -465,7 +_,7 @@
final String redirect = node.getRedirect() == this.root ? "..." : "-> " + node.getRedirect().getUsageText(); final String redirect = node.getRedirect() == root ? "..." : "-> " + node.getRedirect().getUsageText();
return self + CommandDispatcher.ARGUMENT_SEPARATOR + redirect; return self + ARGUMENT_SEPARATOR + redirect;
} else { } else {
- final Collection<CommandNode<S>> children = node.getChildren().stream().filter(c -> c.canUse(source)).collect(Collectors.toList()); - final Collection<CommandNode<S>> children = node.getChildren().stream().filter(c -> c.canUse(source)).collect(Collectors.toList());
+ final Collection<CommandNode<S>> children = node.getChildren().stream().filter(c -> source == null || c.canUse(source)).collect(Collectors.toList()); // Paper + final Collection<CommandNode<S>> children = node.getChildren().stream().filter(c -> source == null || c.canUse(source)).collect(Collectors.toList()); // Paper
if (children.size() == 1) { if (children.size() == 1) {
final String usage = this.getSmartUsage(children.iterator().next(), source, childOptional, childOptional); final String usage = getSmartUsage(children.iterator().next(), source, childOptional, childOptional);
if (usage != null) { if (usage != null) {
@@ -537,10 +545,14 @@ @@ -537,10 +_,14 @@
int i = 0; int i = 0;
for (final CommandNode<S> node : parent.getChildren()) { for (final CommandNode<S> node : parent.getChildren()) {
CompletableFuture<Suggestions> future = Suggestions.empty(); CompletableFuture<Suggestions> future = Suggestions.empty();

View file

@ -1,6 +1,6 @@
--- a/com/mojang/brigadier/builder/ArgumentBuilder.java --- a/com/mojang/brigadier/builder/ArgumentBuilder.java
+++ b/com/mojang/brigadier/builder/ArgumentBuilder.java +++ b/com/mojang/brigadier/builder/ArgumentBuilder.java
@@ -14,9 +14,17 @@ @@ -14,9 +_,17 @@
import java.util.function.Predicate; import java.util.function.Predicate;
public abstract class ArgumentBuilder<S, T extends ArgumentBuilder<S, T>> { public abstract class ArgumentBuilder<S, T extends ArgumentBuilder<S, T>> {

View file

@ -1,6 +1,6 @@
--- a/com/mojang/brigadier/tree/CommandNode.java --- a/com/mojang/brigadier/tree/CommandNode.java
+++ b/com/mojang/brigadier/tree/CommandNode.java +++ b/com/mojang/brigadier/tree/CommandNode.java
@@ -3,6 +3,7 @@ @@ -3,6 +_,7 @@
package com.mojang.brigadier.tree; package com.mojang.brigadier.tree;
@ -8,7 +8,7 @@
import com.mojang.brigadier.AmbiguityConsumer; import com.mojang.brigadier.AmbiguityConsumer;
import com.mojang.brigadier.Command; import com.mojang.brigadier.Command;
import com.mojang.brigadier.RedirectModifier; import com.mojang.brigadier.RedirectModifier;
@@ -22,6 +23,7 @@ @@ -22,6 +_,7 @@
import java.util.Set; import java.util.Set;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.function.Predicate; import java.util.function.Predicate;
@ -16,7 +16,7 @@
public abstract class CommandNode<S> implements Comparable<CommandNode<S>> { public abstract class CommandNode<S> implements Comparable<CommandNode<S>> {
private final Map<String, CommandNode<S>> children = new LinkedHashMap<>(); private final Map<String, CommandNode<S>> children = new LinkedHashMap<>();
@@ -32,6 +34,16 @@ @@ -32,6 +_,16 @@
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;
@ -33,12 +33,12 @@
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 = command; this.command = command;
@@ -61,7 +73,17 @@ @@ -61,7 +_,17 @@
return this.modifier; return modifier;
} }
- public boolean canUse(final S source) { - public boolean canUse(final S source) {
+ // CraftBukkit start + // Paper start
+ public synchronized boolean canUse(final S source) { + public synchronized boolean canUse(final S source) {
+ if (source instanceof CommandSourceStack) { + if (source instanceof CommandSourceStack) {
+ try { + try {
@ -48,28 +48,28 @@
+ ((CommandSourceStack) source).currentCommand.remove(Thread.currentThread()); // Paper - Thread Safe Vanilla Command permission checking + ((CommandSourceStack) source).currentCommand.remove(Thread.currentThread()); // Paper - Thread Safe Vanilla Command permission checking
+ } + }
+ } + }
+ // CraftBukkit end + // Paper end
return this.requirement.test(source); return requirement.test(source);
} }
@@ -151,6 +173,12 @@ @@ -151,6 +_,12 @@
protected abstract String getSortedKey(); protected abstract String getSortedKey();
public Collection<? extends CommandNode<S>> getRelevantNodes(final StringReader input) { public Collection<? extends CommandNode<S>> getRelevantNodes(final StringReader input) {
+ // Paper start - prioritize mc commands in function parsing + // Paper start - prioritize mc commands in function parsing
+ return this.getRelevantNodes(input, null); + return this.getRelevantNodes(input, null);
+ } + }
+ @org.jetbrains.annotations.ApiStatus.Internal + @org.jetbrains.annotations.ApiStatus.Internal
+ public Collection<? extends CommandNode<S>> getRelevantNodes(final StringReader input, final Object source) { + public Collection<? extends CommandNode<S>> getRelevantNodes(final StringReader input, final Object source) {
+ // Paper end - prioritize mc commands in function parsing + // Paper end - prioritize mc commands in function parsing
if (this.literals.size() > 0) { if (literals.size() > 0) {
final int cursor = input.getCursor(); final int cursor = input.getCursor();
while (input.canRead() && input.peek() != ' ') { while (input.canRead() && input.peek() != ' ') {
@@ -158,7 +186,21 @@ @@ -158,7 +_,21 @@
} }
final String text = input.getString().substring(cursor, input.getCursor()); final String text = input.getString().substring(cursor, input.getCursor());
input.setCursor(cursor); input.setCursor(cursor);
- final LiteralCommandNode<S> literal = this.literals.get(text); - final LiteralCommandNode<S> literal = literals.get(text);
+ // Paper start - prioritize mc commands in function parsing + // Paper start - prioritize mc commands in function parsing
+ LiteralCommandNode<S> literal = null; + LiteralCommandNode<S> literal = null;
+ if (source instanceof CommandSourceStack css && css.source == net.minecraft.commands.CommandSource.NULL) { + if (source instanceof CommandSourceStack css && css.source == net.minecraft.commands.CommandSource.NULL) {
@ -88,7 +88,7 @@
if (literal != null) { if (literal != null) {
return Collections.singleton(literal); return Collections.singleton(literal);
} else { } else {
@@ -183,4 +225,11 @@ @@ -183,4 +_,11 @@
} }
public abstract Collection<String> getExamples(); public abstract Collection<String> getExamples();

View file

@ -1,6 +1,6 @@
--- a/com/mojang/brigadier/tree/LiteralCommandNode.java --- a/com/mojang/brigadier/tree/LiteralCommandNode.java
+++ b/com/mojang/brigadier/tree/LiteralCommandNode.java +++ b/com/mojang/brigadier/tree/LiteralCommandNode.java
@@ -23,11 +23,19 @@ @@ -23,11 +_,19 @@
public class LiteralCommandNode<S> extends CommandNode<S> { public class LiteralCommandNode<S> extends CommandNode<S> {
private final String literal; private final String literal;
private final String literalLowerCase; private final String literalLowerCase;
@ -20,7 +20,7 @@
} }
public String getLiteral() { public String getLiteral() {
@@ -42,7 +50,12 @@ @@ -42,7 +_,12 @@
@Override @Override
public void parse(final StringReader reader, final CommandContextBuilder<S> contextBuilder) throws CommandSyntaxException { public void parse(final StringReader reader, final CommandContextBuilder<S> contextBuilder) throws CommandSyntaxException {
final int start = reader.getCursor(); final int start = reader.getCursor();
@ -34,7 +34,7 @@
if (end > -1) { if (end > -1) {
contextBuilder.withNode(this, StringRange.between(start, end)); contextBuilder.withNode(this, StringRange.between(start, end));
return; return;
@@ -51,7 +64,10 @@ @@ -51,7 +_,10 @@
throw CommandSyntaxException.BUILT_IN_EXCEPTIONS.literalIncorrect().createWithContext(reader, literal); throw CommandSyntaxException.BUILT_IN_EXCEPTIONS.literalIncorrect().createWithContext(reader, literal);
} }
@ -46,7 +46,7 @@
final int start = reader.getCursor(); final int start = reader.getCursor();
if (reader.canRead(literal.length())) { if (reader.canRead(literal.length())) {
final int end = start + literal.length(); final int end = start + literal.length();
@@ -78,7 +94,7 @@ @@ -78,7 +_,7 @@
@Override @Override
public boolean isValidInput(final String input) { public boolean isValidInput(final String input) {