From b4e3b3d1dd447bac4cbf478595c1ec320bc6dd4b Mon Sep 17 00:00:00 2001 From: Md5Lukas Date: Mon, 28 Aug 2023 13:21:13 +0200 Subject: [PATCH] Allow non-op players to execute the click event callback (#9652) --- LICENSE.md | 1 + patches/server/0010-Adventure.patch | 4 +- patches/server/0011-Paper-command.patch | 90 ++++++++++--------- patches/server/0013-Paper-Plugins.patch | 10 +-- patches/server/0016-Starlight.patch | 6 +- .../server/0019-Rewrite-chunk-system.patch | 6 +- ...ault-permission-message-configurable.patch | 4 +- .../0346-Add-debug-for-sync-chunk-loads.patch | 4 +- ...-Add-tick-times-API-and-mspt-command.patch | 6 +- .../server/0421-Paper-dumpitem-command.patch | 4 +- ...aper-mobcaps-and-paper-playermobcaps.patch | 4 +- ...0896-Add-paper-dumplisteners-command.patch | 4 +- 12 files changed, 73 insertions(+), 70 deletions(-) diff --git a/LICENSE.md b/LICENSE.md index b26adb448..ae1df51b8 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -62,4 +62,5 @@ dawon Ollie <69084614+olijeffers0n@users.noreply.github.com> Oliwier Miodun aerulion +Lukas Planz ``` diff --git a/patches/server/0010-Adventure.patch b/patches/server/0010-Adventure.patch index 289b2559f..dce8dbed8 100644 --- a/patches/server/0010-Adventure.patch +++ b/patches/server/0010-Adventure.patch @@ -1268,7 +1268,7 @@ index 0000000000000000000000000000000000000000..2ee72fe7cb56e70404b8c86f0c957875 +} diff --git a/src/main/java/io/papermc/paper/adventure/providers/ClickCallbackProviderImpl.java b/src/main/java/io/papermc/paper/adventure/providers/ClickCallbackProviderImpl.java new file mode 100644 -index 0000000000000000000000000000000000000000..3c17001bcd3862a76a22df488bff80a0ff4d1b83 +index 0000000000000000000000000000000000000000..23432eea862c6df716d7726a32da3a0612a3fb77 --- /dev/null +++ b/src/main/java/io/papermc/paper/adventure/providers/ClickCallbackProviderImpl.java @@ -0,0 +1,96 @@ @@ -1292,7 +1292,7 @@ index 0000000000000000000000000000000000000000..3c17001bcd3862a76a22df488bff80a0 + + @Override + public @NotNull ClickEvent create(final @NotNull ClickCallback callback, final ClickCallback.@NotNull Options options) { -+ return ClickEvent.runCommand("/paper callback " + CALLBACK_MANAGER.addCallback(callback, options)); ++ return ClickEvent.runCommand("/paper:callback " + CALLBACK_MANAGER.addCallback(callback, options)); + } + + public static final class CallbackManager { diff --git a/patches/server/0011-Paper-command.patch b/patches/server/0011-Paper-command.patch index e001415eb..7f917c5d8 100644 --- a/patches/server/0011-Paper-command.patch +++ b/patches/server/0011-Paper-command.patch @@ -5,6 +5,47 @@ Subject: [PATCH] Paper command Co-authored-by: Zach Brown +diff --git a/src/main/java/io/papermc/paper/command/CallbackCommand.java b/src/main/java/io/papermc/paper/command/CallbackCommand.java +new file mode 100644 +index 0000000000000000000000000000000000000000..fa4202abd13c1c286bd398938103d1103d5443e7 +--- /dev/null ++++ b/src/main/java/io/papermc/paper/command/CallbackCommand.java +@@ -0,0 +1,35 @@ ++package io.papermc.paper.command; ++ ++import io.papermc.paper.adventure.providers.ClickCallbackProviderImpl; ++import org.bukkit.command.Command; ++import org.bukkit.command.CommandSender; ++import org.checkerframework.checker.nullness.qual.NonNull; ++import org.checkerframework.framework.qual.DefaultQualifier; ++import java.util.UUID; ++ ++@DefaultQualifier(NonNull.class) ++public class CallbackCommand extends Command { ++ ++ protected CallbackCommand(final String name) { ++ super(name); ++ this.description = "ClickEvent callback"; ++ this.usageMessage = "/callback "; ++ } ++ ++ @Override ++ public boolean execute(final CommandSender sender, final String commandLabel, final String[] args) { ++ if (args.length != 1) { ++ return false; ++ } ++ ++ final UUID id; ++ try { ++ id = UUID.fromString(args[0]); ++ } catch (final IllegalArgumentException ignored) { ++ return false; ++ } ++ ++ ClickCallbackProviderImpl.CALLBACK_MANAGER.runCallback(sender, id); ++ return true; ++ } ++} diff --git a/src/main/java/io/papermc/paper/command/CommandUtil.java b/src/main/java/io/papermc/paper/command/CommandUtil.java new file mode 100644 index 0000000000000000000000000000000000000000..953c30500892e5f0c55b8597bc708ea85bf56d6e @@ -82,10 +123,10 @@ index 0000000000000000000000000000000000000000..953c30500892e5f0c55b8597bc708ea8 +} diff --git a/src/main/java/io/papermc/paper/command/PaperCommand.java b/src/main/java/io/papermc/paper/command/PaperCommand.java new file mode 100644 -index 0000000000000000000000000000000000000000..e7931b6cb2a46d07ac017f620b807e3474dc481e +index 0000000000000000000000000000000000000000..8ccc59473bac983ced6b9e4a57e0ec4ebd2b0f32 --- /dev/null +++ b/src/main/java/io/papermc/paper/command/PaperCommand.java -@@ -0,0 +1,144 @@ +@@ -0,0 +1,143 @@ +package io.papermc.paper.command; + +import io.papermc.paper.command.subcommands.*; @@ -125,7 +166,6 @@ index 0000000000000000000000000000000000000000..e7931b6cb2a46d07ac017f620b807e34 + commands.put(Set.of("entity"), new EntityCommand()); + commands.put(Set.of("reload"), new ReloadCommand()); + commands.put(Set.of("version"), new VersionCommand()); -+ commands.put(Set.of("callback"), new CallbackCommand()); + + return commands.entrySet().stream() + .flatMap(entry -> entry.getKey().stream().map(s -> Map.entry(s, entry.getValue()))) @@ -232,10 +272,10 @@ index 0000000000000000000000000000000000000000..e7931b6cb2a46d07ac017f620b807e34 +} diff --git a/src/main/java/io/papermc/paper/command/PaperCommands.java b/src/main/java/io/papermc/paper/command/PaperCommands.java new file mode 100644 -index 0000000000000000000000000000000000000000..6a00f3d38da8107825ab1d405f337fd077b09f72 +index 0000000000000000000000000000000000000000..5e5ec700a368cfdaa1ea0b3f0fa82089895d4b92 --- /dev/null +++ b/src/main/java/io/papermc/paper/command/PaperCommands.java -@@ -0,0 +1,27 @@ +@@ -0,0 +1,28 @@ +package io.papermc.paper.command; + +import net.minecraft.server.MinecraftServer; @@ -255,6 +295,7 @@ index 0000000000000000000000000000000000000000..6a00f3d38da8107825ab1d405f337fd0 + private static final Map COMMANDS = new HashMap<>(); + static { + COMMANDS.put("paper", new PaperCommand("paper")); ++ COMMANDS.put("callback", new CallbackCommand("callback")); + } + + public static void registerCommands(final MinecraftServer server) { @@ -289,45 +330,6 @@ index 0000000000000000000000000000000000000000..7e9e0ff8639be135bf8575e375cbada5 + return true; + } +} -diff --git a/src/main/java/io/papermc/paper/command/subcommands/CallbackCommand.java b/src/main/java/io/papermc/paper/command/subcommands/CallbackCommand.java -new file mode 100644 -index 0000000000000000000000000000000000000000..c5111eef4ba85ed96f7496b7db6954106fa05053 ---- /dev/null -+++ b/src/main/java/io/papermc/paper/command/subcommands/CallbackCommand.java -@@ -0,0 +1,33 @@ -+package io.papermc.paper.command.subcommands; -+ -+import io.papermc.paper.adventure.providers.ClickCallbackProviderImpl; -+import io.papermc.paper.command.PaperSubcommand; -+import java.util.UUID; -+import org.bukkit.command.CommandSender; -+import org.checkerframework.checker.nullness.qual.NonNull; -+import org.checkerframework.framework.qual.DefaultQualifier; -+ -+@DefaultQualifier(NonNull.class) -+public final class CallbackCommand implements PaperSubcommand { -+ @Override -+ public boolean execute(final CommandSender sender, final String subCommand, final String[] args) { -+ if (args.length != 1) { -+ return false; -+ } -+ -+ final UUID id; -+ try { -+ id = UUID.fromString(args[0]); -+ } catch (final IllegalArgumentException ignored) { -+ return false; -+ } -+ -+ ClickCallbackProviderImpl.CALLBACK_MANAGER.runCallback(sender, id); -+ return true; -+ } -+ -+ @Override -+ public boolean tabCompletes() { -+ return false; -+ } -+} diff --git a/src/main/java/io/papermc/paper/command/subcommands/EntityCommand.java b/src/main/java/io/papermc/paper/command/subcommands/EntityCommand.java new file mode 100644 index 0000000000000000000000000000000000000000..ff99336e0b8131ae161cfa5c4fc83c6905e3dbc8 diff --git a/patches/server/0013-Paper-Plugins.patch b/patches/server/0013-Paper-Plugins.patch index 51cb1ac36..b4d83fd88 100644 --- a/patches/server/0013-Paper-Plugins.patch +++ b/patches/server/0013-Paper-Plugins.patch @@ -5,22 +5,22 @@ Subject: [PATCH] Paper Plugins diff --git a/src/main/java/io/papermc/paper/command/PaperCommand.java b/src/main/java/io/papermc/paper/command/PaperCommand.java -index e7931b6cb2a46d07ac017f620b807e3474dc481e..16fdfda717300a3168c27526470f83ce6239e95f 100644 +index 8ccc59473bac983ced6b9e4a57e0ec4ebd2b0f32..6d06b772ffb9d47d6a717462a4b2b494544e80ae 100644 --- a/src/main/java/io/papermc/paper/command/PaperCommand.java +++ b/src/main/java/io/papermc/paper/command/PaperCommand.java -@@ -38,6 +38,7 @@ public final class PaperCommand extends Command { +@@ -37,6 +37,7 @@ public final class PaperCommand extends Command { + commands.put(Set.of("entity"), new EntityCommand()); commands.put(Set.of("reload"), new ReloadCommand()); commands.put(Set.of("version"), new VersionCommand()); - commands.put(Set.of("callback"), new CallbackCommand()); + commands.put(Set.of("dumpplugins"), new DumpPluginsCommand()); return commands.entrySet().stream() .flatMap(entry -> entry.getKey().stream().map(s -> Map.entry(s, entry.getValue()))) diff --git a/src/main/java/io/papermc/paper/command/PaperCommands.java b/src/main/java/io/papermc/paper/command/PaperCommands.java -index 6a00f3d38da8107825ab1d405f337fd077b09f72..d44d0074446c1c54e87dc8078dff7fef1d92f343 100644 +index 5e5ec700a368cfdaa1ea0b3f0fa82089895d4b92..72f2e81b9905a0d57ed8e2a88578f62d5235c456 100644 --- a/src/main/java/io/papermc/paper/command/PaperCommands.java +++ b/src/main/java/io/papermc/paper/command/PaperCommands.java -@@ -23,5 +23,6 @@ public final class PaperCommands { +@@ -24,5 +24,6 @@ public final class PaperCommands { COMMANDS.forEach((s, command) -> { server.server.getCommandMap().register(s, "Paper", command); }); diff --git a/patches/server/0016-Starlight.patch b/patches/server/0016-Starlight.patch index 2cedc9864..57337b431 100644 --- a/patches/server/0016-Starlight.patch +++ b/patches/server/0016-Starlight.patch @@ -4346,12 +4346,12 @@ index 0000000000000000000000000000000000000000..dd995e25ae620ae36cd5eecb2fe10ad0 + +} diff --git a/src/main/java/io/papermc/paper/command/PaperCommand.java b/src/main/java/io/papermc/paper/command/PaperCommand.java -index 16fdfda717300a3168c27526470f83ce6239e95f..a52e6e8be323863ece6624a8ae7f9455279bdc23 100644 +index 6d06b772ffb9d47d6a717462a4b2b494544e80ae..de0e1ad2c78e5132651494f198703533847c84bd 100644 --- a/src/main/java/io/papermc/paper/command/PaperCommand.java +++ b/src/main/java/io/papermc/paper/command/PaperCommand.java -@@ -39,6 +39,7 @@ public final class PaperCommand extends Command { +@@ -38,6 +38,7 @@ public final class PaperCommand extends Command { + commands.put(Set.of("reload"), new ReloadCommand()); commands.put(Set.of("version"), new VersionCommand()); - commands.put(Set.of("callback"), new CallbackCommand()); commands.put(Set.of("dumpplugins"), new DumpPluginsCommand()); + commands.put(Set.of("fixlight"), new FixLightCommand()); diff --git a/patches/server/0019-Rewrite-chunk-system.patch b/patches/server/0019-Rewrite-chunk-system.patch index c48daa546..929bd1e9d 100644 --- a/patches/server/0019-Rewrite-chunk-system.patch +++ b/patches/server/0019-Rewrite-chunk-system.patch @@ -15403,11 +15403,11 @@ index 0000000000000000000000000000000000000000..f7b0e2564ac4bd2db1d2b2bdc230c9f5 + } +} diff --git a/src/main/java/io/papermc/paper/command/PaperCommand.java b/src/main/java/io/papermc/paper/command/PaperCommand.java -index a52e6e8be323863ece6624a8ae7f9455279bdc23..e3467aaf6d0c8d486b84362e3c20b3fe631b50ff 100644 +index de0e1ad2c78e5132651494f198703533847c84bd..0dd48e4098191c8b6e29945d62bc473e9f3a1e77 100644 --- a/src/main/java/io/papermc/paper/command/PaperCommand.java +++ b/src/main/java/io/papermc/paper/command/PaperCommand.java -@@ -40,6 +40,7 @@ public final class PaperCommand extends Command { - commands.put(Set.of("callback"), new CallbackCommand()); +@@ -39,6 +39,7 @@ public final class PaperCommand extends Command { + commands.put(Set.of("version"), new VersionCommand()); commands.put(Set.of("dumpplugins"), new DumpPluginsCommand()); commands.put(Set.of("fixlight"), new FixLightCommand()); + commands.put(Set.of("debug", "chunkinfo", "holderinfo"), new ChunkDebugCommand()); diff --git a/patches/server/0281-Make-the-default-permission-message-configurable.patch b/patches/server/0281-Make-the-default-permission-message-configurable.patch index 98e26f28a..1d37711a0 100644 --- a/patches/server/0281-Make-the-default-permission-message-configurable.patch +++ b/patches/server/0281-Make-the-default-permission-message-configurable.patch @@ -5,10 +5,10 @@ Subject: [PATCH] Make the default permission message configurable diff --git a/src/main/java/io/papermc/paper/command/PaperCommand.java b/src/main/java/io/papermc/paper/command/PaperCommand.java -index e3467aaf6d0c8d486b84362e3c20b3fe631b50ff..8f16640fc2f1233c10392d7e32a54d784fd8e370 100644 +index 0dd48e4098191c8b6e29945d62bc473e9f3a1e77..ae51993e0de706cb62c96795ca9de7663893a5bf 100644 --- a/src/main/java/io/papermc/paper/command/PaperCommand.java +++ b/src/main/java/io/papermc/paper/command/PaperCommand.java -@@ -76,7 +76,7 @@ public final class PaperCommand extends Command { +@@ -75,7 +75,7 @@ public final class PaperCommand extends Command { if (sender.hasPermission(BASE_PERM + permission) || sender.hasPermission("bukkit.command.paper")) { return true; } diff --git a/patches/server/0346-Add-debug-for-sync-chunk-loads.patch b/patches/server/0346-Add-debug-for-sync-chunk-loads.patch index f8e0482a0..03f1500bc 100644 --- a/patches/server/0346-Add-debug-for-sync-chunk-loads.patch +++ b/patches/server/0346-Add-debug-for-sync-chunk-loads.patch @@ -194,10 +194,10 @@ index 0000000000000000000000000000000000000000..0bb4aaa546939b67a5d22865190f3047 + } +} diff --git a/src/main/java/io/papermc/paper/command/PaperCommand.java b/src/main/java/io/papermc/paper/command/PaperCommand.java -index 8f16640fc2f1233c10392d7e32a54d784fd8e370..1e9f191dc0f9d98f4404d2796f15b13912860b13 100644 +index ae51993e0de706cb62c96795ca9de7663893a5bf..5bfa245a621a0bf7ef60cd01f4c04576b770384e 100644 --- a/src/main/java/io/papermc/paper/command/PaperCommand.java +++ b/src/main/java/io/papermc/paper/command/PaperCommand.java -@@ -41,6 +41,7 @@ public final class PaperCommand extends Command { +@@ -40,6 +40,7 @@ public final class PaperCommand extends Command { commands.put(Set.of("dumpplugins"), new DumpPluginsCommand()); commands.put(Set.of("fixlight"), new FixLightCommand()); commands.put(Set.of("debug", "chunkinfo", "holderinfo"), new ChunkDebugCommand()); diff --git a/patches/server/0358-Add-tick-times-API-and-mspt-command.patch b/patches/server/0358-Add-tick-times-API-and-mspt-command.patch index f941d2897..fa98fef7a 100644 --- a/patches/server/0358-Add-tick-times-API-and-mspt-command.patch +++ b/patches/server/0358-Add-tick-times-API-and-mspt-command.patch @@ -113,13 +113,13 @@ index 0000000000000000000000000000000000000000..8b5293b0c696ef21d0101493ffa41b60 + } +} diff --git a/src/main/java/io/papermc/paper/command/PaperCommands.java b/src/main/java/io/papermc/paper/command/PaperCommands.java -index d44d0074446c1c54e87dc8078dff7fef1d92f343..bbb8b1933ef33a3b91f69545f69dd3cfb84b27f5 100644 +index 72f2e81b9905a0d57ed8e2a88578f62d5235c456..7b58b2d6297800c2dcdbf7539e5ab8e7703f39f1 100644 --- a/src/main/java/io/papermc/paper/command/PaperCommands.java +++ b/src/main/java/io/papermc/paper/command/PaperCommands.java -@@ -17,6 +17,7 @@ public final class PaperCommands { - private static final Map COMMANDS = new HashMap<>(); +@@ -18,6 +18,7 @@ public final class PaperCommands { static { COMMANDS.put("paper", new PaperCommand("paper")); + COMMANDS.put("callback", new CallbackCommand("callback")); + COMMANDS.put("mspt", new MSPTCommand("mspt")); } diff --git a/patches/server/0421-Paper-dumpitem-command.patch b/patches/server/0421-Paper-dumpitem-command.patch index 49612cd29..5722936af 100644 --- a/patches/server/0421-Paper-dumpitem-command.patch +++ b/patches/server/0421-Paper-dumpitem-command.patch @@ -6,10 +6,10 @@ Subject: [PATCH] Paper dumpitem command Let's you quickly view the item in your hands NBT data diff --git a/src/main/java/io/papermc/paper/command/PaperCommand.java b/src/main/java/io/papermc/paper/command/PaperCommand.java -index 1e9f191dc0f9d98f4404d2796f15b13912860b13..6d56c812262f7f109598ef4a941d0226b1eb638a 100644 +index 5bfa245a621a0bf7ef60cd01f4c04576b770384e..a8b41d6a42e23a7cd839cc3d5e5cae84860f802c 100644 --- a/src/main/java/io/papermc/paper/command/PaperCommand.java +++ b/src/main/java/io/papermc/paper/command/PaperCommand.java -@@ -42,6 +42,7 @@ public final class PaperCommand extends Command { +@@ -41,6 +41,7 @@ public final class PaperCommand extends Command { commands.put(Set.of("fixlight"), new FixLightCommand()); commands.put(Set.of("debug", "chunkinfo", "holderinfo"), new ChunkDebugCommand()); commands.put(Set.of("syncloadinfo"), new SyncLoadInfoCommand()); diff --git a/patches/server/0679-Add-paper-mobcaps-and-paper-playermobcaps.patch b/patches/server/0679-Add-paper-mobcaps-and-paper-playermobcaps.patch index e285c1f3b..6fcc4c42d 100644 --- a/patches/server/0679-Add-paper-mobcaps-and-paper-playermobcaps.patch +++ b/patches/server/0679-Add-paper-mobcaps-and-paper-playermobcaps.patch @@ -10,10 +10,10 @@ Also has a hover text on each mob category listing what entity types are in said category diff --git a/src/main/java/io/papermc/paper/command/PaperCommand.java b/src/main/java/io/papermc/paper/command/PaperCommand.java -index 6d56c812262f7f109598ef4a941d0226b1eb638a..db9567711f7e0ad1778d41e79b59e31916aa9f09 100644 +index a8b41d6a42e23a7cd839cc3d5e5cae84860f802c..b7fc337ab2bbe3c6d80ed70834e294ab3a7f9dc2 100644 --- a/src/main/java/io/papermc/paper/command/PaperCommand.java +++ b/src/main/java/io/papermc/paper/command/PaperCommand.java -@@ -43,6 +43,7 @@ public final class PaperCommand extends Command { +@@ -42,6 +42,7 @@ public final class PaperCommand extends Command { commands.put(Set.of("debug", "chunkinfo", "holderinfo"), new ChunkDebugCommand()); commands.put(Set.of("syncloadinfo"), new SyncLoadInfoCommand()); commands.put(Set.of("dumpitem"), new DumpItemCommand()); diff --git a/patches/server/0896-Add-paper-dumplisteners-command.patch b/patches/server/0896-Add-paper-dumplisteners-command.patch index cbf1598dd..9669276c0 100644 --- a/patches/server/0896-Add-paper-dumplisteners-command.patch +++ b/patches/server/0896-Add-paper-dumplisteners-command.patch @@ -6,10 +6,10 @@ Subject: [PATCH] Add /paper dumplisteners command Co-authored-by: TwoLeggedCat <80929284+TwoLeggedCat@users.noreply.github.com> diff --git a/src/main/java/io/papermc/paper/command/PaperCommand.java b/src/main/java/io/papermc/paper/command/PaperCommand.java -index db9567711f7e0ad1778d41e79b59e31916aa9f09..7ba60b4b4f29a42c58d98aafc5ea0fa3214f554c 100644 +index b7fc337ab2bbe3c6d80ed70834e294ab3a7f9dc2..05b29305f5e3018a662884c2ef1af5ae4f6867ee 100644 --- a/src/main/java/io/papermc/paper/command/PaperCommand.java +++ b/src/main/java/io/papermc/paper/command/PaperCommand.java -@@ -44,6 +44,7 @@ public final class PaperCommand extends Command { +@@ -43,6 +43,7 @@ public final class PaperCommand extends Command { commands.put(Set.of("syncloadinfo"), new SyncLoadInfoCommand()); commands.put(Set.of("dumpitem"), new DumpItemCommand()); commands.put(Set.of("mobcaps", "playermobcaps"), new MobcapsCommand());