mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-09 16:42:03 -07:00
#613: Add PlayerBucketEntityEvent and make PlayerBucketFishEvent deprecated in favor of the newer, more generic event
By: DiamondDagger590 <diamonddagger590@gmail.com>
This commit is contained in:
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
@@ -1,29 +1,23 @@
|
|||||||
package org.bukkit.event.player;
|
package org.bukkit.event.player;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.Warning;
|
||||||
import org.bukkit.entity.Fish;
|
import org.bukkit.entity.Fish;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Cancellable;
|
|
||||||
import org.bukkit.event.HandlerList;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This event is called whenever a player attempts to put a fish in a bucket.
|
* 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 {
|
@Deprecated
|
||||||
|
@Warning(false)
|
||||||
private static final HandlerList handlers = new HandlerList();
|
public class PlayerBucketFishEvent extends PlayerBucketEntityEvent {
|
||||||
private boolean cancalled;
|
|
||||||
private final Fish fish;
|
|
||||||
private final ItemStack waterBucket;
|
|
||||||
private final ItemStack fishBucket;
|
|
||||||
|
|
||||||
public PlayerBucketFishEvent(@NotNull Player player, @NotNull Fish fish, @NotNull ItemStack waterBucket, @NotNull ItemStack fishBucket) {
|
public PlayerBucketFishEvent(@NotNull Player player, @NotNull Fish fish, @NotNull ItemStack waterBucket, @NotNull ItemStack fishBucket) {
|
||||||
super(player);
|
super(player, fish, waterBucket, fishBucket);
|
||||||
this.fish = fish;
|
|
||||||
this.waterBucket = waterBucket;
|
|
||||||
this.fishBucket = fishBucket;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -32,8 +26,9 @@ public class PlayerBucketFishEvent extends PlayerEvent implements Cancellable {
|
|||||||
* @return The fish involved with this event
|
* @return The fish involved with this event
|
||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
|
@Override
|
||||||
public Fish getEntity() {
|
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}.
|
* This refers to the bucket clicked with, ie {@link Material#WATER_BUCKET}.
|
||||||
*
|
*
|
||||||
* @return The used bucket
|
* @return The used bucket
|
||||||
|
* @deprecated Use {@link #getOriginalBucket()}
|
||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
|
@Deprecated
|
||||||
public ItemStack getWaterBucket() {
|
public ItemStack getWaterBucket() {
|
||||||
return waterBucket;
|
return getOriginalBucket();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -55,30 +52,11 @@ public class PlayerBucketFishEvent extends PlayerEvent implements Cancellable {
|
|||||||
* {@link Material#PUFFERFISH_BUCKET}.
|
* {@link Material#PUFFERFISH_BUCKET}.
|
||||||
*
|
*
|
||||||
* @return The bucket that the fish will be put into
|
* @return The bucket that the fish will be put into
|
||||||
|
* @deprecated Use {@link #getEntityBucket()}
|
||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
|
@Deprecated
|
||||||
public ItemStack getFishBucket() {
|
public ItemStack getFishBucket() {
|
||||||
return fishBucket;
|
return getEntityBucket();
|
||||||
}
|
|
||||||
|
|
||||||
@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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user