mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-05 10:20:53 +01:00
31699ae9a8
* Updated Upstream (Bukkit/CraftBukkit) Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: a6a9d2a4 Remove some old ApiStatus.Experimental annotations be72314c SPIGOT-7300, PR-829: Add new DamageSource API providing enhanced information about entity damage b252cf05 SPIGOT-7576, PR-970: Add methods in MushroomCow to change stew effects b1c689bd PR-902: Add Server#isLoggingIPs to get log-ips configuration 08f86d1c PR-971: Add Player methods for client-side potion effects 2e3024a9 PR-963: Add API for in-world structures a23292a7 SPIGOT-7530, PR-948: Improve Resource Pack API with new 1.20.3 functionality 1851857b SPIGOT-3071, PR-969: Add entity spawn method with spawn reason cde4c52a SPIGOT-5553, PR-964: Add EntityKnockbackEvent CraftBukkit Changes: 38fd4bd50 Fix accidentally renamed internal damage method 80f0ce4be SPIGOT-7300, PR-1180: Add new DamageSource API providing enhanced information about entity damage 7e43f3b16 SPIGOT-7581: Fix typo in BlockMushroom ea14b7d90 SPIGOT-7576, PR-1347: Add methods in MushroomCow to change stew effects 4c687f243 PR-1259: Add Server#isLoggingIPs to get log-ips configuration 22a541a29 Improve support for per-world game rules cb7dccce2 PR-1348: Add Player methods for client-side potion effects b8d6109f0 PR-1335: Add API for in-world structures 4398a1b5b SPIGOT-7577: Make CraftWindCharge#explode discard the entity e74107678 Fix Crafter maximum stack size 0bb0f4f6a SPIGOT-7530, PR-1314: Improve Resource Pack API with new 1.20.3 functionality 4949f556d SPIGOT-3071, PR-1345: Add entity spawn method with spawn reason 20ac73ca2 PR-1353: Fix Structure#place not working as documented with 0 palette 3c1b77871 SPIGOT-6911, PR-1349: Change max book length in CraftMetaBook 333701839 SPIGOT-7572: Bee nests generated without bees f48f4174c SPIGOT-5553, PR-1336: Add EntityKnockbackEvent
121 lines
6.4 KiB
Diff
121 lines
6.4 KiB
Diff
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
|
|
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 9939cad5af2d7873f188f18978029663a8d785de..f3cea7a8de334419b4a2f6dc64ef0e20fd715e75 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
|
|
@@ -273,7 +273,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;
|
|
}
|
|
}
|
|
@@ -310,8 +320,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);
|