Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
1package org.bukkit.event.player;
2
3import org.bukkit.entity.CreatureType;
4import org.bukkit.entity.Egg;
5import org.bukkit.entity.Player;
6
7/**
8 * Called when a player throws an egg and it might hatch
9 */
10public class PlayerEggThrowEvent extends PlayerEvent {
11 private Egg egg;
12 private boolean hatching;
13 private CreatureType hatchType;
14 private byte numHatches;
15
16 public PlayerEggThrowEvent(Player player, Egg egg, boolean hatching, byte numHatches, CreatureType hatchType) {
17 super(Type.PLAYER_EGG_THROW, player);
18 this.egg = egg;
19 this.hatching = hatching;
20 this.numHatches = numHatches;
21 this.hatchType = hatchType;
22 }
23
24 /**
25 * Gets the egg involved in this event.
26 *
27 * @return the egg involved in this event
28 */
29 public Egg getEgg() {
30 return egg;
31 }
32
33 /**
34 * Gets whether the egg is hatching or not. Will be what the server
35 * would've done without interaction.
36 *
37 * @return boolean Whether the egg is going to hatch or not
38 */
39 public boolean isHatching() {
40 return hatching;
41 }
42
43 /**
44 * Sets whether the egg will hatch or not.
45 *
46 * @param hatching true if you want the egg to hatch
47 * false if you want it not to
48 */
49 public void setHatching(boolean hatching) {
50 this.hatching = hatching;
51 }
52
53 /**
54 * Get the type of the mob being hatched (CreatureType.CHICKEN by default)
55 *
56 * @return The type of the mob being hatched by the egg
57 */
58 public CreatureType getHatchType() {
59 return CreatureType.fromName(hatchType.getName());
60 }
61
62 /**
63 * Change the type of mob being hatched by the egg
64 *
65 * @param hatchType The type of the mob being hatched by the egg
66 */
67 public void setHatchType(CreatureType hatchType) {
68 this.hatchType = hatchType;
69 }
70
71 /**
72 * Get the number of mob hatches from the egg. By default the number
73 * will be he number the server would've done
74 * <p>
75 * 7/8 chance of being 0
76 * 31/256 ~= 1/8 chance to be 1
77 * 1/256 chance to be 4
78 *
79 * @return The number of mobs going to be hatched by the egg
80 */
81 public byte getNumHatches() {
82 return numHatches;
83 }
84
85 /**
86 * Change the number of mobs coming out of the hatched egg
87 * <p>
88 * The boolean hatching will override this number.
89 * Ie. If hatching = false, this number will not matter
90 *
91 * @param numHatches The number of mobs coming out of the egg
92 */
93 public void setNumHatches(byte numHatches) {
94 this.numHatches = numHatches;
95 }
96}