Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
PlayerEggThrowEvent.java
1 package org.bukkit.event.player;
2 
4 import org.bukkit.entity.Egg;
6 import org.bukkit.entity.Player;
8 
9 /**
10  * Called when a player throws an egg and it might hatch
11  */
12 public class PlayerEggThrowEvent extends PlayerEvent {
13  private static final HandlerList handlers = new HandlerList();
14  private final Egg egg;
15  private boolean hatching;
16  private EntityType hatchType;
17  private byte numHatches;
18 
19  public PlayerEggThrowEvent(final Player player, final Egg egg, final boolean hatching, final byte numHatches, final EntityType hatchingType) {
20  super(player);
21  this.egg = egg;
22  this.hatching = hatching;
23  this.numHatches = numHatches;
24  this.hatchType = hatchingType;
25  }
26 
27  @Deprecated
28  public PlayerEggThrowEvent(Player player, Egg egg, boolean hatching, byte numHatches, CreatureType hatchingType) {
29  this(player, egg, hatching, numHatches, hatchingType.toEntityType());
30  }
31 
32  /**
33  * Gets the egg involved in this event.
34  *
35  * @return the egg involved in this event
36  */
37  public Egg getEgg() {
38  return egg;
39  }
40 
41  /**
42  * Gets whether the egg is hatching or not. Will be what the server
43  * would've done without interaction.
44  *
45  * @return boolean Whether the egg is going to hatch or not
46  */
47  public boolean isHatching() {
48  return hatching;
49  }
50 
51  /**
52  * Sets whether the egg will hatch or not.
53  *
54  * @param hatching true if you want the egg to hatch, false if you want it
55  * not to
56  */
57  public void setHatching(boolean hatching) {
58  this.hatching = hatching;
59  }
60 
61  /**
62  * Get the type of the mob being hatched (EntityType.CHICKEN by default)
63  *
64  * @return The type of the mob being hatched by the egg
65  * @deprecated In favour of {@link #getHatchingType()}.
66  */
67  @Deprecated
69  return CreatureType.fromEntityType(hatchType);
70  }
71 
72  /**
73  * Get the type of the mob being hatched (EntityType.CHICKEN by default)
74  *
75  * @return The type of the mob being hatched by the egg
76  */
78  return hatchType;
79  }
80 
81  /**
82  * Change the type of mob being hatched by the egg
83  *
84  * @param hatchType The type of the mob being hatched by the egg
85  * @deprecated In favour of {@link #setHatchingType(EntityType)}.
86  */
87  @Deprecated
88  public void setHatchType(CreatureType hatchType) {
89  this.hatchType = hatchType.toEntityType();
90  }
91 
92  /**
93  * Change the type of mob being hatched by the egg
94  *
95  * @param hatchType The type of the mob being hatched by the egg
96  */
97  public void setHatchingType(EntityType hatchType) {
98  if(!hatchType.isSpawnable()) throw new IllegalArgumentException("Can't spawn that entity type from an egg!");
99  this.hatchType = hatchType;
100  }
101 
102  /**
103  * Get the number of mob hatches from the egg. By default the number will
104  * be the number the server would've done
105  * <ul>
106  * <li>7/8 chance of being 0
107  * <li>31/256 ~= 1/8 chance to be 1
108  * <li>1/256 chance to be 4
109  * </ul>
110  *
111  * @return The number of mobs going to be hatched by the egg
112  */
113  public byte getNumHatches() {
114  return numHatches;
115  }
116 
117  /**
118  * Change the number of mobs coming out of the hatched egg
119  * <p>
120  * The boolean hatching will override this number. Ie. If hatching =
121  * false, this number will not matter
122  *
123  * @param numHatches The number of mobs coming out of the egg
124  */
125  public void setNumHatches(byte numHatches) {
126  this.numHatches = numHatches;
127  }
128 
129  @Override
130  public HandlerList getHandlers() {
131  return handlers;
132  }
133 
134  public static HandlerList getHandlerList() {
135  return handlers;
136  }
137 }