From 7366520a54a6632c631e18cead7641509347655e 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 + .../Add-tick-times-API-and-mspt-command.patch | 2 +- patches/server/Adventure.patch | 2 +- patches/server/Paper-Plugins.patch | 2 +- patches/server/Paper-command.patch | 82 ++++++++++--------- patches/server/Rewrite-chunk-system.patch | 2 +- patches/server/Starlight.patch | 2 +- 7 files changed, 48 insertions(+), 45 deletions(-) diff --git a/LICENSE.md b/LICENSE.md index 90f8ace470..378a081dd6 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/Add-tick-times-API-and-mspt-command.patch b/patches/server/Add-tick-times-API-and-mspt-command.patch index d76a0be26a..bc476a98b5 100644 --- a/patches/server/Add-tick-times-API-and-mspt-command.patch +++ b/patches/server/Add-tick-times-API-and-mspt-command.patch @@ -117,9 +117,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 --- a/src/main/java/io/papermc/paper/command/PaperCommands.java +++ b/src/main/java/io/papermc/paper/command/PaperCommands.java @@ -0,0 +0,0 @@ public final class PaperCommands { - private static final Map COMMANDS = new HashMap<>(); static { COMMANDS.put("paper", new PaperCommand("paper")); + COMMANDS.put("callback", new CallbackCommand("callback")); + COMMANDS.put("mspt", new MSPTCommand("mspt")); } diff --git a/patches/server/Adventure.patch b/patches/server/Adventure.patch index 5d97f9d7d6..29dfa1c4ed 100644 --- a/patches/server/Adventure.patch +++ b/patches/server/Adventure.patch @@ -1292,7 +1292,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + + @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/Paper-Plugins.patch b/patches/server/Paper-Plugins.patch index 60255044c7..21be113acb 100644 --- a/patches/server/Paper-Plugins.patch +++ b/patches/server/Paper-Plugins.patch @@ -9,9 +9,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 --- a/src/main/java/io/papermc/paper/command/PaperCommand.java +++ b/src/main/java/io/papermc/paper/command/PaperCommand.java @@ -0,0 +0,0 @@ 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() diff --git a/patches/server/Paper-command.patch b/patches/server/Paper-command.patch index 019ce3bc87..869e536513 100644 --- a/patches/server/Paper-command.patch +++ b/patches/server/Paper-command.patch @@ -5,6 +5,47 @@ Subject: [PATCH] Paper command Co-authored-by: Zach Brown <1254957+zachbr@users.noreply.github.com> +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..0000000000000000000000000000000000000000 +--- /dev/null ++++ b/src/main/java/io/papermc/paper/command/CallbackCommand.java +@@ -0,0 +0,0 @@ ++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..0000000000000000000000000000000000000000 @@ -125,7 +166,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + 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()))) @@ -255,6 +295,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + 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..00000000000000000000000000000000 + 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..0000000000000000000000000000000000000000 ---- /dev/null -+++ b/src/main/java/io/papermc/paper/command/subcommands/CallbackCommand.java -@@ -0,0 +0,0 @@ -+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..0000000000000000000000000000000000000000 diff --git a/patches/server/Rewrite-chunk-system.patch b/patches/server/Rewrite-chunk-system.patch index 57a19e8e5c..dd7931972d 100644 --- a/patches/server/Rewrite-chunk-system.patch +++ b/patches/server/Rewrite-chunk-system.patch @@ -15407,7 +15407,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 --- a/src/main/java/io/papermc/paper/command/PaperCommand.java +++ b/src/main/java/io/papermc/paper/command/PaperCommand.java @@ -0,0 +0,0 @@ public final class PaperCommand extends Command { - commands.put(Set.of("callback"), new CallbackCommand()); + 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/Starlight.patch b/patches/server/Starlight.patch index a8767e9628..15bd634d36 100644 --- a/patches/server/Starlight.patch +++ b/patches/server/Starlight.patch @@ -4350,8 +4350,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 --- a/src/main/java/io/papermc/paper/command/PaperCommand.java +++ b/src/main/java/io/papermc/paper/command/PaperCommand.java @@ -0,0 +0,0 @@ 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());