From 6ecda84ad8df2f1af619348d30b42ee7045aa24d Mon Sep 17 00:00:00 2001 From: Jason Penilla <11360596+jpenilla@users.noreply.github.com> Date: Thu, 30 May 2024 12:09:25 -0700 Subject: [PATCH] fixes --- ...ix-CommandRegisteredEvent-not-called.patch | 96 ++++++++++++++++--- 1 file changed, 83 insertions(+), 13 deletions(-) diff --git a/patches/server/1053-Fix-CommandRegisteredEvent-not-called.patch b/patches/server/1053-Fix-CommandRegisteredEvent-not-called.patch index c7d6dc01c0..3baed9fcef 100644 --- a/patches/server/1053-Fix-CommandRegisteredEvent-not-called.patch +++ b/patches/server/1053-Fix-CommandRegisteredEvent-not-called.patch @@ -4,42 +4,75 @@ Date: Wed, 29 May 2024 13:15:43 -0700 Subject: [PATCH] Fix CommandRegisteredEvent not called -diff --git a/src/main/java/io/papermc/paper/command/brigadier/LazyCommandNode.java b/src/main/java/io/papermc/paper/command/brigadier/LazyCommandNode.java +diff --git a/src/main/java/io/papermc/paper/command/brigadier/LazyBukkitCommandNode.java b/src/main/java/io/papermc/paper/command/brigadier/LazyBukkitCommandNode.java new file mode 100644 -index 0000000000000000000000000000000000000000..2ca3ca97874c7a8184ee0ef951c15bacf4d4eadb +index 0000000000000000000000000000000000000000..72d7b46fdcfdfc8a9bac4b7f7ef7eb2a5b0a08ef --- /dev/null -+++ b/src/main/java/io/papermc/paper/command/brigadier/LazyCommandNode.java -@@ -0,0 +1,21 @@ ++++ b/src/main/java/io/papermc/paper/command/brigadier/LazyBukkitCommandNode.java +@@ -0,0 +1,33 @@ +package io.papermc.paper.command.brigadier; + +import com.mojang.brigadier.tree.LiteralCommandNode; ++import io.papermc.paper.command.brigadier.bukkit.BukkitCommandNode; +import java.util.function.Supplier; ++import org.bukkit.command.Command; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; +import org.checkerframework.framework.qual.DefaultQualifier; + +@DefaultQualifier(NonNull.class) -+public class LazyCommandNode extends LiteralCommandNode { -+ private final Supplier<@Nullable LiteralCommandNode> nodeSupplier; ++public class LazyBukkitCommandNode extends LiteralCommandNode { ++ private final Command command; ++ private final Supplier<@Nullable BukkitCommandNode> nodeSupplier; + -+ public LazyCommandNode(final String literal, final Supplier<@Nullable LiteralCommandNode> nodeSupplier) { ++ public LazyBukkitCommandNode( ++ final String literal, ++ final Command command, ++ final Supplier<@Nullable BukkitCommandNode> nodeSupplier ++ ) { + super(literal, null, null, null, null, false); ++ this.command = command; + this.nodeSupplier = nodeSupplier; + } + -+ public @Nullable LiteralCommandNode create() { ++ public @Nullable BukkitCommandNode create() { + return this.nodeSupplier.get(); + } ++ ++ public Command bukkitCommand() { ++ return this.command; ++ } +} +diff --git a/src/main/java/io/papermc/paper/command/brigadier/PaperBrigadier.java b/src/main/java/io/papermc/paper/command/brigadier/PaperBrigadier.java +index 4acf7c3bcfbe61431bfbfa3c8addb33f671eb498..ab9a71faa6696cfe8cc88cd9513cda8b9fad1b6a 100644 +--- a/src/main/java/io/papermc/paper/command/brigadier/PaperBrigadier.java ++++ b/src/main/java/io/papermc/paper/command/brigadier/PaperBrigadier.java +@@ -64,9 +64,15 @@ public final class PaperBrigadier { + CommandDispatcher erasedDispatcher = before.getDispatcher(); + + for (Object node : erasedDispatcher.getRoot().getChildren()) { +- if (node instanceof CommandNode commandNode && commandNode.getCommand() instanceof BukkitCommandNode.BukkitBrigCommand) { ++ if (node instanceof BukkitCommandNode) { + after.getDispatcher().getRoot().removeCommand(((CommandNode) node).getName()); // Remove already existing commands + after.getDispatcher().getRoot().addChild((CommandNode) node); ++ } else if (node instanceof LazyBukkitCommandNode lazy) { ++ after.getDispatcher().getRoot().removeCommand(lazy.getName()); // Remove already existing commands ++ final BukkitCommandNode newNode = lazy.create(); ++ if (newNode != null) { ++ after.getDispatcher().getRoot().addChild((CommandNode) newNode); ++ } + } + } + } diff --git a/src/main/java/io/papermc/paper/command/brigadier/bukkit/BukkitBrigForwardingMap.java b/src/main/java/io/papermc/paper/command/brigadier/bukkit/BukkitBrigForwardingMap.java -index f0cc27640bb3db275295a298d608c9d9f88df617..566bf6729e4e0a768b8ec3a2e574ae681f8eaf7b 100644 +index f0cc27640bb3db275295a298d608c9d9f88df617..6e2911a31f6ba06c47b7e22912447912501de602 100644 --- a/src/main/java/io/papermc/paper/command/brigadier/bukkit/BukkitBrigForwardingMap.java +++ b/src/main/java/io/papermc/paper/command/brigadier/bukkit/BukkitBrigForwardingMap.java @@ -5,6 +5,7 @@ import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.tree.CommandNode; import com.mojang.brigadier.tree.LiteralCommandNode; import io.papermc.paper.command.brigadier.CommandSourceStack; -+import io.papermc.paper.command.brigadier.LazyCommandNode; ++import io.papermc.paper.command.brigadier.LazyBukkitCommandNode; import io.papermc.paper.command.brigadier.PaperBrigadier; import io.papermc.paper.command.brigadier.PaperCommands; import java.util.AbstractCollection; @@ -68,7 +101,7 @@ index f0cc27640bb3db275295a298d608c9d9f88df617..566bf6729e4e0a768b8ec3a2e574ae68 + final List remove = new ArrayList<>(); + final List> list = new ArrayList<>(); + for (final CommandNode child : this.getDispatcher().getRoot().getChildren()) { -+ if (child instanceof LazyCommandNode lazy) { ++ if (child instanceof LazyBukkitCommandNode lazy) { + remove.add(child.getName()); + final LiteralCommandNode newNode = lazy.create(); + if (newNode != null) { @@ -87,14 +120,33 @@ index f0cc27640bb3db275295a298d608c9d9f88df617..566bf6729e4e0a768b8ec3a2e574ae68 @Override public int size() { return this.getDispatcher().getRoot().getChildren().size(); -@@ -95,7 +119,18 @@ public class BukkitBrigForwardingMap extends HashMap { +@@ -70,6 +94,8 @@ public class BukkitBrigForwardingMap extends HashMap { + // If child is a bukkit command node, we can convert it! + if (child instanceof BukkitCommandNode bukkitCommandNode) { + return bukkitCommandNode.getBukkitCommand().equals(value); ++ } else if (child instanceof LazyBukkitCommandNode lazy) { ++ return lazy.bukkitCommand().equals(value); + } + } + +@@ -85,6 +111,8 @@ public class BukkitBrigForwardingMap extends HashMap { + + if (node instanceof BukkitCommandNode bukkitCommandNode) { + return bukkitCommandNode.getBukkitCommand(); ++ } else if (node instanceof LazyBukkitCommandNode lazyBukkitCommandNode) { ++ return lazyBukkitCommandNode.bukkitCommand(); + } + + return PaperBrigadier.wrapNode(node); +@@ -95,7 +123,19 @@ public class BukkitBrigForwardingMap extends HashMap { public Command put(String key, Command value) { Command old = this.get(key); this.getDispatcher().getRoot().removeCommand(key); // Override previous command - this.getDispatcher().getRoot().addChild(BukkitCommandNode.of(key, value)); + if (!this.synced) { -+ final LazyCommandNode node = new LazyCommandNode<>( ++ final LazyBukkitCommandNode node = new LazyBukkitCommandNode<>( + key, ++ value, + () -> BukkitCommandNode.create(key, value, this.getDispatcher()) + ); + this.getDispatcher().getRoot().addChild(node); @@ -107,6 +159,24 @@ index f0cc27640bb3db275295a298d608c9d9f88df617..566bf6729e4e0a768b8ec3a2e574ae68 return old; } +@@ -187,6 +227,8 @@ public class BukkitBrigForwardingMap extends HashMap { + this.lastFetched = next; + if (next instanceof BukkitCommandNode bukkitCommandNode) { + return bukkitCommandNode.getBukkitCommand(); ++ } else if (next instanceof LazyBukkitCommandNode lazyBukkitCommandNode) { ++ return lazyBukkitCommandNode.bukkitCommand(); + } else { + return PaperBrigadier.wrapNode(next); + } +@@ -304,6 +346,8 @@ public class BukkitBrigForwardingMap extends HashMap { + private Map.Entry nodeToEntry(CommandNode node) { + if (node instanceof BukkitCommandNode bukkitCommandNode) { + return this.mutableEntry(bukkitCommandNode.getName(), bukkitCommandNode.getBukkitCommand()); ++ } else if (node instanceof LazyBukkitCommandNode lazyBukkitCommandNode) { ++ return this.mutableEntry(lazyBukkitCommandNode.getName(), lazyBukkitCommandNode.bukkitCommand()); + } else { + Command wrapped = PaperBrigadier.wrapNode(node); + return this.mutableEntry(node.getName(), wrapped); diff --git a/src/main/java/io/papermc/paper/command/brigadier/bukkit/BukkitCommandNode.java b/src/main/java/io/papermc/paper/command/brigadier/bukkit/BukkitCommandNode.java index 10a113b057b0a4d27cce3bae975e1108aaa7b517..dd9a586789995cde207e3b4c79ff3dfeba944135 100644 --- a/src/main/java/io/papermc/paper/command/brigadier/bukkit/BukkitCommandNode.java