Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
PlayerFishEvent.java
1 package org.bukkit.event.player;
2 
3 import org.bukkit.entity.Fish;
4 import org.bukkit.entity.Player;
6 import org.bukkit.entity.Entity;
8 
9 /**
10  * Thrown when a player is fishing
11  */
12 public class PlayerFishEvent extends PlayerEvent implements Cancellable {
13  private static final HandlerList handlers = new HandlerList();
14  private final Entity entity;
15  private boolean cancel = false;
16  private int exp;
17  private final State state;
18  private final Fish hookEntity;
19 
20  /**
21  * @deprecated replaced by {@link #PlayerFishEvent(Player, Entity, Fish,
22  * State)} to include the {@link Fish} hook entity.
23  * @param player
24  * @param entity
25  * @param state
26  */
27  @Deprecated
28  public PlayerFishEvent(final Player player, final Entity entity, final State state) {
29  this(player, entity, null, state);
30  }
31 
32  public PlayerFishEvent(final Player player, final Entity entity, final Fish hookEntity, final State state) {
33  super(player);
34  this.entity = entity;
35  this.hookEntity = hookEntity;
36  this.state = state;
37  }
38 
39  /**
40  * Gets the entity caught by the player
41  *
42  * @return Entity caught by the player, null if fishing, bobber has gotten
43  * stuck in the ground or nothing has been caught
44  */
45  public Entity getCaught() {
46  return entity;
47  }
48 
49  /**
50  * Gets the fishing hook.
51  *
52  * @return Fish the entity representing the fishing hook/bobber.
53  */
54  public Fish getHook() {
55  return hookEntity;
56  }
57 
58  public boolean isCancelled() {
59  return cancel;
60  }
61 
62  public void setCancelled(boolean cancel) {
63  this.cancel = cancel;
64  }
65 
66  /**
67  * Gets the amount of experience received when fishing.
68  * <p>
69  * Note: This value has no default effect unless the event state is {@link
70  * State#CAUGHT_FISH}.
71  *
72  * @return the amount of experience to drop
73  */
74  public int getExpToDrop() {
75  return exp;
76  }
77 
78  /**
79  * Sets the amount of experience received when fishing.
80  * <p>
81  * Note: This value has no default effect unless the event state is {@link
82  * State#CAUGHT_FISH}.
83  *
84  * @param amount the amount of experience to drop
85  */
86  public void setExpToDrop(int amount) {
87  exp = amount;
88  }
89 
90  /**
91  * Gets the state of the fishing
92  *
93  * @return A State detailing the state of the fishing
94  */
95  public State getState() {
96  return state;
97  }
98 
99  @Override
100  public HandlerList getHandlers() {
101  return handlers;
102  }
103 
104  public static HandlerList getHandlerList() {
105  return handlers;
106  }
107 
108  /**
109  * An enum to specify the state of the fishing
110  */
111  public enum State {
112 
113  /**
114  * When a player is fishing, ie casting the line out.
115  */
117  /**
118  * When a player has successfully caught a fish and is reeling it in.
119  */
121  /**
122  * When a player has successfully caught an entity
123  */
125  /**
126  * When a bobber is stuck in the ground
127  */
129  /**
130  * When a player fails to catch anything while fishing usually due to
131  * poor aiming or timing
132  */
134  }
135 }
PlayerFishEvent(final Player player, final Entity entity, final State state)