Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
at develop 114 lines 3.9 kB view raw
1package org.bukkit.craftbukkit.entity; 2 3import net.minecraft.server.EntityWolf; 4import net.minecraft.server.PathEntity; 5import org.bukkit.craftbukkit.CraftServer; 6import org.bukkit.entity.AnimalTamer; 7import org.bukkit.entity.Player; 8import org.bukkit.entity.Wolf; 9 10public class CraftWolf extends CraftAnimals implements Wolf { 11 private AnimalTamer owner; 12 13 public CraftWolf(CraftServer server, EntityWolf wolf) { 14 super(server, wolf); 15 } 16 17 public boolean isAngry() { 18 return getHandle().isAngry(); 19 } 20 21 public void setAngry(boolean angry) { 22 getHandle().setAngry(angry); 23 } 24 25 public boolean isSitting() { 26 return getHandle().isSitting(); 27 } 28 29 public void setSitting(boolean sitting) { 30 getHandle().setSitting(sitting); 31 // TODO determine what the following would do - it is affected every time a player makes their wolf sit or stand 32 // getHandle().ay = false; 33 setPath((PathEntity) null); 34 } 35 36 public boolean isTamed() { 37 return getHandle().isTamed(); 38 } 39 40 public void setTamed(boolean tame) { 41 getHandle().setTamed(tame); 42 } 43 44 public AnimalTamer getOwner() { 45 // If the wolf has a previously set owner use that, otherwise try and find the player who owns it 46 if (owner == null) { 47 // TODO try and recover owner from persistence store before defaulting to playername 48 owner = getServer().getPlayer(getOwnerName()); 49 } 50 return owner; 51 } 52 53 public void setOwner(AnimalTamer tamer) { 54 owner = tamer; 55 if (owner != null) { 56 setTamed(true); /* Make him tame */ 57 setPath((PathEntity) null); /* Clear path */ 58 /* Set owner */ 59 // TODO persist owner to the persistence store 60 if (owner instanceof Player) { 61 setOwnerName(((Player) owner).getName()); 62 } else { 63 setOwnerName(""); 64 } 65 } else { 66 setTamed(false); /* Make him not tame */ 67 setOwnerName(""); /* Clear owner */ 68 } 69 } 70 71 /** 72 * The owner's name is how MC knows and persists the Wolf's owner. Since we choose to instead use an AnimalTamer, this functionality 73 * is used only as a backup. If the animal tamer is a player, we will store their name, otherwise we store an empty string. 74 * 75 * @return the owner's name, if they are a player; otherwise, the empty string or null. 76 */ 77 String getOwnerName() { 78 return getHandle().getOwnerName(); 79 } 80 81 void setOwnerName(String ownerName) { 82 getHandle().setOwnerName(ownerName); 83 } 84 85 /** 86 * Only used internally at the moment, and there to set the path to null (that is stop the thing from running around) 87 * TODO use this later to extend the API, when we have Path classes in Bukkit 88 * 89 * @param pathentity currently the MC defined PathEntity class. Should be replaced with an API interface at some point. 90 */ 91 private void setPath(PathEntity pathentity) { 92 getHandle().setPathEntity(pathentity); 93 } 94 95 /* 96 * This method requires a(boolean) to be made visible. It will allow for hearts to be animated on a successful taming. 97 * TODO add this to the API, and make it visible 98 private void playTamingAnimation(boolean successful){ 99 getHandle().a(successful); 100 } 101 */ 102 103 @Override 104 public EntityWolf getHandle() { 105 // It's somewhat easier to override this here, as many internal methods rely on EntityWolf specific methods. 106 // Doing this has no impact on anything outside this class. 107 return (EntityWolf) entity; 108 } 109 110 @Override 111 public String toString() { 112 return "CraftWolf[anger=" + isAngry() + ",owner=" + getOwner() + ",tame=" + isTamed() + ",sitting=" + isSitting() + "]"; 113 } 114}