From cdc53a1abe7970225a2a915b301a0bf3f42c0e85 Mon Sep 17 00:00:00 2001 From: Jason Penilla <11360596+jpenilla@users.noreply.github.com> Date: Wed, 29 May 2024 14:29:32 -0700 Subject: [PATCH] fix tests --- ...x-CommandRegisteredEvent-not-called.patch} | 35 +++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) rename patches/server/{1051-Fix-CommandRegisteredEvent-not-called.patch => 1053-Fix-CommandRegisteredEvent-not-called.patch} (84%) diff --git a/patches/server/1051-Fix-CommandRegisteredEvent-not-called.patch b/patches/server/1053-Fix-CommandRegisteredEvent-not-called.patch similarity index 84% rename from patches/server/1051-Fix-CommandRegisteredEvent-not-called.patch rename to patches/server/1053-Fix-CommandRegisteredEvent-not-called.patch index 28052e31bb..c7d6dc01c0 100644 --- a/patches/server/1051-Fix-CommandRegisteredEvent-not-called.patch +++ b/patches/server/1053-Fix-CommandRegisteredEvent-not-called.patch @@ -108,7 +108,7 @@ index f0cc27640bb3db275295a298d608c9d9f88df617..566bf6729e4e0a768b8ec3a2e574ae68 } 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..5d2d2bf7e170a4546d687f10305d28ebc7c02037 100644 +index 10a113b057b0a4d27cce3bae975e1108aaa7b517..dd9a586789995cde207e3b4c79ff3dfeba944135 100644 --- a/src/main/java/io/papermc/paper/command/brigadier/bukkit/BukkitCommandNode.java +++ b/src/main/java/io/papermc/paper/command/brigadier/bukkit/BukkitCommandNode.java @@ -1,6 +1,7 @@ @@ -144,7 +144,7 @@ index 10a113b057b0a4d27cce3bae975e1108aaa7b517..5d2d2bf7e170a4546d687f10305d28eb public class BukkitCommandNode extends LiteralCommandNode { -@@ -43,16 +53,51 @@ public class BukkitCommandNode extends LiteralCommandNode { +@@ -43,16 +53,58 @@ public class BukkitCommandNode extends LiteralCommandNode { this.command = command; } @@ -182,10 +182,17 @@ index 10a113b057b0a4d27cce3bae975e1108aaa7b517..5d2d2bf7e170a4546d687f10305d28eb + return (BukkitCommandNode) commandNode; + } + LiteralCommandNode defaultNode = commandNode; ++ final CraftServer craftServer; ++ if (Bukkit.getServer() instanceof CraftServer cs) { ++ craftServer = cs; ++ } else { ++ // Testing ++ craftServer = null; ++ } + com.destroystokyo.paper.event.brigadier.CommandRegisteredEvent event = + new com.destroystokyo.paper.event.brigadier.CommandRegisteredEvent<>( + name, -+ new BukkitCommandWrapper(((CraftServer) Bukkit.getServer()), command), ++ new BukkitCommandWrapper(craftServer, command), + command, + (RootCommandNode) dispatcher.getRoot(), + (LiteralCommandNode) commandNode, @@ -223,3 +230,25 @@ index 94a31c8f903eb61eb6d203e8e6fe8fb0beca28b1..b50a8b7000b707a5ff48cc670300f60d this.loadPlugins(); this.enablePlugins(PluginLoadOrder.STARTUP); this.enablePlugins(PluginLoadOrder.POSTWORLD); +diff --git a/src/test/java/io/papermc/paper/command/brigadier/BukkitCommandConversionTest.java b/src/test/java/io/papermc/paper/command/brigadier/BukkitCommandConversionTest.java +index 6475510ea1084a003fb2c8645cb4538b3f48e1c7..0c43cb683cc3928a1225013d7fee64c6721be2d4 100644 +--- a/src/test/java/io/papermc/paper/command/brigadier/BukkitCommandConversionTest.java ++++ b/src/test/java/io/papermc/paper/command/brigadier/BukkitCommandConversionTest.java +@@ -46,7 +46,8 @@ public class BukkitCommandConversionTest extends AbstractTestingBase { + + CommandDispatcher dispatcher = DATA_PACK.commands.getDispatcher(); + dispatcher.setConsumer((context, success, result) -> {}); +- CommandMap commandMap = new SimpleCommandMap(Bukkit.getServer(), new BukkitBrigForwardingMap()); ++ final BukkitBrigForwardingMap map = new BukkitBrigForwardingMap(); ++ CommandMap commandMap = new SimpleCommandMap(Bukkit.getServer(), map); + Map stringCommandMap = commandMap.getKnownCommands(); + // All commands should be mirrored -- or equal + int commandMapSize = stringCommandMap.values().size(); +@@ -56,6 +57,7 @@ public class BukkitCommandConversionTest extends AbstractTestingBase { + + // Register a new command + commandMap.register("test", exampleCommand); ++ map.onSync(); + Assertions.assertEquals(commandMapSize + (3 * 2), stringCommandMap.values().size()); // Make sure commands are accounted for, including those with namespaced keys + + // Test Registration