summaryrefslogtreecommitdiffhomepage
path: root/patches/server/0560-Fix-commands-from-signs-not-firing-command-events.patch
diff options
context:
space:
mode:
authorBjarne Koll <[email protected]>2024-09-19 16:36:07 +0200
committerGitHub <[email protected]>2024-09-19 16:36:07 +0200
commitc5a10665b8b80af650500b9263036f778f06d500 (patch)
treefedc133f0dbc101067951e1fccd9d577c312fdb8 /patches/server/0560-Fix-commands-from-signs-not-firing-command-events.patch
parent5c829557332f21b34bc81e6ad1a73e511faef8f6 (diff)
downloadPaper-c5a10665b8b80af650500b9263036f778f06d500.tar.gz
Paper-c5a10665b8b80af650500b9263036f778f06d500.zip
Remove wall-time / unused skip tick protection (#11412)
Spigot still maintains some partial implementation of "tick skipping", a practice in which the MinecraftServer.currentTick field is updated not by an increment of one per actual tick, but instead set to System.currentTimeMillis() / 50. This behaviour means that the tracked tick may "skip" a tick value in case a previous tick took more than the expected 50ms. To compensate for this in important paths, spigot/craftbukkit implements "wall-time". Instead of incrementing/decrementing ticks on block entities/entities by one for each call to their tick() method, they instead increment/decrement important values, like an ItemEntity's age or pickupDelay, by the difference of `currentTick - lastTick`, where `lastTick` is the value of `currentTick` during the last tick() call. These "fixes" however do not play nicely with minecraft's simulation distance as entities/block entities implementing the above behaviour would "catch up" their values when moving from a non-ticking chunk to a ticking one as their `lastTick` value remains stuck on the last tick in a ticking chunk and hence lead to a large "catch up" once ticked again. Paper completely removes the "tick skipping" behaviour (See patch "Further-improve-server-tick-loop"), making the above precautions completely unnecessary, which also rids paper of the previous described incompatibility with non-ticking chunks.
Diffstat (limited to 'patches/server/0560-Fix-commands-from-signs-not-firing-command-events.patch')
-rw-r--r--patches/server/0560-Fix-commands-from-signs-not-firing-command-events.patch120
1 files changed, 120 insertions, 0 deletions
diff --git a/patches/server/0560-Fix-commands-from-signs-not-firing-command-events.patch b/patches/server/0560-Fix-commands-from-signs-not-firing-command-events.patch
new file mode 100644
index 0000000000..b86e341359
--- /dev/null
+++ b/patches/server/0560-Fix-commands-from-signs-not-firing-command-events.patch
@@ -0,0 +1,120 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Jake Potrebic <[email protected]>
+Date: Fri, 9 Jul 2021 13:50:48 -0700
+Subject: [PATCH] Fix commands from signs not firing command events
+
+This patch changes sign command logic so that `run_command` click events:
+ - are logged to the console
+ - fire PlayerCommandPreprocessEvent
+ - work with double-slash commands like `//wand`
+ - sends failure messages to the player who clicked the sign
+
+diff --git a/src/main/java/io/papermc/paper/commands/DelegatingCommandSource.java b/src/main/java/io/papermc/paper/commands/DelegatingCommandSource.java
+new file mode 100644
+index 0000000000000000000000000000000000000000..01a2bc1feec808790bb93618ce46adb9bea5a9c8
+--- /dev/null
++++ b/src/main/java/io/papermc/paper/commands/DelegatingCommandSource.java
+@@ -0,0 +1,42 @@
++package io.papermc.paper.commands;
++
++import net.minecraft.commands.CommandSource;
++import net.minecraft.commands.CommandSourceStack;
++import net.minecraft.network.chat.Component;
++import org.bukkit.command.CommandSender;
++
++import java.util.UUID;
++
++public class DelegatingCommandSource implements CommandSource {
++
++ private final CommandSource delegate;
++
++ public DelegatingCommandSource(CommandSource delegate) {
++ this.delegate = delegate;
++ }
++
++ @Override
++ public void sendSystemMessage(Component message) {
++ delegate.sendSystemMessage(message);
++ }
++
++ @Override
++ public boolean acceptsSuccess() {
++ return delegate.acceptsSuccess();
++ }
++
++ @Override
++ public boolean acceptsFailure() {
++ return delegate.acceptsFailure();
++ }
++
++ @Override
++ public boolean shouldInformAdmins() {
++ return delegate.shouldInformAdmins();
++ }
++
++ @Override
++ public CommandSender getBukkitSender(CommandSourceStack wrapper) {
++ return delegate.getBukkitSender(wrapper);
++ }
++}
+diff --git a/src/main/java/net/minecraft/world/level/block/entity/SignBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/SignBlockEntity.java
+index 87e272cfb145c37d26b0bf56f97ec784a9bfd98e..bfe8029852385875af4ebe73c63e688f61042021 100644
+--- a/src/main/java/net/minecraft/world/level/block/entity/SignBlockEntity.java
++++ b/src/main/java/net/minecraft/world/level/block/entity/SignBlockEntity.java
+@@ -274,7 +274,17 @@ public class SignBlockEntity extends BlockEntity implements CommandSource { // C
+ ClickEvent chatclickable = chatmodifier.getClickEvent();
+
+ if (chatclickable != null && chatclickable.getAction() == ClickEvent.Action.RUN_COMMAND) {
+- player.getServer().getCommands().performPrefixedCommand(this.createCommandSourceStack(player, world, pos), chatclickable.getValue());
++ // Paper start - Fix commands from signs not firing command events
++ String command = chatclickable.getValue().startsWith("/") ? chatclickable.getValue() : "/" + chatclickable.getValue();
++ if (org.spigotmc.SpigotConfig.logCommands) {
++ LOGGER.info("{} issued server command: {}", player.getScoreboardName(), command);
++ }
++ io.papermc.paper.event.player.PlayerSignCommandPreprocessEvent event = new io.papermc.paper.event.player.PlayerSignCommandPreprocessEvent((org.bukkit.entity.Player) player.getBukkitEntity(), command, new org.bukkit.craftbukkit.util.LazyPlayerSet(player.getServer()), (org.bukkit.block.Sign) CraftBlock.at(this.level, this.worldPosition).getState(), front ? Side.FRONT : Side.BACK);
++ if (!event.callEvent()) {
++ return false;
++ }
++ player.getServer().getCommands().performPrefixedCommand(this.createCommandSourceStack(((org.bukkit.craftbukkit.entity.CraftPlayer) event.getPlayer()).getHandle(), world, pos), event.getMessage());
++ // Paper end - Fix commands from signs not firing command events
+ flag1 = true;
+ }
+ }
+@@ -311,8 +321,23 @@ public class SignBlockEntity extends BlockEntity implements CommandSource { // C
+ String s = player == null ? "Sign" : player.getName().getString();
+ Object object = player == null ? Component.literal("Sign") : player.getDisplayName();
+
++ // Paper start - Fix commands from signs not firing command events
++ CommandSource commandSource = this.level.paperConfig().misc.showSignClickCommandFailureMsgsToPlayer ? new io.papermc.paper.commands.DelegatingCommandSource(this) {
++ @Override
++ public void sendSystemMessage(Component message) {
++ if (player != null) {
++ player.sendSystemMessage(message);
++ }
++ }
++
++ @Override
++ public boolean acceptsFailure() {
++ return true;
++ }
++ } : this;
++ // Paper end - Fix commands from signs not firing command events
+ // CraftBukkit - this
+- return new CommandSourceStack(this, Vec3.atCenterOf(pos), Vec2.ZERO, (ServerLevel) world, 2, s, (Component) object, world.getServer(), player);
++ return new CommandSourceStack(commandSource, Vec3.atCenterOf(pos), Vec2.ZERO, (ServerLevel) world, 2, s, (Component) object, world.getServer(), player); // Paper - Fix commands from signs not firing command events
+ }
+
+ @Override
+diff --git a/src/main/java/org/bukkit/craftbukkit/command/BukkitCommandWrapper.java b/src/main/java/org/bukkit/craftbukkit/command/BukkitCommandWrapper.java
+index d113e54a30db16e2ad955170df6030d15de530d6..21b6f90cf5bd7087d1a0f512289d971f2c3e1afa 100644
+--- a/src/main/java/org/bukkit/craftbukkit/command/BukkitCommandWrapper.java
++++ b/src/main/java/org/bukkit/craftbukkit/command/BukkitCommandWrapper.java
+@@ -61,7 +61,7 @@ public class BukkitCommandWrapper implements com.mojang.brigadier.Command<Comman
+ CommandSender sender = context.getSource().getBukkitSender();
+
+ try {
+- return this.server.dispatchCommand(sender, context.getInput()) ? 1 : 0;
++ return this.server.dispatchCommand(sender, context.getRange().get(context.getInput())) ? 1 : 0; // Paper - Fix commands from signs not firing command events; actually use the StringRange from context
+ } catch (CommandException ex) {
+ sender.sendMessage(org.bukkit.ChatColor.RED + "An internal error occurred while attempting to perform this command");
+ this.server.getLogger().log(Level.SEVERE, null, ex);