summaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authorRyan Michela <deltahat@gmail.com>2016-06-18 21:03:28 -0700
committermd_5 <git@md-5.net>2016-06-19 20:08:52 +1000
commitda1195392ac6db7015a83165a01b9c62b8380a24 (patch)
tree04b00be11d520636333f1fcc59aa87651ab1376e /src/main/java
parenteb9f4ee387c12e0179e32cd581575d79d2b93ec5 (diff)
downloadbukkit-da1195392ac6db7015a83165a01b9c62b8380a24.tar
bukkit-da1195392ac6db7015a83165a01b9c62b8380a24.tar.gz
bukkit-da1195392ac6db7015a83165a01b9c62b8380a24.tar.lz
bukkit-da1195392ac6db7015a83165a01b9c62b8380a24.tar.xz
bukkit-da1195392ac6db7015a83165a01b9c62b8380a24.zip
SPIGOT-1319: Add EntityBreedEvent
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/bukkit/event/entity/EntityBreedEvent.java119
1 files changed, 119 insertions, 0 deletions
diff --git a/src/main/java/org/bukkit/event/entity/EntityBreedEvent.java b/src/main/java/org/bukkit/event/entity/EntityBreedEvent.java
new file mode 100644
index 00000000..f8b58e23
--- /dev/null
+++ b/src/main/java/org/bukkit/event/entity/EntityBreedEvent.java
@@ -0,0 +1,119 @@
+package org.bukkit.event.entity;
+
+import org.apache.commons.lang.Validate;
+import org.bukkit.entity.LivingEntity;
+import org.bukkit.event.Cancellable;
+import org.bukkit.event.HandlerList;
+import org.bukkit.inventory.ItemStack;
+
+/**
+ * Called when one Entity breeds with another Entity.
+ */
+public class EntityBreedEvent extends EntityEvent implements Cancellable {
+
+ private static final HandlerList handlers = new HandlerList();
+ //
+ private final LivingEntity mother;
+ private final LivingEntity father;
+ private final LivingEntity breeder;
+ private final ItemStack bredWith;
+ private int experience;
+ //
+ private boolean cancel;
+
+ public EntityBreedEvent(LivingEntity child, LivingEntity mother, LivingEntity father, LivingEntity breeder, ItemStack bredWith, int experience) {
+ super(child);
+
+ Validate.notNull(child, "Cannot have null child");
+ Validate.notNull(mother, "Cannot have null mother");
+ Validate.notNull(father, "Cannot have null father");
+
+ // Breeder can be null in the case of spontaneous conception
+ this.mother = mother;
+ this.father = father;
+ this.breeder = breeder;
+ this.bredWith = bredWith;
+
+ setExperience(experience);
+ }
+
+ @Override
+ public LivingEntity getEntity() {
+ return (LivingEntity) entity;
+ }
+
+ /**
+ * Gets the parent creating this entity.
+ *
+ * @return The "birth" parent
+ */
+ public LivingEntity getMother() {
+ return mother;
+ }
+
+ /**
+ * Gets the other parent of the newly born entity.
+ *
+ * @return the other parent
+ */
+ public LivingEntity getFather() {
+ return father;
+ }
+
+ /**
+ * Gets the Entity responsible for breeding. Breeder is null for spontaneous
+ * conception.
+ *
+ * @return The Entity who initiated breeding.
+ */
+ public LivingEntity getBreeder() {
+ return breeder;
+ }
+
+ /**
+ * The ItemStack that was used to initiate breeding, if present.
+ *
+ * @return ItemStack used to initiate breeding.
+ */
+ public ItemStack getBredWith() {
+ return bredWith;
+ }
+
+ /**
+ * Get the amount of experience granted by breeding.
+ *
+ * @return experience amount
+ */
+ public int getExperience() {
+ return experience;
+ }
+
+ /**
+ * Set the amount of experience granted by breeding.
+ *
+ * @param experience experience amount
+ */
+ public void setExperience(int experience) {
+ Validate.isTrue(experience >= 0, "Experience cannot be negative");
+ this.experience = experience;
+ }
+
+ @Override
+ public boolean isCancelled() {
+ return cancel;
+ }
+
+ @Override
+ public void setCancelled(boolean cancel) {
+ this.cancel = cancel;
+ }
+
+ @Override
+ public HandlerList getHandlers() {
+ return handlers;
+ }
+
+ public static HandlerList getHandlerList() {
+ return handlers;
+ }
+}