Removed sanity checks and idiot checks

This commit is contained in:
Andrew 2013-08-01 21:19:50 +12:00
parent cf2cc926ae
commit c2fdb3c201
19 changed files with 104 additions and 141 deletions

View File

@ -108,10 +108,22 @@ public class FlagWatcher {
return entityValues.equals(flagWatcher.entityValues);
}
public org.bukkit.inventory.ItemStack[] getArmor() {
org.bukkit.inventory.ItemStack[] armor = new org.bukkit.inventory.ItemStack[4];
for (int i = 0; i < 4; i++) {
armor[i] = items[i];
}
return armor;
}
private boolean getFlag(int i) {
return ((Byte) getValue(0, (byte) 0) & 1 << i) != 0;
}
public org.bukkit.inventory.ItemStack getHeldItem() {
return getItemStack(SlotType.HELD_ITEM);
}
public org.bukkit.inventory.ItemStack getItemStack(int slot) {
return items[slot];
}
@ -150,10 +162,6 @@ public class FlagWatcher {
return getFlag(3);
}
protected boolean isTrue(int id, int no) {
return ((Byte) getValue(id, (byte) 0) & no) != 0;
}
protected void sendData(int data) {
if (disguise.getWatcher() == null || !DisguiseAPI.isDisguised(disguise.getEntity()))
return;
@ -177,31 +185,34 @@ public class FlagWatcher {
}
}
public void setArmor(org.bukkit.inventory.ItemStack[] itemstack) {
for (int i = 0; i < itemstack.length; i++)
setItemStack(i, itemstack[i]);
}
public void setBurning(boolean setBurning) {
if (isSneaking() != setBurning) {
setFlag(0, 0, true);
setFlag(0, 0, setBurning);
sendData(0);
}
protected void setFlag(int no, int i, boolean flag) {
byte b0 = (Byte) getValue(no, (byte) 0);
if (flag) {
setValue(no, (byte) (b0 | 1 << i));
} else {
setValue(no, (byte) (b0 & ~(1 << i)));
}
}
protected void setFlag(int id, int no, boolean flag) {
if (isTrue(id, no) != flag) {
byte b0 = (Byte) getValue(id, (byte) 0);
if (flag) {
setValue(id, (byte) (b0 | (no)));
} else {
setValue(id, (byte) (b0 & -(no + 1)));
}
sendData(id);
}
public void setHeldItem(org.bukkit.inventory.ItemStack itemstack) {
setItemStack(SlotType.HELD_ITEM, itemstack);
}
public void setInvisible(boolean setInvis) {
if (isInvisible() != setInvis) {
setFlag(0, 5, true);
setFlag(0, 5, setInvis);
sendData(0);
}
}
public void setItemStack(int slot, org.bukkit.inventory.ItemStack itemStack) {
// Itemstack which is null means that its not replacing the disguises itemstack.
@ -248,32 +259,24 @@ public class FlagWatcher {
}
public void setRiding(boolean setRiding) {
if (isSprinting() != setRiding) {
setFlag(0, 2, true);
setFlag(0, 2, setRiding);
sendData(0);
}
}
public void setRightClicking(boolean setRightClicking) {
if (isRightClicking() != setRightClicking) {
setFlag(0, 4, true);
setFlag(0, 4, setRightClicking);
sendData(0);
}
}
public void setSneaking(boolean setSneaking) {
if (isSneaking() != setSneaking) {
setFlag(0, 1, true);
setFlag(0, 1, setSneaking);
sendData(0);
}
}
public void setSprinting(boolean setSprinting) {
if (isSprinting() != setSprinting) {
setFlag(0, 3, true);
setFlag(0, 3, setSprinting);
sendData(0);
}
}
protected void setValue(int no, Object value) {
entityValues.put(no, value);

View File

@ -13,10 +13,8 @@ public class AgeableWatcher extends LivingWatcher {
}
public void setAdult(boolean isAdult) {
if (isAdult != isAdult()) {
setValue(12, isAdult ? 0 : -24000);
sendData(12);
}
}
}

View File

@ -16,6 +16,7 @@ public class ArrowWatcher extends FlagWatcher {
public void setMoving(boolean moving) {
setValue(16, (byte) (moving ? 1 : 0));
sendData(16);
}
}

View File

@ -14,9 +14,7 @@ public class BatWatcher extends LivingWatcher {
}
public void setFlying(boolean flying) {
if (isFlying() != flying) {
setValue(16, (byte) (flying ? 0 : 1));
sendData(16);
}
}
}

View File

@ -18,17 +18,13 @@ public class BoatWatcher extends FlagWatcher {
}
public void setDamage(float dmg) {
if ((Float) getValue(19, 40F) != dmg) {
setValue(19, dmg);
sendData(19);
}
}
public void setHealth(int health) {
if ((Integer) getValue(17, 10) != health) {
setValue(17, health);
sendData(17);
}
}
}

View File

@ -17,15 +17,11 @@ public class CreeperWatcher extends LivingWatcher {
}
public void setFuse(boolean isFused) {
if (isFused == isFused())
return;
setValue(16, (byte) (isFused ? 1 : -1));
sendData(16);
}
public void setPowered(boolean powered) {
if (powered == isPowered())
return;
setValue(17, (byte) (powered ? 1 : 0));
sendData(17);
}

View File

@ -21,19 +21,15 @@ public class EndermanWatcher extends LivingWatcher {
}
public void setAgressive(boolean isAgressive) {
if (isAgressive() != isAgressive()) {
setValue(18, (byte) (isAgressive ? 1 : 0));
sendData(18);
}
}
public void setCarriedItem(int id, int dataValue) {
if (getCarriedId() != id || getCarriedData() != dataValue) {
setValue(16, (byte) (id & 255));
setValue(17, (byte) (dataValue & 255));
sendData(16);
sendData(17);
}
}
}

