From c3373081e2d2e3a5f25ae2111ec30a118efd1c84 Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Fri, 17 Jun 2011 14:46:01 -0400 Subject: [PATCH] Added BlockSpread, BlockForm and BlockFade events. By: EvilSeph --- .../src/main/java/org/bukkit/event/Event.java | 18 ++++++ .../bukkit/event/block/BlockFadeEvent.java | 48 ++++++++++++++++ .../bukkit/event/block/BlockFormEvent.java | 56 +++++++++++++++++++ .../org/bukkit/event/block/BlockListener.java | 23 ++++++++ .../bukkit/event/block/BlockSpreadEvent.java | 25 +++++++++ .../bukkit/plugin/java/JavaPluginLoader.java | 24 +++++++- 6 files changed, 193 insertions(+), 1 deletion(-) create mode 100644 paper-api/src/main/java/org/bukkit/event/block/BlockFadeEvent.java create mode 100644 paper-api/src/main/java/org/bukkit/event/block/BlockFormEvent.java create mode 100644 paper-api/src/main/java/org/bukkit/event/block/BlockSpreadEvent.java diff --git a/paper-api/src/main/java/org/bukkit/event/Event.java b/paper-api/src/main/java/org/bukkit/event/Event.java index 90ffc599d5..80cc1c9567 100644 --- a/paper-api/src/main/java/org/bukkit/event/Event.java +++ b/paper-api/src/main/java/org/bukkit/event/Event.java @@ -376,6 +376,24 @@ public abstract class Event implements Serializable { * @see org.bukkit.event.block.SnowFormEvent */ SNOW_FORM (Category.BLOCK), + /** + * Called when a block is formed based on world conditions + * + * @see org.bukkit.event.block.BlockFormEvent + */ + BLOCK_FORM (Category.BLOCK), + /** + * Called when a block spreads based on world conditions + * + * @see org.bukkit.event.block.BlockSpreadEvent + */ + BLOCK_SPREAD (Category.BLOCK), + /** + * Called when a block fades, melts or disappears based on world conditions + * + * @see org.bukkit.event.block.BlockFadeEvent + */ + BLOCK_FADE (Category.BLOCK), /** * INVENTORY EVENTS diff --git a/paper-api/src/main/java/org/bukkit/event/block/BlockFadeEvent.java b/paper-api/src/main/java/org/bukkit/event/block/BlockFadeEvent.java new file mode 100644 index 0000000000..9dd9c96ce2 --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/block/BlockFadeEvent.java @@ -0,0 +1,48 @@ +package org.bukkit.event.block; + +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockState; +import org.bukkit.event.Cancellable; +/** + *Called when a block fades, melts or disappears based on world conditions + */ +public class BlockFadeEvent extends BlockEvent implements Cancellable { + private boolean cancelled; + private BlockState newState; + + public BlockFadeEvent(Block block, BlockState newState) { + super(Type.BLOCK_FADE, block); + this.newState = newState; + this.cancelled = false; + } + + /** + * Gets the state of the block that will be fading + * + * @return the block state + */ + public BlockState getNewState() { + return newState; + } + + /** + * Gets the cancellation state of this event. A cancelled event will not + * be executed in the server, but will still pass to other plugins + * + * @return true if this event is cancelled + */ + public boolean isCancelled() { + return cancelled; + } + + /** + * Sets the cancellation state of this event. A cancelled event will not + * be executed in the server, but will still pass to other plugins + * + * @param cancel true if you wish to cancel snow from forming during a ice formation + */ + public void setCancelled(boolean cancel) { + this.cancelled = cancel; + } +} diff --git a/paper-api/src/main/java/org/bukkit/event/block/BlockFormEvent.java b/paper-api/src/main/java/org/bukkit/event/block/BlockFormEvent.java new file mode 100644 index 0000000000..a769fd4085 --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/block/BlockFormEvent.java @@ -0,0 +1,56 @@ +package org.bukkit.event.block; + +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockState; +import org.bukkit.event.Cancellable; +/** + * Called when a block is formed or spreads based on world conditions + */ +public class BlockFormEvent extends BlockEvent implements Cancellable { + private boolean cancelled; + private BlockState newState; + + public BlockFormEvent(Block block, BlockState newState) { + super(Type.BLOCK_FORM, block); + this.block = block; + this.newState = newState; + this.cancelled = false; + } + + public BlockFormEvent(Type type, Block block, BlockState newState) { + super(type, block); + this.block = block; + this.newState = newState; + this.cancelled = false; + } + + /** + * Gets the state of the block where it will form or spread to + * + * @return the block state + */ + public BlockState getNewState() { + return newState; + } + + /** + * Gets the cancellation state of this event. A cancelled event will not + * be executed in the server, but will still pass to other plugins + * + * @return true if this event is cancelled + */ + public boolean isCancelled() { + return cancelled; + } + + /** + * Sets the cancellation state of this event. A cancelled event will not + * be executed in the server, but will still pass to other plugins + * + * @param cancel true if you wish to cancel snow from forming during a ice formation + */ + public void setCancelled(boolean cancel) { + this.cancelled = cancel; + } +} diff --git a/paper-api/src/main/java/org/bukkit/event/block/BlockListener.java b/paper-api/src/main/java/org/bukkit/event/block/BlockListener.java index 2b501f8b46..b36234594a 100644 --- a/paper-api/src/main/java/org/bukkit/event/block/BlockListener.java +++ b/paper-api/src/main/java/org/bukkit/event/block/BlockListener.java @@ -103,9 +103,32 @@ public class BlockListener implements Listener { * Called when a world is attempting to place a block during a snowfall * * @param event Relevant event details + * @deprecated be prepared to use onBlockForm instead as it will be replacing this event after the RB */ + @Deprecated public void onSnowForm(SnowFormEvent event) {} + /** + * Called when a block is formed based on world conditions + * + * @param event Relevant event details + */ + public void onBlockForm(BlockFormEvent event) {} + + /** + * Called when a block spreads based on world conditions + * + * @param event Relevant event details + */ + public void onBlockSpread(BlockSpreadEvent event) {} + + /** + * Called when a block fades, melts or disappears based on world conditions + * + * @param event Relevant event details + */ + public void onBlockFade(BlockFadeEvent event) {} + /** * Called when a block is dispensing an item * diff --git a/paper-api/src/main/java/org/bukkit/event/block/BlockSpreadEvent.java b/paper-api/src/main/java/org/bukkit/event/block/BlockSpreadEvent.java new file mode 100644 index 0000000000..aa8706137e --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/block/BlockSpreadEvent.java @@ -0,0 +1,25 @@ +package org.bukkit.event.block; + +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockState; +/** + *Represents any event that spreads blocks + */ +public class BlockSpreadEvent extends BlockFormEvent { + private Block source; + + public BlockSpreadEvent(Block block, Block source, BlockState newState) { + super(Type.BLOCK_SPREAD, block, newState); + this.source = source; + } + + /** + * Gets the source block + * + * @return the block state + */ + public Block getSource() { + return source; + } +} diff --git a/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java index 47cffca42e..4757032d2e 100644 --- a/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java +++ b/paper-api/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java @@ -490,6 +490,28 @@ public final class JavaPluginLoader implements PluginLoader { } }; + case BLOCK_FORM: + return new EventExecutor() { + public void execute(Listener listener, Event event) { + ((BlockListener) listener).onBlockForm((BlockFormEvent) event); + } + }; + + case BLOCK_SPREAD: + return new EventExecutor() { + public void execute(Listener listener, Event event) { + ((BlockListener) listener).onBlockSpread((BlockSpreadEvent) event); + } + }; + + + case BLOCK_FADE: + return new EventExecutor() { + public void execute(Listener listener, Event event) { + ((BlockListener) listener).onBlockFade((BlockFadeEvent) event); + } + }; + case BLOCK_DISPENSE: return new EventExecutor() { public void execute(Listener listener, Event event) { @@ -526,7 +548,7 @@ public final class JavaPluginLoader implements PluginLoader { ((WorldListener) listener).onChunkLoad((ChunkLoadEvent) event); } }; - + case CHUNK_POPULATED: return new EventExecutor() { public void execute(Listener listener, Event event) {