Fixed sending data on a flagwatcher not taking their real metadata into account when its adding metadata
This commit is contained in:
		@@ -15,6 +15,7 @@ import com.comphenix.protocol.PacketType;
 | 
				
			|||||||
import com.comphenix.protocol.ProtocolLibrary;
 | 
					import com.comphenix.protocol.ProtocolLibrary;
 | 
				
			||||||
import com.comphenix.protocol.events.PacketContainer;
 | 
					import com.comphenix.protocol.events.PacketContainer;
 | 
				
			||||||
import com.comphenix.protocol.reflect.StructureModifier;
 | 
					import com.comphenix.protocol.reflect.StructureModifier;
 | 
				
			||||||
 | 
					import com.comphenix.protocol.wrappers.WrappedDataWatcher;
 | 
				
			||||||
import com.comphenix.protocol.wrappers.WrappedWatchableObject;
 | 
					import com.comphenix.protocol.wrappers.WrappedWatchableObject;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import me.libraryaddict.disguise.DisguiseAPI;
 | 
					import me.libraryaddict.disguise.DisguiseAPI;
 | 
				
			||||||
@@ -45,7 +46,7 @@ public class FlagWatcher {
 | 
				
			|||||||
    private TargetedDisguise disguise;
 | 
					    private TargetedDisguise disguise;
 | 
				
			||||||
    private HashMap<Integer, Object> entityValues = new HashMap<Integer, Object>();
 | 
					    private HashMap<Integer, Object> entityValues = new HashMap<Integer, Object>();
 | 
				
			||||||
    private boolean hasDied;
 | 
					    private boolean hasDied;
 | 
				
			||||||
    private org.bukkit.inventory.ItemStack[] items = new org.bukkit.inventory.ItemStack[5];
 | 
					    private ItemStack[] items = new ItemStack[5];
 | 
				
			||||||
    private HashSet<Integer> modifiedEntityAnimations = new HashSet<Integer>();
 | 
					    private HashSet<Integer> modifiedEntityAnimations = new HashSet<Integer>();
 | 
				
			||||||
    private List<WrappedWatchableObject> watchableObjects;
 | 
					    private List<WrappedWatchableObject> watchableObjects;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -53,6 +54,17 @@ public class FlagWatcher {
 | 
				
			|||||||
        this.disguise = (TargetedDisguise) disguise;
 | 
					        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) {
 | 
					    public FlagWatcher clone(Disguise owningDisguise) {
 | 
				
			||||||
        FlagWatcher cloned = null;
 | 
					        FlagWatcher cloned = null;
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
@@ -89,15 +101,8 @@ public class FlagWatcher {
 | 
				
			|||||||
                value = backupEntityValues.get(dataType);
 | 
					                value = backupEntityValues.get(dataType);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            if (value != null) {
 | 
					            if (value != null) {
 | 
				
			||||||
                if (addEntityAnimations && dataType == 0) {
 | 
					                if (isEntityAnimationsAdded() && dataType == 0) {
 | 
				
			||||||
                    byte watcher = (Byte) watch.getValue();
 | 
					                    value = this.addEntityAnimations((Byte) value, (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;
 | 
					 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                boolean isDirty = watch.getDirtyState();
 | 
					                boolean isDirty = watch.getDirtyState();
 | 
				
			||||||
                watch = new WrappedWatchableObject(dataType, value);
 | 
					                watch = new WrappedWatchableObject(dataType, value);
 | 
				
			||||||
@@ -237,6 +242,9 @@ public class FlagWatcher {
 | 
				
			|||||||
            if (!entityValues.containsKey(data) || entityValues.get(data) == null)
 | 
					            if (!entityValues.containsKey(data) || entityValues.get(data) == null)
 | 
				
			||||||
                continue;
 | 
					                continue;
 | 
				
			||||||
            Object value = entityValues.get(data);
 | 
					            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));
 | 
					            list.add(new WrappedWatchableObject(data, value));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        if (!list.isEmpty()) {
 | 
					        if (!list.isEmpty()) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1303,7 +1303,7 @@ public class PacketsManager {
 | 
				
			|||||||
                            // Convert the datawatcher
 | 
					                            // Convert the datawatcher
 | 
				
			||||||
                            List<WrappedWatchableObject> list = new ArrayList<WrappedWatchableObject>();
 | 
					                            List<WrappedWatchableObject> list = new ArrayList<WrappedWatchableObject>();
 | 
				
			||||||
                            if (DisguiseConfig.isMetadataPacketsEnabled()) {
 | 
					                            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);
 | 
					                                list = disguise.getWatcher().convert(list);
 | 
				
			||||||
                            } else {
 | 
					                            } else {
 | 
				
			||||||
                                for (WrappedWatchableObject obj : disguise.getWatcher().getWatchableObjects()) {
 | 
					                                for (WrappedWatchableObject obj : disguise.getWatcher().getWatchableObjects()) {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user