Added tameable watcher

This commit is contained in:
libraryaddict 2014-05-23 16:40:22 +12:00
parent f3a81a84a4
commit 9e4ad0ba8e
4 changed files with 69 additions and 92 deletions

View File

@ -14,6 +14,7 @@ import me.libraryaddict.disguise.disguisetypes.watchers.HorseWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.MinecartWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.SlimeWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.TameableWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher;
import me.libraryaddict.disguise.utilities.DisguiseSound;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
@ -30,6 +31,7 @@ import org.bukkit.entity.Ageable;
import org.bukkit.entity.Damageable;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Tameable;
import org.bukkit.entity.Zombie;
import org.bukkit.plugin.java.JavaPlugin;
@ -171,7 +173,9 @@ public class LibsDisguises extends JavaPlugin {
} catch (ClassNotFoundException ex) {
// There is no explicit watcher for this entity.
Class entityClass = disguiseType.getEntityType().getEntityClass();
if (Ageable.class.isAssignableFrom(entityClass)) {
if (Tameable.class.isAssignableFrom(entityClass)) {
watcherClass = TameableWatcher.class;
} else if (Ageable.class.isAssignableFrom(entityClass)) {
watcherClass = AgeableWatcher.class;
} else if (LivingEntity.class.isAssignableFrom(entityClass)) {
watcherClass = LivingWatcher.class;

View File

@ -5,55 +5,16 @@ import me.libraryaddict.disguise.disguisetypes.Disguise;
import org.bukkit.entity.Ocelot;
import org.bukkit.entity.Ocelot.Type;
public class OcelotWatcher extends AgeableWatcher {
public class OcelotWatcher extends TameableWatcher {
public OcelotWatcher(Disguise disguise) {
super(disguise);
}
public String getOwner() {
return (String) getValue(17, "");
}
public Type getType() {
return Ocelot.Type.getType((Byte) getValue(18, (byte) 0));
}
public boolean isSitting() {
return isTrue(1);
}
public boolean isTamed() {
return isTrue(4);
}
private boolean isTrue(int no) {
return ((Byte) getValue(16, (byte) 0) & no) != 0;
}
private void setFlag(int no, boolean flag) {
byte b0 = (Byte) getValue(16, (byte) 0);
if (flag) {
setValue(16, (byte) (b0 | no));
} else {
setValue(16, (byte) (b0 & -(no + 1)));
}
sendData(16);
}
public void setOwner(String newOwner) {
setValue(17, newOwner);
sendData(17);
}
public void setSitting(boolean sitting) {
setFlag(1, sitting);
}
public void setTamed(boolean tamed) {
setFlag(4, tamed);
}
public void setType(Type newType) {
setValue(18, (byte) newType.getId());
sendData(18);

View File

@ -0,0 +1,62 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
public class TameableWatcher extends AgeableWatcher {
public TameableWatcher(Disguise disguise) {
super(disguise);
}
@Override
public float getHealth() {
return (Float) getValue(18, 8F);
}
public String getOwner() {
return (String) getValue(17, "");
}
public boolean isSitting() {
return isTrue(1);
}
public boolean isTamed() {
return isTrue(4);
}
protected boolean isTrue(int no) {
return ((Byte) getValue(16, (byte) 0) & no) != 0;
}
protected void setFlag(int no, boolean flag) {
byte b0 = (Byte) getValue(16, (byte) 0);
if (flag) {
setValue(16, (byte) (b0 | no));
} else {
setValue(16, (byte) (b0 & -(no + 1)));
}
sendData(16);
}
@Override
public void setHealth(float newHealth) {
setValue(18, newHealth);
sendData(18);
super.setHealth(newHealth);
}
public void setOwner(String owner) {
setValue(17, owner);
sendData(17);
}
public void setSitting(boolean sitting) {
setFlag(1, sitting);
}
public void setTamed(boolean tamed) {
setFlag(4, tamed);
}
}

View File

@ -3,7 +3,7 @@ package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.AnimalColor;
import me.libraryaddict.disguise.disguisetypes.Disguise;
public class WolfWatcher extends AgeableWatcher {
public class WolfWatcher extends TameableWatcher {
public WolfWatcher(Disguise disguise) {
super(disguise);
@ -13,31 +13,10 @@ public class WolfWatcher extends AgeableWatcher {
return AnimalColor.values()[(Byte) getValue(20, (byte) 14)];
}
@Override
public float getHealth() {
return (Float) getValue(18, 8F);
}
public String getOwner() {
return (String) getValue(17, "");
}
public boolean isAngry() {
return isTrue(2);
}
public boolean isSitting() {
return isTrue(1);
}
public boolean isTamed() {
return isTrue(4);
}
private boolean isTrue(int no) {
return ((Byte) getValue(16, (byte) 0) & no) != 0;
}
public void setAngry(boolean angry) {
setFlag(2, angry);
}
@ -52,33 +31,4 @@ public class WolfWatcher extends AgeableWatcher {
}
}
private void setFlag(int no, boolean flag) {
byte b0 = (Byte) getValue(16, (byte) 0);
if (flag) {
setValue(16, (byte) (b0 | no));
} else {
setValue(16, (byte) (b0 & -(no + 1)));
}
sendData(16);
}
@Override
public void setHealth(float newHealth) {
setValue(18, newHealth);
sendData(18);
}
public void setOwner(String owner) {
setValue(17, owner);
sendData(17);
}
public void setSitting(boolean sitting) {
setFlag(1, sitting);
}
public void setTamed(boolean tamed) {
setFlag(4, tamed);
}
}