13
0
geforkt von Mirrors/Paper

Add cause to PlayerOpenSignEvent (#9441)

Also fire the event for plugin-opened signs
Dieser Commit ist enthalten in:
Jake Potrebic 2023-07-26 09:25:14 -07:00
Ursprung aa3e3b9b14
Commit cbfc2065f5
2 geänderte Dateien mit 82 neuen und 4 gelöschten Zeilen

Datei anzeigen

@ -18,6 +18,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+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;
+
+/**
@ -28,13 +29,16 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+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;
+ private final Sign sign;
+ private final Side side;
+ private final Cause cause;
+
+ public PlayerOpenSignEvent(@NotNull Player editor, @NotNull Sign sign, @NotNull Side side) {
+ @ApiStatus.Internal
+ public PlayerOpenSignEvent(final @NotNull Player editor, final @NotNull Sign sign, final @NotNull Side side, final @NotNull Cause cause) {
+ super(editor);
+ this.sign = sign;
+ this.side = side;
+ this.cause = cause;
+ }
+
+ /**
@ -58,6 +62,15 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ return side;
+ }
+
+ /**
+ * The cause of this sign open.
+ *
+ * @return the cause
+ */
+ public @NotNull Cause getCause() {
+ return cause;
+ }
+
+ @Override
+ public boolean isCancelled() {
+ return cancel;
@ -78,4 +91,26 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ public static HandlerList getHandlerList() {
+ return HANDLER_LIST;
+ }
+
+ /**
+ * The cause of the {@link PlayerOpenSignEvent}.
+ */
+ public enum Cause {
+ /**
+ * The event was triggered by the placement of a sign.
+ */
+ PLACE,
+ /**
+ * The event was triggered by an interaction with a sign.
+ */
+ INTERACT,
+ /**
+ * The event was triggered via a plugin with {@link org.bukkit.entity.HumanEntity#openSign(Sign, Side)}
+ */
+ PLUGIN,
+ /**
+ * Fallback cause for any unknown cause.
+ */
+ UNKNOWN,
+ }
+}

Datei anzeigen

@ -4,24 +4,67 @@ 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/item/ItemStack.java b/src/main/java/net/minecraft/world/item/ItemStack.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/item/ItemStack.java
+++ b/src/main/java/net/minecraft/world/item/ItemStack.java
@@ -0,0 +0,0 @@ public final class ItemStack {
try {
if (world.getBlockEntity(SignItem.openSign) instanceof SignBlockEntity tileentitysign) {
if (world.getBlockState(SignItem.openSign).getBlock() instanceof SignBlock blocksign) {
- blocksign.openTextEdit(entityhuman, tileentitysign, true);
+ blocksign.openTextEdit(entityhuman, tileentitysign, true, io.papermc.paper.event.player.PlayerOpenSignEvent.Cause.PLACE); // Paper
}
}
} finally {
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
} else if (bl3) {
return InteractionResult.SUCCESS;
} else if (!this.otherPlayerIsEditingSign(player, signBlockEntity) && player.mayBuild() && this.hasEditableText(player, signBlockEntity, bl2)) {
- this.openTextEdit(player, signBlockEntity, bl2);
+ this.openTextEdit(player, signBlockEntity, bl2, io.papermc.paper.event.player.PlayerOpenSignEvent.Cause.INTERACT); // Paper
return InteractionResult.SUCCESS;
} else {
return InteractionResult.PASS;
@@ -0,0 +0,0 @@ public abstract class SignBlock extends BaseEntityBlock implements SimpleWaterlo
return woodType;
}
+ @io.papermc.paper.annotation.DoNotUse @Deprecated // Paper
public void openTextEdit(Player player, SignBlockEntity blockEntity, boolean front) {
+ // Paper start
+ this.openTextEdit(player, blockEntity, front, io.papermc.paper.event.player.PlayerOpenSignEvent.Cause.UNKNOWN);
+ }
+ public void openTextEdit(Player player, SignBlockEntity blockEntity, boolean front, io.papermc.paper.event.player.PlayerOpenSignEvent.Cause cause) {
+ 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);
+ front ? org.bukkit.block.sign.Side.FRONT : org.bukkit.block.sign.Side.BACK,
+ cause);
+ if (!event.callEvent()) return;
+ // Paper end
blockEntity.setAllowedPlayerEditor(player.getUUID());
player.openTextEdit(blockEntity, front);
}
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftSign.java b/src/main/java/org/bukkit/craftbukkit/block/CraftSign.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftSign.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftSign.java
@@ -0,0 +0,0 @@ public class CraftSign<T extends SignBlockEntity> extends CraftBlockEntityState<
SignBlockEntity handle = ((CraftSign<?>) sign).getTileEntity();
+ // Paper start
+ io.papermc.paper.event.player.PlayerOpenSignEvent event = new io.papermc.paper.event.player.PlayerOpenSignEvent((Player) player, sign, side, io.papermc.paper.event.player.PlayerOpenSignEvent.Cause.PLUGIN);
+ if (!event.callEvent()) return;
+ // Paper end
handle.setAllowedPlayerEditor(player.getUniqueId()); // Paper
((org.bukkit.craftbukkit.entity.CraftHumanEntity) player).getHandle().openTextEdit(handle, Side.FRONT == side); // Paper - change move open sign to HumanEntity
}