Fix isRightClicking() and add isSpinning()
This commit is contained in:
		| @@ -18,6 +18,7 @@ import me.libraryaddict.disguise.LibsDisguises; | |||||||
| import me.libraryaddict.disguise.utilities.DisguiseUtilities; | import me.libraryaddict.disguise.utilities.DisguiseUtilities; | ||||||
| import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue; | import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue; | ||||||
| import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; | import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; | ||||||
|  | import me.libraryaddict.disguise.utilities.reflection.NmsRemovedIn; | ||||||
| import me.libraryaddict.disguise.utilities.reflection.NmsVersion; | import me.libraryaddict.disguise.utilities.reflection.NmsVersion; | ||||||
| import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; | import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; | ||||||
| import net.md_5.bungee.api.chat.BaseComponent; | import net.md_5.bungee.api.chat.BaseComponent; | ||||||
| @@ -52,7 +53,6 @@ public class FlagWatcher { | |||||||
|     private boolean[] modifiedEntityAnimations = new boolean[8]; |     private boolean[] modifiedEntityAnimations = new boolean[8]; | ||||||
|     private transient List<WrappedWatchableObject> watchableObjects; |     private transient List<WrappedWatchableObject> watchableObjects; | ||||||
|     private boolean sleeping; |     private boolean sleeping; | ||||||
|     private boolean swimming; |  | ||||||
|     private transient boolean previouslySneaking; |     private transient boolean previouslySneaking; | ||||||
|     @Getter |     @Getter | ||||||
|     private boolean upsideDown; |     private boolean upsideDown; | ||||||
| @@ -88,7 +88,6 @@ public class FlagWatcher { | |||||||
|         cloned.modifiedEntityAnimations = Arrays.copyOf(modifiedEntityAnimations, modifiedEntityAnimations.length); |         cloned.modifiedEntityAnimations = Arrays.copyOf(modifiedEntityAnimations, modifiedEntityAnimations.length); | ||||||
|         cloned.addEntityAnimations = addEntityAnimations; |         cloned.addEntityAnimations = addEntityAnimations; | ||||||
|         cloned.upsideDown = upsideDown; |         cloned.upsideDown = upsideDown; | ||||||
|         cloned.swimming = swimming; |  | ||||||
|         cloned.sleeping = sleeping; |         cloned.sleeping = sleeping; | ||||||
|  |  | ||||||
|         return cloned; |         return cloned; | ||||||
| @@ -559,11 +558,17 @@ public class FlagWatcher { | |||||||
|         sendData(MetaIndex.ENTITY_NO_GRAVITY); |         sendData(MetaIndex.ENTITY_NO_GRAVITY); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     //@NmsRemovedIn(val = NmsVersion.v1_13) | ||||||
|     public boolean isRightClicking() { |     public boolean isRightClicking() { | ||||||
|         return getEntityFlag(4); |         return !NmsVersion.v1_13.isSupported() && getEntityFlag(4); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     //@NmsRemovedIn(val = NmsVersion.v1_13) | ||||||
|     public void setRightClicking(boolean setRightClicking) { |     public void setRightClicking(boolean setRightClicking) { | ||||||
|  |         if (NmsVersion.v1_13.isSupported()) { | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  |  | ||||||
|         setEntityFlag(4, setRightClicking); |         setEntityFlag(4, setRightClicking); | ||||||
|         sendData(MetaIndex.ENTITY_META); |         sendData(MetaIndex.ENTITY_META); | ||||||
|     } |     } | ||||||
| @@ -796,7 +801,7 @@ public class FlagWatcher { | |||||||
|  |  | ||||||
|     @NmsAddedIn(val = NmsVersion.v1_14) |     @NmsAddedIn(val = NmsVersion.v1_14) | ||||||
|     public boolean isSwimming() { |     public boolean isSwimming() { | ||||||
|         return swimming; |         return getEntityFlag(4); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @NmsAddedIn(val = NmsVersion.v1_14) |     @NmsAddedIn(val = NmsVersion.v1_14) | ||||||
| @@ -805,7 +810,7 @@ public class FlagWatcher { | |||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         this.swimming = swimming; |         setEntityFlag(4, swimming); | ||||||
|  |  | ||||||
|         updatePose(); |         updatePose(); | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -17,7 +17,6 @@ public class InsentientWatcher extends LivingWatcher { | |||||||
|  |  | ||||||
|     public void setMainHand(MainHand mainHand) { |     public void setMainHand(MainHand mainHand) { | ||||||
|         setInsentientFlag(2, mainHand == MainHand.RIGHT); |         setInsentientFlag(2, mainHand == MainHand.RIGHT); | ||||||
|         sendData(MetaIndex.INSENTIENT_META); |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public boolean isAI() { |     public boolean isAI() { | ||||||
| @@ -26,7 +25,6 @@ public class InsentientWatcher extends LivingWatcher { | |||||||
|  |  | ||||||
|     public void setAI(boolean ai) { |     public void setAI(boolean ai) { | ||||||
|         setInsentientFlag(1, ai); |         setInsentientFlag(1, ai); | ||||||
|         sendData(MetaIndex.INSENTIENT_META); |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private void setInsentientFlag(int i, boolean flag) { |     private void setInsentientFlag(int i, boolean flag) { | ||||||
| @@ -37,6 +35,8 @@ public class InsentientWatcher extends LivingWatcher { | |||||||
|         } else { |         } else { | ||||||
|             setData(MetaIndex.INSENTIENT_META, (byte) (b0 & i)); |             setData(MetaIndex.INSENTIENT_META, (byte) (b0 & i)); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |         sendData(MetaIndex.INSENTIENT_META); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private boolean getInsentientFlag(int i) { |     private boolean getInsentientFlag(int i) { | ||||||
| @@ -51,6 +51,5 @@ public class InsentientWatcher extends LivingWatcher { | |||||||
|     @NmsAddedIn(val = NmsVersion.v1_14) |     @NmsAddedIn(val = NmsVersion.v1_14) | ||||||
|     public void setEnraged(boolean enraged) { |     public void setEnraged(boolean enraged) { | ||||||
|         setInsentientFlag(4, enraged); |         setInsentientFlag(4, enraged); | ||||||
|         sendData(MetaIndex.INSENTIENT_META); |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -4,6 +4,7 @@ import com.comphenix.protocol.PacketType.Play.Server; | |||||||
| 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.wrappers.BlockPosition; | import com.comphenix.protocol.wrappers.BlockPosition; | ||||||
|  | import com.comphenix.protocol.wrappers.EnumWrappers; | ||||||
| import com.comphenix.protocol.wrappers.WrappedAttribute; | import com.comphenix.protocol.wrappers.WrappedAttribute; | ||||||
| import com.comphenix.protocol.wrappers.WrappedAttribute.Builder; | import com.comphenix.protocol.wrappers.WrappedAttribute.Builder; | ||||||
| import me.libraryaddict.disguise.DisguiseAPI; | import me.libraryaddict.disguise.DisguiseAPI; | ||||||
| @@ -11,11 +12,13 @@ import me.libraryaddict.disguise.disguisetypes.Disguise; | |||||||
| import me.libraryaddict.disguise.disguisetypes.FlagWatcher; | import me.libraryaddict.disguise.disguisetypes.FlagWatcher; | ||||||
| import me.libraryaddict.disguise.disguisetypes.MetaIndex; | import me.libraryaddict.disguise.disguisetypes.MetaIndex; | ||||||
| import me.libraryaddict.disguise.utilities.DisguiseUtilities; | import me.libraryaddict.disguise.utilities.DisguiseUtilities; | ||||||
|  | import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue; | ||||||
| import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; | import me.libraryaddict.disguise.utilities.reflection.NmsAddedIn; | ||||||
| import me.libraryaddict.disguise.utilities.reflection.NmsVersion; | import me.libraryaddict.disguise.utilities.reflection.NmsVersion; | ||||||
| import org.bukkit.Color; | import org.bukkit.Color; | ||||||
| import org.bukkit.entity.Entity; | import org.bukkit.entity.Entity; | ||||||
| import org.bukkit.entity.Player; | import org.bukkit.entity.Player; | ||||||
|  | import org.bukkit.inventory.MainHand; | ||||||
| import org.bukkit.potion.PotionEffectType; | import org.bukkit.potion.PotionEffectType; | ||||||
|  |  | ||||||
| import java.lang.reflect.InvocationTargetException; | import java.lang.reflect.InvocationTargetException; | ||||||
| @@ -68,6 +71,52 @@ public class LivingWatcher extends FlagWatcher { | |||||||
|         sendData(MetaIndex.LIVING_HEALTH); |         sendData(MetaIndex.LIVING_HEALTH); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /*@NmsAddedIn(val = NmsVersion.v1_13) | ||||||
|  |     public MainHand getMainHand() { | ||||||
|  |         return getHandFlag(0) ? MainHand.RIGHT : MainHand.LEFT; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     @NmsAddedIn(val = NmsVersion.v1_13) | ||||||
|  |     public void setMainHand(MainHand hand) { | ||||||
|  |         setHandFlag(0, hand == MainHand.RIGHT); | ||||||
|  |     }*/ | ||||||
|  |  | ||||||
|  |     private boolean getHandFlag(int byteValue) { | ||||||
|  |         return (getData(MetaIndex.LIVING_HAND) & 1 << byteValue) != 0; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     private void setHandFlag(int byteValue, boolean flag) { | ||||||
|  |         byte b0 = getData(MetaIndex.LIVING_HAND); | ||||||
|  |  | ||||||
|  |         if (flag) { | ||||||
|  |             setData(MetaIndex.LIVING_HAND, (byte) (b0 | 1 << byteValue)); | ||||||
|  |         } else { | ||||||
|  |             setData(MetaIndex.LIVING_HAND, (byte) (b0 & ~(1 << byteValue))); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         sendData(MetaIndex.LIVING_HAND); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     @NmsAddedIn(val = NmsVersion.v1_13) | ||||||
|  |     public boolean isRightClicking() { | ||||||
|  |         return getHandFlag(0); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     @NmsAddedIn(val = NmsVersion.v1_13) | ||||||
|  |     public void setRightClicking(boolean setRightClicking) { | ||||||
|  |         setHandFlag(0, setRightClicking); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     @NmsAddedIn(val = NmsVersion.v1_13) | ||||||
|  |     public boolean isSpinning() { | ||||||
|  |         return getHandFlag(2); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     @NmsAddedIn(val = NmsVersion.v1_13) | ||||||
|  |     public void setSpinning(boolean setSpinning) { | ||||||
|  |         setHandFlag(2, setSpinning); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     public double getMaxHealth() { |     public double getMaxHealth() { | ||||||
|         return maxHealth; |         return maxHealth; | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -84,16 +84,17 @@ public class PacketHandlerEquipment implements IPacketHandler { | |||||||
|                 newSlots.add(pair); |                 newSlots.add(pair); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             if (disguise.getWatcher().isRightClicking() && slot == EquipmentSlot.HAND) { |             if (disguise.getWatcher().isRightClicking() && | ||||||
|                 ItemStack heldItem = packets.getPackets().get(0).getItemModifier().read(0); |                     (slot == EquipmentSlot.HAND || slot == EquipmentSlot.OFF_HAND)) { | ||||||
|  |                 itemStack = ReflectionManager.getBukkitItem(pair.getSecond()); | ||||||
|  |  | ||||||
|                 if (heldItem != null && heldItem.getType() != Material.AIR) { |                 if (itemStack != null && itemStack.getType() != Material.AIR) { | ||||||
|                     // Convert the datawatcher |                     // Convert the datawatcher | ||||||
|                     List<WrappedWatchableObject> list = new ArrayList<>(); |                     List<WrappedWatchableObject> list = new ArrayList<>(); | ||||||
|  |  | ||||||
|                     if (DisguiseConfig.isMetaPacketsEnabled()) { |                     if (DisguiseConfig.isMetaPacketsEnabled()) { | ||||||
|                         WrappedWatchableObject watch = ReflectionManager.createWatchable(MetaIndex.ENTITY_META, |                         WrappedWatchableObject watch = ReflectionManager.createWatchable(MetaIndex.LIVING_HAND, | ||||||
|                                 WrappedDataWatcher.getEntityWatcher(entity).getByte(0)); |                                 WrappedDataWatcher.getEntityWatcher(entity).getByte(MetaIndex.LIVING_HAND.getIndex())); | ||||||
|  |  | ||||||
|                         if (watch != null) |                         if (watch != null) | ||||||
|                             list.add(watch); |                             list.add(watch); | ||||||
| @@ -101,7 +102,7 @@ public class PacketHandlerEquipment implements IPacketHandler { | |||||||
|                         list = disguise.getWatcher().convert(list); |                         list = disguise.getWatcher().convert(list); | ||||||
|                     } else { |                     } else { | ||||||
|                         for (WrappedWatchableObject obj : disguise.getWatcher().getWatchableObjects()) { |                         for (WrappedWatchableObject obj : disguise.getWatcher().getWatchableObjects()) { | ||||||
|                             if (obj.getIndex() == 0) { |                             if (obj.getIndex() == MetaIndex.LIVING_HAND.getIndex()) { | ||||||
|                                 list.add(obj); |                                 list.add(obj); | ||||||
|                                 break; |                                 break; | ||||||
|                             } |                             } | ||||||
| @@ -117,7 +118,7 @@ public class PacketHandlerEquipment implements IPacketHandler { | |||||||
|                     PacketContainer packetUnblock = packetBlock.deepClone(); |                     PacketContainer packetUnblock = packetBlock.deepClone(); | ||||||
|                     // Make a packet to send the 'unblock' |                     // Make a packet to send the 'unblock' | ||||||
|                     for (WrappedWatchableObject watcher : packetUnblock.getWatchableCollectionModifier().read(0)) { |                     for (WrappedWatchableObject watcher : packetUnblock.getWatchableCollectionModifier().read(0)) { | ||||||
|                         watcher.setValue((byte) ((byte) watcher.getValue() & ~(1 << 4))); |                         watcher.setValue((byte) 0); | ||||||
|                     } |                     } | ||||||
|  |  | ||||||
|                     // Send the unblock before the itemstack change so that the 2nd metadata packet works. Why? |                     // Send the unblock before the itemstack change so that the 2nd metadata packet works. Why? | ||||||
| @@ -158,16 +159,17 @@ public class PacketHandlerEquipment implements IPacketHandler { | |||||||
|                     .write(2, ReflectionManager.getNmsItem(itemStack.getType() == Material.AIR ? null : itemStack)); |                     .write(2, ReflectionManager.getNmsItem(itemStack.getType() == Material.AIR ? null : itemStack)); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         if (disguise.getWatcher().isRightClicking() && slot == EquipmentSlot.HAND) { |         if (disguise.getWatcher().isRightClicking() && (slot == EquipmentSlot.HAND || slot == EquipmentSlot.OFF_HAND)) { | ||||||
|             ItemStack heldItem = packets.getPackets().get(0).getItemModifier().read(0); |             ItemStack heldItem = packets.getPackets().get(0).getItemModifier().read(0); | ||||||
|  |  | ||||||
|             if (heldItem != null && heldItem.getType() != Material.AIR) { |             if (heldItem != null && heldItem.getType() != Material.AIR) { | ||||||
|                 // Convert the datawatcher |                 // Convert the datawatcher | ||||||
|                 List<WrappedWatchableObject> list = new ArrayList<>(); |                 List<WrappedWatchableObject> list = new ArrayList<>(); | ||||||
|  |                 MetaIndex toUse = NmsVersion.v1_13.isSupported() ? MetaIndex.LIVING_HAND : MetaIndex.ENTITY_META; | ||||||
|  |  | ||||||
|                 if (DisguiseConfig.isMetaPacketsEnabled()) { |                 if (DisguiseConfig.isMetaPacketsEnabled()) { | ||||||
|                     WrappedWatchableObject watch = ReflectionManager.createWatchable(MetaIndex.ENTITY_META, |                     WrappedWatchableObject watch = ReflectionManager.createWatchable(toUse, | ||||||
|                             WrappedDataWatcher.getEntityWatcher(entity).getByte(0)); |                             WrappedDataWatcher.getEntityWatcher(entity).getByte(toUse.getIndex())); | ||||||
|  |  | ||||||
|                     if (watch != null) |                     if (watch != null) | ||||||
|                         list.add(watch); |                         list.add(watch); | ||||||
| @@ -175,7 +177,7 @@ public class PacketHandlerEquipment implements IPacketHandler { | |||||||
|                     list = disguise.getWatcher().convert(list); |                     list = disguise.getWatcher().convert(list); | ||||||
|                 } else { |                 } else { | ||||||
|                     for (WrappedWatchableObject obj : disguise.getWatcher().getWatchableObjects()) { |                     for (WrappedWatchableObject obj : disguise.getWatcher().getWatchableObjects()) { | ||||||
|                         if (obj.getIndex() == 0) { |                         if (obj.getIndex() == toUse.getIndex()) { | ||||||
|                             list.add(obj); |                             list.add(obj); | ||||||
|                             break; |                             break; | ||||||
|                         } |                         } | ||||||
| @@ -191,7 +193,11 @@ public class PacketHandlerEquipment implements IPacketHandler { | |||||||
|                 PacketContainer packetUnblock = packetBlock.deepClone(); |                 PacketContainer packetUnblock = packetBlock.deepClone(); | ||||||
|                 // Make a packet to send the 'unblock' |                 // Make a packet to send the 'unblock' | ||||||
|                 for (WrappedWatchableObject watcher : packetUnblock.getWatchableCollectionModifier().read(0)) { |                 for (WrappedWatchableObject watcher : packetUnblock.getWatchableCollectionModifier().read(0)) { | ||||||
|                     watcher.setValue((byte) ((byte) watcher.getValue() & ~(1 << 4))); |                     if (NmsVersion.v1_13.isSupported()) { | ||||||
|  |                         watcher.setValue((byte) 0); | ||||||
|  |                     } else { | ||||||
|  |                         watcher.setValue((byte) ((byte) watcher.getValue() & ~(1 << 4))); | ||||||
|  |                     } | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
|                 // Send the unblock before the itemstack change so that the 2nd metadata packet works. Why? |                 // Send the unblock before the itemstack change so that the 2nd metadata packet works. Why? | ||||||
|   | |||||||
| @@ -235,9 +235,10 @@ public class DisguiseParser { | |||||||
|  |  | ||||||
|             if (!Objects.deepEquals(dObj, object)) { |             if (!Objects.deepEquals(dObj, object)) { | ||||||
|                 throw new IllegalStateException(String.format( |                 throw new IllegalStateException(String.format( | ||||||
|                         "%s has conflicting values! This means it expected the same value again but received a " + |                         "%s has conflicting values in class %s! This means it expected the same value again but " + | ||||||
|  |                                 "received a " + | ||||||
|                                 "different value on a different disguise! %s is not the same as %s!", |                                 "different value on a different disguise! %s is not the same as %s!", | ||||||
|                         setMethod.getName(), object, dObj)); |                         setMethod.getName(), setMethod.getDeclaringClass().getName(), object, dObj)); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             return; |             return; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user