View File

@ -13,10 +13,8 @@ public class GhastWatcher extends LivingWatcher {
}
public void setAgressive(boolean isAgressive) {
if (isAgressive() != isAgressive) {
setValue(16, (byte) (isAgressive ? 1 : 0));
sendData(16);
}
}
}

View File

@ -68,7 +68,6 @@ public class HorseWatcher extends AgeableWatcher {
}
private void setFlag(int i, boolean flag) {
if (isTrue(i) != flag) {
int j = (Integer) getValue(16, (byte) 0);
if (flag) {
setValue(16, j | i);
@ -77,7 +76,6 @@ public class HorseWatcher extends AgeableWatcher {
}
sendData(16);
}
}
public void setGrazing(boolean grazing) {
setFlag(32, grazing);

View File

@ -24,6 +24,7 @@ public class ItemFrameWatcher extends FlagWatcher {
else {
setValue(3, CraftItemStack.asCraftCopy(newItem));
}
sendData(3);
}
}

View File

@ -71,11 +71,9 @@ public class LivingWatcher extends FlagWatcher {
}
public void removePotionParticles(boolean particles) {
if (particles != getPotionParticlesRemoved()) {
setValue(8, (byte) (particles ? 1 : 0));
sendData(8);
}
}
private void sendPotionEffects() {
setValue(7, PotionBrewer.a(potionEffects));
@ -83,20 +81,16 @@ public class LivingWatcher extends FlagWatcher {
}
public void setCustomName(String name) {
if (!getCustomName().equals(name)) {
if (name.length() > 64)
name = name.substring(0, 64);
setValue(10, name);
sendData(10);
}
}
public void setCustomNameVisible(boolean display) {
if (isCustomNameVisible() != display) {
setValue(11, (byte) (display ? 1 : 0));
sendData(11);
}
}
public void setHealth(float health) {
setValue(6, health);

View File

@ -10,13 +10,12 @@ public class MinecartWatcher extends FlagWatcher {
}
public float getDamage() {
if (getValue(19, 0F) != null)
return (Float) getValue(19, 0F);
return 0F;
}
public void setDamage(float damage) {
setValue(19, damage);
sendData(19);
}
}

View File

@ -21,20 +21,21 @@ public class OcelotWatcher extends AgeableWatcher {
public void setOwner(String newOwner) {
setValue(17, newOwner);
sendData(17);
}
public void setSitting(boolean sitting) {
setFlag(16, 1, sitting);
sendData(16);
}
public void setTamed(boolean tamed) {
setFlag(16, 4, tamed);
sendData(16);
}
public void setType(Type newType) {
if (getType() != newType) {
setValue(18, (byte) newType.getId());
sendData(18);
}
}
}

View File

@ -13,9 +13,7 @@ public class PigWatcher extends AgeableWatcher {
}
public void setSaddled(boolean isSaddled) {
if (isSaddled() != isSaddled) {
setValue(16, (byte) (isSaddled ? 1 : 0));
sendData(16);
}
}
}

View File

@ -13,10 +13,8 @@ public class PlayerWatcher extends LivingWatcher {
}
public void setArrowsSticking(int arrowsNo) {
if (arrowsNo != getArrowsSticking()) {
setValue(9, (byte) arrowsNo);
sendData(9);
}
}
}

View File

@ -19,15 +19,12 @@ public class SheepWatcher extends AgeableWatcher {
}
public void setColor(AnimalColor color) {
if (getColor() != color) {
byte b0 = (Byte) getValue(16, (byte) 0);
setValue(16, (byte) (b0 & 240 | color.getId() & 15));
sendData(16);
}
}
public void setSheared(boolean flag) {
if (isSheared() != flag) {
byte b0 = (Byte) getValue(16, (byte) 0);
if (flag) {
setValue(16, (byte) (b0 | 16));
@ -37,4 +34,3 @@ public class SheepWatcher extends AgeableWatcher {
sendData(16);
}
}
}

View File

@ -18,10 +18,8 @@ public class VillagerWatcher extends AgeableWatcher {
}
public void setProfession(Profession newProfession) {
if (getProfession() != newProfession) {
setValue(16, newProfession.getId());
sendData(16);
}
}
}

View File

@ -49,7 +49,6 @@ public class WolfWatcher extends AgeableWatcher {
}
private void setFlag(int no, boolean flag) {
if (isTrue(no) != flag) {
byte b0 = (Byte) getValue(16, (byte) 0);
if (flag) {
setValue(16, (byte) (b0 | (no)));
@ -58,7 +57,6 @@ public class WolfWatcher extends AgeableWatcher {
}
sendData(16);
}
}
public void setHealth(float newHealth) {
setValue(18, newHealth);

View File

@ -17,17 +17,13 @@ public class ZombieWatcher extends LivingWatcher {
}
public void setAdult(boolean adult) {
if (isAdult() != adult) {
setValue(12, (byte) (adult ? 0 : 1));
sendData(12);
}
}
public void setVillager(boolean villager) {
if (isVillager() != villager) {
setValue(13, (byte) (villager ? 1 : 0));
sendData(13);
}
}
}