From c11905550eb3cde9ea528205531df9a88f8a916e Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Sun, 17 Jul 2011 17:01:05 +0200 Subject: [PATCH] Refactor Bucket events By: Erik Broes --- .../event/player/PlayerBucketEmptyEvent.java | 42 +--------- .../event/player/PlayerBucketEvent.java | 79 +++++++++++++++++++ .../event/player/PlayerBucketFillEvent.java | 43 +--------- 3 files changed, 83 insertions(+), 81 deletions(-) create mode 100644 paper-api/src/main/java/org/bukkit/event/player/PlayerBucketEvent.java diff --git a/paper-api/src/main/java/org/bukkit/event/player/PlayerBucketEmptyEvent.java b/paper-api/src/main/java/org/bukkit/event/player/PlayerBucketEmptyEvent.java index e086165b01..b7ddc92d1e 100644 --- a/paper-api/src/main/java/org/bukkit/event/player/PlayerBucketEmptyEvent.java +++ b/paper-api/src/main/java/org/bukkit/event/player/PlayerBucketEmptyEvent.java @@ -4,52 +4,14 @@ import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.entity.Player; -import org.bukkit.event.Cancellable; import org.bukkit.inventory.ItemStack; /** * Called when a player empties a bucket */ -public class PlayerBucketEmptyEvent extends PlayerEvent implements Cancellable { - ItemStack itemStack; - boolean cancelled = false; - Block blockClicked; - BlockFace blockFace; - Material bucket; - +public class PlayerBucketEmptyEvent extends PlayerBucketEvent { public PlayerBucketEmptyEvent(Player who, Block blockClicked, BlockFace blockFace, Material bucket, ItemStack itemInHand) { - super(Type.PLAYER_BUCKET_EMPTY, who); - this.blockClicked = blockClicked; - this.blockFace = blockFace; - this.itemStack = itemInHand; - this.bucket = bucket; - } + super(Type.PLAYER_BUCKET_EMPTY, who, blockClicked, blockFace, bucket, itemInHand); - public Material getBucket() { - return bucket; - } - - public ItemStack getItemStack() { - return itemStack; - } - - public Block getBlockClicked() { - return blockClicked; - } - - public BlockFace getBlockFace() { - return blockFace; - } - - public void setItemStack(ItemStack itemStack) { - this.itemStack = itemStack; - } - - public boolean isCancelled() { - return cancelled; - } - - public void setCancelled(boolean cancel) { - this.cancelled = cancel; } } diff --git a/paper-api/src/main/java/org/bukkit/event/player/PlayerBucketEvent.java b/paper-api/src/main/java/org/bukkit/event/player/PlayerBucketEvent.java new file mode 100644 index 0000000000..ec45668c98 --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/player/PlayerBucketEvent.java @@ -0,0 +1,79 @@ +package org.bukkit.event.player; + +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.inventory.ItemStack; + +public abstract class PlayerBucketEvent extends PlayerEvent implements Cancellable { + + private ItemStack itemStack; + private boolean cancelled = false; + private Block blockClicked; + private BlockFace blockFace; + private Material bucket; + + public PlayerBucketEvent(Type type, Player who, Block blockClicked, BlockFace blockFace, Material bucket, ItemStack itemInHand) { + super(type, who); + this.blockClicked = blockClicked; + this.blockFace = blockFace; + this.itemStack = itemInHand; + this.bucket = bucket; + } + + /** + * Returns the bucket used in this event + * + * @return the used bucket + */ + public Material getBucket() { + return bucket; + } + + /** + * Get the resulting item in hand after the bucket event + * + * @return Itemstack hold in hand after the event. + */ + public ItemStack getItemStack() { + return itemStack; + } + + /** + * Set the item in hand after the event + * + * @param itemStack the new held itemstack after the bucket event. + */ + public void setItemStack(ItemStack itemStack) { + this.itemStack = itemStack; + } + + + /** + * Return the block clicked + * + * @return the blicked block + */ + public Block getBlockClicked() { + return blockClicked; + } + + /** + * Get the face on the clicked block + * + * @return the clicked face + */ + public BlockFace getBlockFace() { + return blockFace; + } + + public boolean isCancelled() { + return cancelled; + } + + public void setCancelled(boolean cancel) { + this.cancelled = cancel; + } +} \ No newline at end of file diff --git a/paper-api/src/main/java/org/bukkit/event/player/PlayerBucketFillEvent.java b/paper-api/src/main/java/org/bukkit/event/player/PlayerBucketFillEvent.java index 1df709f044..5f1ff0df59 100644 --- a/paper-api/src/main/java/org/bukkit/event/player/PlayerBucketFillEvent.java +++ b/paper-api/src/main/java/org/bukkit/event/player/PlayerBucketFillEvent.java @@ -4,52 +4,13 @@ import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.entity.Player; -import org.bukkit.event.Cancellable; import org.bukkit.inventory.ItemStack; /** * Called when a player fills a bucket */ -public class PlayerBucketFillEvent extends PlayerEvent implements Cancellable { - ItemStack itemStack; - boolean cancelled = false; - Block blockClicked; - BlockFace blockFace; - Material bucket; - +public class PlayerBucketFillEvent extends PlayerBucketEvent { public PlayerBucketFillEvent(Player who, Block blockClicked, BlockFace blockFace, Material bucket, ItemStack itemInHand) { - super(Type.PLAYER_BUCKET_FILL, who); - this.blockClicked = blockClicked; - this.blockFace = blockFace; - this.itemStack = itemInHand; - this.bucket = bucket; - } - - public Material getBucket() { - return bucket; - } - - public ItemStack getItemStack() { - return itemStack; - } - - public Block getBlockClicked() { - return blockClicked; - } - - public BlockFace getBlockFace() { - return blockFace; - } - - public void setItemStack(ItemStack itemStack) { - this.itemStack = itemStack; - } - - public boolean isCancelled() { - return cancelled; - } - - public void setCancelled(boolean cancel) { - this.cancelled = cancel; + super(Type.PLAYER_BUCKET_FILL, who, blockClicked, blockFace, bucket, itemInHand); } }