From 14e4e9a16c9cb7dc050573f6d3d124c035f80a58 Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Wed, 16 Jun 2021 08:34:08 +1000 Subject: [PATCH] SPIGOT-6562: Add more specific sculk sensor event By: md_5 --- .../event/block/BlockReceiveGameEvent.java | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 paper-api/src/main/java/org/bukkit/event/block/BlockReceiveGameEvent.java diff --git a/paper-api/src/main/java/org/bukkit/event/block/BlockReceiveGameEvent.java b/paper-api/src/main/java/org/bukkit/event/block/BlockReceiveGameEvent.java new file mode 100644 index 0000000000..e226d13064 --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/block/BlockReceiveGameEvent.java @@ -0,0 +1,70 @@ +package org.bukkit.event.block; + +import org.bukkit.GameEvent; +import org.bukkit.block.Block; +import org.bukkit.entity.Entity; +import org.bukkit.event.Cancellable; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * Called when a Sculk sensor receives a game event and hence might activate. + * + * Will be called cancelled if the block's default behavior is to ignore the + * event. + */ +public class BlockReceiveGameEvent extends BlockEvent implements Cancellable { + + private static final HandlerList handlers = new HandlerList(); + private final GameEvent event; + private final Entity entity; + private boolean cancelled; + + public BlockReceiveGameEvent(@NotNull GameEvent event, @NotNull Block block, @Nullable Entity entity) { + super(block); + this.event = event; + this.entity = entity; + } + + /** + * Get the underlying event. + * + * @return the event + */ + @NotNull + public GameEvent getEvent() { + return event; + } + + /** + * Get the entity which triggered this event, if present. + * + * @return triggering entity or null + */ + @Nullable + public Entity getEntity() { + return entity; + } + + @Override + public void setCancelled(boolean cancel) { + this.cancelled = cancel; + } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @NotNull + @Override + public HandlerList getHandlers() { + return handlers; + } + + @NotNull + public static HandlerList getHandlerList() { + return handlers; + } +}