Commits

Ryan Michela authored and md_5 committed da1195392ac
SPIGOT-1319: Add EntityBreedEvent
No tags

src/main/java/org/bukkit/event/entity/EntityBreedEvent.java

Added
1 +package org.bukkit.event.entity;
2 +
3 +import org.apache.commons.lang.Validate;
4 +import org.bukkit.entity.LivingEntity;
5 +import org.bukkit.event.Cancellable;
6 +import org.bukkit.event.HandlerList;
7 +import org.bukkit.inventory.ItemStack;
8 +
9 +/**
10 + * Called when one Entity breeds with another Entity.
11 + */
12 +public class EntityBreedEvent extends EntityEvent implements Cancellable {
13 +
14 + private static final HandlerList handlers = new HandlerList();
15 + //
16 + private final LivingEntity mother;
17 + private final LivingEntity father;
18 + private final LivingEntity breeder;
19 + private final ItemStack bredWith;
20 + private int experience;
21 + //
22 + private boolean cancel;
23 +
24 + public EntityBreedEvent(LivingEntity child, LivingEntity mother, LivingEntity father, LivingEntity breeder, ItemStack bredWith, int experience) {
25 + super(child);
26 +
27 + Validate.notNull(child, "Cannot have null child");
28 + Validate.notNull(mother, "Cannot have null mother");
29 + Validate.notNull(father, "Cannot have null father");
30 +
31 + // Breeder can be null in the case of spontaneous conception
32 + this.mother = mother;
33 + this.father = father;
34 + this.breeder = breeder;
35 + this.bredWith = bredWith;
36 +
37 + setExperience(experience);
38 + }
39 +
40 + @Override
41 + public LivingEntity getEntity() {
42 + return (LivingEntity) entity;
43 + }
44 +
45 + /**
46 + * Gets the parent creating this entity.
47 + *
48 + * @return The "birth" parent
49 + */
50 + public LivingEntity getMother() {
51 + return mother;
52 + }
53 +
54 + /**
55 + * Gets the other parent of the newly born entity.
56 + *
57 + * @return the other parent
58 + */
59 + public LivingEntity getFather() {
60 + return father;
61 + }
62 +
63 + /**
64 + * Gets the Entity responsible for breeding. Breeder is null for spontaneous
65 + * conception.
66 + *
67 + * @return The Entity who initiated breeding.
68 + */
69 + public LivingEntity getBreeder() {
70 + return breeder;
71 + }
72 +
73 + /**
74 + * The ItemStack that was used to initiate breeding, if present.
75 + *
76 + * @return ItemStack used to initiate breeding.
77 + */
78 + public ItemStack getBredWith() {
79 + return bredWith;
80 + }
81 +
82 + /**
83 + * Get the amount of experience granted by breeding.
84 + *
85 + * @return experience amount
86 + */
87 + public int getExperience() {
88 + return experience;
89 + }
90 +
91 + /**
92 + * Set the amount of experience granted by breeding.
93 + *
94 + * @param experience experience amount
95 + */
96 + public void setExperience(int experience) {
97 + Validate.isTrue(experience >= 0, "Experience cannot be negative");
98 + this.experience = experience;
99 + }
100 +
101 + @Override
102 + public boolean isCancelled() {
103 + return cancel;
104 + }
105 +
106 + @Override
107 + public void setCancelled(boolean cancel) {
108 + this.cancel = cancel;
109 + }
110 +
111 + @Override
112 + public HandlerList getHandlers() {
113 + return handlers;
114 + }
115 +
116 + public static HandlerList getHandlerList() {
117 + return handlers;
118 + }
119 +}

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

Add shortcut