Add cause to PlayerOpenSignEvent (#9441)

Also fire the event for plugin-opened signs
This commit is contained in:
Jake Potrebic
2023-07-26 09:25:14 -07:00
parent aa3e3b9b14
commit cbfc2065f5
2 changed files with 82 additions and 4 deletions

View File

@@ -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,
+ }
+}