From e751cf4582a0d532dfdf73631e4d7ad68fc9a092 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Mon, 13 Jun 2016 02:22:56 +1200 Subject: [PATCH] Current work --- pom.xml | 4 +- .../libraryaddict/disguise/LibsDisguises.java | 14 +- .../disguise/disguisetypes/Disguise.java | 130 +-------- .../disguise/disguisetypes/DisguiseType.java | 2 +- .../disguise/disguisetypes/FlagType.java | 260 ++++++++++++++++++ .../disguise/disguisetypes/FlagWatcher.java | 242 ++++++++-------- .../disguise/disguisetypes/RabbitType.java | 1 - .../watchers/AgeableWatcher.java | 7 +- .../watchers/AreaEffectCloudWatcher.java | 48 ++-- .../watchers/ArmorStandWatcher.java | 21 +- .../disguisetypes/watchers/ArrowWatcher.java | 19 +- .../disguisetypes/watchers/BatWatcher.java | 20 +- .../disguisetypes/watchers/BlazeWatcher.java | 7 +- .../disguisetypes/watchers/BoatWatcher.java | 7 +- .../watchers/CreeperWatcher.java | 31 ++- .../watchers/DroppedItemWatcher.java | 20 +- .../watchers/EnderCrystalWatcher.java | 13 +- .../watchers/EnderDragonWatcher.java | 19 +- .../watchers/EndermanWatcher.java | 45 ++- .../watchers/FallingBlockWatcher.java | 25 +- .../disguisetypes/watchers/GhastWatcher.java | 19 +- .../watchers/GuardianWatcher.java | 77 ++++-- .../disguisetypes/watchers/HorseWatcher.java | 56 ++-- .../watchers/InsentientWatcher.java | 63 +++++ .../watchers/ItemFrameWatcher.java | 45 +-- .../disguisetypes/watchers/LivingWatcher.java | 25 +- .../watchers/MinecartWatcher.java | 26 +- .../disguisetypes/watchers/OcelotWatcher.java | 19 +- .../watchers/PaintingWatcher.java | 20 +- .../disguisetypes/watchers/PigWatcher.java | 19 +- .../disguisetypes/watchers/PlayerWatcher.java | 31 ++- .../disguisetypes/watchers/RabbitWatcher.java | 19 +- .../disguisetypes/watchers/SheepWatcher.java | 53 ++-- .../watchers/ShulkerWatcher.java | 26 +- .../watchers/SkeletonWatcher.java | 20 +- .../disguisetypes/watchers/SlimeWatcher.java | 23 +- .../watchers/SplashPotionWatcher.java | 21 +- .../watchers/TameableWatcher.java | 20 +- .../watchers/TippedArrowWatcher.java | 21 +- .../watchers/VillagerWatcher.java | 24 +- .../disguisetypes/watchers/WitchWatcher.java | 20 +- .../watchers/WitherSkullWatcher.java | 19 +- .../disguisetypes/watchers/WitherWatcher.java | 46 ++-- .../disguisetypes/watchers/WolfWatcher.java | 63 +++-- .../disguisetypes/watchers/ZombieWatcher.java | 89 +++--- .../disguise/utilities/DisguiseUtilities.java | 104 +++---- .../disguise/utilities/DisguiseValues.java | 9 +- 47 files changed, 1209 insertions(+), 703 deletions(-) create mode 100644 src/me/libraryaddict/disguise/disguisetypes/FlagType.java create mode 100644 src/me/libraryaddict/disguise/disguisetypes/watchers/InsentientWatcher.java diff --git a/pom.xml b/pom.xml index eb91d88c..7e28babc 100644 --- a/pom.xml +++ b/pom.xml @@ -42,12 +42,12 @@ org.spigotmc spigot-api - 1.9.4-R0.1-SNAPSHOT + 1.10-R0.1-SNAPSHOT org.spigotmc spigot - 1.9.4-R0.1-SNAPSHOT + 1.10-R0.1-SNAPSHOT diff --git a/src/me/libraryaddict/disguise/LibsDisguises.java b/src/me/libraryaddict/disguise/LibsDisguises.java index 32dd54dc..0b038fec 100644 --- a/src/me/libraryaddict/disguise/LibsDisguises.java +++ b/src/me/libraryaddict/disguise/LibsDisguises.java @@ -30,6 +30,7 @@ import me.libraryaddict.disguise.commands.UndisguiseEntityCommand; import me.libraryaddict.disguise.commands.UndisguisePlayerCommand; import me.libraryaddict.disguise.commands.UndisguiseRadiusCommand; import me.libraryaddict.disguise.disguisetypes.DisguiseType; +import me.libraryaddict.disguise.disguisetypes.FlagType; import me.libraryaddict.disguise.disguisetypes.FlagWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.GuardianWatcher; @@ -299,7 +300,18 @@ public class LibsDisguises extends JavaPlugin for (WrappedWatchableObject watch : watcher.getWatchableObjects()) { - disguiseValues.setMetaValue(watch.getIndex(), watch.getValue()); + FlagType flagType = FlagType.getFlag(watcherClass, watch.getIndex()); + + if (flagType == null) + { + System.err.println("Error finding the FlagType for " + disguiseType.name() + "! " + watch.getIndex() + + " cannot be found!"); + System.err.println("Lib's Disguises will continue to load, but this will not work properly!"); + continue; + } + + disguiseValues.setMetaValue(flagType, watch.getValue()); + // Uncomment when I need to find the new datawatcher values for a class.. // int id = watch.getIndex(); // Object val = watch.getValue(); diff --git a/src/me/libraryaddict/disguise/disguisetypes/Disguise.java b/src/me/libraryaddict/disguise/disguisetypes/Disguise.java index 253a0350..eef5b624 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/Disguise.java +++ b/src/me/libraryaddict/disguise/disguisetypes/Disguise.java @@ -6,6 +6,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Map.Entry; import java.util.UUID; import org.bukkit.Bukkit; @@ -782,134 +783,15 @@ public abstract class Disguise */ private void setupWatcher() { - HashMap disguiseValues = DisguiseValues.getMetaValues(getType()); - HashMap entityValues = DisguiseValues.getMetaValues(DisguiseType.getType(getEntity().getType())); + HashMap disguiseValues = DisguiseValues.getMetaValues(getType()); + HashMap entityValues = DisguiseValues.getMetaValues(DisguiseType.getType(getEntity().getType())); - // Start from 2 as they ALL share 0 and 1 - for (int dataNo = 0; dataNo <= 31; dataNo++) + for (Entry entry : entityValues.entrySet()) { - // STEP 1. Find out if the watcher has set data on it. - // If the watcher already set a metadata on this - if (getWatcher().hasValue(dataNo)) - { - // Better check that the value is stable. - // To check this, I'm going to check if there exists a default value - // Then I'm going to check if the watcher value is the same as the default value. - if (disguiseValues.containsKey(dataNo)) - { - // Now check if they are the same class, or both null. - if (disguiseValues.get(dataNo) == null || getWatcher().getValue(dataNo, null) == null) - { - if (disguiseValues.get(dataNo) == null && getWatcher().getValue(dataNo, null) == null) - { - // They are both null. Idk what this means really. - continue; - } - } - else if (getWatcher().getValue(dataNo, null).getClass() == disguiseValues.get(dataNo).getClass()) - { - // The classes are the same. The client "shouldn't" crash. - continue; - } - } - } - - // STEP 2. As the watcher has not set data on it, check if I need to set the default data. - // If neither of them touch it - if (!entityValues.containsKey(dataNo) && !disguiseValues.containsKey(dataNo)) - { + if (disguiseValues.containsKey(entry.getKey())) continue; - } - // If the disguise has this, but not the entity. Then better set it! - if (!entityValues.containsKey(dataNo) && disguiseValues.containsKey(dataNo)) - { - getWatcher().setBackupValue(dataNo, disguiseValues.get(dataNo)); - continue; - } - - // Else if the disguise doesn't have it. But the entity does. Better remove it! - if (entityValues.containsKey(dataNo) && !disguiseValues.containsKey(dataNo)) - { - getWatcher().setBackupValue(dataNo, null); - continue; - } - - Object eObj = entityValues.get(dataNo); - Object dObj = disguiseValues.get(dataNo); - - if (eObj == null || dObj == null) - { - if (eObj == null && dObj == null) - { - continue; - } - else - { - getWatcher().setBackupValue(dataNo, dObj); - continue; - } - } - - if (eObj.getClass() != dObj.getClass()) - { - getWatcher().setBackupValue(dataNo, dObj); - continue; - } - - // Since they both share it. With the same classes. Time to check if its from something they extend. - // Better make this clear before I compare the values because some default values are different! - // Entity is 0 & 1 - But we aint gonna be checking that - // EntityAgeable is 11 - // EntityInsentient is 10 - // EntityLiving is 5 & 6 & 7 & 8 & 9 - // Lets use switch - Class baseClass = null; - - switch (dataNo) - { - case 5: - case 6: - case 7: - case 8: - case 9: - baseClass = ReflectionManager.getNmsClass("EntityLiving"); - break; - case 10: - baseClass = ReflectionManager.getNmsClass("EntityInsentient"); - break; - case 11: - baseClass = ReflectionManager.getNmsClass("EntityAgeable"); - break; - default: - break; - } - - Class nmsEntityClass = ReflectionManager.getNmsEntity(getEntity()).getClass(); - Class nmsDisguiseClass = DisguiseValues.getNmsEntityClass(getType()); - - if (nmsDisguiseClass != null) - { - // If they both extend the same base class. They OBVIOUSLY share the same datavalue. Right..? - if (baseClass != null && baseClass.isAssignableFrom(nmsDisguiseClass) - && baseClass.isAssignableFrom(nmsEntityClass)) - { - continue; - } - - // So they don't extend a basic class. - // Maybe if I check that they extend each other.. - // Seeing as I only store the finished forms of entitys. This should raise no problems and allow for more shared - // datawatchers. - if (nmsEntityClass.isAssignableFrom(nmsDisguiseClass) || nmsDisguiseClass.isAssignableFrom(nmsEntityClass)) - { - continue; - } - } - - // Well I can't find a reason I should leave it alone. They will probably conflict. - // Time to set the value to the disguises value so no conflicts! - getWatcher().setBackupValue(dataNo, disguiseValues.get(dataNo)); + getWatcher().setBackupValue(entry.getKey(), entry.getValue()); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java b/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java index 4407edf8..2bdd0069 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java +++ b/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java @@ -337,7 +337,7 @@ public enum DisguiseType return objectId; } - public Class getWatcherClass() + public Class getWatcherClass() { return watcherClass; } diff --git a/src/me/libraryaddict/disguise/disguisetypes/FlagType.java b/src/me/libraryaddict/disguise/disguisetypes/FlagType.java new file mode 100644 index 00000000..6b0a8079 --- /dev/null +++ b/src/me/libraryaddict/disguise/disguisetypes/FlagType.java @@ -0,0 +1,260 @@ +package me.libraryaddict.disguise.disguisetypes; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.UUID; +import java.util.Map.Entry; + +import org.bukkit.Color; +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; + +import com.google.common.base.Optional; + +import me.libraryaddict.disguise.disguisetypes.watchers.*; + +public class FlagType +{ + private static FlagType[] _values = new FlagType[0]; + + public static FlagType AGEABLE_BABY = new FlagType(AgeableWatcher.class, 11, false); + + public static FlagType AREA_EFFECT_COLOR = new FlagType(AreaEffectCloudWatcher.class, 6, + Color.BLACK.asRGB()); + + public static FlagType AREA_EFFECT_IGNORE_RADIUS = new FlagType(AreaEffectCloudWatcher.class, 7, false); + + public static FlagType AREA_EFFECT_PARTICLE = new FlagType(AreaEffectCloudWatcher.class, 8, 0); + + public static FlagType AREA_EFFECT_RADIUS = new FlagType(AreaEffectCloudWatcher.class, 6, 0F); + + public static FlagType ARMORSTAND_META = new FlagType(ArmorStandWatcher.class, 10, (byte) 0); + + public static FlagType ARROW_CRITICAL = new FlagType(ArrowWatcher.class, 6, (byte) 0); + + public static FlagType BAT_HANGING = new FlagType(BatWatcher.class, 11, (byte) 1); + + public static FlagType BLAZE_BLAZING = new FlagType(BlazeWatcher.class, 11, false); + + public static FlagType BOAT_DAMAGE = new FlagType(BoatWatcher.class, 7, 40F); + + public static FlagType CREEPER_IGNITED = new FlagType(CreeperWatcher.class, 13, false); + + public static FlagType CREEPER_POWERED = new FlagType(CreeperWatcher.class, 12, false); + + public static FlagType DROPPED_ITEM = new FlagType(DroppedItemWatcher.class, 6, + new ItemStack(Material.AIR)); + + public static FlagType ENDER_CRYSTAL_BEAM = new FlagType(EnderCrystalWatcher.class, 6, Optional.absent()); + + public static FlagType ENDER_CRYSTAL_PLATE = new FlagType(EnderCrystalWatcher.class, 6, false); + + public static FlagType ENDERDRAGON_PHASE = new FlagType(EnderDragonWatcher.class, 6, 0); + + public static FlagType ENDERMAN_AGRESSIVE = new FlagType(EndermanWatcher.class, 12, false); + + public static FlagType> ENDERMAN_ITEM = new FlagType>(EndermanWatcher.class, 11, + Optional.of(1)); + + public static FlagType ENTITY_AIR_TICKS = new FlagType(FlagWatcher.class, 1, 0); + + public static FlagType ENTITY_CUSTOM_NAME = new FlagType(FlagWatcher.class, 2, null); + + public static FlagType ENTITY_CUSTOM_NAME_VISIBLE = new FlagType(FlagWatcher.class, 3, false); + + public static FlagType ENTITY_META = new FlagType(FlagWatcher.class, 0, (byte) 0); + + public static FlagType ENTITY_NO_GRAVITY = new FlagType(FlagWatcher.class, 5, false); + + public static FlagType ENTITY_SILENT = new FlagType(FlagWatcher.class, 4, 0); + + public static FlagType GHAST_AGRESSIVE = new FlagType(GhastWatcher.class, 11, false); + + public static FlagType GUARDIAN_FLAG = new FlagType(GuardianWatcher.class, 11, (byte) 0); + + public static FlagType GUARDIAN_TARGET = new FlagType(GuardianWatcher.class, 12, 0); + + public static FlagType HORSE_ARMOR = new FlagType(HorseWatcher.class, 16, 0); + + public static FlagType HORSE_COLOR = new FlagType(HorseWatcher.class, 14, 0); + + public static FlagType HORSE_META = new FlagType(HorseWatcher.class, 12, (byte) 0); + + public static FlagType> HORSE_OWNER = new FlagType>(HorseWatcher.class, 15, + Optional. absent()); + + public static FlagType HORSE_STYLE = new FlagType(HorseWatcher.class, 14, 0); + + public static FlagType HORSE_VARIANT = new FlagType(HorseWatcher.class, 13, 0); + + public static FlagType INSENTIENT_META = new FlagType(LivingWatcher.class, 10, (byte) 0); + + public static FlagType ITEMFRAME_ITEM = new FlagType(ItemFrameWatcher.class, 6, null); + + public static FlagType ITEMFRAME_ROTATION = new FlagType(ItemFrameWatcher.class, 6, (byte) 0); + + public static FlagType LIVING_ARROWS = new FlagType(LivingWatcher.class, 9, 0); + + public static FlagType LIVING_HEALTH = new FlagType(LivingWatcher.class, 6, 0F); + + public static FlagType LIVING_POTION_AMBIENT = new FlagType(LivingWatcher.class, 8, false); + + public static FlagType LIVING_POTIONS = new FlagType(LivingWatcher.class, 7, 0); + + public static FlagType MINECART_BLOCK = new FlagType(MinecartWatcher.class, 8, 0); + + public static FlagType MINECART_BLOCK_VISIBLE = new FlagType(MinecartWatcher.class, 10, false); + + public static FlagType MINECART_BLOCK_Y = new FlagType(MinecartWatcher.class, 9, 0); + + public static FlagType OCELOT_TYPE = new FlagType(OcelotWatcher.class, 14, 0); + + public static FlagType PIG_SADDLED = new FlagType(PigWatcher.class, 12, false); + + public static FlagType PLAYER_SKIN = new FlagType(PlayerWatcher.class, 12, (byte) 0); + + public static FlagType RABBIT_TYPE = new FlagType(RabbitWatcher.class, 12, 0); + + public static FlagType SHEEP_WOOL = new FlagType(SheepWatcher.class, 12, (byte) 0); + + public static FlagType SKELETON_TYPE = new FlagType(SkeletonWatcher.class, 11, 0); + + public static FlagType SLIME_SIZE = new FlagType(SlimeWatcher.class, 11, 0); + + public static FlagType TAMEABLE_META = new FlagType(TameableWatcher.class, 12, (byte) 0); + + public static FlagType> TAMEABLE_OWNER = new FlagType>(TameableWatcher.class, 13, + Optional. absent()); + + public static FlagType TIPPED_ARROW_COLOR = new FlagType(TippedArrowWatcher.class, 6, Color.WHITE.asRGB()); + + public static FlagType VILLAGER_PROFESSION = new FlagType(VillagerWatcher.class, 12, 0); + + public static FlagType WITCH_AGGRESSIVE = new FlagType(WitchWatcher.class, 11, false); + + public static FlagType WITHER_INVUL = new FlagType(WitchWatcher.class, 14, 0); + + public static FlagType WITHER_TARGET_1 = new FlagType(WitherWatcher.class, 11, 0); + + public static FlagType WITHER_TARGET_2 = new FlagType(WitherWatcher.class, 12, 0); + + public static FlagType WITHER_TARGET_3 = new FlagType(WitherWatcher.class, 13, 0); + + public static FlagType WITHERSKULL_BLUE = new FlagType(WitherSkullWatcher.class, 6, false); + + public static FlagType WOLF_BEGGING = new FlagType(WolfWatcher.class, 15, false); + + public static FlagType WOLF_COLLAR = new FlagType(WolfWatcher.class, 16, 14); + + public static FlagType WOLF_DAMAGE = new FlagType(WolfWatcher.class, 14, 0F); + + public static FlagType ZOMBIE_AGGRESSIVE = new FlagType(ZombieWatcher.class, 14, false); + + public static FlagType ZOMBIE_BABY = new FlagType(ZombieWatcher.class, 11, false); + + public static FlagType ZOMBIE_PROFESSION = new FlagType(ZombieWatcher.class, 12, 0); + + public static FlagType ZOMBIE_SHAKING = new FlagType(ZombieWatcher.class, 13, false); + + static + { + // Simple verification for the dev that he's setting up the FlagType's properly. + // All flag types should be from 0 to with no empty numbers. + // All flag types should never occur twice. + + HashMap maxValues = new HashMap(); + + for (FlagType type : values()) + { + if (maxValues.containsKey(type.getFlagWatcher()) && maxValues.get(type.getFlagWatcher()) > type.getIndex()) + continue; + + maxValues.put(type.getFlagWatcher(), type.getIndex()); + } + + for (Entry entry : maxValues.entrySet()) + { + loop: + + for (int i = 0; i < entry.getValue(); i++) + { + FlagType found = null; + + for (FlagType type : values()) + { + if (type.getIndex() != i) + continue; + + if (!type.getFlagWatcher().isAssignableFrom(entry.getKey())) + continue; + + if (found != null) + { + System.err.println(entry.getKey().getSimpleName() + " has multiple FlagType's registered for the index " + + i + " (" + type.getFlagWatcher().getSimpleName() + ", " + found.getFlagWatcher().getSimpleName() + + ")"); + continue loop; + } + + found = type; + } + + if (found != null) + continue; + + System.err.println(entry.getKey().getSimpleName() + " has no FlagType registered for the index " + i); + } + } + } + + public static FlagType getFlag(Class watcherClass, int flagNo) + { + for (FlagType type : values()) + { + if (type.getIndex() != flagNo) + continue; + + if (!type.getFlagWatcher().isAssignableFrom(watcherClass)) + continue; + + return type; + } + + return null; + } + + public static FlagType[] values() + { + return _values; + } + + private Y _defaultValue; + + private int _index; + + private Class _watcher; + + private FlagType(Class watcher, int index, Y defaultValue) + { + _index = index; + _watcher = watcher; + + _values = Arrays.copyOf(_values, _values.length + 1); + _values[_values.length - 1] = this; + } + + public Y getDefault() + { + return _defaultValue; + } + + public Class getFlagWatcher() + { + return _watcher; + } + + public int getIndex() + { + return _index; + } +} diff --git a/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java index fb03576c..d0894d30 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java @@ -28,16 +28,15 @@ import me.libraryaddict.disguise.utilities.ReflectionManager; public class FlagWatcher { - private boolean addEntityAnimations = DisguiseConfig.isEntityAnimationsAdded(); /** * These are the entity values I need to add else it could crash them.. */ - private HashMap backupEntityValues = new HashMap<>(); + private HashMap backupEntityValues = new HashMap<>(); private TargetedDisguise disguise; - private HashMap entityValues = new HashMap<>(); - private boolean hasDied; + private HashMap entityValues = new HashMap<>(); private EntityEquipment equipment; + private boolean hasDied; private HashSet modifiedEntityAnimations = new HashSet<>(); private List watchableObjects; @@ -78,7 +77,7 @@ public class FlagWatcher cloned = new FlagWatcher(getDisguise()); } - cloned.entityValues = (HashMap) entityValues.clone(); + cloned.entityValues = (HashMap) entityValues.clone(); cloned.equipment = ReflectionManager.createEntityEquipment(cloned.getDisguise().getEntity()); cloned.modifiedEntityAnimations = (HashSet) modifiedEntityAnimations.clone(); cloned.addEntityAnimations = addEntityAnimations; @@ -159,7 +158,7 @@ public class FlagWatcher if (sendAllCustom) { // Its sending the entire meta data. Better add the custom meta - for (int id : entityValues.keySet()) + for (FlagType id : entityValues.keySet()) { if (sentValues.contains(id)) { @@ -173,7 +172,8 @@ public class FlagWatcher continue; } - WrappedWatchableObject watch = new WrappedWatchableObject(ReflectionManager.createDataWatcherItem(id, value)); + WrappedWatchableObject watch = new WrappedWatchableObject( + ReflectionManager.createDataWatcherItem(id.getIndex(), value)); newList.add(watch); } @@ -235,7 +235,7 @@ public class FlagWatcher public String getCustomName() { - return (String) getValue(2, null); + return (String) getValue(FlagType.ENTITY_CUSTOM_NAME); } protected TargetedDisguise getDisguise() @@ -245,7 +245,12 @@ public class FlagWatcher private boolean getEntityFlag(int byteValue) { - return ((byte) getValue(0, (byte) 0) & 1 << byteValue) != 0; + return ((byte) getValue(FlagType.ENTITY_META) & 1 << byteValue) != 0; + } + + public EntityEquipment getEquipment() + { + return equipment; } public ItemStack getItemInMainHand() @@ -264,19 +269,38 @@ public class FlagWatcher return equipment.getItemInOffHand(); } - public EntityEquipment getEquipment() + public ItemStack getItemStack(EquipmentSlot slot) { - return equipment; + if (equipment == null) + return null; + + switch (slot) + { + case CHEST: + return equipment.getChestplate(); + case FEET: + return equipment.getBoots(); + case HAND: + return equipment.getItemInMainHand(); + case HEAD: + return equipment.getHelmet(); + case LEGS: + return equipment.getLeggings(); + case OFF_HAND: + return equipment.getItemInOffHand(); + } + + return null; } - protected Y getValue(int no, Y backup) + protected Y getValue(FlagType no) { if (entityValues.containsKey(no)) { return (Y) entityValues.get(no); } - return backup; + return no.getDefault(); } public List getWatchableObjects() @@ -299,9 +323,14 @@ public class FlagWatcher return entityValues.containsKey(no); } + public boolean isBurning() + { + return getEntityFlag(0); + } + public boolean isCustomNameVisible() { - return (boolean) getValue(3, false); + return getValue(FlagType.ENTITY_CUSTOM_NAME_VISIBLE); } public boolean isEntityAnimationsAdded() @@ -309,9 +338,29 @@ public class FlagWatcher return addEntityAnimations; } - public boolean isBurning() + public boolean isFlyingWithElytra() { - return getEntityFlag(0); + return getEntityFlag(7); + } + + public boolean isGlowing() + { + return getEntityFlag(6); + } + + public boolean isInvisible() + { + return getEntityFlag(5); + } + + public boolean isNoGravity() + { + return getValue(FlagType.ENTITY_NO_GRAVITY); + } + + public boolean isRightClicking() + { + return getEntityFlag(4); } public boolean isSneaking() @@ -324,26 +373,6 @@ public class FlagWatcher return getEntityFlag(3); } - public boolean isRightClicking() - { - return getEntityFlag(4); - } - - public boolean isInvisible() - { - return getEntityFlag(5); - } - - public boolean isGlowing() - { - return getEntityFlag(6); - } - - public boolean isFlyingWithElytra() - { - return getEntityFlag(7); - } - public void rebuildWatchableObjects() { watchableObjects = new ArrayList<>(); @@ -368,7 +397,7 @@ public class FlagWatcher } } - protected void sendData(int... dataValues) + protected void sendData(FlagType... dataValues) { if (!DisguiseAPI.isDisguiseInUse(getDisguise()) || getDisguise().getWatcher() != this) { @@ -377,7 +406,7 @@ public class FlagWatcher List list = new ArrayList<>(); - for (int data : dataValues) + for (FlagType data : dataValues) { if (!entityValues.containsKey(data) || entityValues.get(data) == null) { @@ -386,7 +415,7 @@ public class FlagWatcher Object value = entityValues.get(data); - if (isEntityAnimationsAdded() && DisguiseConfig.isMetadataPacketsEnabled() && data == 0) + if (isEntityAnimationsAdded() && DisguiseConfig.isMetadataPacketsEnabled() && data == FlagType.ENTITY_META) { if (!PacketsManager.isStaticMetadataDisguiseType(disguise)) { @@ -395,7 +424,8 @@ public class FlagWatcher } } - WrappedWatchableObject watch = new WrappedWatchableObject(ReflectionManager.createDataWatcherItem(data, value)); + WrappedWatchableObject watch = new WrappedWatchableObject( + ReflectionManager.createDataWatcherItem(data.getIndex(), value)); list.add(watch); } @@ -436,7 +466,7 @@ public class FlagWatcher setItemStack(EquipmentSlot.FEET, itemstack[3]); } - protected void setBackupValue(int no, Object value) + protected void setBackupValue(FlagType no, Object value) { backupEntityValues.put(no, value); } @@ -445,7 +475,7 @@ public class FlagWatcher { setEntityFlag(0, setBurning); - sendData(0); + sendData(FlagType.ENTITY_META); } public void setCustomName(String name) @@ -455,48 +485,48 @@ public class FlagWatcher name = name.substring(0, 64); } - setValue(2, name); - sendData(2); + setValue(FlagType.ENTITY_CUSTOM_NAME, name); + sendData(FlagType.ENTITY_CUSTOM_NAME); } public void setCustomNameVisible(boolean display) { - setValue(3, display); - sendData(3); + setValue(FlagType.ENTITY_CUSTOM_NAME_VISIBLE, display); + sendData(FlagType.ENTITY_CUSTOM_NAME_VISIBLE); } private void setEntityFlag(int byteValue, boolean flag) { modifiedEntityAnimations.add(byteValue); - byte b0 = (byte) getValue(0, (byte) 0); + byte b0 = (byte) getValue(FlagType.ENTITY_META); if (flag) { - setValue(0, (byte) (b0 | 1 << byteValue)); + setValue(FlagType.ENTITY_META, (byte) (b0 | 1 << byteValue)); } else { - setValue(0, (byte) (b0 & ~(1 << byteValue))); + setValue(FlagType.ENTITY_META, (byte) (b0 & ~(1 << byteValue))); } } - public void setInvisible(boolean setInvis) - { - setEntityFlag(5, setInvis); - sendData(0); - } - - public void setGlowing(boolean glowing) - { - setEntityFlag(6, glowing); - sendData(0); - } - public void setFlyingWithElytra(boolean flying) { setEntityFlag(7, flying); - sendData(0); + sendData(FlagType.ENTITY_META); + } + + public void setGlowing(boolean glowing) + { + setEntityFlag(6, glowing); + sendData(FlagType.ENTITY_META); + } + + public void setInvisible(boolean setInvis) + { + setEntityFlag(5, setInvis); + sendData(FlagType.ENTITY_META); } /** @@ -520,6 +550,34 @@ public class FlagWatcher setItemStack(EquipmentSlot.OFF_HAND, itemstack); } + private void setItemStack(EntityEquipment equipment, EquipmentSlot slot, ItemStack itemStack) + { + if (equipment == null) + return; + + switch (slot) + { + case CHEST: + equipment.setChestplate(itemStack); + break; + case FEET: + equipment.setBoots(itemStack); + break; + case HAND: + equipment.setItemInMainHand(itemStack); + break; + case HEAD: + equipment.setHelmet(itemStack); + break; + case LEGS: + equipment.setLeggings(itemStack); + break; + case OFF_HAND: + equipment.setItemInOffHand(itemStack); + break; + } + } + public void setItemStack(EquipmentSlot slot, ItemStack itemStack) { if (equipment == null) @@ -569,77 +627,31 @@ public class FlagWatcher } } - private void setItemStack(EntityEquipment equipment, EquipmentSlot slot, ItemStack itemStack) + public void setNoGravity(boolean noGravity) { - if (equipment == null) - return; - - switch (slot) - { - case CHEST: - equipment.setChestplate(itemStack); - break; - case FEET: - equipment.setBoots(itemStack); - break; - case HAND: - equipment.setItemInMainHand(itemStack); - break; - case HEAD: - equipment.setHelmet(itemStack); - break; - case LEGS: - equipment.setLeggings(itemStack); - break; - case OFF_HAND: - equipment.setItemInOffHand(itemStack); - break; - } - } - - public ItemStack getItemStack(EquipmentSlot slot) - { - if (equipment == null) - return null; - - switch (slot) - { - case CHEST: - return equipment.getChestplate(); - case FEET: - return equipment.getBoots(); - case HAND: - return equipment.getItemInMainHand(); - case HEAD: - return equipment.getHelmet(); - case LEGS: - return equipment.getLeggings(); - case OFF_HAND: - return equipment.getItemInOffHand(); - } - - return null; + setValue(FlagType.ENTITY_NO_GRAVITY, noGravity); + sendData(FlagType.ENTITY_NO_GRAVITY); } public void setRightClicking(boolean setRightClicking) { setEntityFlag(4, setRightClicking); - sendData(0); + sendData(FlagType.ENTITY_META); } public void setSneaking(boolean setSneaking) { setEntityFlag(1, setSneaking); - sendData(0); + sendData(FlagType.ENTITY_META); } public void setSprinting(boolean setSprinting) { setEntityFlag(3, setSprinting); - sendData(0); + sendData(FlagType.ENTITY_META); } - protected void setValue(int id, Object value) + protected void setValue(FlagType id, Y value) { entityValues.put(id, value); diff --git a/src/me/libraryaddict/disguise/disguisetypes/RabbitType.java b/src/me/libraryaddict/disguise/disguisetypes/RabbitType.java index 0f74e5bf..13d52b4c 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/RabbitType.java +++ b/src/me/libraryaddict/disguise/disguisetypes/RabbitType.java @@ -2,7 +2,6 @@ package me.libraryaddict.disguise.disguisetypes; public enum RabbitType { - BLACK(2), BROWN(0), GOLD(4), KILLER_BUNNY(99), PATCHES(3), PEPPER(5), WHITE(1); public static RabbitType getType(int id) diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/AgeableWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/AgeableWatcher.java index 97289e2a..eacf5919 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/AgeableWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/AgeableWatcher.java @@ -1,6 +1,7 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.FlagType; public class AgeableWatcher extends LivingWatcher { @@ -17,7 +18,7 @@ public class AgeableWatcher extends LivingWatcher public boolean isBaby() { - return (boolean) getValue(11, false); + return getValue(FlagType.AGEABLE_BABY); } public void setAdult() @@ -32,8 +33,8 @@ public class AgeableWatcher extends LivingWatcher public void setBaby(boolean isBaby) { - setValue(11, isBaby); - sendData(11); + setValue(FlagType.AGEABLE_BABY, isBaby); + sendData(FlagType.AGEABLE_BABY); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/AreaEffectCloudWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/AreaEffectCloudWatcher.java index acfee458..efa17141 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/AreaEffectCloudWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/AreaEffectCloudWatcher.java @@ -3,48 +3,58 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import java.awt.Color; import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.FlagType; import me.libraryaddict.disguise.disguisetypes.FlagWatcher; /** * @author Navid */ -public class AreaEffectCloudWatcher extends FlagWatcher { +public class AreaEffectCloudWatcher extends FlagWatcher +{ - public AreaEffectCloudWatcher(Disguise disguise) { + public AreaEffectCloudWatcher(Disguise disguise) + { super(disguise); } - public float getRadius() { - return (float) getValue(5, 0f); + public float getRadius() + { + return getValue(FlagType.AREA_EFFECT_RADIUS); } - public int getColor() { - return (int) getValue(6, Color.BLACK.getRGB()); + public int getColor() + { + return getValue(FlagType.AREA_EFFECT_COLOR); } - public boolean isIgnoreRadius() { - return (boolean) getValue(7, false); + public boolean isIgnoreRadius() + { + return getValue(FlagType.AREA_EFFECT_IGNORE_RADIUS); } - public int getParticleId() { - return (int) getValue(8, 0); + public int getParticleId() + { + return getValue(FlagType.AREA_EFFECT_PARTICLE); } - public void setRadius(float radius) { - setValue(5, radius); + public void setRadius(float radius) + { + setValue(FlagType.AREA_EFFECT_RADIUS, radius); } - public void setColor(int color) { - setValue(6, color); + public void setColor(int color) + { + setValue(FlagType.AREA_EFFECT_COLOR, color); } - public void setIgnoreRadius(boolean ignore) { - setValue(7, ignore); + public void setIgnoreRadius(boolean ignore) + { + setValue(FlagType.AREA_EFFECT_IGNORE_RADIUS, ignore); } - public void setParticleId(int particleId) { - setValue(8, particleId); + public void setParticleId(int particleId) + { + setValue(FlagType.AREA_EFFECT_PARTICLE, particleId); } - } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/ArmorStandWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/ArmorStandWatcher.java index 32b7f894..136d0bd8 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/ArmorStandWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/ArmorStandWatcher.java @@ -1,6 +1,7 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.FlagType; public class ArmorStandWatcher extends LivingWatcher { @@ -12,7 +13,7 @@ public class ArmorStandWatcher extends LivingWatcher private boolean getArmorStandFlag(int value) { - return (getValue(10, 0) & value) != 0; + return (getValue(FlagType.ARMORSTAND_META) & value) != 0; } public boolean isNoBasePlate() @@ -42,7 +43,8 @@ public class ArmorStandWatcher extends LivingWatcher private void setArmorStandFlag(int value, boolean isTrue) { - byte b1 = (byte) getValue(10, (byte) 0); + byte b1 = (byte) getValue(FlagType.ARMORSTAND_META); + if (isTrue) { b1 = (byte) (b1 | value); @@ -51,38 +53,39 @@ public class ArmorStandWatcher extends LivingWatcher { b1 = (byte) (b1 & value); } - setValue(10, b1); - sendData(10); + + setValue(FlagType.ARMORSTAND_META, b1); + sendData(FlagType.ARMORSTAND_META); } public void setNoBasePlate(boolean noBasePlate) { setArmorStandFlag(8, noBasePlate); - sendData(10); + sendData(FlagType.ARMORSTAND_META); } public void setNoGravity(boolean noGravity) { setArmorStandFlag(2, noGravity); - sendData(10); + sendData(FlagType.ARMORSTAND_META); } public void setShowArms(boolean showArms) { setArmorStandFlag(4, showArms); - sendData(10); + sendData(FlagType.ARMORSTAND_META); } public void setSmall(boolean isSmall) { setArmorStandFlag(1, isSmall); - sendData(10); + sendData(FlagType.ARMORSTAND_META); } public void setMarker(boolean isMarker) { setArmorStandFlag(10, isMarker); - sendData(10); + sendData(FlagType.ARMORSTAND_META); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/ArrowWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/ArrowWatcher.java index 93c5d890..1285ead8 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/ArrowWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/ArrowWatcher.java @@ -1,21 +1,26 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.FlagType; import me.libraryaddict.disguise.disguisetypes.FlagWatcher; -public class ArrowWatcher extends FlagWatcher { +public class ArrowWatcher extends FlagWatcher +{ - public ArrowWatcher(Disguise disguise) { + public ArrowWatcher(Disguise disguise) + { super(disguise); } - public boolean isCritical() { - return (byte) getValue(5, (byte) 0) == 1; + public boolean isCritical() + { + return (byte) getValue(FlagType.ARROW_CRITICAL) == 1; } - public void setCritical(boolean critical) { - setValue(5, (byte) (critical ? 1 : 0)); - sendData(5); + public void setCritical(boolean critical) + { + setValue(FlagType.ARROW_CRITICAL, (byte) (critical ? 1 : 0)); + sendData(FlagType.ARROW_CRITICAL); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/BatWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/BatWatcher.java index d6464d9a..b2a824ac 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/BatWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/BatWatcher.java @@ -1,20 +1,26 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.FlagType; -public class BatWatcher extends LivingWatcher { +public class BatWatcher extends LivingWatcher +{ - public BatWatcher(Disguise disguise) { + public BatWatcher(Disguise disguise) + { super(disguise); + setHanging(false); } - public boolean isHanging() { - return ((byte)getValue(11, (byte) 1)) == 1; + public boolean isHanging() + { + return ((byte) getValue(FlagType.BAT_HANGING)) == 1; } - public void setHanging(boolean hanging) { - setValue(11, hanging ? (byte) 1 : (byte) 0); - sendData(11); + public void setHanging(boolean hanging) + { + setValue(FlagType.BAT_HANGING, hanging ? (byte) 1 : (byte) 0); + sendData(FlagType.BAT_HANGING); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/BlazeWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/BlazeWatcher.java index 6e8d4f57..9a0cf850 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/BlazeWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/BlazeWatcher.java @@ -1,6 +1,7 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.FlagType; public class BlazeWatcher extends LivingWatcher { @@ -11,13 +12,13 @@ public class BlazeWatcher extends LivingWatcher public boolean isBlazing() { - return (boolean) getValue(11, false); + return getValue(FlagType.BLAZE_BLAZING); } public void setBlazing(boolean isBlazing) { - setValue(11, isBlazing); - sendData(11); + setValue(FlagType.BLAZE_BLAZING, isBlazing); + sendData(FlagType.BLAZE_BLAZING); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/BoatWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/BoatWatcher.java index 2eca213b..0f7338ce 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/BoatWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/BoatWatcher.java @@ -1,6 +1,7 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.FlagType; import me.libraryaddict.disguise.disguisetypes.FlagWatcher; public class BoatWatcher extends FlagWatcher @@ -15,13 +16,13 @@ public class BoatWatcher extends FlagWatcher public float getDamage() { - return getValue(7, 40F); + return getValue(FlagType.BOAT_DAMAGE); } public void setDamage(float dmg) { - setValue(7, dmg); - sendData(7); + setValue(FlagType.BOAT_DAMAGE, dmg); + sendData(FlagType.BOAT_DAMAGE); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/CreeperWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/CreeperWatcher.java index 79189c95..0e9f5784 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/CreeperWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/CreeperWatcher.java @@ -1,29 +1,36 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.FlagType; -public class CreeperWatcher extends LivingWatcher { +public class CreeperWatcher extends LivingWatcher +{ - public CreeperWatcher(Disguise disguise) { + public CreeperWatcher(Disguise disguise) + { super(disguise); } - public boolean isIgnited() { - return (boolean) getValue(13, false); + public boolean isIgnited() + { + return (boolean) getValue(FlagType.CREEPER_IGNITED); } - public boolean isPowered() { - return (boolean) getValue(12, false); + public boolean isPowered() + { + return (boolean) getValue(FlagType.CREEPER_POWERED); } - public void setIgnited(boolean ignited) { - setValue(13, ignited); - sendData(13); + public void setIgnited(boolean ignited) + { + setValue(FlagType.CREEPER_IGNITED, ignited); + sendData(FlagType.CREEPER_IGNITED); } - public void setPowered(boolean powered) { - setValue(12, powered); - sendData(12); + public void setPowered(boolean powered) + { + setValue(FlagType.CREEPER_POWERED, powered); + sendData(FlagType.CREEPER_POWERED); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/DroppedItemWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/DroppedItemWatcher.java index 04b28ccf..596b16b4 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/DroppedItemWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/DroppedItemWatcher.java @@ -1,23 +1,29 @@ package me.libraryaddict.disguise.disguisetypes.watchers; +import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.FlagType; import me.libraryaddict.disguise.disguisetypes.FlagWatcher; //TODO: Add support for custom items instead of just stone -public class DroppedItemWatcher extends FlagWatcher { +public class DroppedItemWatcher extends FlagWatcher +{ - public DroppedItemWatcher(Disguise disguise) { + public DroppedItemWatcher(Disguise disguise) + { super(disguise); } - public ItemStack getItemStack() { - return (ItemStack) getValue(5, new ItemStack(1)); + public ItemStack getItemStack() + { + return getValue(FlagType.DROPPED_ITEM); } - public void setItemStack(ItemStack item) { - setValue(5, item); - sendData(5); + public void setItemStack(ItemStack item) + { + setValue(FlagType.DROPPED_ITEM, item); + sendData(FlagType.DROPPED_ITEM); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/EnderCrystalWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/EnderCrystalWatcher.java index 2666d2e3..94f91856 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/EnderCrystalWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/EnderCrystalWatcher.java @@ -4,6 +4,7 @@ import com.comphenix.protocol.wrappers.BlockPosition; import com.google.common.base.Optional; import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.FlagType; import me.libraryaddict.disguise.disguisetypes.FlagWatcher; /** @@ -18,24 +19,24 @@ public class EnderCrystalWatcher extends FlagWatcher public void setBeamTarget(BlockPosition position) { - setValue(5, Optional.of(position)); - sendData(5); + setValue(FlagType.ENDER_CRYSTAL_BEAM, Optional.of(position)); + sendData(FlagType.ENDER_CRYSTAL_BEAM); } public Optional getBeamTarget() { - return (Optional) getValue(5, Optional.absent()); + return getValue(FlagType.ENDER_CRYSTAL_BEAM); } public void setShowBottom(boolean bool) { - setValue(6, bool); - sendData(6); + setValue(FlagType.ENDER_CRYSTAL_PLATE, bool); + sendData(FlagType.ENDER_CRYSTAL_PLATE); } public boolean isShowBottom() { - return (boolean) getValue(6, false); + return getValue(FlagType.ENDER_CRYSTAL_PLATE); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/EnderDragonWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/EnderDragonWatcher.java index f299b18c..c3bd8b38 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/EnderDragonWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/EnderDragonWatcher.java @@ -1,22 +1,27 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.FlagType; /** * @author Navid */ -public class EnderDragonWatcher extends LivingWatcher { +public class EnderDragonWatcher extends LivingWatcher +{ - public EnderDragonWatcher(Disguise disguise) { + public EnderDragonWatcher(Disguise disguise) + { super(disguise); } - public int getPhase() { - return (int) getValue(11, 0); + public int getPhase() + { + return getValue(FlagType.ENDERDRAGON_PHASE); } - public void setPhase(int phase) { - setValue(11, phase); - sendData(11); + public void setPhase(int phase) + { + setValue(FlagType.ENDERDRAGON_PHASE, phase); + sendData(FlagType.ENDERDRAGON_PHASE); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/EndermanWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/EndermanWatcher.java index 20daf454..4778bbe2 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/EndermanWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/EndermanWatcher.java @@ -6,48 +6,63 @@ import org.bukkit.inventory.ItemStack; import com.google.common.base.Optional; import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.FlagType; import me.libraryaddict.disguise.utilities.ReflectionManager; -public class EndermanWatcher extends LivingWatcher { +public class EndermanWatcher extends LivingWatcher +{ - public EndermanWatcher(Disguise disguise) { + public EndermanWatcher(Disguise disguise) + { super(disguise); } @Override - public ItemStack getItemInMainHand() { - Optional value = (Optional) getValue(11, Optional.of(1)); - if (value.isPresent()) { + public ItemStack getItemInMainHand() + { + Optional value = getValue(FlagType.ENDERMAN_ITEM); + + if (value.isPresent()) + { Pair pair = ReflectionManager.getFromCombinedId(value.get()); int id = pair.getLeft(); int data = pair.getRight(); + return new ItemStack(id, 1, (short) data); - } else { + } + else + { return null; } } @Override - public void setItemInMainHand(ItemStack itemstack) { + public void setItemInMainHand(ItemStack itemstack) + { setItemInMainHand(itemstack.getTypeId(), itemstack.getDurability()); } - public void setItemInMainHand(int typeId) { + public void setItemInMainHand(int typeId) + { setItemInMainHand(typeId, 0); } - public void setItemInMainHand(int typeId, int data) { + public void setItemInMainHand(int typeId, int data) + { int combined = ReflectionManager.getCombinedId(typeId, data); - setValue(11, Optional.of(combined)); + + setValue(FlagType.ENDERMAN_ITEM, Optional.of(combined)); } - public boolean isAggressive() { - return (boolean) getValue(12, false); + public boolean isAggressive() + { + return getValue(FlagType.ENDERMAN_AGRESSIVE); } - public void setAggressive(boolean isAggressive) { - setValue(12, isAggressive); - sendData(12); + public void setAggressive(boolean isAggressive) + { + setValue(FlagType.ENDERMAN_AGRESSIVE, isAggressive); + sendData(FlagType.ENDERMAN_AGRESSIVE); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/FallingBlockWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/FallingBlockWatcher.java index b71ab1ab..a5fd6d74 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/FallingBlockWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/FallingBlockWatcher.java @@ -8,31 +8,40 @@ import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.FlagWatcher; import me.libraryaddict.disguise.utilities.DisguiseUtilities; -public class FallingBlockWatcher extends FlagWatcher { - +public class FallingBlockWatcher extends FlagWatcher +{ private ItemStack block; - public FallingBlockWatcher(Disguise disguise) { + public FallingBlockWatcher(Disguise disguise) + { super(disguise); } @Override - public FallingBlockWatcher clone(Disguise disguise) { + public FallingBlockWatcher clone(Disguise disguise) + { FallingBlockWatcher watcher = (FallingBlockWatcher) super.clone(disguise); watcher.setBlock(getBlock()); + return watcher; } - public ItemStack getBlock() { + public ItemStack getBlock() + { return block; } - public void setBlock(ItemStack block) { + public void setBlock(ItemStack block) + { this.block = block; - if (block.getType() == null || block.getType() == Material.AIR) { + + if (block.getType() == null || block.getType() == Material.AIR) + { block.setType(Material.STONE); } - if (DisguiseAPI.isDisguiseInUse(getDisguise()) && getDisguise().getWatcher() == this) { + + if (DisguiseAPI.isDisguiseInUse(getDisguise()) && getDisguise().getWatcher() == this) + { DisguiseUtilities.refreshTrackers(getDisguise()); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/GhastWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/GhastWatcher.java index e965df26..deb6304d 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/GhastWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/GhastWatcher.java @@ -1,20 +1,25 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.FlagType; -public class GhastWatcher extends LivingWatcher { +public class GhastWatcher extends LivingWatcher +{ - public GhastWatcher(Disguise disguise) { + public GhastWatcher(Disguise disguise) + { super(disguise); } - public boolean isAggressive() { - return (boolean) getValue(11, false); + public boolean isAggressive() + { + return getValue(FlagType.GHAST_AGRESSIVE); } - public void setAggressive(boolean isAggressive) { - setValue(11, isAggressive); - sendData(11); + public void setAggressive(boolean isAggressive) + { + setValue(FlagType.GHAST_AGRESSIVE, isAggressive); + sendData(FlagType.GHAST_AGRESSIVE); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/GuardianWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/GuardianWatcher.java index b8a3629c..2acafcc1 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/GuardianWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/GuardianWatcher.java @@ -1,72 +1,101 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import org.bukkit.Bukkit; +import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.FlagType; -public class GuardianWatcher extends LivingWatcher { +public class GuardianWatcher extends LivingWatcher +{ - public GuardianWatcher(Disguise disguise) { + public GuardianWatcher(Disguise disguise) + { super(disguise); } /** * Is this guardian targetting someone? + * * @return */ - public boolean isTarget() { - return ((int)getValue(12, 0)) != 0; + public boolean isTarget() + { + return ((int) getValue(FlagType.GUARDIAN_TARGET)) != 0; } /** * Shoot a beam at the given entityId. + * * @param entityId */ - public void setTarget(int entityId) { - setValue(12, entityId); - sendData(12); + public void setTarget(int entityId) + { + setValue(FlagType.GUARDIAN_TARGET, entityId); + sendData(FlagType.GUARDIAN_TARGET); + } + + public void setTarget(Entity entity) + { + setTarget(entity == null ? 0 : entity.getEntityId()); } /** * Shoot a beam at the given player name. + * * @param playername */ - public void setTarget(String playername) { + public void setTarget(String playername) + { Player player = Bukkit.getPlayer(playername); - if (player == null) return; - setValue(12, player.getEntityId()); - sendData(12); + + if (player == null) + return; + + setValue(FlagType.GUARDIAN_TARGET, player.getEntityId()); + sendData(FlagType.GUARDIAN_TARGET); } - public boolean isRetractingSpikes() { + public boolean isRetractingSpikes() + { return isGuardianFlag(2); } - public void setRetractingSpikes(boolean isRetracting) { + public void setRetractingSpikes(boolean isRetracting) + { setGuardianFlag(2, isRetracting); } - public boolean isElder() { + public boolean isElder() + { return isGuardianFlag(4); } - public void setElder(boolean isGuardian) { + public void setElder(boolean isGuardian) + { setGuardianFlag(4, isGuardian); } - protected boolean isGuardianFlag(int no) { - return ((byte) getValue(11, (byte) 0) & no) != 0; + protected boolean isGuardianFlag(int no) + { + return (getValue(FlagType.GUARDIAN_FLAG) & no) != 0; } - protected void setGuardianFlag(int no, boolean flag) { - byte b0 = (byte) getValue(11, (byte) 0); - if (flag) { - setValue(11, (byte) (b0 | no)); - } else { - setValue(11, (byte) (b0 & -(no + 1))); + protected void setGuardianFlag(int no, boolean flag) + { + byte b0 = getValue(FlagType.GUARDIAN_FLAG); + + if (flag) + { + setValue(FlagType.GUARDIAN_FLAG, (byte) (b0 | no)); } - sendData(11); + else + { + setValue(FlagType.GUARDIAN_FLAG, (byte) (b0 & -(no + 1))); + } + + sendData(FlagType.GUARDIAN_FLAG); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/HorseWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/HorseWatcher.java index 3e8fe68d..d3b4d78c 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/HorseWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/HorseWatcher.java @@ -11,6 +11,7 @@ import org.bukkit.inventory.ItemStack; import com.google.common.base.Optional; import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.FlagType; import me.libraryaddict.disguise.utilities.DisguiseUtilities; public class HorseWatcher extends AgeableWatcher @@ -19,13 +20,14 @@ public class HorseWatcher extends AgeableWatcher public HorseWatcher(Disguise disguise) { super(disguise); + setStyle(Style.values()[DisguiseUtilities.random.nextInt(Style.values().length)]); setColor(Color.values()[DisguiseUtilities.random.nextInt(Color.values().length)]); } public Variant getVariant() { - return Variant.values()[(int) getValue(13, 0)]; + return Variant.values()[getValue(FlagType.HORSE_VARIANT)]; } public void setVariant(Variant variant) @@ -39,45 +41,48 @@ public class HorseWatcher extends AgeableWatcher { variant = 0; // Crashing people is mean } - setValue(13, variant); - sendData(13); + + setValue(FlagType.HORSE_VARIANT, variant); + sendData(FlagType.HORSE_VARIANT); } public Color getColor() { - return Color.values()[((Integer) getValue(14, 0) & 0xFF)]; + return Color.values()[((Integer) getValue(FlagType.HORSE_COLOR) & 0xFF)]; } public ItemStack getHorseArmor() { int horseValue = getHorseArmorAsInt(); + switch (horseValue) { case 1: - return new ItemStack(Material.getMaterial("IRON_BARDING")); + return new ItemStack(Material.IRON_BARDING); case 2: - return new ItemStack(Material.getMaterial("GOLD_BARDING")); + return new ItemStack(Material.GOLD_BARDING); case 3: - return new ItemStack(Material.getMaterial("DIAMOND_BARDING")); + return new ItemStack(Material.DIAMOND_BARDING); default: break; } + return null; } protected int getHorseArmorAsInt() { - return (int) getValue(16, 0); + return getValue(FlagType.HORSE_ARMOR); } public Optional getOwner() { - return getValue(15, Optional. absent()); + return getValue(FlagType.HORSE_OWNER); } public Style getStyle() { - return Style.values()[((int) getValue(14, 0) >>> 8)]; + return Style.values()[(getValue(FlagType.HORSE_STYLE) >>> 8)]; } public boolean hasChest() @@ -122,7 +127,7 @@ public class HorseWatcher extends AgeableWatcher private byte getHorseFlag() { - return (byte) getValue(12, (byte) 0); + return getValue(FlagType.HORSE_META); } public void setCanBreed(boolean breed) @@ -137,22 +142,24 @@ public class HorseWatcher extends AgeableWatcher public void setColor(Color color) { - setValue(14, color.ordinal() & 0xFF | getStyle().ordinal() << 8); - sendData(14); + setValue(FlagType.HORSE_COLOR, color.ordinal() & 0xFF | getStyle().ordinal() << 8); + sendData(FlagType.HORSE_COLOR); } private void setHorseFlag(int i, boolean flag) { - byte j = (byte) getValue(12, (byte) 0); + byte j = getValue(FlagType.HORSE_META); + if (flag) { - setValue(12, (byte) (j | i)); + setValue(FlagType.HORSE_META, (byte) (j | i)); } else { - setValue(12, (byte) (j & ~i)); + setValue(FlagType.HORSE_META, (byte) (j & ~i)); } - sendData(12); + + sendData(FlagType.HORSE_META); } public void setGrazing(boolean grazing) @@ -162,16 +169,18 @@ public class HorseWatcher extends AgeableWatcher protected void setHorseArmor(int armor) { - setValue(16, armor); - sendData(16); + setValue(FlagType.HORSE_ARMOR, armor); + sendData(FlagType.HORSE_ARMOR); } public void setHorseArmor(ItemStack item) { int value = 0; + if (item != null) { Material mat = item.getType(); + if (mat == Material.IRON_BARDING) { value = 1; @@ -185,6 +194,7 @@ public class HorseWatcher extends AgeableWatcher value = 3; } } + setHorseArmor(value); } @@ -195,8 +205,8 @@ public class HorseWatcher extends AgeableWatcher public void setOwner(UUID uuid) { - setValue(15, Optional.of(uuid)); - sendData(15); + setValue(FlagType.HORSE_OWNER, Optional.of(uuid)); + sendData(FlagType.HORSE_OWNER); } public void setRearing(boolean rear) @@ -211,8 +221,8 @@ public class HorseWatcher extends AgeableWatcher public void setStyle(Style style) { - setValue(14, getColor().ordinal() & 0xFF | style.ordinal() << 8); - sendData(14); + setValue(FlagType.HORSE_STYLE, getColor().ordinal() & 0xFF | style.ordinal() << 8); + sendData(FlagType.HORSE_STYLE); } public void setTamed(boolean tamed) diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/InsentientWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/InsentientWatcher.java new file mode 100644 index 00000000..928bb35e --- /dev/null +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/InsentientWatcher.java @@ -0,0 +1,63 @@ +package me.libraryaddict.disguise.disguisetypes.watchers; + +import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.FlagType; + +public class InsentientWatcher extends LivingWatcher +{ + public InsentientWatcher(Disguise disguise) + { + super(disguise); + } + + public void setLeftHanded(boolean leftHanded) + { + setRightHanded(!leftHanded); + } + + public void setRightHanded(boolean rightHanded) + { + setInsentientFlag(2, rightHanded); + sendData(FlagType.INSENTIENT_META); + } + + public boolean isRightHanded() + { + return getInsentientFlag(2); + } + + public boolean isLeftHanded() + { + return !isRightHanded(); + } + + public boolean isAI() + { + return getInsentientFlag(1); + } + + public void setAI(boolean ai) + { + setInsentientFlag(1, ai); + sendData(FlagType.INSENTIENT_META); + } + + private void setInsentientFlag(int i, boolean flag) + { + byte b0 = (byte) getValue(FlagType.INSENTIENT_META); + + if (flag) + { + setValue(FlagType.INSENTIENT_META, (byte) (b0 | 1 << i)); + } + else + { + setValue(FlagType.INSENTIENT_META, (byte) (b0 & (~1 << i))); + } + } + + private boolean getInsentientFlag(int i) + { + return ((byte) getValue(FlagType.PLAYER_SKIN) & 1 << i) != 0; + } +} diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/ItemFrameWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/ItemFrameWatcher.java index cccd5881..78ecbeab 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/ItemFrameWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/ItemFrameWatcher.java @@ -1,40 +1,53 @@ package me.libraryaddict.disguise.disguisetypes.watchers; +import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.FlagType; import me.libraryaddict.disguise.disguisetypes.FlagWatcher; -public class ItemFrameWatcher extends FlagWatcher { +public class ItemFrameWatcher extends FlagWatcher +{ - public ItemFrameWatcher(Disguise disguise) { + public ItemFrameWatcher(Disguise disguise) + { super(disguise); } - public ItemStack getItem() { - if (getValue(5, null) == null) { - return new ItemStack(0); + public ItemStack getItem() + { + if (getValue(FlagType.ITEMFRAME_ITEM) == null) + { + return new ItemStack(Material.AIR); } - return (ItemStack) getValue(5, null); + + return (ItemStack) getValue(FlagType.ITEMFRAME_ITEM); } - public int getRotation() { - return (int) getValue(6, 0); + public int getRotation() + { + return getValue(FlagType.ITEMFRAME_ROTATION); } - public void setItem(ItemStack newItem) { - if (newItem == null) { - newItem = new ItemStack(0); + public void setItem(ItemStack newItem) + { + if (newItem == null) + { + newItem = new ItemStack(Material.AIR); } + newItem = newItem.clone(); newItem.setAmount(1); - setValue(5, newItem); - sendData(5); + + setValue(FlagType.ITEMFRAME_ITEM, newItem); + sendData(FlagType.ITEMFRAME_ITEM); } - public void setRotation(int rotation) { - setValue(6, (byte) (rotation % 4)); - sendData(6); + public void setRotation(int rotation) + { + setValue(FlagType.ITEMFRAME_ROTATION, (byte) (rotation % 4)); + sendData(FlagType.ITEMFRAME_ROTATION); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/LivingWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/LivingWatcher.java index b237018c..f18bf354 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/LivingWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/LivingWatcher.java @@ -20,13 +20,13 @@ import com.comphenix.protocol.wrappers.WrappedAttribute.Builder; import me.libraryaddict.disguise.DisguiseAPI; import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.FlagType; import me.libraryaddict.disguise.disguisetypes.FlagWatcher; import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.ReflectionManager; public class LivingWatcher extends FlagWatcher { - static Map list = new HashMap<>(); static Method getId; @@ -36,6 +36,7 @@ public class LivingWatcher extends FlagWatcher { getId = ReflectionManager.getNmsMethod("MobEffectList", "getId", ReflectionManager.getNmsClass("MobEffectList")); Object REGISTRY = ReflectionManager.getNmsField("MobEffectList", "REGISTRY").get(null); + for (Object next : ((Iterable) REGISTRY)) { int id = (int) getId.invoke(null, next); @@ -81,7 +82,7 @@ public class LivingWatcher extends FlagWatcher public float getHealth() { - return (float) getValue(6, 0F); + return (float) getValue(FlagType.LIVING_HEALTH); } public double getMaxHealth() @@ -91,7 +92,7 @@ public class LivingWatcher extends FlagWatcher public boolean isPotionParticlesAmbient() { - return (boolean) getValue(8, false); + return (boolean) getValue(FlagType.LIVING_POTION_AMBIENT); } private int getPotions() @@ -151,31 +152,31 @@ public class LivingWatcher extends FlagWatcher public void setPotionParticlesAmbient(boolean particles) { - setValue(8, particles); - sendData(8); + setValue(FlagType.LIVING_POTION_AMBIENT, particles); + sendData(FlagType.LIVING_POTION_AMBIENT); } private void sendPotionEffects() { - setValue(7, getPotions()); - sendData(7); + setValue(FlagType.LIVING_POTIONS, getPotions()); + sendData(FlagType.LIVING_POTIONS); } public void setHealth(float health) { - setValue(6, health); - sendData(6); + setValue(FlagType.LIVING_HEALTH, health); + sendData(FlagType.LIVING_HEALTH); } public int getArrowsSticking() { - return (int) getValue(9, 0); + return (int) getValue(FlagType.LIVING_ARROWS); } public void setArrowsSticking(int arrowsNo) { - setValue(9, arrowsNo); - sendData(9); + setValue(FlagType.LIVING_ARROWS, arrowsNo); + sendData(FlagType.LIVING_ARROWS); } public void setMaxHealth(double newHealth) diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/MinecartWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/MinecartWatcher.java index c73b911c..091d9120 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/MinecartWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/MinecartWatcher.java @@ -3,6 +3,7 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import org.bukkit.inventory.ItemStack; import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.FlagType; import me.libraryaddict.disguise.disguisetypes.FlagWatcher; public class MinecartWatcher extends FlagWatcher @@ -15,39 +16,42 @@ public class MinecartWatcher extends FlagWatcher public ItemStack getBlockInCart() { - int id = (int) getValue(8, 0) & 0xffff; - int data = (int) getValue(8, 0) >> 16; + int id = (int) getValue(FlagType.MINECART_BLOCK) & 0xffff; + int data = (int) getValue(FlagType.MINECART_BLOCK) >> 16; + return new ItemStack(id, 1, (short) data); } public int getBlockYOffset() { - return (int) getValue(9, 0); + return (int) getValue(FlagType.MINECART_BLOCK_Y); } public boolean isViewBlockInCart() { - return (boolean) getValue(10, false); + return (boolean) getValue(FlagType.MINECART_BLOCK_VISIBLE); } public void setBlockInCart(ItemStack item) { int id = item.getTypeId(); int data = item.getDurability(); - setValue(8, id & 0xffff | data << 16); - setValue(10, true); // Show block - sendData(8, 10); + + setValue(FlagType.MINECART_BLOCK, id & 0xffff | data << 16); + setValue(FlagType.MINECART_BLOCK_VISIBLE, true); // Show block + + sendData(FlagType.MINECART_BLOCK); } public void setBlockOffset(int i) { - setValue(9, i); - sendData(9); + setValue(FlagType.MINECART_BLOCK_Y, i); + sendData(FlagType.MINECART_BLOCK_Y); } public void setViewBlockInCart(boolean viewBlock) { - setValue(10, viewBlock); - sendData(10); + setValue(FlagType.MINECART_BLOCK_VISIBLE, viewBlock); + sendData(FlagType.MINECART_BLOCK_VISIBLE); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/OcelotWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/OcelotWatcher.java index 83a71d1d..c7a7828a 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/OcelotWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/OcelotWatcher.java @@ -4,19 +4,24 @@ import org.bukkit.entity.Ocelot; import org.bukkit.entity.Ocelot.Type; import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.FlagType; -public class OcelotWatcher extends TameableWatcher { +public class OcelotWatcher extends TameableWatcher +{ - public OcelotWatcher(Disguise disguise) { + public OcelotWatcher(Disguise disguise) + { super(disguise); } - public Type getType() { - return Ocelot.Type.getType((int) getValue(14, 0)); + public Type getType() + { + return Ocelot.Type.getType(getValue(FlagType.OCELOT_TYPE)); } - public void setType(Type newType) { - setValue(14, newType.getId()); - sendData(14); + public void setType(Type newType) + { + setValue(FlagType.OCELOT_TYPE, newType.getId()); + sendData(FlagType.OCELOT_TYPE); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/PaintingWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/PaintingWatcher.java index 9d72b060..406794be 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/PaintingWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/PaintingWatcher.java @@ -6,28 +6,36 @@ import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.FlagWatcher; import me.libraryaddict.disguise.utilities.DisguiseUtilities; -public class PaintingWatcher extends FlagWatcher { +public class PaintingWatcher extends FlagWatcher +{ private Art painting; - public PaintingWatcher(Disguise disguise) { + public PaintingWatcher(Disguise disguise) + { super(disguise); } @Override - public PaintingWatcher clone(Disguise disguise) { + public PaintingWatcher clone(Disguise disguise) + { PaintingWatcher watcher = (PaintingWatcher) super.clone(disguise); watcher.setArt(getArt()); + return watcher; } - public Art getArt() { + public Art getArt() + { return painting; } - public void setArt(Art newPainting) { + public void setArt(Art newPainting) + { this.painting = newPainting; - if (getDisguise().getEntity() != null && getDisguise().getWatcher() == this) { + + if (getDisguise().getEntity() != null && getDisguise().getWatcher() == this) + { DisguiseUtilities.refreshTrackers(getDisguise()); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/PigWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/PigWatcher.java index 64e101d3..8e0cbc80 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/PigWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/PigWatcher.java @@ -1,19 +1,24 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.FlagType; -public class PigWatcher extends AgeableWatcher { +public class PigWatcher extends AgeableWatcher +{ - public PigWatcher(Disguise disguise) { + public PigWatcher(Disguise disguise) + { super(disguise); } - public boolean isSaddled() { - return (boolean) getValue(12, false); + public boolean isSaddled() + { + return (boolean) getValue(FlagType.PIG_SADDLED); } - public void setSaddled(boolean isSaddled) { - setValue(12, isSaddled); - sendData(12); + public void setSaddled(boolean isSaddled) + { + setValue(FlagType.PIG_SADDLED, isSaddled); + sendData(FlagType.PIG_SADDLED); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/PlayerWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/PlayerWatcher.java index e3e64229..7d94c56a 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/PlayerWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/PlayerWatcher.java @@ -12,6 +12,7 @@ import com.comphenix.protocol.wrappers.WrappedGameProfile; import me.libraryaddict.disguise.DisguiseAPI; import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.FlagType; import me.libraryaddict.disguise.disguisetypes.PlayerDisguise; import me.libraryaddict.disguise.utilities.DisguiseUtilities; @@ -60,7 +61,7 @@ public class PlayerWatcher extends LivingWatcher private boolean isSkinFlag(int i) { - return ((byte) getValue(12, (byte) 0) & 1 << i) != 0; + return ((byte) getValue(FlagType.PLAYER_SKIN) & 1 << i) != 0; } public boolean isCapeEnabled() @@ -101,43 +102,50 @@ public class PlayerWatcher extends LivingWatcher public void setCapeEnabled(boolean enabled) { setSkinFlags(1, enabled); - sendData(12); + + sendData(FlagType.PLAYER_SKIN); } public void setJackedEnabled(boolean enabled) { setSkinFlags(2, enabled); - sendData(12); + + sendData(FlagType.PLAYER_SKIN); } public void setLeftSleeveEnabled(boolean enabled) { setSkinFlags(3, enabled); - sendData(12); + + sendData(FlagType.PLAYER_SKIN); } public void setRightSleeveEnabled(boolean enabled) { setSkinFlags(4, enabled); - sendData(12); + + sendData(FlagType.PLAYER_SKIN); } public void setLeftPantsEnabled(boolean enabled) { setSkinFlags(5, enabled); - sendData(12); + + sendData(FlagType.PLAYER_SKIN); } public void setRightPantsEnabled(boolean enabled) { setSkinFlags(6, enabled); - sendData(12); + + sendData(FlagType.PLAYER_SKIN); } public void setHatEnabled(boolean enabled) { setSkinFlags(7, enabled); - sendData(12); + + sendData(FlagType.PLAYER_SKIN); } public boolean isSleeping() @@ -232,14 +240,15 @@ public class PlayerWatcher extends LivingWatcher private void setSkinFlags(int i, boolean flag) { - byte b0 = (byte) getValue(12, (byte) 0); + byte b0 = (byte) getValue(FlagType.PLAYER_SKIN); + if (flag) { - setValue(12, (byte) (b0 | 1 << i)); + setValue(FlagType.PLAYER_SKIN, (byte) (b0 | 1 << i)); } else { - setValue(12, (byte) (b0 & (~1 << i))); + setValue(FlagType.PLAYER_SKIN, (byte) (b0 & (~1 << i))); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/RabbitWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/RabbitWatcher.java index bf497cde..1415db11 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/RabbitWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/RabbitWatcher.java @@ -1,23 +1,28 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.FlagType; import me.libraryaddict.disguise.disguisetypes.RabbitType; import me.libraryaddict.disguise.utilities.DisguiseUtilities; -public class RabbitWatcher extends AgeableWatcher { +public class RabbitWatcher extends AgeableWatcher +{ - public RabbitWatcher(Disguise disguise) { + public RabbitWatcher(Disguise disguise) + { super(disguise); setType(RabbitType.values()[DisguiseUtilities.random.nextInt(RabbitType.values().length)]); } - public RabbitType getType() { - return RabbitType.getType((int) getValue(18, 0)); + public RabbitType getType() + { + return RabbitType.getType((int) getValue(FlagType.RABBIT_TYPE)); } - public void setType(RabbitType type) { - setValue(12, type.getTypeId()); - sendData(12); + public void setType(RabbitType type) + { + setValue(FlagType.RABBIT_TYPE, type.getTypeId()); + sendData(FlagType.RABBIT_TYPE); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/SheepWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/SheepWatcher.java index 204ef3c3..63b44789 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/SheepWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/SheepWatcher.java @@ -4,39 +4,54 @@ import org.bukkit.DyeColor; import me.libraryaddict.disguise.disguisetypes.AnimalColor; import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.FlagType; -public class SheepWatcher extends AgeableWatcher { +public class SheepWatcher extends AgeableWatcher +{ - public SheepWatcher(Disguise disguise) { + public SheepWatcher(Disguise disguise) + { super(disguise); - setValue(12, (byte) 0); + + setValue(FlagType.SHEEP_WOOL, (byte) 0); } - public AnimalColor getColor() { - return AnimalColor.getColor(((int) getValue(12, (byte) 0) & 15)); + public AnimalColor getColor() + { + return AnimalColor.getColor(((int) getValue(FlagType.SHEEP_WOOL) & 15)); } - public boolean isSheared() { - return ((byte) getValue(12, (byte) 0) & 16) != 0; + public boolean isSheared() + { + return ((byte) getValue(FlagType.SHEEP_WOOL) & 16) != 0; } - public void setColor(AnimalColor color) { + public void setColor(AnimalColor color) + { setColor(DyeColor.getByWoolData((byte) color.getId())); } - public void setColor(DyeColor color) { - byte b0 = (byte) getValue(12, (byte) 0); - setValue(12, (byte) (b0 & 240 | color.getWoolData() & 15)); - sendData(12); + public void setColor(DyeColor color) + { + byte b0 = (byte) getValue(FlagType.SHEEP_WOOL); + + setValue(FlagType.SHEEP_WOOL, (byte) (b0 & 240 | color.getWoolData() & 15)); + sendData(FlagType.SHEEP_WOOL); } - public void setSheared(boolean flag) { - byte b0 = (byte) getValue(12, (byte) 0); - if (flag) { - setValue(12, (byte) (b0 | 16)); - } else { - setValue(12, (byte) (b0 & -17)); + public void setSheared(boolean flag) + { + byte b0 = (byte) getValue(FlagType.SHEEP_WOOL); + + if (flag) + { + setValue(FlagType.SHEEP_WOOL, (byte) (b0 | 16)); } - sendData(12); + else + { + setValue(FlagType.SHEEP_WOOL, (byte) (b0 & -17)); + } + + sendData(FlagType.SHEEP_WOOL); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/ShulkerWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/ShulkerWatcher.java index a5e7fb5a..39aa5fbb 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/ShulkerWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/ShulkerWatcher.java @@ -10,34 +10,42 @@ import me.libraryaddict.disguise.disguisetypes.Disguise; /** * @author Navid */ -//TODO: Add the appropriate data values to this class -public class ShulkerWatcher extends LivingWatcher { +// TODO: Add the appropriate data values to this class +public class ShulkerWatcher extends LivingWatcher +{ - public ShulkerWatcher(Disguise disguise) { + public ShulkerWatcher(Disguise disguise) + { super(disguise); } - public BlockFace getFacingDirection() { + public BlockFace getFacingDirection() + { return BlockFace.UP; } - public void setFacingDirection() { + public void setFacingDirection() + { } - public Optional getAttachmentPosition() { + public Optional getAttachmentPosition() + { return Optional.absent(); } - public void setAttachmentPosition(BlockPosition pos) { + public void setAttachmentPosition(BlockPosition pos) + { } - public byte getShieldHeight() { + public byte getShieldHeight() + { return 0x00; } - public void setShieldHeight() { + public void setShieldHeight() + { } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/SkeletonWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/SkeletonWatcher.java index 26910584..b0c9a666 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/SkeletonWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/SkeletonWatcher.java @@ -3,22 +3,26 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import org.bukkit.entity.Skeleton.SkeletonType; import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.FlagType; /** * @author Navid */ -public class SkeletonWatcher extends LivingWatcher { - - public SkeletonWatcher(Disguise disguise) { +public class SkeletonWatcher extends LivingWatcher +{ + public SkeletonWatcher(Disguise disguise) + { super(disguise); } - public void setType(SkeletonType type) { - setValue(11, type.getId()); - sendData(11); + public void setType(SkeletonType type) + { + setValue(FlagType.SKELETON_TYPE, type.ordinal()); + sendData(FlagType.SKELETON_TYPE); } - public SkeletonType getType() { - return SkeletonType.getType((int) getValue(11, SkeletonType.NORMAL.getId())); + public SkeletonType getType() + { + return SkeletonType.values()[getValue(FlagType.SKELETON_TYPE)]; } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/SlimeWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/SlimeWatcher.java index feb70c58..6d45fb8c 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/SlimeWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/SlimeWatcher.java @@ -1,25 +1,32 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.FlagType; import me.libraryaddict.disguise.utilities.DisguiseUtilities; -public class SlimeWatcher extends LivingWatcher { +public class SlimeWatcher extends LivingWatcher +{ - public SlimeWatcher(Disguise disguise) { + public SlimeWatcher(Disguise disguise) + { super(disguise); setSize(DisguiseUtilities.random.nextInt(4) + 1); } - public int getSize() { - return (int) getValue(11, 1); + public int getSize() + { + return (int) getValue(FlagType.SLIME_SIZE); } - public void setSize(int size) { - if (size <= 0 || size >= 128) { + public void setSize(int size) + { + if (size <= 0 || size >= 128) + { size = 1; } - setValue(11, size); - sendData(11); + + setValue(FlagType.SLIME_SIZE, size); + sendData(FlagType.SLIME_SIZE); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/SplashPotionWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/SplashPotionWatcher.java index 09c28318..481c883e 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/SplashPotionWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/SplashPotionWatcher.java @@ -4,28 +4,35 @@ import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.FlagWatcher; import me.libraryaddict.disguise.utilities.DisguiseUtilities; -public class SplashPotionWatcher extends FlagWatcher { - +public class SplashPotionWatcher extends FlagWatcher +{ private int potionId; - public SplashPotionWatcher(Disguise disguise) { + public SplashPotionWatcher(Disguise disguise) + { super(disguise); } @Override - public SplashPotionWatcher clone(Disguise disguise) { + public SplashPotionWatcher clone(Disguise disguise) + { SplashPotionWatcher watcher = (SplashPotionWatcher) super.clone(disguise); watcher.setPotionId(getPotionId()); + return watcher; } - public int getPotionId() { + public int getPotionId() + { return potionId; } - public void setPotionId(int newPotionId) { + public void setPotionId(int newPotionId) + { this.potionId = newPotionId; - if (getDisguise().getEntity() != null && getDisguise().getWatcher() == this) { + + if (getDisguise().getEntity() != null && getDisguise().getWatcher() == this) + { DisguiseUtilities.refreshTrackers(getDisguise()); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/TameableWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/TameableWatcher.java index 1135d890..76643235 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/TameableWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/TameableWatcher.java @@ -5,10 +5,10 @@ import java.util.UUID; import com.google.common.base.Optional; import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.FlagType; public class TameableWatcher extends AgeableWatcher { - public TameableWatcher(Disguise disguise) { super(disguise); @@ -16,7 +16,7 @@ public class TameableWatcher extends AgeableWatcher public Optional getOwner() { - return getValue(13, Optional. absent()); + return getValue(FlagType.TAMEABLE_OWNER); } public boolean isSitting() @@ -31,27 +31,29 @@ public class TameableWatcher extends AgeableWatcher protected boolean isTameableFlag(int no) { - return ((byte) getValue(12, (byte) 0) & no) != 0; + return ((byte) getValue(FlagType.TAMEABLE_META) & no) != 0; } protected void setTameableFlag(int no, boolean flag) { - byte value = (byte) getValue(12, (byte) 0); + byte value = (byte) getValue(FlagType.TAMEABLE_META); + if (flag) { - setValue(12, (byte) (value | no)); + setValue(FlagType.TAMEABLE_META, (byte) (value | no)); } else { - setValue(12, (byte) (value & -(no + 1))); + setValue(FlagType.TAMEABLE_META, (byte) (value & -(no + 1))); } - sendData(12); + + sendData(FlagType.TAMEABLE_META); } public void setOwner(UUID owner) { - setValue(13, Optional.of(owner)); - sendData(13); + setValue(FlagType.TAMEABLE_OWNER, Optional.of(owner)); + sendData(FlagType.TAMEABLE_OWNER); } public void setSitting(boolean sitting) diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/TippedArrowWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/TippedArrowWatcher.java index 121e5fb0..2f2a5e6b 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/TippedArrowWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/TippedArrowWatcher.java @@ -3,28 +3,35 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import org.bukkit.Color; import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.FlagType; import me.libraryaddict.disguise.utilities.DisguiseUtilities; /** * @author Navid */ -public class TippedArrowWatcher extends ArrowWatcher { +public class TippedArrowWatcher extends ArrowWatcher +{ - public TippedArrowWatcher(Disguise disguise) { + public TippedArrowWatcher(Disguise disguise) + { super(disguise); + int r = DisguiseUtilities.random.nextInt(256); int g = DisguiseUtilities.random.nextInt(256); int b = DisguiseUtilities.random.nextInt(256); + setColor(Color.fromRGB(r, g, b)); } - public Color getColor() { - int color = (int) getValue(5, Color.WHITE.asRGB()); + public Color getColor() + { + int color = (int) getValue(FlagType.TIPPED_ARROW_COLOR); return Color.fromRGB(color); } - public void setColor(Color color) { - setValue(5, color.asRGB()); - sendData(5); + public void setColor(Color color) + { + setValue(FlagType.TIPPED_ARROW_COLOR, color.asRGB()); + sendData(FlagType.TIPPED_ARROW_COLOR); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/VillagerWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/VillagerWatcher.java index 96ab0f89..d982d3af 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/VillagerWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/VillagerWatcher.java @@ -3,25 +3,31 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import org.bukkit.entity.Villager.Profession; import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.FlagType; import me.libraryaddict.disguise.utilities.DisguiseUtilities; -public class VillagerWatcher extends AgeableWatcher { +public class VillagerWatcher extends AgeableWatcher +{ - public VillagerWatcher(Disguise disguise) { + public VillagerWatcher(Disguise disguise) + { super(disguise); setProfession(Profession.values()[DisguiseUtilities.random.nextInt(Profession.values().length)]); } - public Profession getProfession() { - return Profession.getProfession((int) getValue(16, 0)); + public Profession getProfession() + { + return Profession.values()[getValue(FlagType.VILLAGER_PROFESSION)]; } - public void setProfession(int professionId) { - setValue(12, professionId); - sendData(12); + public void setProfession(int professionId) + { + setValue(FlagType.VILLAGER_PROFESSION, professionId); + sendData(FlagType.VILLAGER_PROFESSION); } - public void setProfession(Profession newProfession) { - setProfession(newProfession.getId()); + public void setProfession(Profession newProfession) + { + setProfession(newProfession.ordinal()); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/WitchWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/WitchWatcher.java index 4dd4f491..955b0f9c 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/WitchWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/WitchWatcher.java @@ -1,24 +1,28 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.FlagType; /** * @author Navid */ -public class WitchWatcher extends LivingWatcher { +public class WitchWatcher extends LivingWatcher +{ - public WitchWatcher(Disguise disguise) { + public WitchWatcher(Disguise disguise) + { super(disguise); } - - public boolean isAggressive() { - return (boolean) getValue(11, false); + public boolean isAggressive() + { + return (boolean) getValue(FlagType.WITCH_AGGRESSIVE); } - public void setAggressive(boolean aggressive) { - setValue(11, aggressive); - sendData(11); + public void setAggressive(boolean aggressive) + { + setValue(FlagType.WITCH_AGGRESSIVE, aggressive); + sendData(FlagType.WITCH_AGGRESSIVE); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/WitherSkullWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/WitherSkullWatcher.java index 2c39a5ae..26d84d32 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/WitherSkullWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/WitherSkullWatcher.java @@ -1,21 +1,26 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.FlagType; import me.libraryaddict.disguise.disguisetypes.FlagWatcher; -public class WitherSkullWatcher extends FlagWatcher { +public class WitherSkullWatcher extends FlagWatcher +{ - public WitherSkullWatcher(Disguise disguise) { + public WitherSkullWatcher(Disguise disguise) + { super(disguise); } - public boolean isBlue() { - return (boolean) getValue(5, false); + public boolean isBlue() + { + return (boolean) getValue(FlagType.WITHERSKULL_BLUE); } - public void setBlue(boolean blue) { - setValue(5, blue); - sendData(5); + public void setBlue(boolean blue) + { + setValue(FlagType.WITHERSKULL_BLUE, blue); + sendData(FlagType.WITHERSKULL_BLUE); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/WitherWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/WitherWatcher.java index 3414f15e..61505d33 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/WitherWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/WitherWatcher.java @@ -5,42 +5,54 @@ import java.security.InvalidParameterException; import org.bukkit.ChatColor; import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.FlagType; -public class WitherWatcher extends LivingWatcher { +public class WitherWatcher extends LivingWatcher +{ - public WitherWatcher(Disguise disguise) { + public WitherWatcher(Disguise disguise) + { super(disguise); } /** * Returns the amount of time this Wither is invulnerable for + * * @return */ - public int getInvulnerability() { - return (int) getValue(14, 0); + public int getInvulnerability() + { + return (int) getValue(FlagType.WITHER_INVUL); } - public int[] getTargets() { - return new int[]{(Integer) getValue(11, 0), (Integer) getValue(12, 0), (Integer) getValue(13, 0)}; + public int[] getTargets() + { + return new int[] + { + getValue(FlagType.WITHER_TARGET_1), getValue(FlagType.WITHER_TARGET_2), getValue(FlagType.WITHER_TARGET_3) + }; } /** * Sets the amount of time this Wither is invulnerable for */ - public void setInvulnerability(int invulnerability) { - setValue(14, invulnerability); - sendData(14); + public void setInvulnerability(int invulnerability) + { + setValue(FlagType.WITHER_INVUL, invulnerability); + sendData(FlagType.WITHER_INVUL); } - public void setTargets(int... targets) { - if (targets.length != 3) { - throw new InvalidParameterException(ChatColor.RED + "Expected 3 numbers for wither setTargets. Received " - + targets.length); + public void setTargets(int... targets) + { + if (targets.length != 3) + { + throw new InvalidParameterException( + ChatColor.RED + "Expected 3 numbers for wither setTargets. Received " + targets.length); } - setValue(11, targets[0]); - setValue(12, targets[1]); - setValue(13, targets[2]); - sendData(11, 12, 13); + setValue(FlagType.WITHER_TARGET_1, targets[0]); + setValue(FlagType.WITHER_TARGET_2, targets[1]); + setValue(FlagType.WITHER_TARGET_3, targets[2]); + sendData(FlagType.WITHER_TARGET_1, FlagType.WITHER_TARGET_2, FlagType.WITHER_TARGET_3); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/WolfWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/WolfWatcher.java index b881df27..8a7689e8 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/WolfWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/WolfWatcher.java @@ -4,63 +4,82 @@ import org.bukkit.DyeColor; import me.libraryaddict.disguise.disguisetypes.AnimalColor; import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.FlagType; -public class WolfWatcher extends TameableWatcher { +public class WolfWatcher extends TameableWatcher +{ - public WolfWatcher(Disguise disguise) { + public WolfWatcher(Disguise disguise) + { super(disguise); } - public AnimalColor getCollarColor() { - return AnimalColor.getColor((int) getValue(16, 14)); + public AnimalColor getCollarColor() + { + return AnimalColor.getColor(getValue(FlagType.WOLF_COLLAR)); } /** * Used for tail rotation. + * * @return */ - public float getDamageTaken() { - return (float) getValue(14, 0); + public float getDamageTaken() + { + return (float) getValue(FlagType.WOLF_DAMAGE); } /** * Used for tail rotation. + * * @param damage */ - public void setDamageTaken(float damage) { - setValue(14, damage); - sendData(14); + public void setDamageTaken(float damage) + { + setValue(FlagType.WOLF_DAMAGE, damage); + sendData(FlagType.WOLF_DAMAGE); } - public boolean isBegging() { - return (boolean) getValue(15, false); + public boolean isBegging() + { + return (boolean) getValue(FlagType.WOLF_BEGGING); } - public void setBegging(boolean begging) { - setValue(15, begging); - sendData(15); + public void setBegging(boolean begging) + { + setValue(FlagType.WOLF_BEGGING, begging); + sendData(FlagType.WOLF_BEGGING); } - public boolean isAngry() { + public boolean isAngry() + { return isTameableFlag(2); } - public void setAngry(boolean angry) { + public void setAngry(boolean angry) + { setTameableFlag(2, angry); } - public void setCollarColor(AnimalColor color) { + public void setCollarColor(AnimalColor color) + { setCollarColor(DyeColor.getByWoolData((byte) color.getId())); } - public void setCollarColor(DyeColor newColor) { - if (!isTamed()) { + public void setCollarColor(DyeColor newColor) + { + if (!isTamed()) + { setTamed(true); } - if (newColor.getWoolData() != getCollarColor().getId()) { - setValue(16, (int) newColor.getDyeData()); - sendData(16); + + if (newColor.getWoolData() == getCollarColor().getId()) + { + return; } + + setValue(FlagType.WOLF_COLLAR, (int) newColor.getDyeData()); + sendData(FlagType.WOLF_COLLAR); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/ZombieWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/ZombieWatcher.java index 039db9ea..4ee741ab 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/ZombieWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/ZombieWatcher.java @@ -3,87 +3,104 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import org.bukkit.entity.Villager.Profession; import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.FlagType; -public class ZombieWatcher extends LivingWatcher { +public class ZombieWatcher extends LivingWatcher +{ - public ZombieWatcher(Disguise disguise) { + public ZombieWatcher(Disguise disguise) + { super(disguise); } - public boolean isAdult() { + public boolean isAdult() + { return !isBaby(); } - public boolean isBaby() { - return (boolean) getValue(11, false); + public boolean isBaby() + { + return getValue(FlagType.ZOMBIE_BABY); } - public boolean isShaking() { - return (boolean) getValue(14, false); + public boolean isShaking() + { + return getValue(FlagType.ZOMBIE_SHAKING); } /** * Is this zombie a villager? + * * @return */ - public boolean isVillager() { - return ((int)getValue(12, 0)) != 0; + public boolean isVillager() + { + return ((int) getValue(FlagType.ZOMBIE_PROFESSION)) != 0; } - public boolean isAggressive() { - return (boolean) getValue(14, false); + public boolean isAggressive() + { + return (boolean) getValue(FlagType.ZOMBIE_AGGRESSIVE); } /** - * Only returns a valid value if this zombie - * is a villager. + * Only returns a valid value if this zombie is a villager. + * * @return */ - public Profession getProfession() { - return Profession.getProfession((int) getValue(12, 0)); + public Profession getProfession() + { + return Profession.values()[getValue(FlagType.ZOMBIE_PROFESSION)]; } - public void setAdult() { + public void setAdult() + { setBaby(false); } - public void setBaby() { + public void setBaby() + { setBaby(true); } - public void setBaby(boolean baby) { - setValue(11, baby); - sendData(11); + public void setBaby(boolean baby) + { + setValue(FlagType.ZOMBIE_BABY, baby); + sendData(FlagType.ZOMBIE_BABY); } - public void setShaking(boolean shaking) { - setValue(13, (byte) (shaking ? 1 : 0)); - sendData(13); + public void setShaking(boolean shaking) + { + setValue(FlagType.ZOMBIE_SHAKING, shaking); + sendData(FlagType.ZOMBIE_SHAKING); } /** - * Sets the profession of this zombie, in turn - * turning it into a Zombie Villager + * Sets the profession of this zombie, in turn turning it into a Zombie Villager + * * @param id */ - public void setProfession(int id) { - setValue(12, id); - sendData(12); + public void setProfession(int id) + { + setValue(FlagType.ZOMBIE_PROFESSION, id); + sendData(FlagType.ZOMBIE_PROFESSION); } /** - * Sets the profession of this zombie, in turn - * turning it into a Zombie Villager + * Sets the profession of this zombie, in turn turning it into a Zombie Villager + * * @param profession */ - public void setProfession(Profession profession) { - setValue(12, profession.getId()); - sendData(12); + public void setProfession(Profession profession) + { + setValue(FlagType.ZOMBIE_PROFESSION, profession.ordinal()); + sendData(FlagType.ZOMBIE_PROFESSION); } - public void setAggressive(boolean handsup) { - setValue(14, handsup); - sendData(14); + public void setAggressive(boolean handsup) + { + setValue(FlagType.ZOMBIE_AGGRESSIVE, handsup); + sendData(FlagType.ZOMBIE_AGGRESSIVE); } } diff --git a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index b8ad744c..489bb13b 100644 --- a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -57,7 +57,6 @@ import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher; public class DisguiseUtilities { - public static final Random random = new Random(); /** * This is a list of names which was called by other plugins. As such, don't remove from the gameProfiles as its the duty of @@ -359,30 +358,30 @@ public class DisguiseUtilities { Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(disguise.getEntity()); - if (entityTrackerEntry != null) - { - Set trackedPlayers = (Set) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers") - .get(entityTrackerEntry); + if (entityTrackerEntry == null) + return; - // If the tracker exists. Remove himself from his tracker - trackedPlayers = (Set) new HashSet(trackedPlayers).clone(); // Copy before iterating to prevent - // ConcurrentModificationException + Set trackedPlayers = (Set) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers") + .get(entityTrackerEntry); - PacketContainer destroyPacket = new PacketContainer(Server.ENTITY_DESTROY); + // If the tracker exists. Remove himself from his tracker + trackedPlayers = (Set) new HashSet(trackedPlayers).clone(); // Copy before iterating to prevent + // ConcurrentModificationException - destroyPacket.getIntegerArrays().write(0, new int[] - { - disguise.getEntity().getEntityId() - }); + PacketContainer destroyPacket = new PacketContainer(Server.ENTITY_DESTROY); - for (Object p : trackedPlayers) + destroyPacket.getIntegerArrays().write(0, new int[] { - Player player = (Player) ReflectionManager.getBukkitEntity(p); + disguise.getEntity().getEntityId() + }); - if (player == disguise.getEntity() || disguise.canSee(player)) - { - ProtocolLibrary.getProtocolManager().sendServerPacket(player, destroyPacket); - } + for (Object p : trackedPlayers) + { + Player player = (Player) ReflectionManager.getBukkitEntity(p); + + if (player == disguise.getEntity() || disguise.canSee(player)) + { + ProtocolLibrary.getProtocolManager().sendServerPacket(player, destroyPacket); } } } @@ -664,6 +663,7 @@ public class DisguiseUtilities for (Object p : trackedPlayers) { Player player = (Player) ReflectionManager.getBukkitEntity(p); + if (((TargetedDisguise) disguise).canSee(player)) { players.add(player); @@ -919,48 +919,48 @@ public class DisguiseUtilities { final Object entityTrackerEntry = ReflectionManager.getEntityTrackerEntry(disguise.getEntity()); - if (entityTrackerEntry != null) + if (entityTrackerEntry == null) + return; + + Set trackedPlayers = (Set) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers") + .get(entityTrackerEntry); + + Method clear = ReflectionManager.getNmsMethod("EntityTrackerEntry", "clear", + ReflectionManager.getNmsClass("EntityPlayer")); + + final Method updatePlayer = ReflectionManager.getNmsMethod("EntityTrackerEntry", "updatePlayer", + ReflectionManager.getNmsClass("EntityPlayer")); + + trackedPlayers = (Set) new HashSet(trackedPlayers).clone(); // Copy before iterating to prevent + // ConcurrentModificationException + for (final Object p : trackedPlayers) { - Set trackedPlayers = (Set) ReflectionManager.getNmsField("EntityTrackerEntry", "trackedPlayers") - .get(entityTrackerEntry); + Player pl = (Player) ReflectionManager.getBukkitEntity(p); - Method clear = ReflectionManager.getNmsMethod("EntityTrackerEntry", "clear", - ReflectionManager.getNmsClass("EntityPlayer")); + if (!player.equalsIgnoreCase((pl).getName())) + continue; - final Method updatePlayer = ReflectionManager.getNmsMethod("EntityTrackerEntry", "updatePlayer", - ReflectionManager.getNmsClass("EntityPlayer")); + clear.invoke(entityTrackerEntry, p); - trackedPlayers = (Set) new HashSet(trackedPlayers).clone(); // Copy before iterating to prevent - // ConcurrentModificationException - for (final Object p : trackedPlayers) + ProtocolLibrary.getProtocolManager().sendServerPacket(pl, destroyPacket); + + Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() { - Player pl = (Player) ReflectionManager.getBukkitEntity(p); - if (player.equalsIgnoreCase((pl).getName())) + @Override + public void run() { - clear.invoke(entityTrackerEntry, p); - - ProtocolLibrary.getProtocolManager().sendServerPacket(pl, destroyPacket); - - Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() + try { - - @Override - public void run() - { - try - { - updatePlayer.invoke(entityTrackerEntry, p); - } - catch (Exception ex) - { - ex.printStackTrace(System.out); - } - } - }, 2); - break; + updatePlayer.invoke(entityTrackerEntry, p); + } + catch (Exception ex) + { + ex.printStackTrace(System.out); + } } - } + }, 2); + break; } } } diff --git a/src/me/libraryaddict/disguise/utilities/DisguiseValues.java b/src/me/libraryaddict/disguise/utilities/DisguiseValues.java index 338cae2e..4279dce5 100644 --- a/src/me/libraryaddict/disguise/utilities/DisguiseValues.java +++ b/src/me/libraryaddict/disguise/utilities/DisguiseValues.java @@ -3,6 +3,7 @@ package me.libraryaddict.disguise.utilities; import java.util.HashMap; import me.libraryaddict.disguise.disguisetypes.DisguiseType; +import me.libraryaddict.disguise.disguisetypes.FlagType; public class DisguiseValues { @@ -39,7 +40,7 @@ public class DisguiseValues return values.get(type); } - public static HashMap getMetaValues(DisguiseType type) + public static HashMap getMetaValues(DisguiseType type) { return getDisguiseValues(type).getMetaValues(); } @@ -53,7 +54,7 @@ public class DisguiseValues private FakeBoundingBox babyBox; private float[] entitySize; private double maxHealth; - private HashMap metaValues = new HashMap<>(); + private HashMap metaValues = new HashMap<>(); private Class nmsEntityClass; public DisguiseValues(DisguiseType type, Class classType, int entitySize, double maxHealth) @@ -83,7 +84,7 @@ public class DisguiseValues return maxHealth; } - public HashMap getMetaValues() + public HashMap getMetaValues() { return metaValues; } @@ -108,7 +109,7 @@ public class DisguiseValues this.entitySize = size; } - public void setMetaValue(int id, Object value) + public void setMetaValue(FlagType id, Object value) { metaValues.put(id, value); }