Paper/patches/api/0459-Add-BlockPressChangeEv...

83 lines
2.5 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jakub Zacek <dawon@dawon.eu>
Date: Thu, 1 Feb 2024 22:15:45 +0100
Subject: [PATCH] Add BlockPressChangeEvent
diff --git a/src/main/java/io/papermc/paper/event/block/BlockPressChangeEvent.java b/src/main/java/io/papermc/paper/event/block/BlockPressChangeEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..1744a8e47337e6408b2facc03d8070d851ad9be0
--- /dev/null
+++ b/src/main/java/io/papermc/paper/event/block/BlockPressChangeEvent.java
@@ -0,0 +1,70 @@
+package io.papermc.paper.event.block;
+
+import org.bukkit.block.Block;
+import org.bukkit.entity.Entity;
+import org.bukkit.event.Cancellable;
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.block.BlockEvent;
+import org.jetbrains.annotations.ApiStatus;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Called when a block (e.g. Button or Pressure Plate) is being pressed or released.
+ * <p>
+ * If this event is cancelled for release, the release check will be retried after default press delay for specific block.
+ */
+public class BlockPressChangeEvent extends BlockEvent implements Cancellable {
+
+ private static final HandlerList HANDLER_LIST = new HandlerList();
+
+ private final Entity entity;
+ private final boolean pressed;
+
+ private boolean cancelled;
+
+ @ApiStatus.Internal
+ public BlockPressChangeEvent(@NotNull Block block, @Nullable Entity entity, boolean pressed) {
+ super(block);
+ this.entity = entity;
+ this.pressed = pressed;
+ }
+
+ /**
+ * Returns Entity that caused this block to be pressed. For release this is always null.
+ *
+ * @return Entity that caused this block to be pressed or null for release
+ */
+ public @Nullable Entity getEntity() {
+ return entity;
+ }
+
+ /**
+ * Returns whether this block is being pressed or released
+ *
+ * @return true when pressed, false when released
+ */
+ public boolean isPressed() {
+ return pressed;
+ }
+
+ @Override
+ public boolean isCancelled() {
+ return this.cancelled;
+ }
+
+ @Override
+ public void setCancelled(boolean cancel) {
+ this.cancelled = cancel;
+ }
+
+ @NotNull
+ public HandlerList getHandlers() {
+ return HANDLER_LIST;
+ }
+
+ @NotNull
+ public static HandlerList getHandlerList() {
+ return HANDLER_LIST;
+ }
+}