Add FakeEntityTameEvent to match expected behavior for an animal being tamed.

This commit is contained in:
GJ 2014-02-28 12:04:00 -05:00
parent 47db522cc1
commit ce59488e8e
3 changed files with 28 additions and 0 deletions

View File

@ -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);
}
}

View File

@ -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();

View File

@ -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);