diff --git a/src/main/java/com/gmail/nossr50/events/fake/FakeEntityTameEvent.java b/src/main/java/com/gmail/nossr50/events/fake/FakeEntityTameEvent.java new file mode 100644 index 000000000..2f9cad620 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/events/fake/FakeEntityTameEvent.java @@ -0,0 +1,14 @@ +package com.gmail.nossr50.events.fake; + +import org.bukkit.entity.AnimalTamer; +import org.bukkit.entity.LivingEntity; +import org.bukkit.event.entity.EntityTameEvent; + +/** + * Called when mcMMO tames an animal via Call of the Wild + */ +public class FakeEntityTameEvent extends EntityTameEvent { + public FakeEntityTameEvent(LivingEntity entity, AnimalTamer owner) { + super (entity, owner); + } +} diff --git a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java index 15fe46c6c..485b07f8d 100644 --- a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java @@ -1,5 +1,6 @@ package com.gmail.nossr50.listeners; +import com.gmail.nossr50.events.fake.FakeEntityTameEvent; import org.bukkit.OfflinePlayer; import org.bukkit.block.Block; import org.bukkit.enchantments.Enchantment; @@ -566,6 +567,10 @@ public class EntityListener implements Listener { */ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onEntityTame(EntityTameEvent event) { + if (event instanceof FakeEntityTameEvent) { + return; + } + Player player = (Player) event.getOwner(); LivingEntity entity = event.getEntity(); diff --git a/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java b/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java index db1fe031a..863ed12cc 100644 --- a/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java +++ b/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java @@ -1,5 +1,6 @@ package com.gmail.nossr50.skills.taming; +import com.gmail.nossr50.events.fake.FakeEntityTameEvent; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.Horse; @@ -225,6 +226,14 @@ public class TamingManager extends SkillManager { for (int i = 0; i < amount; i++) { LivingEntity entity = (LivingEntity) player.getWorld().spawnEntity(player.getLocation(), type); + + FakeEntityTameEvent event = new FakeEntityTameEvent(entity, player); + mcMMO.p.getServer().getPluginManager().callEvent(event); + + if (event.isCancelled()) { + continue; + } + entity.setMetadata(mcMMO.entityMetadataKey, mcMMO.metadataValue); ((Tameable) entity).setOwner(player); entity.setRemoveWhenFarAway(false);