From 19aabb265638c692fec9c1a73dc8f9cc3fa0e542 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sat, 24 May 2014 05:14:14 +1200 Subject: [PATCH] Fixed sending data on a flagwatcher not taking their real metadata into account when its adding metadata --- .../disguise/disguisetypes/FlagWatcher.java | 28 ++++++++++++------- .../disguise/utilities/PacketsManager.java | 2 +- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java index 79169d74..9ffde0c0 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java @@ -15,6 +15,7 @@ import com.comphenix.protocol.PacketType; import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.reflect.StructureModifier; +import com.comphenix.protocol.wrappers.WrappedDataWatcher; import com.comphenix.protocol.wrappers.WrappedWatchableObject; import me.libraryaddict.disguise.DisguiseAPI; @@ -45,7 +46,7 @@ public class FlagWatcher { private TargetedDisguise disguise; private HashMap entityValues = new HashMap(); private boolean hasDied; - private org.bukkit.inventory.ItemStack[] items = new org.bukkit.inventory.ItemStack[5]; + private ItemStack[] items = new ItemStack[5]; private HashSet modifiedEntityAnimations = new HashSet(); private List watchableObjects; @@ -53,6 +54,17 @@ public class FlagWatcher { this.disguise = (TargetedDisguise) disguise; } + private byte addEntityAnimations(byte originalValue, byte entityValue) { + byte valueByte = (Byte) originalValue; + for (int i = 0; i < 6; i++) { + if ((entityValue & 1 << i) != 0 && !modifiedEntityAnimations.contains(i)) { + valueByte = (byte) (valueByte | 1 << i); + } + } + originalValue = valueByte; + return originalValue; + } + public FlagWatcher clone(Disguise owningDisguise) { FlagWatcher cloned = null; try { @@ -89,15 +101,8 @@ public class FlagWatcher { value = backupEntityValues.get(dataType); } if (value != null) { - if (addEntityAnimations && dataType == 0) { - byte watcher = (Byte) watch.getValue(); - byte valueByte = (Byte) value; - for (int i = 0; i < 6; i++) { - if ((watcher & 1 << i) != 0 && !modifiedEntityAnimations.contains(i)) { - valueByte = (byte) (valueByte | 1 << i); - } - } - value = valueByte; + if (isEntityAnimationsAdded() && dataType == 0) { + value = this.addEntityAnimations((Byte) value, (Byte) watch.getValue()); } boolean isDirty = watch.getDirtyState(); watch = new WrappedWatchableObject(dataType, value); @@ -237,6 +242,9 @@ public class FlagWatcher { if (!entityValues.containsKey(data) || entityValues.get(data) == null) continue; Object value = entityValues.get(data); + if (isEntityAnimationsAdded() && DisguiseConfig.isMetadataPacketsEnabled() && data == 0) { + value = addEntityAnimations((Byte) value, WrappedDataWatcher.getEntityWatcher(disguise.getEntity()).getByte(0)); + } list.add(new WrappedWatchableObject(data, value)); } if (!list.isEmpty()) { diff --git a/src/me/libraryaddict/disguise/utilities/PacketsManager.java b/src/me/libraryaddict/disguise/utilities/PacketsManager.java index ef4fbdf4..42962b46 100644 --- a/src/me/libraryaddict/disguise/utilities/PacketsManager.java +++ b/src/me/libraryaddict/disguise/utilities/PacketsManager.java @@ -1303,7 +1303,7 @@ public class PacketsManager { // Convert the datawatcher List list = new ArrayList(); if (DisguiseConfig.isMetadataPacketsEnabled()) { - list.add(new WrappedWatchableObject(0, WrappedDataWatcher.getEntityWatcher(entity).getObject(0))); + list.add(new WrappedWatchableObject(0, WrappedDataWatcher.getEntityWatcher(entity).getByte(0))); list = disguise.getWatcher().convert(list); } else { for (WrappedWatchableObject obj : disguise.getWatcher().getWatchableObjects()) {