Paper/patches/api/0442-Add-API-for-client-sid...

122 lines
4.2 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Lukas Planz <me@md5lukas.de>
Date: Mon, 2 Oct 2023 15:47:27 +0200
Subject: [PATCH] Add API for client-side signs
diff --git a/src/main/java/io/papermc/paper/event/packet/PreSignChangeEvent.java b/src/main/java/io/papermc/paper/event/packet/PreSignChangeEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..65e1be58c2b50fcb442bcee32f66d7ac9bba3db5
--- /dev/null
+++ b/src/main/java/io/papermc/paper/event/packet/PreSignChangeEvent.java
@@ -0,0 +1,85 @@
+package io.papermc.paper.event.packet;
+
+import io.papermc.paper.math.BlockPosition;
+import net.kyori.adventure.text.Component;
+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.ApiStatus;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Unmodifiable;
+import java.util.List;
+
+/**
+ * Called when a sign edit packet has been received, but the location at which the sign should be edited
+ * has not yet been checked for the existence of a real sign.
+ * <p>
+ * Cancelling this event will prevent further processing of the sign change, but needs further handling
+ * by the plugin because the local world might be in an inconsistent state.
+ */
+public class PreSignChangeEvent extends PlayerEvent implements Cancellable {
+
+ private static final HandlerList HANDLER_LIST = new HandlerList();
+ private boolean cancel = false;
+ private final BlockPosition block;
+ private final Side side;
+ private final List<Component> lines;
+
+ @ApiStatus.Internal
+ public PreSignChangeEvent(final @NotNull Player editor, @NotNull final BlockPosition block, final @NotNull Side side, @NotNull final List<@NotNull Component> lines) {
+ super(editor);
+ this.block = block;
+ this.side = side;
+ this.lines = lines;
+ }
+
+ /**
+ * Gets the location at which an unknown sign was edited.
+ *
+ * @return location where the change happened
+ */
+ public @NotNull BlockPosition getBlock() {
+ return block;
+ }
+
+ /**
+ * Gets which side of the sign was edited.
+ *
+ * @return {@link Side} that was edited
+ */
+ public @NotNull Side getSide() {
+ return side;
+ }
+
+ /**
+ * Gets the lines that the player has entered
+ *
+ * @return the lines
+ */
+ public @NotNull @Unmodifiable List<@NotNull Component> getLines() {
+ return lines;
+ }
+
+ @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/src/main/java/org/bukkit/entity/Player.java b/src/main/java/org/bukkit/entity/Player.java
index 20fa1024f9ad8f478a347be5c554b5e45b398a1c..eb735b76c833a8de171cc98e2a4aceae38a7f741 100644
--- a/src/main/java/org/bukkit/entity/Player.java
+++ b/src/main/java/org/bukkit/entity/Player.java
@@ -2811,6 +2811,19 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
* @param side The side to edit
*/
public void openSign(@NotNull Sign sign, @NotNull Side side);
+ // Paper start
+ /**
+ * Open a sign for editing by the player.
+ * <p>
+ * The sign must only be placed locally for the player, which can be done with {@link #sendBlockChange(Location, BlockData)} and {@link #sendBlockUpdate(Location, TileState)}.
+ * A side-effect of this is that no events will be called for this action.
+ * </p>
+ *
+ * @param block The block where the client has a sign placed
+ * @param side The side to edit
+ */
+ void openLocalSign(@NotNull io.papermc.paper.math.BlockPosition block, @NotNull Side side);
+ // Paper end
/**
* Shows the demo screen to the player, this screen is normally only seen in