From c2fdb3c201705f1930aba54f9b0d4a34d136a693 Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 1 Aug 2013 21:19:50 +1200 Subject: [PATCH] Removed sanity checks and idiot checks --- .../disguise/DisguiseTypes/FlagWatcher.java | 77 ++++++++++--------- .../Watchers/AgeableWatcher.java | 6 +- .../DisguiseTypes/Watchers/ArrowWatcher.java | 1 + .../DisguiseTypes/Watchers/BatWatcher.java | 6 +- .../DisguiseTypes/Watchers/BoatWatcher.java | 12 +-- .../Watchers/CreeperWatcher.java | 4 - .../Watchers/EndermanWatcher.java | 16 ++-- .../DisguiseTypes/Watchers/GhastWatcher.java | 6 +- .../DisguiseTypes/Watchers/HorseWatcher.java | 14 ++-- .../Watchers/ItemFrameWatcher.java | 1 + .../DisguiseTypes/Watchers/LivingWatcher.java | 22 ++---- .../Watchers/MinecartWatcher.java | 5 +- .../DisguiseTypes/Watchers/OcelotWatcher.java | 9 ++- .../DisguiseTypes/Watchers/PigWatcher.java | 6 +- .../DisguiseTypes/Watchers/PlayerWatcher.java | 6 +- .../DisguiseTypes/Watchers/SheepWatcher.java | 22 +++--- .../Watchers/VillagerWatcher.java | 6 +- .../DisguiseTypes/Watchers/WolfWatcher.java | 14 ++-- .../DisguiseTypes/Watchers/ZombieWatcher.java | 12 +-- 19 files changed, 104 insertions(+), 141 deletions(-) diff --git a/src/me/libraryaddict/disguise/DisguiseTypes/FlagWatcher.java b/src/me/libraryaddict/disguise/DisguiseTypes/FlagWatcher.java index 2e214b5e..41f10c3b 100644 --- a/src/me/libraryaddict/disguise/DisguiseTypes/FlagWatcher.java +++ b/src/me/libraryaddict/disguise/DisguiseTypes/FlagWatcher.java @@ -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,30 +185,33 @@ 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); - sendData(0); + 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); - sendData(0); - } + setFlag(0, 5, setInvis); + sendData(0); } public void setItemStack(int slot, org.bukkit.inventory.ItemStack itemStack) { @@ -248,31 +259,23 @@ public class FlagWatcher { } public void setRiding(boolean setRiding) { - if (isSprinting() != setRiding) { - setFlag(0, 2, true); - sendData(0); - } + setFlag(0, 2, setRiding); + sendData(0); } public void setRightClicking(boolean setRightClicking) { - if (isRightClicking() != setRightClicking) { - setFlag(0, 4, true); - sendData(0); - } + setFlag(0, 4, setRightClicking); + sendData(0); } public void setSneaking(boolean setSneaking) { - if (isSneaking() != setSneaking) { - setFlag(0, 1, true); - sendData(0); - } + setFlag(0, 1, setSneaking); + sendData(0); } public void setSprinting(boolean setSprinting) { - if (isSprinting() != setSprinting) { - setFlag(0, 3, true); - sendData(0); - } + setFlag(0, 3, setSprinting); + sendData(0); } protected void setValue(int no, Object value) { diff --git a/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/AgeableWatcher.java b/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/AgeableWatcher.java index ac5f000a..ff95c8b3 100644 --- a/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/AgeableWatcher.java +++ b/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/AgeableWatcher.java @@ -13,10 +13,8 @@ public class AgeableWatcher extends LivingWatcher { } public void setAdult(boolean isAdult) { - if (isAdult != isAdult()) { - setValue(12, isAdult ? 0 : -24000); - sendData(12); - } + setValue(12, isAdult ? 0 : -24000); + sendData(12); } } diff --git a/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/ArrowWatcher.java b/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/ArrowWatcher.java index 68cc84fc..9f5cb829 100644 --- a/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/ArrowWatcher.java +++ b/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/ArrowWatcher.java @@ -16,6 +16,7 @@ public class ArrowWatcher extends FlagWatcher { public void setMoving(boolean moving) { setValue(16, (byte) (moving ? 1 : 0)); + sendData(16); } } diff --git a/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/BatWatcher.java b/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/BatWatcher.java index ab2ab469..5c9f2453 100644 --- a/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/BatWatcher.java +++ b/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/BatWatcher.java @@ -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); - } + setValue(16, (byte) (flying ? 0 : 1)); + sendData(16); } } diff --git a/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/BoatWatcher.java b/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/BoatWatcher.java index b0884ccc..66e67651 100644 --- a/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/BoatWatcher.java +++ b/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/BoatWatcher.java @@ -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); - } + setValue(19, dmg); + sendData(19); } public void setHealth(int health) { - if ((Integer) getValue(17, 10) != health) { - setValue(17, health); - sendData(17); - } + setValue(17, health); + sendData(17); } } diff --git a/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/CreeperWatcher.java b/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/CreeperWatcher.java index fe6b73dd..0d0f952a 100644 --- a/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/CreeperWatcher.java +++ b/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/CreeperWatcher.java @@ -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); } diff --git a/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/EndermanWatcher.java b/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/EndermanWatcher.java index c0e2ebd1..367fa912 100644 --- a/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/EndermanWatcher.java +++ b/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/EndermanWatcher.java @@ -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); - } + 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); - } + setValue(16, (byte) (id & 255)); + setValue(17, (byte) (dataValue & 255)); + sendData(16); + sendData(17); } } diff --git a/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/GhastWatcher.java b/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/GhastWatcher.java index 8e8e3874..9ce282a0 100644 --- a/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/GhastWatcher.java +++ b/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/GhastWatcher.java @@ -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); - } + setValue(16, (byte) (isAgressive ? 1 : 0)); + sendData(16); } } diff --git a/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/HorseWatcher.java b/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/HorseWatcher.java index 0d851bd1..cca76296 100644 --- a/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/HorseWatcher.java +++ b/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/HorseWatcher.java @@ -68,15 +68,13 @@ 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); - } else { - setValue(16, j & ~i); - } - sendData(16); + int j = (Integer) getValue(16, (byte) 0); + if (flag) { + setValue(16, j | i); + } else { + setValue(16, j & ~i); } + sendData(16); } public void setGrazing(boolean grazing) { diff --git a/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/ItemFrameWatcher.java b/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/ItemFrameWatcher.java index 43f54240..eafedbcf 100644 --- a/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/ItemFrameWatcher.java +++ b/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/ItemFrameWatcher.java @@ -24,6 +24,7 @@ public class ItemFrameWatcher extends FlagWatcher { else { setValue(3, CraftItemStack.asCraftCopy(newItem)); } + sendData(3); } } diff --git a/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/LivingWatcher.java b/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/LivingWatcher.java index d3691dfd..246b0887 100644 --- a/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/LivingWatcher.java +++ b/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/LivingWatcher.java @@ -71,10 +71,8 @@ public class LivingWatcher extends FlagWatcher { } public void removePotionParticles(boolean particles) { - if (particles != getPotionParticlesRemoved()) { - setValue(8, (byte) (particles ? 1 : 0)); - sendData(8); - } + setValue(8, (byte) (particles ? 1 : 0)); + sendData(8); } private void sendPotionEffects() { @@ -83,19 +81,15 @@ 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); - } + 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); - } + setValue(11, (byte) (display ? 1 : 0)); + sendData(11); } public void setHealth(float health) { diff --git a/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/MinecartWatcher.java b/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/MinecartWatcher.java index 44671be5..c8253cf7 100644 --- a/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/MinecartWatcher.java +++ b/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/MinecartWatcher.java @@ -10,13 +10,12 @@ public class MinecartWatcher extends FlagWatcher { } public float getDamage() { - if (getValue(19, 0F) != null) - return (Float) getValue(19, 0F); - return 0F; + return (Float) getValue(19, 0F); } public void setDamage(float damage) { setValue(19, damage); + sendData(19); } } diff --git a/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/OcelotWatcher.java b/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/OcelotWatcher.java index 779ed7e8..deb68f8a 100644 --- a/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/OcelotWatcher.java +++ b/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/OcelotWatcher.java @@ -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); - } + setValue(18, (byte) newType.getId()); + sendData(18); } } diff --git a/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/PigWatcher.java b/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/PigWatcher.java index 4f6b31bb..480db10c 100644 --- a/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/PigWatcher.java +++ b/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/PigWatcher.java @@ -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); - } + setValue(16, (byte) (isSaddled ? 1 : 0)); + sendData(16); } } diff --git a/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/PlayerWatcher.java b/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/PlayerWatcher.java index caa39565..0be8718d 100644 --- a/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/PlayerWatcher.java +++ b/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/PlayerWatcher.java @@ -13,10 +13,8 @@ public class PlayerWatcher extends LivingWatcher { } public void setArrowsSticking(int arrowsNo) { - if (arrowsNo != getArrowsSticking()) { - setValue(9, (byte) arrowsNo); - sendData(9); - } + setValue(9, (byte) arrowsNo); + sendData(9); } } diff --git a/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/SheepWatcher.java b/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/SheepWatcher.java index 7487c8cf..d50b5277 100644 --- a/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/SheepWatcher.java +++ b/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/SheepWatcher.java @@ -19,22 +19,18 @@ 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); - } + 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)); - } else { - setValue(16, (byte) (b0 & -17)); - } - sendData(16); + byte b0 = (Byte) getValue(16, (byte) 0); + if (flag) { + setValue(16, (byte) (b0 | 16)); + } else { + setValue(16, (byte) (b0 & -17)); } + sendData(16); } } diff --git a/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/VillagerWatcher.java b/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/VillagerWatcher.java index 9a57def9..894f5ead 100644 --- a/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/VillagerWatcher.java +++ b/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/VillagerWatcher.java @@ -18,10 +18,8 @@ public class VillagerWatcher extends AgeableWatcher { } public void setProfession(Profession newProfession) { - if (getProfession() != newProfession) { - setValue(16, newProfession.getId()); - sendData(16); - } + setValue(16, newProfession.getId()); + sendData(16); } } diff --git a/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/WolfWatcher.java b/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/WolfWatcher.java index 8c0580c7..6c4167bb 100644 --- a/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/WolfWatcher.java +++ b/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/WolfWatcher.java @@ -49,15 +49,13 @@ 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))); - } else { - setValue(16, (byte) (b0 & -(no + 1))); - } - sendData(16); + 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 setHealth(float newHealth) { diff --git a/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/ZombieWatcher.java b/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/ZombieWatcher.java index 35279355..7729d497 100644 --- a/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/ZombieWatcher.java +++ b/src/me/libraryaddict/disguise/DisguiseTypes/Watchers/ZombieWatcher.java @@ -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); - } + setValue(12, (byte) (adult ? 0 : 1)); + sendData(12); } public void setVillager(boolean villager) { - if (isVillager() != villager) { - setValue(13, (byte) (villager ? 1 : 0)); - sendData(13); - } + setValue(13, (byte) (villager ? 1 : 0)); + sendData(13); } }