From d1fb662ec53c4fd8bc718039b76a3e9a11346371 Mon Sep 17 00:00:00 2001 From: DiamondDagger590 Date: Fri, 26 Jun 2020 11:12:25 +1000 Subject: [PATCH] SPIGOT-5735: Add EntityEnterLoveModeEvent --- nms-patches/EntityAnimal.patch | 32 +++++++++++++++---- .../craftbukkit/event/CraftEventFactory.java | 12 +++++++ 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/nms-patches/EntityAnimal.patch b/nms-patches/EntityAnimal.patch index fbf81b386f..0285870160 100644 --- a/nms-patches/EntityAnimal.patch +++ b/nms-patches/EntityAnimal.patch @@ -1,6 +1,15 @@ --- a/net/minecraft/server/EntityAnimal.java +++ b/net/minecraft/server/EntityAnimal.java -@@ -8,6 +8,7 @@ +@@ -3,11 +3,16 @@ + import java.util.Random; + import java.util.UUID; + import javax.annotation.Nullable; ++// CraftBukkit start ++import org.bukkit.craftbukkit.event.CraftEventFactory; ++import org.bukkit.event.entity.EntityEnterLoveModeEvent; ++// CraftBukkit end + + public abstract class EntityAnimal extends EntityAgeable { public int loveTicks; public UUID breedCause; @@ -8,7 +17,7 @@ protected EntityAnimal(EntityTypes entitytypes, World world) { super(entitytypes, world); -@@ -44,6 +45,9 @@ +@@ -44,6 +49,9 @@ } @@ -18,7 +27,7 @@ @Override public boolean damageEntity(DamageSource damagesource, float f) { if (this.isInvulnerable(damagesource)) { -@@ -53,6 +57,7 @@ +@@ -53,6 +61,7 @@ return super.damageEntity(damagesource, f); } } @@ -26,7 +35,18 @@ @Override public float a(BlockPosition blockposition, IWorldReader iworldreader) { -@@ -147,6 +152,7 @@ +@@ -143,10 +152,17 @@ + } + + public void g(@Nullable EntityHuman entityhuman) { +- this.loveTicks = 600; ++ // CraftBukkit start ++ EntityEnterLoveModeEvent entityEnterLoveModeEvent = CraftEventFactory.callEntityEnterLoveModeEvent(entityhuman, this, 600); ++ if (entityEnterLoveModeEvent.isCancelled()) { ++ return; ++ } ++ this.loveTicks = entityEnterLoveModeEvent.getTicksInLove(); ++ // CraftBukkit end if (entityhuman != null) { this.breedCause = entityhuman.getUniqueID(); } @@ -34,7 +54,7 @@ this.world.broadcastEntityEffect(this, (byte) 18); } -@@ -186,11 +192,24 @@ +@@ -186,11 +202,24 @@ EntityAgeable entityageable = this.createChild(entityanimal); if (entityageable != null) { @@ -59,7 +79,7 @@ if (entityplayer != null) { entityplayer.a(StatisticList.ANIMALS_BRED); -@@ -203,10 +222,14 @@ +@@ -203,10 +232,14 @@ entityanimal.resetLove(); entityageable.a(true); entityageable.setPositionRotation(this.locX(), this.locY(), this.locZ(), 0.0F, 0.0F); diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index e6970cbd22..62111e83d7 100644 --- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -97,12 +97,14 @@ import org.bukkit.craftbukkit.util.CraftDamageSource; import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.entity.AbstractHorse; +import org.bukkit.entity.Animals; import org.bukkit.entity.AreaEffectCloud; import org.bukkit.entity.Bat; import org.bukkit.entity.Creeper; import org.bukkit.entity.EntityType; import org.bukkit.entity.ExperienceOrb; import org.bukkit.entity.Firework; +import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Item; import org.bukkit.entity.LightningStrike; import org.bukkit.entity.LivingEntity; @@ -151,6 +153,7 @@ import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.entity.EntityDamageEvent.DamageModifier; import org.bukkit.event.entity.EntityDeathEvent; +import org.bukkit.event.entity.EntityEnterLoveModeEvent; import org.bukkit.event.entity.EntityPickupItemEvent; import org.bukkit.event.entity.EntityPlaceEvent; import org.bukkit.event.entity.EntityPortalEvent; @@ -272,6 +275,15 @@ public class CraftEventFactory { return nmsBedResult; } + /** + * Entity Enter Love Mode Event + */ + public static EntityEnterLoveModeEvent callEntityEnterLoveModeEvent(EntityHuman entityHuman, EntityAnimal entityAnimal, int loveTicks) { + EntityEnterLoveModeEvent entityEnterLoveModeEvent = new EntityEnterLoveModeEvent((Animals) entityAnimal.getBukkitEntity(), entityHuman != null ? (HumanEntity) entityHuman.getBukkitEntity() : null, loveTicks); + Bukkit.getPluginManager().callEvent(entityEnterLoveModeEvent); + return entityEnterLoveModeEvent; + } + /** * Trade Index Change Event */