From 3d74697e246fde98712fb0e2d5a83e06f1037ecc Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Fri, 28 May 2021 08:39:24 +1000 Subject: [PATCH] #613: Add PlayerBucketEntityEvent and make PlayerBucketFishEvent deprecated in favor of the newer, more generic event By: DiamondDagger590 --- .../event/player/PlayerBucketEntityEvent.java | 84 +++++++++++++++++++ .../event/player/PlayerBucketFishEvent.java | 52 ++++-------- 2 files changed, 99 insertions(+), 37 deletions(-) create mode 100644 paper-api/src/main/java/org/bukkit/event/player/PlayerBucketEntityEvent.java diff --git a/paper-api/src/main/java/org/bukkit/event/player/PlayerBucketEntityEvent.java b/paper-api/src/main/java/org/bukkit/event/player/PlayerBucketEntityEvent.java new file mode 100644 index 0000000000..e0ce294b54 --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/event/player/PlayerBucketEntityEvent.java @@ -0,0 +1,84 @@ +package org.bukkit.event.player; + +import org.bukkit.Material; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.HandlerList; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; + +/** + * This event is called whenever a player captures an entity in a bucket. + */ +public class PlayerBucketEntityEvent extends PlayerEvent implements Cancellable { + + private static final HandlerList handlers = new HandlerList(); + private boolean cancelled; + private final Entity entity; + private final ItemStack originalBucket; + private final ItemStack entityBucket; + + public PlayerBucketEntityEvent(@NotNull Player player, @NotNull Entity entity, @NotNull ItemStack originalBucket, @NotNull ItemStack entityBucket) { + super(player); + this.entity = entity; + this.originalBucket = originalBucket; + this.entityBucket = entityBucket; + } + + /** + * Gets the {@link Entity} being put into the bucket. + * + * @return The {@link Entity} being put into the bucket + */ + @NotNull + public Entity getEntity() { + return entity; + } + + /** + * Gets the bucket used to capture the {@link Entity}. + * + * This refers to the bucket clicked with, eg {@link Material#WATER_BUCKET}. + * + * @return The used bucket + */ + @NotNull + public ItemStack getOriginalBucket() { + return originalBucket; + } + + /** + * Gets the bucket that the {@link Entity} will be put into. + * + * This refers to the bucket with the entity, eg + * {@link Material#PUFFERFISH_BUCKET}. + * + * @return The bucket that the {@link Entity} will be put into + */ + @NotNull + public ItemStack getEntityBucket() { + return entityBucket; + } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancel) { + this.cancelled = cancel; + } + + @NotNull + @Override + public HandlerList getHandlers() { + return handlers; + } + + @NotNull + public static HandlerList getHandlerList() { + return handlers; + } +} diff --git a/paper-api/src/main/java/org/bukkit/event/player/PlayerBucketFishEvent.java b/paper-api/src/main/java/org/bukkit/event/player/PlayerBucketFishEvent.java index 8564c55a90..2c0ae1b066 100644 --- a/paper-api/src/main/java/org/bukkit/event/player/PlayerBucketFishEvent.java +++ b/paper-api/src/main/java/org/bukkit/event/player/PlayerBucketFishEvent.java @@ -1,29 +1,23 @@ package org.bukkit.event.player; import org.bukkit.Material; +import org.bukkit.Warning; import org.bukkit.entity.Fish; import org.bukkit.entity.Player; -import org.bukkit.event.Cancellable; -import org.bukkit.event.HandlerList; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; /** * This event is called whenever a player attempts to put a fish in a bucket. + * + * @deprecated Use the more generic {@link PlayerBucketEntityEvent} */ -public class PlayerBucketFishEvent extends PlayerEvent implements Cancellable { - - private static final HandlerList handlers = new HandlerList(); - private boolean cancalled; - private final Fish fish; - private final ItemStack waterBucket; - private final ItemStack fishBucket; +@Deprecated +@Warning(false) +public class PlayerBucketFishEvent extends PlayerBucketEntityEvent { public PlayerBucketFishEvent(@NotNull Player player, @NotNull Fish fish, @NotNull ItemStack waterBucket, @NotNull ItemStack fishBucket) { - super(player); - this.fish = fish; - this.waterBucket = waterBucket; - this.fishBucket = fishBucket; + super(player, fish, waterBucket, fishBucket); } /** @@ -32,8 +26,9 @@ public class PlayerBucketFishEvent extends PlayerEvent implements Cancellable { * @return The fish involved with this event */ @NotNull + @Override public Fish getEntity() { - return fish; + return (Fish) super.getEntity(); } /** @@ -42,10 +37,12 @@ public class PlayerBucketFishEvent extends PlayerEvent implements Cancellable { * This refers to the bucket clicked with, ie {@link Material#WATER_BUCKET}. * * @return The used bucket + * @deprecated Use {@link #getOriginalBucket()} */ @NotNull + @Deprecated public ItemStack getWaterBucket() { - return waterBucket; + return getOriginalBucket(); } /** @@ -55,30 +52,11 @@ public class PlayerBucketFishEvent extends PlayerEvent implements Cancellable { * {@link Material#PUFFERFISH_BUCKET}. * * @return The bucket that the fish will be put into + * @deprecated Use {@link #getEntityBucket()} */ @NotNull + @Deprecated public ItemStack getFishBucket() { - return fishBucket; - } - - @Override - public boolean isCancelled() { - return cancalled; - } - - @Override - public void setCancelled(boolean cancel) { - this.cancalled = cancel; - } - - @NotNull - @Override - public HandlerList getHandlers() { - return handlers; - } - - @NotNull - public static HandlerList getHandlerList() { - return handlers; + return getEntityBucket(); } }