From 126a7a4a6a46a731405dfcfbfa22ed9624a38eb7 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sun, 27 Nov 2016 04:36:57 +1300 Subject: [PATCH] Fix disguises and stuff --- .../libraryaddict/disguise/LibsDisguises.java | 13 +- .../disguise/disguisetypes/Disguise.java | 26 -- .../disguise/disguisetypes/DisguiseType.java | 53 +-- .../disguise/disguisetypes/FlagType.java | 49 ++- .../disguise/disguisetypes/FlagWatcher.java | 329 ++++++------------ .../watchers/AreaEffectCloudWatcher.java | 36 +- .../watchers/DroppedItemWatcher.java | 18 +- .../watchers/EnderDragonWatcher.java | 6 +- .../watchers/FireworkWatcher.java | 24 +- .../watchers/FishingHookWatcher.java | 6 +- .../watchers/GuardianWatcher.java | 61 +--- .../watchers/HorseChestedWatcher.java | 6 +- .../watchers/ItemFrameWatcher.java | 30 +- .../watchers/SkeletonWatcher.java | 25 +- .../watchers/SplashPotionWatcher.java | 30 +- .../watchers/WitherSkullWatcher.java | 6 +- .../watchers/ZombieVillagerWatcher.java | 61 ++++ .../disguisetypes/watchers/ZombieWatcher.java | 82 +---- .../disguise/utilities/DisguiseValues.java | 42 +-- .../disguise/utilities/PacketsManager.java | 15 + .../disguise/utilities/ReflectionManager.java | 16 +- .../PacketListenerViewDisguises.java | 84 ++--- 22 files changed, 373 insertions(+), 645 deletions(-) create mode 100644 src/me/libraryaddict/disguise/disguisetypes/watchers/ZombieVillagerWatcher.java diff --git a/src/me/libraryaddict/disguise/LibsDisguises.java b/src/me/libraryaddict/disguise/LibsDisguises.java index 81780e35..8ce446b4 100644 --- a/src/me/libraryaddict/disguise/LibsDisguises.java +++ b/src/me/libraryaddict/disguise/LibsDisguises.java @@ -225,7 +225,7 @@ public class LibsDisguises extends JavaPlugin { case ZOMBIE_VILLAGER: case DONKEY: case MULE: - case UNDEAD_HORSE: + case ZOMBIE_HORSE: case SKELETON_HORSE: case STRAY: case HUSK: @@ -319,6 +319,17 @@ public class LibsDisguises extends JavaPlugin { System.err.println("Lib's Disguises will continue to load, but this will not work properly!"); continue; } + + if (ReflectionManager.convertInvalidItem(flagType.getDefault()).getClass() != ReflectionManager + .convertInvalidItem(watch.getValue()).getClass()) { + System.err.println("Mismatch of FlagType's for " + disguiseType.name() + "! Index " + watch.getIndex() + + " has the wrong classtype!"); + System.err.println("Value is " + watch.getRawValue() + " (" + watch.getRawValue().getClass() + ") (" + + nmsEntity.getClass() + ") & " + watcherClass.getSimpleName() + " which doesn't match up with " + + flagType.getDefault().getClass()); + System.err.println("Lib's Disguises will continue to load, but this will not work properly!"); + continue; + } } DisguiseSound sound = DisguiseSound.getType(disguiseType.name()); diff --git a/src/me/libraryaddict/disguise/disguisetypes/Disguise.java b/src/me/libraryaddict/disguise/disguisetypes/Disguise.java index 2dd42c97..15d7b980 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/Disguise.java +++ b/src/me/libraryaddict/disguise/disguisetypes/Disguise.java @@ -13,8 +13,6 @@ import org.bukkit.Location; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; -import org.bukkit.entity.Skeleton.SkeletonType; -import org.bukkit.entity.Villager.Profession; import org.bukkit.scheduler.BukkitTask; import org.bukkit.util.Vector; @@ -29,8 +27,6 @@ import me.libraryaddict.disguise.LibsDisguises; import me.libraryaddict.disguise.disguisetypes.TargetedDisguise.TargetType; import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.BatWatcher; -import me.libraryaddict.disguise.disguisetypes.watchers.GuardianWatcher; -import me.libraryaddict.disguise.disguisetypes.watchers.SkeletonWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher; import me.libraryaddict.disguise.events.DisguiseEvent; import me.libraryaddict.disguise.events.UndisguiseEvent; @@ -106,28 +102,6 @@ public abstract class Disguise { } } - // If the disguise type is a wither, set the flagwatcher value for the skeleton to a wither skeleton - if (getType() == DisguiseType.WITHER_SKELETON) { - ((SkeletonWatcher) getWatcher()).setType(SkeletonType.WITHER); - } - else if (getType() == DisguiseType.STRAY) { - ((SkeletonWatcher) getWatcher()).setType(SkeletonType.STRAY); - } // Else if its a zombie, but the disguise type is a zombie villager. Set the value. - else if (getType() == DisguiseType.ZOMBIE_VILLAGER) { - Profession profession = null; - - while (profession == null || profession == Profession.NORMAL || profession == Profession.HUSK) - profession = Profession.values()[DisguiseUtilities.random.nextInt(Profession.values().length)]; - - ((ZombieWatcher) getWatcher()).setProfession(profession); - } - else if (getType() == DisguiseType.HUSK) { - ((ZombieWatcher) getWatcher()).setProfession(Profession.HUSK); - } - else if (getType() == DisguiseType.ELDER_GUARDIAN) { - ((GuardianWatcher) getWatcher()).setElder(true); - } - final boolean alwaysSendVelocity; switch (getType()) { diff --git a/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java b/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java index a86664be..55f84eb2 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java +++ b/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java @@ -3,11 +3,6 @@ package me.libraryaddict.disguise.disguisetypes; import org.apache.commons.lang.StringUtils; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; -import org.bukkit.entity.Guardian; -import org.bukkit.entity.Horse; -import org.bukkit.entity.Skeleton; -import org.bukkit.entity.Skeleton.SkeletonType; -import org.bukkit.entity.Zombie; public enum DisguiseType { AREA_EFFECT_CLOUD(3, 0), @@ -154,9 +149,9 @@ public enum DisguiseType { THROWN_EXP_BOTTLE(75), - TIPPED_ARROW(92), + TIPPED_ARROW(60), - UNDEAD_HORSE, + ZOMBIE_HORSE, UNKNOWN, @@ -190,7 +185,7 @@ public enum DisguiseType { DisguiseType toUse = type; String name; - switch (type) { + /* switch (type) { // Disguise item frame isn't supported. So we don't give it a entity type which should prevent it from being.. // Usable. case ITEM_FRAME: @@ -199,16 +194,9 @@ public enum DisguiseType { case HUSK: toUse = DisguiseType.ZOMBIE; break; - case WITHER_SKELETON: - case STRAY: - toUse = DisguiseType.SKELETON; - break; - case ELDER_GUARDIAN: - toUse = DisguiseType.GUARDIAN; - break; default: break; - } + }*/ name = toUse.name(); @@ -223,39 +211,6 @@ public enum DisguiseType { public static DisguiseType getType(Entity entity) { DisguiseType disguiseType = getType(entity.getType()); - switch (disguiseType) { - case ZOMBIE: - - if (((Zombie) entity).isVillager()) { - disguiseType = DisguiseType.ZOMBIE_VILLAGER; - } - - break; - - case HORSE: - - disguiseType = DisguiseType.valueOf(((Horse) entity).getVariant().name()); - - break; - - case SKELETON: - - if (((Skeleton) entity).getSkeletonType() == SkeletonType.WITHER) { - disguiseType = DisguiseType.WITHER_SKELETON; - } - - break; - case GUARDIAN: - - if (((Guardian) entity).isElder()) { - disguiseType = DisguiseType.ELDER_GUARDIAN; - } - - break; - default: - break; - } - return disguiseType; } diff --git a/src/me/libraryaddict/disguise/disguisetypes/FlagType.java b/src/me/libraryaddict/disguise/disguisetypes/FlagType.java index b1929864..0c389dd9 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/FlagType.java +++ b/src/me/libraryaddict/disguise/disguisetypes/FlagType.java @@ -64,6 +64,7 @@ import me.libraryaddict.disguise.disguisetypes.watchers.WitchWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.WitherSkullWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.WitherWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.WolfWatcher; +import me.libraryaddict.disguise.disguisetypes.watchers.ZombieVillagerWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher; public class FlagType { @@ -71,7 +72,7 @@ public class FlagType { public static FlagType AGEABLE_BABY = new FlagType(AgeableWatcher.class, 0, false); - public static FlagType AREA_EFFECT_COLOR = new FlagType(AreaEffectCloudWatcher.class, 1, + public static FlagType AREA_EFFECT_CLOUD_COLOR = new FlagType(AreaEffectCloudWatcher.class, 1, Color.BLACK.asRGB()); public static FlagType AREA_EFFECT_IGNORE_RADIUS = new FlagType(AreaEffectCloudWatcher.class, 2, false); @@ -126,15 +127,15 @@ public class FlagType { public static FlagType CREEPER_STATE = new FlagType(CreeperWatcher.class, 0, -1); - public static FlagType> DROPPED_ITEM = new FlagType>(DroppedItemWatcher.class, 0, - Optional. of(new ItemStack(Material.STONE))); + public static FlagType DROPPED_ITEM = new FlagType(DroppedItemWatcher.class, 0, + new ItemStack(Material.STONE)); public static FlagType> ENDER_CRYSTAL_BEAM = new FlagType>( EnderCrystalWatcher.class, 0, Optional. absent()); public static FlagType ENDER_CRYSTAL_PLATE = new FlagType(EnderCrystalWatcher.class, 1, false); - public static FlagType ENDERDRAGON_PHASE = new FlagType(EnderDragonWatcher.class, 0, 0); + public static FlagType ENDERD_RAGON_PHASE = new FlagType(EnderDragonWatcher.class, 0, 0); public static FlagType ENDERMAN_AGRESSIVE = new FlagType(EndermanWatcher.class, 1, false); @@ -158,14 +159,14 @@ public class FlagType { public static FlagType FALLING_BLOCK_POSITION = new FlagType(FallingBlockWatcher.class, 0, BlockPosition.ORIGIN); - public static FlagType> FIREWORK_ITEM = new FlagType>(FireworkWatcher.class, 0, - Optional. absent()); + public static FlagType FIREWORK_ITEM = new FlagType(FireworkWatcher.class, 0, + new ItemStack(Material.AIR)); - public static FlagType FISHING_HOOK = new FlagType(FishingHookWatcher.class, 0, 0); + public static FlagType FISHING_HOOK_HOOKED = new FlagType(FishingHookWatcher.class, 0, 0); public static FlagType GHAST_AGRESSIVE = new FlagType(GhastWatcher.class, 0, false); - public static FlagType GUARDIAN_FLAG = new FlagType(GuardianWatcher.class, 0, (byte) 0); + public static FlagType GUARDIAN_RETRACT_SPIKES = new FlagType(GuardianWatcher.class, 0, false); public static FlagType GUARDIAN_TARGET = new FlagType(GuardianWatcher.class, 1, 0); @@ -175,7 +176,7 @@ public class FlagType { public static FlagType HORSE_META = new FlagType(HorseAbstractWatcher.class, 0, (byte) 0); - public static FlagType HORSE_CARRYING_CHEST = new FlagType(HorseChestedWatcher.class, 0, false); + public static FlagType HORSE_CHESTED_CARRYING_CHEST = new FlagType(HorseChestedWatcher.class, 0, false); public static FlagType> HORSE_OWNER = new FlagType>(HorseAbstractWatcher.class, 1, Optional. absent()); @@ -186,8 +187,8 @@ public class FlagType { public static FlagType IRON_GOLEM_PLAYER_CREATED = new FlagType(IronGolemWatcher.class, 0, (byte) 0); - public static FlagType> ITEMFRAME_ITEM = new FlagType>(ItemFrameWatcher.class, 0, - Optional. absent()); + public static FlagType ITEMFRAME_ITEM = new FlagType(ItemFrameWatcher.class, 0, + new ItemStack(Material.AIR)); public static FlagType ITEMFRAME_ROTATION = new FlagType(ItemFrameWatcher.class, 1, 0); @@ -246,9 +247,7 @@ public class FlagType { public static FlagType SHULKER_COLOR = new FlagType(ShulkerWatcher.class, 3, (byte) 10); - public static FlagType SKELETON_SWING_ARMS = new FlagType(SkeletonWatcher.class, 1, false); - - public static FlagType SKELETON_TYPE = new FlagType(SkeletonWatcher.class, 0, 0); + public static FlagType SKELETON_SWING_ARMS = new FlagType(SkeletonWatcher.class, 0, false); public static FlagType SLIME_SIZE = new FlagType(SlimeWatcher.class, 0, 0); @@ -256,14 +255,14 @@ public class FlagType { public static FlagType SPIDER_CLIMB = new FlagType(SpiderWatcher.class, 0, (byte) 0); - public static FlagType> SPLASH_POTION_ITEM = new FlagType>(SplashPotionWatcher.class, - 1, Optional.of(new ItemStack(Material.SPLASH_POTION))); // Yeah, the '1' isn't a bug. No idea why but MC thinks - // there's a '0' already. + public static FlagType SPLASH_POTION_ITEM = new FlagType(SplashPotionWatcher.class, 1, + new ItemStack(Material.SPLASH_POTION)); // Yeah, the '1' isn't a bug. No idea why but MC thinks + // there's a '0' already. - public static FlagType> SPLASH_POTION_ITEM_BAD = new FlagType>( - SplashPotionWatcher.class, 0, Optional.of(new ItemStack(Material.SPLASH_POTION))); // Yeah, the '1' isn't a bug. No - // idea why but MC thinks there's a - // '0' already. + public static FlagType SPLASH_POTION_ITEM_BAD = new FlagType(SplashPotionWatcher.class, 0, + new ItemStack(Material.SPLASH_POTION)); // Yeah, the '1' isn't a bug. No + // idea why but MC thinks there's a + // '0' already. public static FlagType TAMEABLE_META = new FlagType(TameableWatcher.class, 0, (byte) 0); @@ -290,7 +289,7 @@ public class FlagType { public static FlagType WITHER_TARGET_3 = new FlagType(WitherWatcher.class, 2, 0); - public static FlagType WITHERSKULL_BLUE = new FlagType(WitherSkullWatcher.class, 0, false); + public static FlagType WITHER_SKULL_BLUE = new FlagType(WitherSkullWatcher.class, 0, false); public static FlagType WOLF_BEGGING = new FlagType(WolfWatcher.class, 1, false); @@ -298,13 +297,13 @@ public class FlagType { public static FlagType WOLF_DAMAGE = new FlagType(WolfWatcher.class, 0, 0F); - public static FlagType ZOMBIE_AGGRESSIVE = new FlagType(ZombieWatcher.class, 3, false); + public static FlagType ZOMBIE_AGGRESSIVE = new FlagType(ZombieWatcher.class, 2, false); public static FlagType ZOMBIE_BABY = new FlagType(ZombieWatcher.class, 0, false); - public static FlagType ZOMBIE_PROFESSION = new FlagType(ZombieWatcher.class, 1, 0); + public static FlagType ZOMBIE_VILLAGER_PROFESSION = new FlagType(ZombieVillagerWatcher.class, 1, 0); - public static FlagType ZOMBIE_SHAKING = new FlagType(ZombieWatcher.class, 2, false); + public static FlagType ZOMBIE_VILLAGER_SHAKING = new FlagType(ZombieVillagerWatcher.class, 0, false); static { for (FlagType flagType : values()) { diff --git a/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java index 0fe03c7b..72096159 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java @@ -26,8 +26,7 @@ import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.PacketsManager; import me.libraryaddict.disguise.utilities.ReflectionManager; -public class FlagWatcher -{ +public class FlagWatcher { private boolean _addEntityAnimations = DisguiseConfig.isEntityAnimationsAdded(); /** * These are the entity values I need to add else it could crash them.. @@ -40,20 +39,18 @@ public class FlagWatcher private HashSet _modifiedEntityAnimations = new HashSet<>(); private List _watchableObjects; - public FlagWatcher(Disguise disguise) - { + public FlagWatcher(Disguise disguise) { _disguise = (TargetedDisguise) disguise; _equipment = ReflectionManager.createEntityEquipment(disguise.getEntity()); + + this.setData(FlagType.ENTITY_AIR_TICKS, 0); } - private byte addEntityAnimations(byte originalValue, byte entityValue) - { + private byte addEntityAnimations(byte originalValue, byte entityValue) { byte valueByte = originalValue; - for (int i = 0; i < 6; i++) - { - if ((entityValue & 1 << i) != 0 && !_modifiedEntityAnimations.contains(i)) - { + for (int i = 0; i < 6; i++) { + if ((entityValue & 1 << i) != 0 && !_modifiedEntityAnimations.contains(i)) { valueByte = (byte) (valueByte | 1 << i); } } @@ -63,16 +60,13 @@ public class FlagWatcher return originalValue; } - public FlagWatcher clone(Disguise owningDisguise) - { + public FlagWatcher clone(Disguise owningDisguise) { FlagWatcher cloned; - try - { + try { cloned = getClass().getConstructor(Disguise.class).newInstance(getDisguise()); } - catch (Exception e) - { + catch (Exception e) { e.printStackTrace(); cloned = new FlagWatcher(getDisguise()); } @@ -85,49 +79,40 @@ public class FlagWatcher return cloned; } - public List convert(List list) - { + public List convert(List list) { List newList = new ArrayList<>(); HashSet sentValues = new HashSet<>(); boolean sendAllCustom = false; - for (WrappedWatchableObject watch : list) - { + for (WrappedWatchableObject watch : list) { int id = watch.getIndex(); sentValues.add(id); // Its sending the air metadata. This is the least commonly sent metadata which all entitys still share. // I send my custom values if I see this! - if (id == 1) - { + if (id == 1) { sendAllCustom = true; } Object value = null; - if (_entityValues.containsKey(id)) - { - if (_entityValues.get(id) == null) - { + if (_entityValues.containsKey(id)) { + if (_entityValues.get(id) == null) { continue; } value = _entityValues.get(id); } - else if (_backupEntityValues.containsKey(id)) - { - if (_backupEntityValues.get(id) == null) - { + else if (_backupEntityValues.containsKey(id)) { + if (_backupEntityValues.get(id) == null) { continue; } value = _backupEntityValues.get(id); } - if (value != null) - { - if (isEntityAnimationsAdded() && id == 0) - { + if (value != null) { + if (isEntityAnimationsAdded() && id == 0) { value = addEntityAnimations((byte) value, (byte) watch.getValue()); } @@ -138,13 +123,11 @@ public class FlagWatcher if (watch == null) continue; - if (!isDirty) - { + if (!isDirty) { watch.setDirtyState(false); } } - else - { + else { boolean isDirty = watch.getDirtyState(); watch = ReflectionManager.createWatchable(id, watch.getValue()); @@ -152,8 +135,7 @@ public class FlagWatcher if (watch == null) continue; - if (!isDirty) - { + if (!isDirty) { watch.setDirtyState(false); } } @@ -161,20 +143,16 @@ public class FlagWatcher newList.add(watch); } - if (sendAllCustom) - { + if (sendAllCustom) { // Its sending the entire meta data. Better add the custom meta - for (Integer id : _entityValues.keySet()) - { - if (sentValues.contains(id)) - { + for (Integer id : _entityValues.keySet()) { + if (sentValues.contains(id)) { continue; } Object value = _entityValues.get(id); - if (value == null) - { + if (value == null) { continue; } @@ -188,41 +166,31 @@ public class FlagWatcher } // Here we check for if there is a health packet that says they died. if (getDisguise().isSelfDisguiseVisible() && getDisguise().getEntity() != null - && getDisguise().getEntity() instanceof Player) - { - for (WrappedWatchableObject watch : newList) - { + && getDisguise().getEntity() instanceof Player) { + for (WrappedWatchableObject watch : newList) { // Its a health packet - if (watch.getIndex() == 6) - { + if (watch.getIndex() == 6) { Object value = watch.getValue(); - if (value != null && value instanceof Float) - { + if (value != null && value instanceof Float) { float newHealth = (Float) value; - if (newHealth > 0 && _hasDied) - { + if (newHealth > 0 && _hasDied) { _hasDied = false; - Bukkit.getScheduler().scheduleSyncDelayedTask(DisguiseUtilities.getPlugin(), new Runnable() - { + Bukkit.getScheduler().scheduleSyncDelayedTask(DisguiseUtilities.getPlugin(), new Runnable() { @Override - public void run() - { - try - { + public void run() { + try { DisguiseUtilities.sendSelfDisguise((Player) getDisguise().getEntity(), _disguise); } - catch (Exception ex) - { + catch (Exception ex) { ex.printStackTrace(); } } }, 2); } - else if (newHealth <= 0 && !_hasDied) - { + else if (newHealth <= 0 && !_hasDied) { _hasDied = true; } } @@ -233,57 +201,48 @@ public class FlagWatcher return newList; } - public ItemStack[] getArmor() - { + public ItemStack[] getArmor() { ItemStack[] armor = new ItemStack[4]; System.arraycopy(armor, 0, armor, 0, 4); return armor; } - public String getCustomName() - { + public String getCustomName() { return (String) getData(FlagType.ENTITY_CUSTOM_NAME); } - protected TargetedDisguise getDisguise() - { + protected TargetedDisguise getDisguise() { return _disguise; } - private boolean getEntityFlag(int byteValue) - { + private boolean getEntityFlag(int byteValue) { return (getData(FlagType.ENTITY_META) & 1 << byteValue) != 0; } - public EntityEquipment getEquipment() - { + public EntityEquipment getEquipment() { return _equipment; } - public ItemStack getItemInMainHand() - { + public ItemStack getItemInMainHand() { if (_equipment == null) return null; return _equipment.getItemInMainHand(); } - public ItemStack getItemInOffHand() - { + public ItemStack getItemInOffHand() { if (_equipment == null) return null; return _equipment.getItemInOffHand(); } - public ItemStack getItemStack(EquipmentSlot slot) - { + public ItemStack getItemStack(EquipmentSlot slot) { if (_equipment == null) return null; - switch (slot) - { + switch (slot) { case CHEST: return _equipment.getChestplate(); case FEET: @@ -301,104 +260,83 @@ public class FlagWatcher return null; } - protected Y getData(FlagType flagType) - { - if (_entityValues.containsKey(flagType.getIndex())) - { + protected Y getData(FlagType flagType) { + if (_entityValues.containsKey(flagType.getIndex())) { return (Y) _entityValues.get(flagType.getIndex()); } return flagType.getDefault(); } - public List getWatchableObjects() - { - if (_watchableObjects == null) - { + public List getWatchableObjects() { + if (_watchableObjects == null) { rebuildWatchableObjects(); } return _watchableObjects; } - public boolean hasCustomName() - { + public boolean hasCustomName() { return getCustomName() != null; } - protected boolean hasValue(FlagType no) - { + protected boolean hasValue(FlagType no) { return _entityValues.containsKey(no.getIndex()); } - public boolean isBurning() - { + public boolean isBurning() { return getEntityFlag(0); } - public boolean isCustomNameVisible() - { + public boolean isCustomNameVisible() { return getData(FlagType.ENTITY_CUSTOM_NAME_VISIBLE); } - public boolean isEntityAnimationsAdded() - { + public boolean isEntityAnimationsAdded() { return _addEntityAnimations; } - public boolean isFlyingWithElytra() - { + public boolean isFlyingWithElytra() { return getEntityFlag(7); } - public boolean isGlowing() - { + public boolean isGlowing() { return getEntityFlag(6); } - public boolean isInvisible() - { + public boolean isInvisible() { return getEntityFlag(5); } - public boolean isNoGravity() - { + public boolean isNoGravity() { return getData(FlagType.ENTITY_NO_GRAVITY); } - public boolean isRightClicking() - { + public boolean isRightClicking() { return getEntityFlag(4); } - public boolean isSneaking() - { + public boolean isSneaking() { return getEntityFlag(1); } - public boolean isSprinting() - { + public boolean isSprinting() { return getEntityFlag(3); } - public void rebuildWatchableObjects() - { + public void rebuildWatchableObjects() { _watchableObjects = new ArrayList<>(); - for (int i = 0; i <= 31; i++) - { + for (int i = 0; i <= 31; i++) { WrappedWatchableObject watchable = null; - if (_entityValues.containsKey(i) && _entityValues.get(i) != null) - { + if (_entityValues.containsKey(i) && _entityValues.get(i) != null) { watchable = ReflectionManager.createWatchable(i, _entityValues.get(i)); } - else if (_backupEntityValues.containsKey(i) && _backupEntityValues.get(i) != null) - { + else if (_backupEntityValues.containsKey(i) && _backupEntityValues.get(i) != null) { watchable = ReflectionManager.createWatchable(i, _backupEntityValues.get(i)); } - else - { + else { continue; } @@ -409,28 +347,22 @@ public class FlagWatcher } } - protected void sendData(FlagType... dataValues) - { - if (!DisguiseAPI.isDisguiseInUse(getDisguise()) || getDisguise().getWatcher() != this) - { + protected void sendData(FlagType... dataValues) { + if (!DisguiseAPI.isDisguiseInUse(getDisguise()) || getDisguise().getWatcher() != this) { return; } List list = new ArrayList<>(); - for (FlagType data : dataValues) - { - if (!_entityValues.containsKey(data.getIndex()) || _entityValues.get(data.getIndex()) == null) - { + for (FlagType data : dataValues) { + if (!_entityValues.containsKey(data.getIndex()) || _entityValues.get(data.getIndex()) == null) { continue; } Object value = _entityValues.get(data.getIndex()); - if (isEntityAnimationsAdded() && DisguiseConfig.isMetadataPacketsEnabled() && data == FlagType.ENTITY_META) - { - if (!PacketsManager.isStaticMetadataDisguiseType(_disguise)) - { + if (isEntityAnimationsAdded() && DisguiseConfig.isMetadataPacketsEnabled() && data == FlagType.ENTITY_META) { + if (!PacketsManager.isStaticMetadataDisguiseType(_disguise)) { value = addEntityAnimations((byte) value, WrappedDataWatcher.getEntityWatcher(_disguise.getEntity()).getByte(0)); } @@ -444,8 +376,7 @@ public class FlagWatcher list.add(watch); } - if (!list.isEmpty()) - { + if (!list.isEmpty()) { PacketContainer packet = new PacketContainer(Server.ENTITY_METADATA); StructureModifier mods = packet.getModifier(); @@ -453,59 +384,48 @@ public class FlagWatcher packet.getWatchableCollectionModifier().write(0, list); - for (Player player : DisguiseUtilities.getPerverts(getDisguise())) - { - try - { - if (player == getDisguise().getEntity()) - { + for (Player player : DisguiseUtilities.getPerverts(getDisguise())) { + try { + if (player == getDisguise().getEntity()) { PacketContainer temp = packet.shallowClone(); temp.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId()); ProtocolLibrary.getProtocolManager().sendServerPacket(player, temp); } - else - { + else { ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet); } } - catch (InvocationTargetException e) - { + catch (InvocationTargetException e) { e.printStackTrace(); } } } } - public void setAddEntityAnimations(boolean isEntityAnimationsAdded) - { + public void setAddEntityAnimations(boolean isEntityAnimationsAdded) { _addEntityAnimations = isEntityAnimationsAdded; } - public void setArmor(ItemStack[] itemstack) - { + public void setArmor(ItemStack[] itemstack) { setItemStack(EquipmentSlot.HEAD, itemstack[0]); setItemStack(EquipmentSlot.CHEST, itemstack[1]); setItemStack(EquipmentSlot.LEGS, itemstack[2]); setItemStack(EquipmentSlot.FEET, itemstack[3]); } - protected void setBackupValue(FlagType no, Object value) - { + protected void setBackupValue(FlagType no, Object value) { _backupEntityValues.put(no.getIndex(), value); } - public void setBurning(boolean setBurning) - { + public void setBurning(boolean setBurning) { setEntityFlag(0, setBurning); sendData(FlagType.ENTITY_META); } - public void setCustomName(String name) - { - if (name != null && name.length() > 64) - { + public void setCustomName(String name) { + if (name != null && name.length() > 64) { name = name.substring(0, 64); } @@ -513,42 +433,35 @@ public class FlagWatcher sendData(FlagType.ENTITY_CUSTOM_NAME); } - public void setCustomNameVisible(boolean display) - { + public void setCustomNameVisible(boolean display) { setData(FlagType.ENTITY_CUSTOM_NAME_VISIBLE, display); sendData(FlagType.ENTITY_CUSTOM_NAME_VISIBLE); } - private void setEntityFlag(int byteValue, boolean flag) - { + private void setEntityFlag(int byteValue, boolean flag) { _modifiedEntityAnimations.add(byteValue); byte b0 = (byte) getData(FlagType.ENTITY_META); - if (flag) - { + if (flag) { setData(FlagType.ENTITY_META, (byte) (b0 | 1 << byteValue)); } - else - { + else { setData(FlagType.ENTITY_META, (byte) (b0 & ~(1 << byteValue))); } } - public void setFlyingWithElytra(boolean flying) - { + public void setFlyingWithElytra(boolean flying) { setEntityFlag(7, flying); sendData(FlagType.ENTITY_META); } - public void setGlowing(boolean glowing) - { + public void setGlowing(boolean glowing) { setEntityFlag(6, glowing); sendData(FlagType.ENTITY_META); } - public void setInvisible(boolean setInvis) - { + public void setInvisible(boolean setInvis) { setEntityFlag(5, setInvis); sendData(FlagType.ENTITY_META); } @@ -559,28 +472,23 @@ public class FlagWatcher * @param itemstack */ @Deprecated - public void setItemInHand(ItemStack itemstack) - { + public void setItemInHand(ItemStack itemstack) { setItemInMainHand(itemstack); } - public void setItemInMainHand(ItemStack itemstack) - { + public void setItemInMainHand(ItemStack itemstack) { setItemStack(EquipmentSlot.HAND, itemstack); } - public void setItemInOffHand(ItemStack itemstack) - { + public void setItemInOffHand(ItemStack itemstack) { setItemStack(EquipmentSlot.OFF_HAND, itemstack); } - private void setItemStack(EntityEquipment equipment, EquipmentSlot slot, ItemStack itemStack) - { + private void setItemStack(EntityEquipment equipment, EquipmentSlot slot, ItemStack itemStack) { if (equipment == null) return; - switch (slot) - { + switch (slot) { case CHEST: equipment.setChestplate(itemStack); break; @@ -602,17 +510,14 @@ public class FlagWatcher } } - public void setItemStack(EquipmentSlot slot, ItemStack itemStack) - { + public void setItemStack(EquipmentSlot slot, ItemStack itemStack) { if (_equipment == null) return; // Itemstack which is null means that its not replacing the disguises itemstack. - if (itemStack == null) - { + if (itemStack == null) { // Find the item to replace it with - if (getDisguise().getEntity() instanceof LivingEntity) - { + if (getDisguise().getEntity() instanceof LivingEntity) { EntityEquipment equipment = ((LivingEntity) getDisguise().getEntity()).getEquipment(); setItemStack(equipment, slot, itemStack); } @@ -620,15 +525,13 @@ public class FlagWatcher Object itemToSend = null; - if (itemStack != null && itemStack.getTypeId() != 0) - { + if (itemStack != null && itemStack.getTypeId() != 0) { itemToSend = ReflectionManager.getNmsItem(itemStack); } setItemStack(_equipment, slot, itemStack); - if (DisguiseAPI.isDisguiseInUse(getDisguise()) && getDisguise().getWatcher() == this) - { + if (DisguiseAPI.isDisguiseInUse(getDisguise()) && getDisguise().getWatcher() == this) { PacketContainer packet = new PacketContainer(Server.ENTITY_EQUIPMENT); StructureModifier mods = packet.getModifier(); @@ -637,50 +540,44 @@ public class FlagWatcher mods.write(1, ReflectionManager.createEnumItemSlot(slot)); mods.write(2, itemToSend); - for (Player player : DisguiseUtilities.getPerverts(getDisguise())) - { - try - { + for (Player player : DisguiseUtilities.getPerverts(getDisguise())) { + try { ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet); } - catch (InvocationTargetException e) - { + catch (InvocationTargetException e) { e.printStackTrace(); } } } } - public void setNoGravity(boolean noGravity) - { + public void setNoGravity(boolean noGravity) { setData(FlagType.ENTITY_NO_GRAVITY, noGravity); sendData(FlagType.ENTITY_NO_GRAVITY); } - public void setRightClicking(boolean setRightClicking) - { + public void setRightClicking(boolean setRightClicking) { setEntityFlag(4, setRightClicking); sendData(FlagType.ENTITY_META); } - public void setSneaking(boolean setSneaking) - { + public void setSneaking(boolean setSneaking) { setEntityFlag(1, setSneaking); sendData(FlagType.ENTITY_META); } - public void setSprinting(boolean setSprinting) - { + public void setSprinting(boolean setSprinting) { setEntityFlag(3, setSprinting); sendData(FlagType.ENTITY_META); } - protected void setData(FlagType id, Y value) - { + protected void setData(FlagType id, Y value) { + if (value == null && id.getDefault() instanceof ItemStack) + throw new IllegalArgumentException("Cannot use null ItemStacks"); + _entityValues.put(id.getIndex(), value); - if (!DisguiseConfig.isMetadataPacketsEnabled()) - { + if (!DisguiseConfig.isMetadataPacketsEnabled()) { rebuildWatchableObjects(); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/AreaEffectCloudWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/AreaEffectCloudWatcher.java index a0d908a7..c50f850d 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/AreaEffectCloudWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/AreaEffectCloudWatcher.java @@ -7,51 +7,43 @@ 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); + + setRadius(1); } - public float getRadius() - { + public float getRadius() { return getData(FlagType.AREA_EFFECT_RADIUS); } - public int getColor() - { - return getData(FlagType.AREA_EFFECT_COLOR); + public int getColor() { + return getData(FlagType.AREA_EFFECT_CLOUD_COLOR); } - public boolean isIgnoreRadius() - { + public boolean isIgnoreRadius() { return getData(FlagType.AREA_EFFECT_IGNORE_RADIUS); } - public int getParticleId() - { + public int getParticleId() { return getData(FlagType.AREA_EFFECT_PARTICLE); } - public void setRadius(float radius) - { + public void setRadius(float radius) { setData(FlagType.AREA_EFFECT_RADIUS, radius); } - public void setColor(int color) - { - setData(FlagType.AREA_EFFECT_COLOR, color); + public void setColor(int color) { + setData(FlagType.AREA_EFFECT_CLOUD_COLOR, color); } - public void setIgnoreRadius(boolean ignore) - { + public void setIgnoreRadius(boolean ignore) { setData(FlagType.AREA_EFFECT_IGNORE_RADIUS, ignore); } - public void setParticleId(int particleId) - { + public void setParticleId(int particleId) { setData(FlagType.AREA_EFFECT_PARTICLE, particleId); } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/DroppedItemWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/DroppedItemWatcher.java index 3b6e484e..8c2ccdc9 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/DroppedItemWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/DroppedItemWatcher.java @@ -2,27 +2,21 @@ package me.libraryaddict.disguise.disguisetypes.watchers; 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.disguisetypes.FlagWatcher; -public class DroppedItemWatcher extends FlagWatcher -{ - public DroppedItemWatcher(Disguise disguise) - { +public class DroppedItemWatcher extends FlagWatcher { + public DroppedItemWatcher(Disguise disguise) { super(disguise); } - public ItemStack getItemStack() - { - return getData(FlagType.DROPPED_ITEM).get(); + public ItemStack getItemStack() { + return getData(FlagType.DROPPED_ITEM); } - public void setItemStack(ItemStack item) - { - setData(FlagType.DROPPED_ITEM, Optional. of(item)); + public void setItemStack(ItemStack item) { + setData(FlagType.DROPPED_ITEM, item); sendData(FlagType.DROPPED_ITEM); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/EnderDragonWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/EnderDragonWatcher.java index 5bb62a3e..c0a31566 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/EnderDragonWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/EnderDragonWatcher.java @@ -16,12 +16,12 @@ public class EnderDragonWatcher extends InsentientWatcher public int getPhase() { - return getData(FlagType.ENDERDRAGON_PHASE); + return getData(FlagType.ENDERD_RAGON_PHASE); } public void setPhase(int phase) { - setData(FlagType.ENDERDRAGON_PHASE, phase); - sendData(FlagType.ENDERDRAGON_PHASE); + setData(FlagType.ENDERD_RAGON_PHASE, phase); + sendData(FlagType.ENDERD_RAGON_PHASE); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/FireworkWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/FireworkWatcher.java index 433dc3a3..3641f6ef 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/FireworkWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/FireworkWatcher.java @@ -3,40 +3,32 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import org.bukkit.Material; 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.disguisetypes.FlagWatcher; -public class FireworkWatcher extends FlagWatcher -{ - public FireworkWatcher(Disguise disguise) - { +public class FireworkWatcher extends FlagWatcher { + public FireworkWatcher(Disguise disguise) { super(disguise); } - public ItemStack getFirework() - { - if (getData(FlagType.FIREWORK_ITEM) == null) - { + public ItemStack getFirework() { + if (getData(FlagType.FIREWORK_ITEM) == null) { return new ItemStack(Material.AIR); } - return (ItemStack) getData(FlagType.FIREWORK_ITEM).get(); + return (ItemStack) getData(FlagType.FIREWORK_ITEM); } - public void setFirework(ItemStack newItem) - { - if (newItem == null) - { + public void setFirework(ItemStack newItem) { + if (newItem == null) { newItem = new ItemStack(Material.AIR); } newItem = newItem.clone(); newItem.setAmount(1); - setData(FlagType.FIREWORK_ITEM, Optional. of(newItem)); + setData(FlagType.FIREWORK_ITEM, newItem); sendData(FlagType.FIREWORK_ITEM); } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/FishingHookWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/FishingHookWatcher.java index 490da6dc..cb2a0d46 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/FishingHookWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/FishingHookWatcher.java @@ -13,13 +13,13 @@ public class FishingHookWatcher extends FlagWatcher public void setHooked(int hookedId) { - setData(FlagType.FISHING_HOOK, hookedId + 1); - sendData(FlagType.FISHING_HOOK); + setData(FlagType.FISHING_HOOK_HOOKED, hookedId + 1); + sendData(FlagType.FISHING_HOOK_HOOKED); } public int getHooked() { - int hooked = getData(FlagType.FISHING_HOOK); + int hooked = getData(FlagType.FISHING_HOOK_HOOKED); if (hooked > 0) hooked--; diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/GuardianWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/GuardianWatcher.java index 4034c31e..3b259ed6 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/GuardianWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/GuardianWatcher.java @@ -7,11 +7,8 @@ import org.bukkit.entity.Player; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.FlagType; -public class GuardianWatcher extends InsentientWatcher -{ - - public GuardianWatcher(Disguise disguise) - { +public class GuardianWatcher extends InsentientWatcher { + public GuardianWatcher(Disguise disguise) { super(disguise); } @@ -20,8 +17,7 @@ public class GuardianWatcher extends InsentientWatcher * * @return */ - public boolean isTarget() - { + public boolean isTarget() { return ((int) getData(FlagType.GUARDIAN_TARGET)) != 0; } @@ -30,14 +26,12 @@ public class GuardianWatcher extends InsentientWatcher * * @param entityId */ - public void setTarget(int entityId) - { + public void setTarget(int entityId) { setData(FlagType.GUARDIAN_TARGET, entityId); sendData(FlagType.GUARDIAN_TARGET); } - public void setTarget(Entity entity) - { + public void setTarget(Entity entity) { setTarget(entity == null ? 0 : entity.getEntityId()); } @@ -46,8 +40,7 @@ public class GuardianWatcher extends InsentientWatcher * * @param playername */ - public void setTarget(String playername) - { + public void setTarget(String playername) { Player player = Bukkit.getPlayer(playername); if (player == null) @@ -57,45 +50,13 @@ public class GuardianWatcher extends InsentientWatcher sendData(FlagType.GUARDIAN_TARGET); } - public boolean isRetractingSpikes() - { - return isGuardianFlag(2); + public boolean isRetractingSpikes() { + return getData(FlagType.GUARDIAN_RETRACT_SPIKES); } - public void setRetractingSpikes(boolean isRetracting) - { - setGuardianFlag(2, isRetracting); - } - - public boolean isElder() - { - return isGuardianFlag(4); - } - - public void setElder(boolean isGuardian) - { - setGuardianFlag(4, isGuardian); - } - - protected boolean isGuardianFlag(int no) - { - return (getData(FlagType.GUARDIAN_FLAG) & no) != 0; - } - - protected void setGuardianFlag(int no, boolean flag) - { - byte b0 = getData(FlagType.GUARDIAN_FLAG); - - if (flag) - { - setData(FlagType.GUARDIAN_FLAG, (byte) (b0 | no)); - } - else - { - setData(FlagType.GUARDIAN_FLAG, (byte) (b0 & -(no + 1))); - } - - sendData(FlagType.GUARDIAN_FLAG); + public void setRetractingSpikes(boolean isRetracting) { + setData(FlagType.GUARDIAN_RETRACT_SPIKES, isRetracting); + sendData(FlagType.GUARDIAN_RETRACT_SPIKES); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/HorseChestedWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/HorseChestedWatcher.java index 5153909a..7d5d0a3f 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/HorseChestedWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/HorseChestedWatcher.java @@ -10,11 +10,11 @@ public class HorseChestedWatcher extends HorseAbstractWatcher { } public void setCarryingChest(boolean carryingChest) { - setData(FlagType.HORSE_CARRYING_CHEST, carryingChest); - sendData(FlagType.HORSE_CARRYING_CHEST); + setData(FlagType.HORSE_CHESTED_CARRYING_CHEST, carryingChest); + sendData(FlagType.HORSE_CHESTED_CARRYING_CHEST); } public boolean isCarryingChest() { - return getData(FlagType.HORSE_CARRYING_CHEST); + return getData(FlagType.HORSE_CHESTED_CARRYING_CHEST); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/ItemFrameWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/ItemFrameWatcher.java index a8b0f337..cc2533bb 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/ItemFrameWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/ItemFrameWatcher.java @@ -3,50 +3,40 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import org.bukkit.Material; 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.disguisetypes.FlagWatcher; -public class ItemFrameWatcher extends FlagWatcher -{ - public ItemFrameWatcher(Disguise disguise) - { +public class ItemFrameWatcher extends FlagWatcher { + public ItemFrameWatcher(Disguise disguise) { super(disguise); } - public ItemStack getItem() - { - if (getData(FlagType.ITEMFRAME_ITEM) == null) - { + public ItemStack getItem() { + if (getData(FlagType.ITEMFRAME_ITEM) == null) { return new ItemStack(Material.AIR); } - return (ItemStack) getData(FlagType.ITEMFRAME_ITEM).get(); + return (ItemStack) getData(FlagType.ITEMFRAME_ITEM); } - public int getRotation() - { + public int getRotation() { return getData(FlagType.ITEMFRAME_ROTATION); } - public void setItem(ItemStack newItem) - { - if (newItem == null) - { + public void setItem(ItemStack newItem) { + if (newItem == null) { newItem = new ItemStack(Material.AIR); } newItem = newItem.clone(); newItem.setAmount(1); - setData(FlagType.ITEMFRAME_ITEM, Optional. of(newItem)); + setData(FlagType.ITEMFRAME_ITEM, newItem); sendData(FlagType.ITEMFRAME_ITEM); } - public void setRotation(int rotation) - { + public void setRotation(int rotation) { setData(FlagType.ITEMFRAME_ROTATION, rotation % 4); sendData(FlagType.ITEMFRAME_ROTATION); } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/SkeletonWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/SkeletonWatcher.java index a8a96a1f..4d20cd65 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/SkeletonWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/SkeletonWatcher.java @@ -1,39 +1,22 @@ 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 InsentientWatcher -{ - public SkeletonWatcher(Disguise disguise) - { +public class SkeletonWatcher extends InsentientWatcher { + public SkeletonWatcher(Disguise disguise) { super(disguise); } - public void setSwingArms(boolean swingingArms) - { + public void setSwingArms(boolean swingingArms) { setData(FlagType.SKELETON_SWING_ARMS, swingingArms); sendData(FlagType.SKELETON_SWING_ARMS); } - public boolean isSwingArms() - { + public boolean isSwingArms() { return getData(FlagType.SKELETON_SWING_ARMS); } - - public void setType(SkeletonType type) - { - setData(FlagType.SKELETON_TYPE, type.ordinal()); - sendData(FlagType.SKELETON_TYPE); - } - - public SkeletonType getType() - { - return SkeletonType.values()[getData(FlagType.SKELETON_TYPE)]; - } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/SplashPotionWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/SplashPotionWatcher.java index 971fc1e8..9167e31c 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/SplashPotionWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/SplashPotionWatcher.java @@ -2,53 +2,43 @@ package me.libraryaddict.disguise.disguisetypes.watchers; 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.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 setSplashPotion(ItemStack item) - { - setData(FlagType.SPLASH_POTION_ITEM, Optional.of(item)); + public void setSplashPotion(ItemStack item) { + setData(FlagType.SPLASH_POTION_ITEM, item); sendData(FlagType.SPLASH_POTION_ITEM); } - public ItemStack getSplashPotion() - { - return getData(FlagType.SPLASH_POTION_ITEM).get(); + public ItemStack getSplashPotion() { + return getData(FlagType.SPLASH_POTION_ITEM); } - 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/WitherSkullWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/WitherSkullWatcher.java index 677e3f56..1a469213 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/WitherSkullWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/WitherSkullWatcher.java @@ -14,13 +14,13 @@ public class WitherSkullWatcher extends FlagWatcher public boolean isBlue() { - return (boolean) getData(FlagType.WITHERSKULL_BLUE); + return (boolean) getData(FlagType.WITHER_SKULL_BLUE); } public void setBlue(boolean blue) { - setData(FlagType.WITHERSKULL_BLUE, blue); - sendData(FlagType.WITHERSKULL_BLUE); + setData(FlagType.WITHER_SKULL_BLUE, blue); + sendData(FlagType.WITHER_SKULL_BLUE); } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/ZombieVillagerWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/ZombieVillagerWatcher.java new file mode 100644 index 00000000..dbbee79b --- /dev/null +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/ZombieVillagerWatcher.java @@ -0,0 +1,61 @@ +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 ZombieVillagerWatcher extends ZombieWatcher { + + public ZombieVillagerWatcher(Disguise disguise) { + super(disguise); + } + + public boolean isShaking() { + return getData(FlagType.ZOMBIE_VILLAGER_SHAKING); + } + + /** + * Is this zombie a villager? + * + * @return + */ + public boolean isVillager() { + return ((int) getData(FlagType.ZOMBIE_VILLAGER_PROFESSION)) != 0; + } + + public void setShaking(boolean shaking) { + setData(FlagType.ZOMBIE_VILLAGER_SHAKING, shaking); + sendData(FlagType.ZOMBIE_VILLAGER_SHAKING); + } + + /** + * Only returns a valid value if this zombie is a villager. + * + * @return + */ + public Profession getProfession() { + return Profession.values()[getData(FlagType.ZOMBIE_VILLAGER_PROFESSION)]; + } + + /** + * Sets the profession of this zombie, in turn turning it into a Zombie Villager + * + * @param id + */ + public void setProfession(int id) { + setData(FlagType.ZOMBIE_VILLAGER_PROFESSION, id); + sendData(FlagType.ZOMBIE_VILLAGER_PROFESSION); + } + + /** + * Sets the profession of this zombie, in turn turning it into a Zombie Villager + * + * @param profession + */ + public void setProfession(Profession profession) { + setData(FlagType.ZOMBIE_VILLAGER_PROFESSION, profession.ordinal()); + sendData(FlagType.ZOMBIE_VILLAGER_PROFESSION); + } + +} diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/ZombieWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/ZombieWatcher.java index 3a4bf157..cce48210 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/ZombieWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/ZombieWatcher.java @@ -1,104 +1,40 @@ 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 InsentientWatcher -{ +public class ZombieWatcher extends InsentientWatcher { - public ZombieWatcher(Disguise disguise) - { + public ZombieWatcher(Disguise disguise) { super(disguise); } - public boolean isAdult() - { + public boolean isAdult() { return !isBaby(); } - public boolean isBaby() - { + public boolean isBaby() { return getData(FlagType.ZOMBIE_BABY); } - public boolean isShaking() - { - return getData(FlagType.ZOMBIE_SHAKING); - } - - /** - * Is this zombie a villager? - * - * @return - */ - public boolean isVillager() - { - return ((int) getData(FlagType.ZOMBIE_PROFESSION)) != 0; - } - - public boolean isAggressive() - { + public boolean isAggressive() { return (boolean) getData(FlagType.ZOMBIE_AGGRESSIVE); } - /** - * Only returns a valid value if this zombie is a villager. - * - * @return - */ - public Profession getProfession() - { - return Profession.values()[getData(FlagType.ZOMBIE_PROFESSION)]; - } - - public void setAdult() - { + public void setAdult() { setBaby(false); } - public void setBaby() - { + public void setBaby() { setBaby(true); } - public void setBaby(boolean baby) - { + public void setBaby(boolean baby) { setData(FlagType.ZOMBIE_BABY, baby); sendData(FlagType.ZOMBIE_BABY); } - public void setShaking(boolean shaking) - { - setData(FlagType.ZOMBIE_SHAKING, shaking); - sendData(FlagType.ZOMBIE_SHAKING); - } - - /** - * Sets the profession of this zombie, in turn turning it into a Zombie Villager - * - * @param id - */ - public void setProfession(int id) - { - setData(FlagType.ZOMBIE_PROFESSION, id); - sendData(FlagType.ZOMBIE_PROFESSION); - } - - /** - * Sets the profession of this zombie, in turn turning it into a Zombie Villager - * - * @param profession - */ - public void setProfession(Profession profession) - { - setData(FlagType.ZOMBIE_PROFESSION, profession.ordinal()); - sendData(FlagType.ZOMBIE_PROFESSION); - } - - public void setAggressive(boolean handsup) - { + public void setAggressive(boolean handsup) { setData(FlagType.ZOMBIE_AGGRESSIVE, handsup); sendData(FlagType.ZOMBIE_AGGRESSIVE); } diff --git a/src/me/libraryaddict/disguise/utilities/DisguiseValues.java b/src/me/libraryaddict/disguise/utilities/DisguiseValues.java index 20ddd942..2b024d7e 100644 --- a/src/me/libraryaddict/disguise/utilities/DisguiseValues.java +++ b/src/me/libraryaddict/disguise/utilities/DisguiseValues.java @@ -4,18 +4,15 @@ import java.util.HashMap; import me.libraryaddict.disguise.disguisetypes.DisguiseType; -public class DisguiseValues -{ +public class DisguiseValues { private static HashMap values = new HashMap<>(); - public static DisguiseValues getDisguiseValues(DisguiseType type) - { - switch (type) - { + public static DisguiseValues getDisguiseValues(DisguiseType type) { + switch (type) { case DONKEY: case MULE: - case UNDEAD_HORSE: + case ZOMBIE_HORSE: case SKELETON_HORSE: type = DisguiseType.HORSE; break; @@ -28,6 +25,7 @@ public class DisguiseValues type = DisguiseType.MINECART; break; case WITHER_SKELETON: + case STRAY: type = DisguiseType.SKELETON; break; case ZOMBIE_VILLAGER: @@ -39,8 +37,7 @@ public class DisguiseValues return values.get(type); } - public static Class getNmsEntityClass(DisguiseType type) - { + public static Class getNmsEntityClass(DisguiseType type) { return getDisguiseValues(type).getNmsEntityClass(); } @@ -50,50 +47,41 @@ public class DisguiseValues private double maxHealth; private Class nmsEntityClass; - public DisguiseValues(DisguiseType type, Class classType, int entitySize, double maxHealth) - { + public DisguiseValues(DisguiseType type, Class classType, int entitySize, double maxHealth) { values.put(type, this); nmsEntityClass = classType; this.maxHealth = maxHealth; } - public FakeBoundingBox getAdultBox() - { + public FakeBoundingBox getAdultBox() { return adultBox; } - public FakeBoundingBox getBabyBox() - { + public FakeBoundingBox getBabyBox() { return babyBox; } - public float[] getEntitySize() - { + public float[] getEntitySize() { return entitySize; } - public double getMaxHealth() - { + public double getMaxHealth() { return maxHealth; } - public Class getNmsEntityClass() - { + public Class getNmsEntityClass() { return nmsEntityClass; } - public void setAdultBox(FakeBoundingBox newBox) - { + public void setAdultBox(FakeBoundingBox newBox) { adultBox = newBox; } - public void setBabyBox(FakeBoundingBox newBox) - { + public void setBabyBox(FakeBoundingBox newBox) { babyBox = newBox; } - public void setEntitySize(float[] size) - { + public void setEntitySize(float[] size) { this.entitySize = size; } } diff --git a/src/me/libraryaddict/disguise/utilities/PacketsManager.java b/src/me/libraryaddict/disguise/utilities/PacketsManager.java index 067bdb67..9bec63cf 100644 --- a/src/me/libraryaddict/disguise/utilities/PacketsManager.java +++ b/src/me/libraryaddict/disguise/utilities/PacketsManager.java @@ -2,6 +2,7 @@ package me.libraryaddict.disguise.utilities; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map.Entry; @@ -104,6 +105,10 @@ public class PacketsManager { return packets; } + public Collection> getDelayedPackets() { + return delayedPackets.values(); + } + public void sendDelayed(final Player observer) { for (final Entry> entry : delayedPackets.entrySet()) { Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() { @@ -494,6 +499,16 @@ public class PacketsManager { mods.write(1, yaw); } + if (disguise.getType() == DisguiseType.EVOKER_FANGS) { + PacketContainer newPacket = new PacketContainer(Server.ENTITY_STATUS); + + StructureModifier mods = newPacket.getModifier(); + mods.write(0, disguise.getEntity().getEntityId()); + mods.write(1, (byte) 4); + + packets.addPacket(newPacket); + } + return packets; } diff --git a/src/me/libraryaddict/disguise/utilities/ReflectionManager.java b/src/me/libraryaddict/disguise/utilities/ReflectionManager.java index aaa8ff98..5786f6c1 100644 --- a/src/me/libraryaddict/disguise/utilities/ReflectionManager.java +++ b/src/me/libraryaddict/disguise/utilities/ReflectionManager.java @@ -778,7 +778,7 @@ public class ReflectionManager { return null; } - private static Object convertInvalidItem(Object value) { + public static Object convertInvalidItem(Object value) { if (value instanceof Optional) { Optional opt = (Optional) value; @@ -787,10 +787,7 @@ public class ReflectionManager { Object val = opt.get(); - if (val instanceof ItemStack) { - return Optional.of(getNmsItem((ItemStack) val)); - } - else if (val instanceof BlockPosition) { + if (val instanceof BlockPosition) { BlockPosition pos = (BlockPosition) val; try { @@ -840,6 +837,9 @@ public class ReflectionManager { ex.printStackTrace(); } } + else if (value instanceof ItemStack) { + return getNmsItem((ItemStack) value); + } return value; } @@ -871,8 +871,10 @@ public class ReflectionManager { } if (serializer == null) { - throw new IllegalArgumentException( - "Unable to find Serializer for " + value + "! Are you running the latest version of ProtocolLib?"); + throw new IllegalArgumentException("Unable to find Serializer for " + value + + (value instanceof Optional && ((Optional) value).isPresent() + ? " (" + ((Optional) value).get().getClass().getName() + ")" : "") + + "! Are you running the latest version of ProtocolLib?"); } WrappedDataWatcherObject watcherObject = new WrappedDataWatcherObject(id, serializer); diff --git a/src/me/libraryaddict/disguise/utilities/packetlisteners/PacketListenerViewDisguises.java b/src/me/libraryaddict/disguise/utilities/packetlisteners/PacketListenerViewDisguises.java index 66e0a1b8..ac6922c9 100644 --- a/src/me/libraryaddict/disguise/utilities/packetlisteners/PacketListenerViewDisguises.java +++ b/src/me/libraryaddict/disguise/utilities/packetlisteners/PacketListenerViewDisguises.java @@ -22,10 +22,8 @@ import me.libraryaddict.disguise.utilities.PacketsManager; import me.libraryaddict.disguise.utilities.PacketsManager.LibsPackets; import me.libraryaddict.disguise.utilities.ReflectionManager; -public class PacketListenerViewDisguises extends PacketAdapter -{ - public PacketListenerViewDisguises(LibsDisguises plugin) - { +public class PacketListenerViewDisguises extends PacketAdapter { + public PacketListenerViewDisguises(LibsDisguises plugin) { super(plugin, ListenerPriority.HIGH, Server.NAMED_ENTITY_SPAWN, Server.ATTACH_ENTITY, Server.REL_ENTITY_MOVE, Server.REL_ENTITY_MOVE_LOOK, Server.ENTITY_LOOK, Server.ENTITY_TELEPORT, Server.ENTITY_HEAD_ROTATION, Server.ENTITY_METADATA, Server.ENTITY_EQUIPMENT, Server.ANIMATION, Server.BED, Server.ENTITY_EFFECT, @@ -33,25 +31,21 @@ public class PacketListenerViewDisguises extends PacketAdapter } @Override - public void onPacketSending(final PacketEvent event) - { + public void onPacketSending(final PacketEvent event) { if (event.isCancelled()) return; - try - { + try { final Player observer = event.getPlayer(); if (observer.getName().contains("UNKNOWN[")) // If the player is temporary return; - if (event.getPacket().getIntegers().read(0) != observer.getEntityId()) - { + if (event.getPacket().getIntegers().read(0) != observer.getEntityId()) { return; } - if (!DisguiseAPI.isSelfDisguised(observer)) - { + if (!DisguiseAPI.isSelfDisguised(observer)) { return; } @@ -63,45 +57,48 @@ public class PacketListenerViewDisguises extends PacketAdapter // Here I grab the packets to convert them to, So I can display them as if the disguise sent them. LibsPackets transformed = PacketsManager.transformPacket(event.getPacket(), disguise, observer, observer); - if (transformed.isUnhandled()) - { + if (transformed.isUnhandled()) { transformed.getPackets().add(event.getPacket()); } transformed.setPacketType(event.getPacketType()); - for (PacketContainer packet : transformed.getPackets()) - { - if (packet.getType() != Server.PLAYER_INFO) - { - if (packet.equals(event.getPacket())) - { + for (PacketContainer packet : transformed.getPackets()) { + if (packet.getType() != Server.PLAYER_INFO) { + if (packet.equals(event.getPacket())) { packet = packet.shallowClone(); } packet.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId()); } - try - { + try { ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false); } - catch (InvocationTargetException e) - { + catch (InvocationTargetException e) { e.printStackTrace(); } } + for (ArrayList packets : transformed.getDelayedPackets()) { + for (PacketContainer packet : packets) { + if (packet.getType() != Server.PLAYER_INFO) { + if (packet.equals(event.getPacket())) { + packet = packet.shallowClone(); + } + + packet.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId()); + } + } + } + transformed.sendDelayed(observer); - if (event.getPacketType() == Server.ENTITY_METADATA) - { + if (event.getPacketType() == Server.ENTITY_METADATA) { event.setPacket(event.getPacket().deepClone()); - for (WrappedWatchableObject watch : event.getPacket().getWatchableCollectionModifier().read(0)) - { - if (watch.getIndex() == 0) - { + for (WrappedWatchableObject watch : event.getPacket().getWatchableCollectionModifier().read(0)) { + if (watch.getIndex() == 0) { byte b = (byte) watch.getValue(); byte a = (byte) (b | 1 << 5); @@ -113,8 +110,7 @@ public class PacketListenerViewDisguises extends PacketAdapter } } } - else if (event.getPacketType() == Server.NAMED_ENTITY_SPAWN) - { + else if (event.getPacketType() == Server.NAMED_ENTITY_SPAWN) { event.setCancelled(true); PacketContainer packet = new PacketContainer(Server.ENTITY_METADATA); @@ -134,40 +130,32 @@ public class PacketListenerViewDisguises extends PacketAdapter watchableList.add(watch); packet.getWatchableCollectionModifier().write(0, watchableList); - try - { + try { ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet); } - catch (InvocationTargetException e) - { + catch (InvocationTargetException e) { e.printStackTrace(); } } - else if (event.getPacketType() == Server.ANIMATION) - { - if (event.getPacket().getIntegers().read(1) != 2) - { + else if (event.getPacketType() == Server.ANIMATION) { + if (event.getPacket().getIntegers().read(1) != 2) { event.setCancelled(true); } } else if (event.getPacketType() == Server.ATTACH_ENTITY || event.getPacketType() == Server.REL_ENTITY_MOVE || event.getPacketType() == Server.REL_ENTITY_MOVE_LOOK || event.getPacketType() == Server.ENTITY_LOOK || event.getPacketType() == Server.ENTITY_TELEPORT || event.getPacketType() == Server.ENTITY_HEAD_ROTATION - || event.getPacketType() == Server.ENTITY_EFFECT || event.getPacketType() == Server.ENTITY_EQUIPMENT) - { + || event.getPacketType() == Server.ENTITY_EFFECT || event.getPacketType() == Server.ENTITY_EQUIPMENT) { event.setCancelled(true); } - else if (event.getPacketType() == Server.ENTITY_STATUS) - { + else if (event.getPacketType() == Server.ENTITY_STATUS) { if (disguise.isSelfDisguiseSoundsReplaced() && !disguise.getType().isPlayer() - && event.getPacket().getBytes().read(0) == 2) - { + && event.getPacket().getBytes().read(0) == 2) { event.setCancelled(true); } } } - catch (Exception ex) - { + catch (Exception ex) { event.setCancelled(true); ex.printStackTrace(); }