mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-27 15:00:13 +01:00
brig stuff
This commit is contained in:
parent
f2ff5966a6
commit
8324be321a
4 changed files with 29 additions and 29 deletions
|
@ -1,6 +1,6 @@
|
|||
--- a/com/mojang/brigadier/CommandDispatcher.java
|
||||
+++ b/com/mojang/brigadier/CommandDispatcher.java
|
||||
@@ -3,6 +3,7 @@
|
||||
@@ -3,6 +_,7 @@
|
||||
|
||||
package com.mojang.brigadier;
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
|||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.context.CommandContextBuilder;
|
||||
@@ -297,15 +298,21 @@
|
||||
@@ -297,15 +_,21 @@
|
||||
List<ParseResults<S>> potentials = null;
|
||||
final int cursor = originalReader.getCursor();
|
||||
|
||||
|
@ -31,7 +31,7 @@
|
|||
} catch (final RuntimeException ex) {
|
||||
throw CommandSyntaxException.BUILT_IN_EXCEPTIONS.dispatcherParseException().createWithContext(reader, ex.getMessage());
|
||||
}
|
||||
@@ -320,6 +327,7 @@
|
||||
@@ -320,6 +_,7 @@
|
||||
}
|
||||
errors.put(child, ex);
|
||||
reader.setCursor(cursor);
|
||||
|
@ -39,7 +39,7 @@
|
|||
continue;
|
||||
}
|
||||
|
||||
@@ -451,7 +459,7 @@
|
||||
@@ -451,7 +_,7 @@
|
||||
}
|
||||
|
||||
private String getSmartUsage(final CommandNode<S> node, final S source, final boolean optional, final boolean deep) {
|
||||
|
@ -48,16 +48,16 @@
|
|||
return null;
|
||||
}
|
||||
|
||||
@@ -465,7 +473,7 @@
|
||||
final String redirect = node.getRedirect() == this.root ? "..." : "-> " + node.getRedirect().getUsageText();
|
||||
return self + CommandDispatcher.ARGUMENT_SEPARATOR + redirect;
|
||||
@@ -465,7 +_,7 @@
|
||||
final String redirect = node.getRedirect() == root ? "..." : "-> " + node.getRedirect().getUsageText();
|
||||
return self + ARGUMENT_SEPARATOR + redirect;
|
||||
} 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 -> source == null || c.canUse(source)).collect(Collectors.toList()); // Paper
|
||||
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) {
|
||||
@@ -537,10 +545,14 @@
|
||||
@@ -537,10 +_,14 @@
|
||||
int i = 0;
|
||||
for (final CommandNode<S> node : parent.getChildren()) {
|
||||
CompletableFuture<Suggestions> future = Suggestions.empty();
|
|
@ -1,6 +1,6 @@
|
|||
--- a/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;
|
||||
|
||||
public abstract class ArgumentBuilder<S, T extends ArgumentBuilder<S, T>> {
|
|
@ -1,6 +1,6 @@
|
|||
--- a/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;
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
|||
import com.mojang.brigadier.AmbiguityConsumer;
|
||||
import com.mojang.brigadier.Command;
|
||||
import com.mojang.brigadier.RedirectModifier;
|
||||
@@ -22,6 +23,7 @@
|
||||
@@ -22,6 +_,7 @@
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Predicate;
|
||||
|
@ -16,7 +16,7 @@
|
|||
|
||||
public abstract class CommandNode<S> implements Comparable<CommandNode<S>> {
|
||||
private final Map<String, CommandNode<S>> children = new LinkedHashMap<>();
|
||||
@@ -32,6 +34,16 @@
|
||||
@@ -32,6 +_,16 @@
|
||||
private final RedirectModifier<S> modifier;
|
||||
private final boolean forks;
|
||||
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) {
|
||||
this.command = command;
|
||||
@@ -61,7 +73,17 @@
|
||||
return this.modifier;
|
||||
@@ -61,7 +_,17 @@
|
||||
return modifier;
|
||||
}
|
||||
|
||||
- public boolean canUse(final S source) {
|
||||
+ // CraftBukkit start
|
||||
+ // Paper start
|
||||
+ public synchronized boolean canUse(final S source) {
|
||||
+ if (source instanceof CommandSourceStack) {
|
||||
+ try {
|
||||
|
@ -48,28 +48,28 @@
|
|||
+ ((CommandSourceStack) source).currentCommand.remove(Thread.currentThread()); // Paper - Thread Safe Vanilla Command permission checking
|
||||
+ }
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
return this.requirement.test(source);
|
||||
+ // Paper end
|
||||
return requirement.test(source);
|
||||
}
|
||||
|
||||
@@ -151,6 +173,12 @@
|
||||
@@ -151,6 +_,12 @@
|
||||
protected abstract String getSortedKey();
|
||||
|
||||
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);
|
||||
+ }
|
||||
+ @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) {
|
||||
+ // Paper end - prioritize mc commands in function parsing
|
||||
if (literals.size() > 0) {
|
||||
final int cursor = input.getCursor();
|
||||
while (input.canRead() && input.peek() != ' ') {
|
||||
@@ -158,7 +186,21 @@
|
||||
@@ -158,7 +_,21 @@
|
||||
}
|
||||
final String text = input.getString().substring(cursor, input.getCursor());
|
||||
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
|
||||
+ LiteralCommandNode<S> literal = null;
|
||||
+ if (source instanceof CommandSourceStack css && css.source == net.minecraft.commands.CommandSource.NULL) {
|
||||
|
@ -88,7 +88,7 @@
|
|||
if (literal != null) {
|
||||
return Collections.singleton(literal);
|
||||
} else {
|
||||
@@ -183,4 +225,11 @@
|
||||
@@ -183,4 +_,11 @@
|
||||
}
|
||||
|
||||
public abstract Collection<String> getExamples();
|
|
@ -1,6 +1,6 @@
|
|||
--- a/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> {
|
||||
private final String literal;
|
||||
private final String literalLowerCase;
|
||||
|
@ -20,7 +20,7 @@
|
|||
}
|
||||
|
||||
public String getLiteral() {
|
||||
@@ -42,7 +50,12 @@
|
||||
@@ -42,7 +_,12 @@
|
||||
@Override
|
||||
public void parse(final StringReader reader, final CommandContextBuilder<S> contextBuilder) throws CommandSyntaxException {
|
||||
final int start = reader.getCursor();
|
||||
|
@ -34,7 +34,7 @@
|
|||
if (end > -1) {
|
||||
contextBuilder.withNode(this, StringRange.between(start, end));
|
||||
return;
|
||||
@@ -51,7 +64,10 @@
|
||||
@@ -51,7 +_,10 @@
|
||||
throw CommandSyntaxException.BUILT_IN_EXCEPTIONS.literalIncorrect().createWithContext(reader, literal);
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@
|
|||
final int start = reader.getCursor();
|
||||
if (reader.canRead(literal.length())) {
|
||||
final int end = start + literal.length();
|
||||
@@ -78,7 +94,7 @@
|
||||
@@ -78,7 +_,7 @@
|
||||
|
||||
@Override
|
||||
public boolean isValidInput(final String input) {
|
Loading…
Reference in a new issue