From dd613194edb9410699da385545e37dd5e64d6786 Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Thu, 16 Jun 2022 15:03:02 -0700 Subject: [PATCH] Couple fixes for command blocks (#8004) --- patches/server/0008-Adventure.patch | 11 ++++-- ...broadcast-messages-to-command-blocks.patch | 34 +++++++++++++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 patches/server/0915-Don-t-broadcast-messages-to-command-blocks.patch diff --git a/patches/server/0008-Adventure.patch b/patches/server/0008-Adventure.patch index 1447a5df57..5aae89704a 100644 --- a/patches/server/0008-Adventure.patch +++ b/patches/server/0008-Adventure.patch @@ -2012,7 +2012,7 @@ index 40421cc8ef25f1bef32a0a5d2f0f25165efe230a..1357bc97801f892e59fc8e89c3cc2d69 + // Paper end } diff --git a/src/main/java/org/bukkit/craftbukkit/Main.java b/src/main/java/org/bukkit/craftbukkit/Main.java -index c694c6dfed0b3aa098b1822676e39bd3eb04b45a..0d427758182ebe01d612d5140e4a0d519a96d8c0 100644 +index df98326c49973183e81ccb96d4b1a7a7626dffee..18652607d36a980a4b0956584f8a722be776dad2 100644 --- a/src/main/java/org/bukkit/craftbukkit/Main.java +++ b/src/main/java/org/bukkit/craftbukkit/Main.java @@ -19,6 +19,12 @@ public class Main { @@ -2242,15 +2242,20 @@ index 3f5292deeeddb8a6a5df57aac01f48ba11be6d7c..911843bf38ab750edd4a63417ba7a9de Component[] components = new Component[4]; diff --git a/src/main/java/org/bukkit/craftbukkit/command/CraftBlockCommandSender.java b/src/main/java/org/bukkit/craftbukkit/command/CraftBlockCommandSender.java -index 3de88112bdb08d6bd0d28f20582c4090bfd8dbfe..11164a28018be3ba46f898e57a1eefbeb0360426 100644 +index 3de88112bdb08d6bd0d28f20582c4090bfd8dbfe..87f2cea36d852c81fdb0a1bc21162d41377ab2e7 100644 --- a/src/main/java/org/bukkit/craftbukkit/command/CraftBlockCommandSender.java +++ b/src/main/java/org/bukkit/craftbukkit/command/CraftBlockCommandSender.java -@@ -45,6 +45,13 @@ public class CraftBlockCommandSender extends ServerCommandSender implements Bloc +@@ -45,6 +45,18 @@ public class CraftBlockCommandSender extends ServerCommandSender implements Bloc return this.block.getTextName(); } + // Paper start + @Override ++ public void sendMessage(net.kyori.adventure.identity.Identity identity, net.kyori.adventure.text.Component message, net.kyori.adventure.audience.MessageType type) { ++ block.source.sendSystemMessage(io.papermc.paper.adventure.PaperAdventure.asVanilla(message)); ++ } ++ ++ @Override + public net.kyori.adventure.text.Component name() { + return io.papermc.paper.adventure.PaperAdventure.asAdventure(this.block.getDisplayName()); + } diff --git a/patches/server/0915-Don-t-broadcast-messages-to-command-blocks.patch b/patches/server/0915-Don-t-broadcast-messages-to-command-blocks.patch new file mode 100644 index 0000000000..bb8829deda --- /dev/null +++ b/patches/server/0915-Don-t-broadcast-messages-to-command-blocks.patch @@ -0,0 +1,34 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Jake Potrebic +Date: Thu, 16 Jun 2022 14:22:56 -0700 +Subject: [PATCH] Don't broadcast messages to command blocks + +Previously the broadcast method would update the last output +in command blocks, and if called asynchronously, would throw +an error + +diff --git a/src/main/java/net/minecraft/world/level/BaseCommandBlock.java b/src/main/java/net/minecraft/world/level/BaseCommandBlock.java +index c0195f73cd2c8721e882c681eaead65471710081..861b348f73867af3199f1cc0dab1ddd4241d1567 100644 +--- a/src/main/java/net/minecraft/world/level/BaseCommandBlock.java ++++ b/src/main/java/net/minecraft/world/level/BaseCommandBlock.java +@@ -172,6 +172,7 @@ public abstract class BaseCommandBlock implements CommandSource { + @Override + public void sendSystemMessage(Component message) { + if (this.trackOutput) { ++ org.spigotmc.AsyncCatcher.catchOp("sendSystemMessage to a command block"); // Paper + SimpleDateFormat simpledateformat = BaseCommandBlock.TIME_FORMAT; + Date date = new Date(); + +diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java +index f1e5ccfbcd08a73ac3aba9a1cb7b414faef81f9e..72311b27bb642ee05dba45b76935277d183012eb 100644 +--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java ++++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java +@@ -1736,7 +1736,7 @@ public final class CraftServer implements Server { + // Paper end + Set recipients = new HashSet<>(); + for (Permissible permissible : this.getPluginManager().getPermissionSubscriptions(permission)) { +- if (permissible instanceof CommandSender && permissible.hasPermission(permission)) { ++ if (permissible instanceof CommandSender && !(permissible instanceof org.bukkit.command.BlockCommandSender) && permissible.hasPermission(permission)) { // Paper - don't broadcast to BlockCommandSender (specifically Command Blocks) + recipients.add((CommandSender) permissible); + } + }