From d4e8c8b3b3e87accede8a4d1765d601313ad3d9b Mon Sep 17 00:00:00 2001 From: md_5 Date: Tue, 8 Jan 2019 21:23:05 +1100 Subject: [PATCH] SPIGOT-4570: Add FluidLevelChangeEvent --- .../java/org/bukkit/block/data/Levelled.java | 2 + .../event/block/FluidLevelChangeEvent.java | 70 +++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 src/main/java/org/bukkit/event/block/FluidLevelChangeEvent.java diff --git a/src/main/java/org/bukkit/block/data/Levelled.java b/src/main/java/org/bukkit/block/data/Levelled.java index 87610dc9..5255538f 100644 --- a/src/main/java/org/bukkit/block/data/Levelled.java +++ b/src/main/java/org/bukkit/block/data/Levelled.java @@ -9,6 +9,8 @@ package org.bukkit.block.data; * to "falling" fluids. All falling fluids have the same behaviour, but the * level corresponds to that of the block above them, equal to * this.level - 8 + * Note that counterintuitively, an adjusted level of 1 is the highest level, + * whilst 7 is the lowest. *
* May not be higher than {@link #getMaximumLevel()}. */ diff --git a/src/main/java/org/bukkit/event/block/FluidLevelChangeEvent.java b/src/main/java/org/bukkit/event/block/FluidLevelChangeEvent.java new file mode 100644 index 00000000..da0695f3 --- /dev/null +++ b/src/main/java/org/bukkit/event/block/FluidLevelChangeEvent.java @@ -0,0 +1,70 @@ +package org.bukkit.event.block; + +import com.google.common.base.Preconditions; +import org.bukkit.Warning; +import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; +import org.bukkit.event.Cancellable; +import org.bukkit.event.HandlerList; + +/** + * Called when the fluid level of a block changes due to changes in adjacent + * blocks. + * + * @deprecated draft API + */ +@Deprecated +@Warning(false) +public class FluidLevelChangeEvent extends BlockEvent implements Cancellable { + + private static final HandlerList handlers = new HandlerList(); + private boolean cancelled; + // + private BlockData newData; + + public FluidLevelChangeEvent(Block theBlock, BlockData newData) { + super(theBlock); + this.newData = newData; + } + + /** + * Gets the new data of the changed block. + * + * @return new data + */ + public BlockData getNewData() { + return newData; + } + + /** + * Sets the new data of the changed block. Must be of the same Material as + * the old one. + * + * @param newData the new data + */ + public void setNewData(BlockData newData) { + Preconditions.checkArgument(newData != null, "newData null"); + Preconditions.checkArgument(this.newData.getMaterial().equals(newData.getMaterial()), "Cannot change fluid type"); + + this.newData = newData; + } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancelled) { + this.cancelled = cancelled; + } + + @Override + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } +}