2021-07-11 18:06:49 +00:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Jake Potrebic <jake.m.potrebic@gmail.com>
|
|
|
|
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
|
2022-06-08 12:19:54 +00:00
|
|
|
index 0000000000000000000000000000000000000000..01a2bc1feec808790bb93618ce46adb9bea5a9c8
|
2021-07-11 18:06:49 +00:00
|
|
|
--- /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
|
2022-06-08 12:19:54 +00:00
|
|
|
+ public void sendSystemMessage(Component message) {
|
|
|
|
+ delegate.sendSystemMessage(message);
|
2021-07-11 18:06:49 +00:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @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
|
2022-06-14 08:51:53 +00:00
|
|
|
index 831db5ee21938d71e99bf9d17b92a6ca15531740..def4fdd2c7e4f925fa128692a744e5d10ae0203a 100644
|
2021-07-11 18:06:49 +00:00
|
|
|
--- a/src/main/java/net/minecraft/world/level/block/entity/SignBlockEntity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/block/entity/SignBlockEntity.java
|
2021-11-24 23:26:29 +00:00
|
|
|
@@ -40,6 +40,7 @@ public class SignBlockEntity extends BlockEntity implements CommandSource { // C
|
2021-07-11 18:06:49 +00:00
|
|
|
private boolean renderMessagedFiltered;
|
|
|
|
private DyeColor color;
|
|
|
|
private boolean hasGlowingText;
|
|
|
|
+ private static final org.apache.logging.log4j.Logger LOGGER = org.apache.logging.log4j.LogManager.getLogger();
|
|
|
|
|
|
|
|
public SignBlockEntity(BlockPos pos, BlockState state) {
|
|
|
|
super(BlockEntityType.SIGN, pos, state);
|
2022-06-14 08:51:53 +00:00
|
|
|
@@ -224,7 +225,17 @@ public class SignBlockEntity extends BlockEntity implements CommandSource { // C
|
|
|
|
ClickEvent chatclickable = chatmodifier.getClickEvent();
|
2021-07-11 18:06:49 +00:00
|
|
|
|
|
|
|
if (chatclickable != null && chatclickable.getAction() == ClickEvent.Action.RUN_COMMAND) {
|
2022-06-14 08:51:53 +00:00
|
|
|
- player.getServer().getCommands().performPrefixedCommand(this.createCommandSourceStack(player), chatclickable.getValue());
|
2021-07-11 18:06:49 +00:00
|
|
|
+ // Paper start
|
|
|
|
+ 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(player.getBukkitEntity(), command, new org.bukkit.craftbukkit.util.LazyPlayerSet(player.getServer()), (org.bukkit.block.Sign) net.minecraft.server.MCUtil.toBukkitBlock(this.level, this.worldPosition).getState());
|
|
|
|
+ if (!event.callEvent()) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
2022-06-14 08:51:53 +00:00
|
|
|
+ player.getServer().getCommands().performPrefixedCommand(this.createCommandSourceStack(((org.bukkit.craftbukkit.entity.CraftPlayer) event.getPlayer()).getHandle()), event.getMessage());
|
2021-07-11 18:06:49 +00:00
|
|
|
+ // Paper end
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-14 08:51:53 +00:00
|
|
|
@@ -260,8 +271,21 @@ public class SignBlockEntity extends BlockEntity implements CommandSource { // C
|
2021-07-11 18:06:49 +00:00
|
|
|
String s = player == null ? "Sign" : player.getName().getString();
|
2022-06-08 09:31:06 +00:00
|
|
|
Object object = player == null ? Component.literal("Sign") : player.getDisplayName();
|
2021-07-11 18:06:49 +00:00
|
|
|
|
|
|
|
+ // Paper start - send messages back to the player
|
2022-06-09 08:51:45 +00:00
|
|
|
+ CommandSource commandSource = this.level.paperConfig().misc.showSignClickCommandFailureMsgsToPlayer ? new io.papermc.paper.commands.DelegatingCommandSource(this) {
|
2021-07-11 18:06:49 +00:00
|
|
|
+ @Override
|
2022-06-08 12:19:54 +00:00
|
|
|
+ public void sendSystemMessage(Component message) {
|
|
|
|
+ player.sendSystemMessage(message);
|
2021-07-11 18:06:49 +00:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public boolean acceptsFailure() {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ } : this;
|
|
|
|
+ // Paper end
|
|
|
|
// CraftBukkit - this
|
2021-11-24 23:26:29 +00:00
|
|
|
- return new CommandSourceStack(this, Vec3.atCenterOf(this.worldPosition), Vec2.ZERO, (ServerLevel) this.level, 2, s, (Component) object, this.level.getServer(), player);
|
|
|
|
+ return new CommandSourceStack(commandSource, Vec3.atCenterOf(this.worldPosition), Vec2.ZERO, (ServerLevel) this.level, 2, s, (Component) object, this.level.getServer(), player); // Paper
|
2021-07-11 18:06:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public DyeColor getColor() {
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/command/BukkitCommandWrapper.java b/src/main/java/org/bukkit/craftbukkit/command/BukkitCommandWrapper.java
|
2022-07-29 07:11:11 +00:00
|
|
|
index 9e4a660bdeaa70536bd8aeb90aa4a6a979f3f061..2476727cd60034c4df2db36b9ed808e72d7b686f 100644
|
2021-07-11 18:06:49 +00:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/command/BukkitCommandWrapper.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/command/BukkitCommandWrapper.java
|
2022-07-29 07:11:11 +00:00
|
|
|
@@ -56,7 +56,7 @@ public class BukkitCommandWrapper implements com.mojang.brigadier.Command<Comman
|
|
|
|
CommandSender sender = context.getSource().getBukkitSender();
|
2021-07-11 18:06:49 +00:00
|
|
|
|
2022-07-29 07:11:11 +00:00
|
|
|
try {
|
|
|
|
- return this.server.dispatchCommand(sender, context.getInput()) ? 1 : 0;
|
|
|
|
+ return this.server.dispatchCommand(sender, context.getRange().get(context.getInput())) ? 1 : 0; // Paper - 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);
|