diff --git a/paper-server/patches/sources/net/minecraft/world/level/block/entity/SignBlockEntity.java.patch b/paper-server/patches/sources/net/minecraft/world/level/block/entity/SignBlockEntity.java.patch index f20d68befa..470ddc023a 100644 --- a/paper-server/patches/sources/net/minecraft/world/level/block/entity/SignBlockEntity.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/level/block/entity/SignBlockEntity.java.patch @@ -149,16 +149,26 @@ boolean flag1 = false; Component[] aichatbasecomponent = this.getText(front).getMessages(player.isTextFilteringEnabled()); int i = aichatbasecomponent.length; -@@ -242,7 +274,7 @@ +@@ -242,7 +274,17 @@ ClickEvent chatclickable = chatmodifier.getClickEvent(); if (chatclickable != null && chatclickable.getAction() == ClickEvent.Action.RUN_COMMAND) { - player.getServer().getCommands().performPrefixedCommand(SignBlockEntity.createCommandSourceStack(player, world, pos), chatclickable.getValue()); -+ 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; } } -@@ -250,11 +282,40 @@ +@@ -250,11 +292,55 @@ return flag1; } @@ -196,12 +206,27 @@ Object object = player == null ? Component.literal("Sign") : player.getDisplayName(); - return new CommandSourceStack(CommandSource.NULL, Vec3.atCenterOf(pos), Vec2.ZERO, (ServerLevel) world, 2, s, (Component) object, world.getServer(), player); -+ // CraftBukkit - commandSource -+ return new CommandSourceStack(this.commandSource, Vec3.atCenterOf(pos), Vec2.ZERO, (ServerLevel) world, 2, s, (Component) object, world.getServer(), player); ++ // Paper start - Fix commands from signs not firing command events ++ CommandSource commandSource = this.level.paperConfig().misc.showSignClickCommandFailureMsgsToPlayer ? new io.papermc.paper.commands.DelegatingCommandSource(this.commandSource) { ++ @Override ++ public void sendSystemMessage(Component message) { ++ if (player instanceof final ServerPlayer serverPlayer) { ++ serverPlayer.sendSystemMessage(message); ++ } ++ } ++ ++ @Override ++ public boolean acceptsFailure() { ++ return true; ++ } ++ } : this.commandSource; ++ // Paper end - Fix commands from signs not firing command events ++ // CraftBukkit - this ++ 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 -@@ -273,12 +334,17 @@ +@@ -273,12 +359,17 @@ @Nullable public UUID getPlayerWhoMayEdit() { @@ -220,7 +245,7 @@ } public boolean isWaxed() { -@@ -296,7 +362,7 @@ +@@ -296,7 +387,7 @@ } public boolean playerIsTooFarAwayToEdit(UUID uuid) { diff --git a/paper-server/src/main/java/io/papermc/paper/commands/DelegatingCommandSource.java b/paper-server/src/main/java/io/papermc/paper/commands/DelegatingCommandSource.java new file mode 100644 index 0000000000..01a2bc1fee --- /dev/null +++ b/paper-server/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/paper-server/src/main/java/org/bukkit/craftbukkit/command/BukkitCommandWrapper.java b/paper-server/src/main/java/org/bukkit/craftbukkit/command/BukkitCommandWrapper.java index d113e54a30..21b6f90cf5 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/command/BukkitCommandWrapper.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/command/BukkitCommandWrapper.java @@ -61,7 +61,7 @@ public class BukkitCommandWrapper implements com.mojang.brigadier.Command