From 92e54e030d14b96ce377ac80ba35ab97fd38d1d6 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/Adventure.patch | 5 +++ ...broadcast-messages-to-command-blocks.patch | 34 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 patches/server/Don-t-broadcast-messages-to-command-blocks.patch diff --git a/patches/server/Adventure.patch b/patches/server/Adventure.patch index 33edbabd14..8045ed4c6c 100644 --- a/patches/server/Adventure.patch +++ b/patches/server/Adventure.patch @@ -2251,6 +2251,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + // 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/Don-t-broadcast-messages-to-command-blocks.patch b/patches/server/Don-t-broadcast-messages-to-command-blocks.patch new file mode 100644 index 0000000000..f63658a2f4 --- /dev/null +++ b/patches/server/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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/world/level/BaseCommandBlock.java ++++ b/src/main/java/net/minecraft/world/level/BaseCommandBlock.java +@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java ++++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java +@@ -0,0 +0,0 @@ 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); + } + }