Move patches to unapplied
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
--- a/com/mojang/authlib/yggdrasil/YggdrasilGameProfileRepository.java
|
||||
+++ b/com/mojang/authlib/yggdrasil/YggdrasilGameProfileRepository.java
|
||||
@@ -44,6 +44,7 @@
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
final int page = 0;
|
||||
+ boolean hasRequested = false; // Paper - Don't sleep after profile lookups if not needed
|
||||
|
||||
for (final List<String> request : Iterables.partition(criteria, ENTRIES_PER_PAGE)) {
|
||||
final List<String> normalizedRequest = request.stream().map(YggdrasilGameProfileRepository::normalizeName).toList();
|
||||
@@ -75,6 +76,12 @@
|
||||
LOGGER.debug("Couldn't find profile {}", name);
|
||||
callback.onProfileLookupFailed(name, new ProfileNotFoundException("Server did not find the requested profile"));
|
||||
}
|
||||
+ // Paper start - Don't sleep after profile lookups if not needed
|
||||
+ if (!hasRequested) {
|
||||
+ hasRequested = true;
|
||||
+ continue;
|
||||
+ }
|
||||
+ // Paper end - Don't sleep after profile lookups if not needed
|
||||
|
||||
try {
|
||||
Thread.sleep(DELAY_BETWEEN_PAGES);
|
||||
@@ -0,0 +1,75 @@
|
||||
--- a/com/mojang/brigadier/CommandDispatcher.java
|
||||
+++ b/com/mojang/brigadier/CommandDispatcher.java
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
package com.mojang.brigadier;
|
||||
|
||||
+// CHECKSTYLE:OFF
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.context.CommandContextBuilder;
|
||||
@@ -297,15 +298,21 @@
|
||||
List<ParseResults<S>> potentials = null;
|
||||
final int cursor = originalReader.getCursor();
|
||||
|
||||
- for (final CommandNode<S> child : node.getRelevantNodes(originalReader)) {
|
||||
+ for (final CommandNode<S> child : node.getRelevantNodes(originalReader, source)) { // Paper - prioritize mc commands in function parsing
|
||||
if (!child.canUse(source)) {
|
||||
continue;
|
||||
}
|
||||
final CommandContextBuilder<S> context = contextSoFar.copy();
|
||||
final StringReader reader = new StringReader(originalReader);
|
||||
+ boolean stop = false; // Paper - Handle non-recoverable exceptions
|
||||
try {
|
||||
try {
|
||||
child.parse(reader, context);
|
||||
+ // Paper start - Handle non-recoverable exceptions
|
||||
+ } catch (final io.papermc.paper.brigadier.TagParseCommandSyntaxException e) {
|
||||
+ stop = true;
|
||||
+ throw e;
|
||||
+ // Paper end - Handle non-recoverable exceptions
|
||||
} catch (final RuntimeException ex) {
|
||||
throw CommandSyntaxException.BUILT_IN_EXCEPTIONS.dispatcherParseException().createWithContext(reader, ex.getMessage());
|
||||
}
|
||||
@@ -320,6 +327,7 @@
|
||||
}
|
||||
errors.put(child, ex);
|
||||
reader.setCursor(cursor);
|
||||
+ if (stop) return new ParseResults<>(contextSoFar, originalReader, errors); // Paper - Handle non-recoverable exceptions
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -451,7 +459,7 @@
|
||||
}
|
||||
|
||||
private String getSmartUsage(final CommandNode<S> node, final S source, final boolean optional, final boolean deep) {
|
||||
- if (!node.canUse(source)) {
|
||||
+ if (source != null && !node.canUse(source)) { // Paper
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -465,7 +473,7 @@
|
||||
final String redirect = node.getRedirect() == this.root ? "..." : "-> " + node.getRedirect().getUsageText();
|
||||
return self + CommandDispatcher.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);
|
||||
if (usage != null) {
|
||||
@@ -537,10 +545,14 @@
|
||||
int i = 0;
|
||||
for (final CommandNode<S> node : parent.getChildren()) {
|
||||
CompletableFuture<Suggestions> future = Suggestions.empty();
|
||||
+ // Paper start - Don't suggest if the requirement isn't met
|
||||
+ if (parent != this.root || node.canUse(context.getSource())) {
|
||||
try {
|
||||
- future = node.listSuggestions(context.build(truncatedInput), new SuggestionsBuilder(truncatedInput, truncatedInputLowerCase, start));
|
||||
+ future = node.listSuggestions(context.build(truncatedInput), new SuggestionsBuilder(truncatedInput, truncatedInputLowerCase, start)); // CraftBukkit
|
||||
} catch (final CommandSyntaxException ignored) {
|
||||
}
|
||||
+ }
|
||||
+ // Paper end - Don't suggest if the requirement isn't met
|
||||
futures[i++] = future;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
--- a/com/mojang/brigadier/builder/ArgumentBuilder.java
|
||||
+++ b/com/mojang/brigadier/builder/ArgumentBuilder.java
|
||||
@@ -14,9 +14,17 @@
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public abstract class ArgumentBuilder<S, T extends ArgumentBuilder<S, T>> {
|
||||
+ // Paper start - Vanilla command permission fixes
|
||||
+ private static final Predicate<Object> DEFAULT_REQUIREMENT = s -> true;
|
||||
+
|
||||
+ @SuppressWarnings("unchecked")
|
||||
+ public static <S> Predicate<S> defaultRequirement() {
|
||||
+ return (Predicate<S>) DEFAULT_REQUIREMENT;
|
||||
+ }
|
||||
+ // Paper end - Vanilla command permission fixes
|
||||
private final RootCommandNode<S> arguments = new RootCommandNode<>();
|
||||
private Command<S> command;
|
||||
- private Predicate<S> requirement = s -> true;
|
||||
+ private Predicate<S> requirement = defaultRequirement(); // Paper - Vanilla command permission fixes
|
||||
private CommandNode<S> target;
|
||||
private RedirectModifier<S> modifier = null;
|
||||
private boolean forks;
|
||||
@@ -0,0 +1,102 @@
|
||||
--- a/com/mojang/brigadier/tree/CommandNode.java
|
||||
+++ b/com/mojang/brigadier/tree/CommandNode.java
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
package com.mojang.brigadier.tree;
|
||||
|
||||
+// CHECKSTYLE:OFF
|
||||
import com.mojang.brigadier.AmbiguityConsumer;
|
||||
import com.mojang.brigadier.Command;
|
||||
import com.mojang.brigadier.RedirectModifier;
|
||||
@@ -22,6 +23,7 @@
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Predicate;
|
||||
+import net.minecraft.commands.CommandSourceStack;
|
||||
|
||||
public abstract class CommandNode<S> implements Comparable<CommandNode<S>> {
|
||||
private final Map<String, CommandNode<S>> children = new LinkedHashMap<>();
|
||||
@@ -32,6 +34,16 @@
|
||||
private final RedirectModifier<S> modifier;
|
||||
private final boolean forks;
|
||||
private Command<S> command;
|
||||
+ public CommandNode<CommandSourceStack> clientNode; // Paper - Brigadier API
|
||||
+ public CommandNode<io.papermc.paper.command.brigadier.CommandSourceStack> unwrappedCached = null; // Paper - Brigadier Command API
|
||||
+ public CommandNode<io.papermc.paper.command.brigadier.CommandSourceStack> wrappedCached = null; // Paper - Brigadier Command API
|
||||
+ // CraftBukkit start
|
||||
+ public void removeCommand(String name) {
|
||||
+ this.children.remove(name);
|
||||
+ this.literals.remove(name);
|
||||
+ this.arguments.remove(name);
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
- public boolean canUse(final S source) {
|
||||
+ // CraftBukkit start
|
||||
+ public synchronized boolean canUse(final S source) {
|
||||
+ if (source instanceof CommandSourceStack) {
|
||||
+ try {
|
||||
+ ((CommandSourceStack) source).currentCommand.put(Thread.currentThread(), this); // Paper - Thread Safe Vanilla Command permission checking
|
||||
+ return this.requirement.test(source);
|
||||
+ } finally {
|
||||
+ ((CommandSourceStack) source).currentCommand.remove(Thread.currentThread()); // Paper - Thread Safe Vanilla Command permission checking
|
||||
+ }
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
return this.requirement.test(source);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
+ // Paper start - Brigadier Command API
|
||||
+ public void clearAll() {
|
||||
+ this.children.clear();
|
||||
+ this.literals.clear();
|
||||
+ this.arguments.clear();
|
||||
+ }
|
||||
+ // Paper end - Brigadier Command API
|
||||
}
|
||||
@@ -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
|
||||
@@ -0,0 +1,21 @@
|
||||
--- a/com/mojang/datafixers/DataFixerBuilder.java
|
||||
+++ b/com/mojang/datafixers/DataFixerBuilder.java
|
||||
@@ -29,8 +29,10 @@
|
||||
private final Int2ObjectSortedMap<Schema> schemas = new Int2ObjectAVLTreeMap<>();
|
||||
private final List<DataFix> globalList = new ArrayList<>();
|
||||
private final IntSortedSet fixerVersions = new IntAVLTreeSet();
|
||||
+ private final int minDataFixPrecacheVersion; // Paper - Perf: Cache DataFixerUpper Rewrite Rules on demand
|
||||
|
||||
public DataFixerBuilder(final int dataVersion) {
|
||||
+ minDataFixPrecacheVersion = Integer.getInteger("Paper.minPrecachedDatafixVersion", dataVersion+1) * 10; // Paper - Perf: default to precache nothing - mojang stores versions * 10 to allow for 'sub versions'
|
||||
this.dataVersion = dataVersion;
|
||||
}
|
||||
|
||||
@@ -88,6 +90,7 @@
|
||||
final IntIterator iterator = fixerUpper.fixerVersions().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
final int versionKey = iterator.nextInt();
|
||||
+ if (versionKey < minDataFixPrecacheVersion) continue; // Paper - Perf: Cache DataFixerUpper Rewrite Rules on demand
|
||||
final Schema schema = schemas.get(versionKey);
|
||||
for (final String typeName : schema.types()) {
|
||||
if (!requiredTypeNames.contains(typeName)) {
|
||||
@@ -0,0 +1,38 @@
|
||||
--- a/com/mojang/datafixers/util/Either.java
|
||||
+++ b/com/mojang/datafixers/util/Either.java
|
||||
@@ -22,7 +22,7 @@
|
||||
}
|
||||
|
||||
private static final class Left<L, R> extends Either<L, R> {
|
||||
- private final L value;
|
||||
+ private final L value; private Optional<L> valueOptional; // Paper - Perf: Reduce Either Optional allocation
|
||||
|
||||
public Left(final L value) {
|
||||
this.value = value;
|
||||
@@ -51,7 +51,7 @@
|
||||
|
||||
@Override
|
||||
public Optional<L> left() {
|
||||
- return Optional.of(value);
|
||||
+ return this.valueOptional == null ? this.valueOptional = Optional.of(this.value) : this.valueOptional; // Paper - Perf: Reduce Either Optional allocation
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -83,7 +83,7 @@
|
||||
}
|
||||
|
||||
private static final class Right<L, R> extends Either<L, R> {
|
||||
- private final R value;
|
||||
+ private final R value; private Optional<R> valueOptional; // Paper - Perf: Reduce Either Optional allocation
|
||||
|
||||
public Right(final R value) {
|
||||
this.value = value;
|
||||
@@ -117,7 +117,7 @@
|
||||
|
||||
@Override
|
||||
public Optional<R> right() {
|
||||
- return Optional.of(value);
|
||||
+ return this.valueOptional == null ? this.valueOptional = Optional.of(this.value) : this.valueOptional; // Paper - Perf: Reduce Either Optional allocation
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -0,0 +1,12 @@
|
||||
--- a/com/mojang/logging/LogUtils.java
|
||||
+++ b/com/mojang/logging/LogUtils.java
|
||||
@@ -61,4 +61,9 @@
|
||||
public static Logger getLogger() {
|
||||
return LoggerFactory.getLogger(STACK_WALKER.getCallerClass());
|
||||
}
|
||||
+ // Paper start
|
||||
+ public static Logger getClassLogger() {
|
||||
+ return LoggerFactory.getLogger(STACK_WALKER.getCallerClass().getSimpleName());
|
||||
+ }
|
||||
+ // Paper end
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
--- a/com/mojang/math/OctahedralGroup.java
|
||||
+++ b/com/mojang/math/OctahedralGroup.java
|
||||
@@ -110,6 +110,7 @@
|
||||
this.permutation = axisTransformation;
|
||||
this.transformation = new Matrix3f().scaling(flipX ? -1.0F : 1.0F, flipY ? -1.0F : 1.0F, flipZ ? -1.0F : 1.0F);
|
||||
this.transformation.mul(axisTransformation.transformation());
|
||||
+ this.initializeRotationDirections(); // Paper - Avoid Lazy Initialization for Enum Fields
|
||||
}
|
||||
|
||||
private BooleanList packInversions() {
|
||||
@@ -138,7 +139,7 @@
|
||||
return this.name;
|
||||
}
|
||||
|
||||
- public Direction rotate(Direction direction) {
|
||||
+ public void initializeRotationDirections() { // Paper - Avoid Lazy Initialization for Enum Fields
|
||||
if (this.rotatedDirections == null) {
|
||||
this.rotatedDirections = Maps.newEnumMap(Direction.class);
|
||||
Direction.Axis[] axiss = Direction.Axis.values();
|
||||
@@ -153,6 +154,10 @@
|
||||
}
|
||||
}
|
||||
|
||||
+ // Paper start - Avoid Lazy Initialization for Enum Fields
|
||||
+ }
|
||||
+ public Direction rotate(Direction direction) {
|
||||
+ // Paper end - Avoid Lazy Initialization for Enum Fields
|
||||
return this.rotatedDirections.get(direction);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
--- a/com/mojang/serialization/Dynamic.java
|
||||
+++ b/com/mojang/serialization/Dynamic.java
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class Dynamic<T> extends DynamicLike<T> {
|
||||
+ private static final boolean DEBUG_MISSING_KEYS = Boolean.getBoolean("Paper.debugDynamicMissingKeys"); // Paper - Perf: Skip toString on values like NBT
|
||||
private final T value;
|
||||
|
||||
public Dynamic(final DynamicOps<T> ops) {
|
||||
@@ -120,7 +121,7 @@
|
||||
return new OptionalDynamic<>(ops, ops.getMap(value).flatMap(m -> {
|
||||
final T value = m.get(key);
|
||||
if (value == null) {
|
||||
- return DataResult.error(() -> "key missing: " + key + " in " + this.value);
|
||||
+ return DataResult.error(() -> DEBUG_MISSING_KEYS ? "key missing: " + key + " in " + this.value : "key missing: " + key); // Paper - Perf: Skip toString on values like NBT
|
||||
}
|
||||
return DataResult.success(new Dynamic<>(ops, value));
|
||||
}));
|
||||
Reference in New Issue
Block a user