Commits

Cynthia Yantis authored ccf38a975a6
Add PlayerBucketEntityEvent and make PlayerBucketFishEvent deprecated in favor of the newer, more generic event
No tags

src/main/java/org/bukkit/event/player/PlayerBucketEntityEvent.java

Added
1 +package org.bukkit.event.player;
2 +
3 +import org.bukkit.Material;
4 +import org.bukkit.entity.Entity;
5 +import org.bukkit.entity.Player;
6 +import org.bukkit.event.Cancellable;
7 +import org.bukkit.event.HandlerList;
8 +import org.bukkit.inventory.ItemStack;
9 +import org.jetbrains.annotations.NotNull;
10 +
11 +/**
12 + * This event is called whenever a player captures an entity in a bucket.
13 + * <p>
14 + * The initial implementation of this event was {@link PlayerBucketFishEvent}, however
15 + * due to the release of axolotls in the coming releases, a more generic event was needed
16 + * to account for future entities and use cases.
17 + * <p>
18 + * There is no real benefit offered by {@link PlayerBucketFishEvent}, as it now exists soley for
19 + * legacy purposes unless the decided route in the future is to create events per capture type
20 + * such as a PlayerBucketAxolotlEvent.
21 + */
22 +public class PlayerBucketEntityEvent extends PlayerEvent implements Cancellable {
23 +
24 + private static final HandlerList handlers = new HandlerList();
25 + private boolean cancelled;
26 + private final Entity entity;
27 + private final ItemStack originalBucket;
28 + private final ItemStack entityBucket;
29 +
30 + public PlayerBucketEntityEvent(@NotNull Player player, @NotNull Entity entity, @NotNull ItemStack originalBucket, @NotNull ItemStack entityBucket) {
31 + super(player);
32 + this.entity = entity;
33 + this.originalBucket = originalBucket;
34 + this.entityBucket = entityBucket;
35 + }
36 +
37 + /**
38 + * Gets the {@link Entity} being put into the bucket
39 + *
40 + * @return The {@link Entity} being put into the bucket
41 + */
42 + @NotNull
43 + public Entity getEntity() {
44 + return entity;
45 + }
46 +
47 + /**
48 + * Gets the bucket used to capture the {@link Entity}.
49 + * <p>
50 + * This refers to the bucket clicked with, ie {@link Material#WATER_BUCKET}, or
51 + * in future implementations, possibly {@link Material#BUCKET}.
52 + *
53 + * @return The used bucket
54 + */
55 + @NotNull
56 + public ItemStack getOriginalBucket() {
57 + return originalBucket;
58 + }
59 +
60 + /**
61 + * Gets the bucket that the {@link Entity} will be put into.
62 + * <p>
63 + * This refers to the bucket with the entity, ie
64 + * {@link Material#PUFFERFISH_BUCKET}.
65 + *
66 + * @return The bucket that the {@link Entity} will be put into
67 + */
68 + @NotNull
69 + public ItemStack getEntityBucket() {
70 + return entityBucket;
71 + }
72 +
73 + @Override
74 + public boolean isCancelled() {
75 + return cancelled;
76 + }
77 +
78 + @Override
79 + public void setCancelled(boolean cancel) {
80 + this.cancelled = cancel;
81 + }
82 +
83 + @NotNull
84 + @Override
85 + public HandlerList getHandlers() {
86 + return handlers;
87 + }
88 +
89 + @NotNull
90 + public static HandlerList getHandlerList() {
91 + return handlers;
92 + }
93 +}

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut