Paper/patches/server/0838-Don-t-broadcast-messages-to-command-blocks.patch
BlockyTheDev 6dc8e30c92
Fix startup and runtime crashes (experimental branch) (#9606)
* Fix startup error

* Fix runtime error

- The code with '.getKey().getKey().getKey()' looks a bit strange but is necessary so the results on the timings website are the same as before. It gets the key (String) from the NamespacedKey, of the key from the Keyed, from the key of the Map.Entry.

* [ci skip] Add myself to LICENSE.md

* Remove wildcard import

* Revert import order
2023-08-15 09:41:56 -07:00

35 lines
2.1 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
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 e05eb08a9c229b371887676da510df948b896a85..ceeedbd88c56c08ec8b047c9ca2f14cc581e12ad 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 f496d10cb8b5fe311c8cf6c6fa98972ac22b3953..cb6425a458f4ae5ec9e54a108b76061493160a54 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -1801,7 +1801,7 @@ public final class CraftServer implements Server {
// Paper end
Set<CommandSender> 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);
}
}