From 538de63a033431352f5060fb5c72356c6c0d0a48 Mon Sep 17 00:00:00 2001 From: feildmaster Date: Fri, 28 Dec 2012 20:27:41 -0600 Subject: [PATCH] Fix persistence on tamed pets. Fixes BUKKIT-3300 With the persistence api introduced, pets did not have their persistence flag updated to reflect their persistence. This caused tame ocelots to not persist under specific conditions. --- src/main/java/net/minecraft/server/Entity.java | 7 ++++++- src/main/java/net/minecraft/server/EntityWolf.java | 3 ++- .../org/bukkit/craftbukkit/event/CraftEventFactory.java | 2 ++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java index 328041438d..381a6312d4 100644 --- a/src/main/java/net/minecraft/server/Entity.java +++ b/src/main/java/net/minecraft/server/Entity.java @@ -30,7 +30,7 @@ import org.bukkit.plugin.PluginManager; public abstract class Entity { // CraftBukkit start - private static final int CURRENT_LEVEL = 1; + private static final int CURRENT_LEVEL = 2; static boolean isLevelAtLeast(NBTTagCompound tag, int level) { return tag.hasKey("Bukkit.updateLevel") && tag.getInt("Bukkit.updateLevel") >= level; } @@ -1162,6 +1162,11 @@ public abstract class Entity { if (!nbttagcompound.hasKey("Bukkit.MaxHealth")) { entity.maxHealth = entity.getMaxHealth(); } + + // Reset the persistence for tamed animals + if (entity instanceof EntityTameableAnimal && !isLevelAtLeast(nbttagcompound, 2) && !nbttagcompound.getBoolean("PersistenceRequired")) { + entity.persistent = !entity.bj(); + } } // CraftBukkit end diff --git a/src/main/java/net/minecraft/server/EntityWolf.java b/src/main/java/net/minecraft/server/EntityWolf.java index 19de09e230..8ee3318087 100644 --- a/src/main/java/net/minecraft/server/EntityWolf.java +++ b/src/main/java/net/minecraft/server/EntityWolf.java @@ -76,7 +76,8 @@ public class EntityWolf extends EntityTameableAnimal { } protected boolean bj() { - return this.isAngry(); + // CraftBukkit - added && !this.isTamed() + return this.isAngry() && !this.isTamed(); } protected String aY() { diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index 9850ac7e2b..a62adcd2c1 100644 --- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -236,6 +236,8 @@ public class CraftEventFactory { org.bukkit.entity.AnimalTamer bukkitTamer = (tamer != null ? (AnimalTamer) tamer.getBukkitEntity() : null); CraftServer craftServer = (CraftServer) bukkitEntity.getServer(); + entity.persistent = true; + EntityTameEvent event = new EntityTameEvent((LivingEntity) bukkitEntity, bukkitTamer); craftServer.getPluginManager().callEvent(event); return event;