From d7d0c66b753bb982e7693235c77296cf1e03dd62 Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Tue, 1 Feb 2011 18:07:16 +0100 Subject: [PATCH] Interface for BlockBreakEvent By: Meaglin --- .../src/main/java/org/bukkit/event/Event.java | 7 ++++ .../bukkit/event/block/BlockBreakEvent.java | 39 +++++++++++++++++++ .../org/bukkit/event/block/BlockListener.java | 8 ++++ .../bukkit/plugin/java/JavaPluginLoader.java | 6 ++- 4 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 paper-api/src/main/java/org/bukkit/event/block/BlockBreakEvent.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 0db9179757..78bda14771 100644 --- a/paper-api/src/main/java/org/bukkit/event/Event.java +++ b/paper-api/src/main/java/org/bukkit/event/Event.java @@ -319,6 +319,13 @@ public abstract class Event { */ REDSTONE_CHANGE (Category.BLOCK), + /** + * Called when a block is destroyed by a player. + * + * @see org.bukkit.event.block.BlockBreakEvent + */ + BLOCK_BREAK (Category.BLOCK), + /** * INVENTORY EVENTS */ diff --git a/paper-api/src/main/java/org/bukkit/event/block/BlockBreakEvent.java b/paper-api/src/main/java/org/bukkit/event/block/BlockBreakEvent.java new file mode 100644 index 0000000000..81efd2a618 --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/block/BlockBreakEvent.java @@ -0,0 +1,39 @@ +package org.bukkit.event.block; + +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; + +/** + * + * @author Meaglin + */ +public class BlockBreakEvent extends BlockEvent implements Cancellable { + + private Player player; + private boolean cancel; + + public BlockBreakEvent(final Block theBlock, Player player) { + super(Event.Type.BLOCK_BREAK, theBlock); + this.player = player; + this.cancel = false; + } + + /** + * Returns the player doing the damage + * + * @return + */ + public Player getPlayer() { + return player; + } + + public boolean isCancelled() { + return cancel; + } + + public void setCancelled(boolean cancel) { + this.cancel = 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 ff998b18ff..7b7305f2be 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 @@ -101,4 +101,12 @@ public class BlockListener implements Listener { */ public void onBlockBurn(BlockBurnEvent event) { } + + /** + * Called when a block is destroyed by a player. + * + * @param event Relevant event details + */ + public void onBlockBreak(BlockBreakEvent event) { + } } 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 064739b1e4..9c733258dc 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 @@ -235,12 +235,16 @@ public final class JavaPluginLoader implements PluginLoader { ((BlockListener)listener).onBlockRedstoneChange( (BlockFromToEvent)event ); } }; - case BLOCK_BURN: return new EventExecutor() { public void execute( Listener listener, Event event ) { ((BlockListener)listener).onBlockBurn( (BlockBurnEvent)event ); } }; + case BLOCK_BREAK: + return new EventExecutor() { public void execute( Listener listener, Event event ) { + ((BlockListener)listener).onBlockBreak( (BlockBreakEvent)event ); + } + }; // Server Events case PLUGIN_ENABLE: