From 18fa5eef342b6045ada9f1dd611b59ee0d498e20 Mon Sep 17 00:00:00 2001 From: Bit Date: Mon, 26 Jun 2023 18:35:32 -0400 Subject: [PATCH] Add event for player editing sign (#9300) Addresses https://github.com/PaperMC/Paper/issues/9293 --- .../Add-event-for-player-editing-sign.patch | 81 +++++++++++++++++++ .../Add-event-for-player-editing-sign.patch | 27 +++++++ patches/server/MC-Dev-fixes.patch | 25 ++++++ 3 files changed, 133 insertions(+) create mode 100644 patches/api/Add-event-for-player-editing-sign.patch create mode 100644 patches/server/Add-event-for-player-editing-sign.patch diff --git a/patches/api/Add-event-for-player-editing-sign.patch b/patches/api/Add-event-for-player-editing-sign.patch new file mode 100644 index 0000000000..cc7b601a54 --- /dev/null +++ b/patches/api/Add-event-for-player-editing-sign.patch @@ -0,0 +1,81 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: by77er +Date: Sat, 10 Jun 2023 19:06:24 -0400 +Subject: [PATCH] Add event for player editing sign + + +diff --git a/src/main/java/io/papermc/paper/event/player/PlayerOpenSignEvent.java b/src/main/java/io/papermc/paper/event/player/PlayerOpenSignEvent.java +new file mode 100644 +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 +--- /dev/null ++++ b/src/main/java/io/papermc/paper/event/player/PlayerOpenSignEvent.java +@@ -0,0 +0,0 @@ ++package io.papermc.paper.event.player; ++ ++import org.bukkit.block.Sign; ++import org.bukkit.block.sign.Side; ++import org.bukkit.entity.Player; ++import org.bukkit.event.Cancellable; ++import org.bukkit.event.HandlerList; ++import org.bukkit.event.player.PlayerEvent; ++import org.jetbrains.annotations.NotNull; ++ ++/** ++ * Called when a player begins editing a sign's text. ++ *

++ * Cancelling this event stops the sign editing menu from opening. ++ */ ++public class PlayerOpenSignEvent extends PlayerEvent implements Cancellable { ++ private static final HandlerList HANDLER_LIST = new HandlerList(); ++ private boolean cancel = false; ++ @NotNull private final Sign sign; ++ @NotNull private final Side side; ++ ++ public PlayerOpenSignEvent(@NotNull Player editor, @NotNull Sign sign, @NotNull Side side) { ++ super(editor); ++ this.sign = sign; ++ this.side = side; ++ } ++ ++ /** ++ * Gets the sign that was clicked. ++ * ++ * @return {@link Sign} that was clicked ++ */ ++ @NotNull ++ public Sign getSign() { ++ return sign; ++ } ++ ++ /** ++ * Gets which side of the sign was clicked. ++ * ++ * @return {@link Side} that was clicked ++ * @see Sign#getSide(Side) ++ */ ++ @NotNull ++ public Side getSide() { ++ return side; ++ } ++ ++ @Override ++ public boolean isCancelled() { ++ return cancel; ++ } ++ ++ @Override ++ public void setCancelled(boolean cancel) { ++ this.cancel = cancel; ++ } ++ ++ @NotNull ++ @Override ++ public HandlerList getHandlers() { ++ return HANDLER_LIST; ++ } ++ ++ @NotNull ++ public static HandlerList getHandlerList() { ++ return HANDLER_LIST; ++ } ++} diff --git a/patches/server/Add-event-for-player-editing-sign.patch b/patches/server/Add-event-for-player-editing-sign.patch new file mode 100644 index 0000000000..de13af3064 --- /dev/null +++ b/patches/server/Add-event-for-player-editing-sign.patch @@ -0,0 +1,27 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: by77er +Date: Mon, 12 Jun 2023 12:56:46 -0400 +Subject: [PATCH] Add event for player editing sign + + +diff --git a/src/main/java/net/minecraft/world/level/block/SignBlock.java b/src/main/java/net/minecraft/world/level/block/SignBlock.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/world/level/block/SignBlock.java ++++ b/src/main/java/net/minecraft/world/level/block/SignBlock.java +@@ -0,0 +0,0 @@ public abstract class SignBlock extends BaseEntityBlock implements SimpleWaterlo + } + + public void openTextEdit(Player player, SignBlockEntity blockEntity, boolean front) { ++ // Paper start ++ org.bukkit.entity.Player bukkitPlayer = (org.bukkit.entity.Player) player.getBukkitEntity(); ++ org.bukkit.block.Block bukkitBlock = org.bukkit.craftbukkit.block.CraftBlock.at(blockEntity.getLevel(), blockEntity.getBlockPos()); ++ org.bukkit.craftbukkit.block.CraftSign bukkitSign = (org.bukkit.craftbukkit.block.CraftSign) org.bukkit.craftbukkit.block.CraftBlockStates.getBlockState(bukkitBlock); ++ io.papermc.paper.event.player.PlayerOpenSignEvent event = new io.papermc.paper.event.player.PlayerOpenSignEvent( ++ bukkitPlayer, ++ bukkitSign, ++ front ? org.bukkit.block.sign.Side.FRONT : org.bukkit.block.sign.Side.BACK); ++ if (!event.callEvent()) return; ++ // Paper end + blockEntity.setAllowedPlayerEditor(player.getUUID()); + player.openTextEdit(blockEntity, front); + } diff --git a/patches/server/MC-Dev-fixes.patch b/patches/server/MC-Dev-fixes.patch index fb9065d6db..d6d85b5332 100644 --- a/patches/server/MC-Dev-fixes.patch +++ b/patches/server/MC-Dev-fixes.patch @@ -184,6 +184,31 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 })); this.byName = Maps.newHashMap(builder.build()); // CraftBukkit RecipeManager.LOGGER.info("Loaded {} recipes", map1.size()); +diff --git a/src/main/java/net/minecraft/world/level/block/SignBlock.java b/src/main/java/net/minecraft/world/level/block/SignBlock.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/world/level/block/SignBlock.java ++++ b/src/main/java/net/minecraft/world/level/block/SignBlock.java +@@ -0,0 +0,0 @@ public abstract class SignBlock extends BaseEntityBlock implements SimpleWaterlo + public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { + ItemStack itemStack = player.getItemInHand(hand); + Item item = itemStack.getItem(); +- Item signBlockEntity = itemStack.getItem(); +- SignApplicator var10000; +- if (signBlockEntity instanceof SignApplicator signApplicator) { +- var10000 = signApplicator; +- } else { +- var10000 = null; +- } +- +- SignApplicator signApplicator2 = var10000; ++ SignApplicator signApplicator2 = item instanceof SignApplicator signApplicator ? signApplicator : null; // Paper - decompile fixes + boolean bl = signApplicator2 != null && player.mayBuild(); +- BlockEntity bl2 = world.getBlockEntity(pos); +- if (bl2 instanceof SignBlockEntity signBlockEntity) { ++ if (world.getBlockEntity(pos) instanceof SignBlockEntity signBlockEntity) { // Paper - decompile fixes + if (!world.isClientSide) { + boolean bl2 = signBlockEntity.isFacingFrontText(player); + SignText signText = signBlockEntity.getText(bl2); diff --git a/src/main/java/net/minecraft/world/level/chunk/PalettedContainer.java b/src/main/java/net/minecraft/world/level/chunk/PalettedContainer.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/level/chunk/PalettedContainer.java