From ed1bcc5ad9188b9808930901796699ac4a24ee77 Mon Sep 17 00:00:00 2001 From: NavidK0 Date: Sun, 20 Mar 2016 23:29:48 -0400 Subject: [PATCH] Fixed DroppedItem disguise Fixed Fireworks disguise Fixed SplashPotion disguise Fixed Sheep disguise colors Fixed Wolf disguise colors Fixed error with isGlowing in FlagWatcher --- .../disguise/disguisetypes/DisguiseType.java | 2 +- .../disguise/disguisetypes/FlagWatcher.java | 12 ++++----- .../watchers/DroppedItemWatcher.java | 7 +++--- .../disguisetypes/watchers/SheepWatcher.java | 9 +++++-- .../watchers/TameableWatcher.java | 6 ++--- .../disguisetypes/watchers/WolfWatcher.java | 13 +++++++--- .../disguise/utilities/PacketsManager.java | 25 +++++++++++++------ src/main/resources/plugin.yml | 2 +- 8 files changed, 46 insertions(+), 30 deletions(-) diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/DisguiseType.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/DisguiseType.java index 1cf535db..16659ad3 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/DisguiseType.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/DisguiseType.java @@ -24,7 +24,7 @@ public enum DisguiseType { CREEPER, DONKEY, DRAGON_FIREBALL(93), - DROPPED_ITEM(1, 1), + DROPPED_ITEM(2, 1), EGG(62), ELDER_GUARDIAN, ENDER_CRYSTAL(51), diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java index f873c321..6e1d3638 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java @@ -9,6 +9,7 @@ import com.comphenix.protocol.wrappers.WrappedWatchableObject; import me.libraryaddict.disguise.DisguiseAPI; import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.utilities.DisguiseUtilities; +import me.libraryaddict.disguise.utilities.PacketsManager; import me.libraryaddict.disguise.utilities.ReflectionManager; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; @@ -226,11 +227,11 @@ public class FlagWatcher { return getEntityFlag(5); } - public boolean isFlyingWithElytra() { + public boolean isGlowing() { return getEntityFlag(6); } - public boolean isGlowing() { + public boolean isFlyingWithElytra() { return getEntityFlag(7); } @@ -260,11 +261,8 @@ public class FlagWatcher { } Object value = entityValues.get(data); if (isEntityAnimationsAdded() && DisguiseConfig.isMetadataPacketsEnabled() && data == 0) { - if (disguise.getType() != DisguiseType.WOLF && - disguise.getType() != DisguiseType.OCELOT && - disguise.getType() != DisguiseType.ENDERMAN && - disguise.getType() != DisguiseType.SHULKER) - value = addEntityAnimations((byte) value, WrappedDataWatcher.getEntityWatcher(disguise.getEntity()).getByte(0)); + if (!PacketsManager.isStaticMetadataDisguiseType(disguise)) + value = addEntityAnimations((byte) value, WrappedDataWatcher.getEntityWatcher(disguise.getEntity()).getByte(0)); } WrappedWatchableObject watch = new WrappedWatchableObject(ReflectionManager.createDataWatcherItem(data, value)); list.add(watch); diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/DroppedItemWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/DroppedItemWatcher.java index 511ec654..91ca82ba 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/DroppedItemWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/DroppedItemWatcher.java @@ -11,12 +11,11 @@ public class DroppedItemWatcher extends FlagWatcher { } public ItemStack getItemStack() { - return (ItemStack) getValue(5, new ItemStack(1)); + return (ItemStack) getValue(10, new ItemStack(1)); } public void setItemStack(ItemStack item) { - setValue(5, item); - sendData(5); + setValue(10, item); + sendData(10); } - } diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/SheepWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/SheepWatcher.java index 66f4f9b3..6231a3e4 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/SheepWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/SheepWatcher.java @@ -2,6 +2,7 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.AnimalColor; import me.libraryaddict.disguise.disguisetypes.Disguise; +import org.bukkit.DyeColor; public class SheepWatcher extends AgeableWatcher { @@ -11,7 +12,7 @@ public class SheepWatcher extends AgeableWatcher { } public AnimalColor getColor() { - return AnimalColor.getColor((byte) getValue(12, (byte) 0) & 15); + return AnimalColor.getColor(((int) getValue(12, (byte) 0) & 15)); } public boolean isSheared() { @@ -19,8 +20,12 @@ public class SheepWatcher extends AgeableWatcher { } 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.getId() & 15)); + setValue(12, (byte) (b0 & 240 | color.getWoolData() & 15)); sendData(12); } diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/TameableWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/TameableWatcher.java index c240336a..5cea7106 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/TameableWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/TameableWatcher.java @@ -28,11 +28,11 @@ public class TameableWatcher extends AgeableWatcher { } protected void setTameableFlag(int no, boolean flag) { - byte b0 = (byte) getValue(12, (byte) 0); + byte value = (byte) getValue(12, (byte) 0); if (flag) { - setValue(12, (byte) (b0 | no)); + setValue(12, (byte) (value | no)); } else { - setValue(12, (byte) (b0 & -(no + 1))); + setValue(12, (byte) (value & -(no + 1))); } sendData(12); } diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/WolfWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/WolfWatcher.java index 097c9f75..1f35bc01 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/WolfWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/WolfWatcher.java @@ -2,6 +2,7 @@ package me.libraryaddict.disguise.disguisetypes.watchers; import me.libraryaddict.disguise.disguisetypes.AnimalColor; import me.libraryaddict.disguise.disguisetypes.Disguise; +import org.bukkit.DyeColor; public class WolfWatcher extends TameableWatcher { @@ -47,13 +48,17 @@ public class WolfWatcher extends TameableWatcher { setTameableFlag(2, angry); } - public void setCollarColor(AnimalColor newColor) { + public void setCollarColor(AnimalColor color) { + setCollarColor(DyeColor.getByWoolData((byte) color.getId())); + } + + public void setCollarColor(DyeColor newColor) { if (!isTamed()) { setTamed(true); } - if (newColor != getCollarColor()) { - setValue(14, (byte) newColor.getId()); - sendData(14); + if (newColor.getWoolData() != getCollarColor().getId()) { + setValue(16, (int) newColor.getDyeData()); + sendData(16); } } diff --git a/src/main/java/me/libraryaddict/disguise/utilities/PacketsManager.java b/src/main/java/me/libraryaddict/disguise/utilities/PacketsManager.java index ef5adfe7..e1e0e81c 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/PacketsManager.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/PacketsManager.java @@ -1305,10 +1305,7 @@ public class PacketsManager { // Else if the packet is sending entity metadata else if (sentPacket.getType() == Server.ENTITY_METADATA) { - if (DisguiseConfig.isMetadataPacketsEnabled() && (disguise.getType() != DisguiseType.WOLF && - disguise.getType() != DisguiseType.OCELOT && - disguise.getType() != DisguiseType.ENDERMAN && - disguise.getType() != DisguiseType.SHULKER)) { + if (DisguiseConfig.isMetadataPacketsEnabled() && !isStaticMetadataDisguiseType(disguise)) { List watchableObjects = disguise.getWatcher().convert( packets[0].getWatchableCollectionModifier().read(0)); packets[0] = new PacketContainer(sentPacket.getType()); @@ -1420,10 +1417,7 @@ public class PacketsManager { if (heldItem != null && heldItem.getType() != Material.AIR) { // Convert the datawatcher List list = new ArrayList<>(); - if (DisguiseConfig.isMetadataPacketsEnabled() && (disguise.getType() != DisguiseType.WOLF && - disguise.getType() != DisguiseType.OCELOT && - disguise.getType() != DisguiseType.ENDERMAN && - disguise.getType() != DisguiseType.SHULKER)) { + if (DisguiseConfig.isMetadataPacketsEnabled() && !isStaticMetadataDisguiseType(disguise)) { WrappedWatchableObject watch = new WrappedWatchableObject(ReflectionManager.createDataWatcherItem(0, WrappedDataWatcher.getEntityWatcher(entity).getByte(0))); list.add(watch); @@ -1498,4 +1492,19 @@ public class PacketsManager { } return packets == null ? null : new PacketContainer[][]{packets, delayedPackets}; } + + /** + * Returns true if this disguise type doesn't have changing metadata. + * @param disguise + * @return + */ + public static boolean isStaticMetadataDisguiseType(Disguise disguise) { + return (disguise.getType() == DisguiseType.WOLF || + disguise.getType() == DisguiseType.OCELOT || + disguise.getType() == DisguiseType.ENDERMAN || + disguise.getType() == DisguiseType.SHULKER || + disguise.getType() == DisguiseType.SPLASH_POTION || + disguise.getType() == DisguiseType.FIREWORK || + disguise.getType() == DisguiseType.DROPPED_ITEM); + } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 3c3c09f9..850c9c3c 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,7 +1,7 @@ name: LibsDisguises main: me.libraryaddict.disguise.LibsDisguises description: A disguise plugin with various disguises. -version: 9.0 +version: 9.0.1 author: libraryaddict authors: [Byteflux, Navid K.] softdepend: [ProtocolLib]