Fixed metadata not being sent issue for player disguises
This commit is contained in:
parent
e1bcfbb5cc
commit
49910a4fa5
@ -2,6 +2,7 @@ package me.libraryaddict.disguise.disguisetypes;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
@ -23,7 +24,6 @@ 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;
|
||||
|
||||
public class FlagWatcher {
|
||||
@ -36,7 +36,7 @@ public class FlagWatcher {
|
||||
private HashMap<Integer, Object> entityValues = new HashMap<>();
|
||||
private LibsEquipment equipment;
|
||||
private boolean hasDied;
|
||||
private HashSet<Integer> modifiedEntityAnimations = new HashSet<>();
|
||||
private boolean[] modifiedEntityAnimations = new boolean[6];
|
||||
private List<WrappedWatchableObject> watchableObjects;
|
||||
|
||||
public FlagWatcher(Disguise disguise) {
|
||||
@ -46,16 +46,12 @@ public class FlagWatcher {
|
||||
}
|
||||
|
||||
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)) {
|
||||
valueByte = (byte) (valueByte | 1 << i);
|
||||
if ((entityValue & 1 << i) != 0 && !modifiedEntityAnimations[i]) {
|
||||
originalValue = (byte) (originalValue | 1 << i);
|
||||
}
|
||||
}
|
||||
|
||||
originalValue = valueByte;
|
||||
|
||||
return originalValue;
|
||||
}
|
||||
|
||||
@ -72,7 +68,7 @@ public class FlagWatcher {
|
||||
|
||||
cloned.entityValues = (HashMap<Integer, Object>) entityValues.clone();
|
||||
cloned.equipment = equipment.clone(cloned);
|
||||
cloned.modifiedEntityAnimations = (HashSet<Integer>) modifiedEntityAnimations.clone();
|
||||
cloned.modifiedEntityAnimations = Arrays.copyOf(modifiedEntityAnimations, modifiedEntityAnimations.length);
|
||||
cloned.addEntityAnimations = addEntityAnimations;
|
||||
|
||||
return cloned;
|
||||
@ -89,7 +85,7 @@ public class FlagWatcher {
|
||||
|
||||
// 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 == FlagType.ENTITY_AIR_TICKS.getIndex()) {
|
||||
sendAllCustom = true;
|
||||
}
|
||||
|
||||
@ -334,10 +330,7 @@ public class FlagWatcher {
|
||||
Object value = entityValues.get(data.getIndex());
|
||||
|
||||
if (isEntityAnimationsAdded() && DisguiseConfig.isMetadataPacketsEnabled() && data == FlagType.ENTITY_META) {
|
||||
if (!PacketsManager.isStaticMetadataDisguiseType(disguise)) {
|
||||
value = addEntityAnimations((byte) value,
|
||||
WrappedDataWatcher.getEntityWatcher(disguise.getEntity()).getByte(0));
|
||||
}
|
||||
value = addEntityAnimations((byte) value, WrappedDataWatcher.getEntityWatcher(disguise.getEntity()).getByte(0));
|
||||
}
|
||||
|
||||
WrappedWatchableObject watch = ReflectionManager.createWatchable(data.getIndex(), value);
|
||||
@ -408,7 +401,7 @@ public class FlagWatcher {
|
||||
}
|
||||
|
||||
private void setEntityFlag(int byteValue, boolean flag) {
|
||||
modifiedEntityAnimations.add(byteValue);
|
||||
modifiedEntityAnimations[byteValue] = true;
|
||||
|
||||
byte b0 = (byte) getData(FlagType.ENTITY_META);
|
||||
|
||||
|
@ -80,7 +80,7 @@ public class PacketsManager {
|
||||
}
|
||||
|
||||
public void setPacketType(PacketType type) {
|
||||
isSpawnPacket = type.name().contains("SPAWN_");
|
||||
isSpawnPacket = type.name().contains("SPAWN") && type.name().contains("ENTITY");
|
||||
}
|
||||
|
||||
public void addPacket(PacketContainer packet) {
|
||||
@ -142,7 +142,7 @@ public class PacketsManager {
|
||||
private static PacketListener viewDisguisesListener;
|
||||
private static PacketListener tabListListener;
|
||||
private static boolean viewDisguisesListenerEnabled;
|
||||
private static HashMap<Disguise, ArrayList<UUID>> _cancelMeta = new HashMap<Disguise, ArrayList<UUID>>();
|
||||
private static HashMap<Disguise, ArrayList<UUID>> cancelMeta = new HashMap<Disguise, ArrayList<UUID>>();
|
||||
|
||||
public static void addPacketListeners() {
|
||||
// Add a client listener to cancel them interacting with uninteractable disguised entitys.
|
||||
@ -162,7 +162,7 @@ public class PacketsManager {
|
||||
public static void removeCancel(Disguise disguise, Player observer) {
|
||||
ArrayList<UUID> cancel;
|
||||
|
||||
if ((cancel = _cancelMeta.get(disguise)) == null)
|
||||
if ((cancel = cancelMeta.get(disguise)) == null)
|
||||
return;
|
||||
|
||||
cancel.remove(observer.getUniqueId());
|
||||
@ -170,7 +170,7 @@ public class PacketsManager {
|
||||
if (!cancel.isEmpty())
|
||||
return;
|
||||
|
||||
_cancelMeta.remove(disguise);
|
||||
cancelMeta.remove(disguise);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -402,10 +402,11 @@ public class PacketsManager {
|
||||
metaPacket.getIntegers().write(0, entityId); // Id
|
||||
metaPacket.getWatchableCollectionModifier().write(0, newWatcher.getWatchableObjects());
|
||||
|
||||
if (!_cancelMeta.containsKey(disguise))
|
||||
_cancelMeta.put(disguise, new ArrayList<UUID>());
|
||||
if (!cancelMeta.containsKey(disguise))
|
||||
cancelMeta.put(disguise, new ArrayList<UUID>());
|
||||
|
||||
cancelMeta.get(disguise).add(observer.getUniqueId());
|
||||
|
||||
_cancelMeta.get(disguise).add(observer.getUniqueId());
|
||||
packets.addDelayedPacket(metaPacket, 4);
|
||||
}
|
||||
|
||||
@ -929,8 +930,8 @@ public class PacketsManager {
|
||||
else if (sentPacket.getType() == Server.ENTITY_METADATA) {
|
||||
packets.clear();
|
||||
|
||||
if (DisguiseConfig.isMetadataPacketsEnabled() && !isStaticMetadataDisguiseType(disguise)
|
||||
&& (!_cancelMeta.containsKey(disguise) || !_cancelMeta.get(disguise).contains(observer.getUniqueId()))) {
|
||||
if (DisguiseConfig.isMetadataPacketsEnabled()
|
||||
&& (!cancelMeta.containsKey(disguise) || !cancelMeta.get(disguise).contains(observer.getUniqueId()))) {
|
||||
List<WrappedWatchableObject> watchableObjects = disguise.getWatcher()
|
||||
.convert(sentPacket.getWatchableCollectionModifier().read(0));
|
||||
|
||||
@ -1066,7 +1067,7 @@ public class PacketsManager {
|
||||
packets.addPacket(equipPacket);
|
||||
|
||||
equipPacket.getModifier().write(2,
|
||||
(itemStack.getTypeId() == 0 ? null : ReflectionManager.getNmsItem(itemStack)));
|
||||
ReflectionManager.getNmsItem(itemStack.getType() == Material.AIR ? null : itemStack));
|
||||
}
|
||||
|
||||
if (disguise.getWatcher().isRightClicking() && slot == EquipmentSlot.HAND) {
|
||||
@ -1076,7 +1077,7 @@ public class PacketsManager {
|
||||
// Convert the datawatcher
|
||||
List<WrappedWatchableObject> list = new ArrayList<>();
|
||||
|
||||
if (DisguiseConfig.isMetadataPacketsEnabled() && !isStaticMetadataDisguiseType(disguise)) {
|
||||
if (DisguiseConfig.isMetadataPacketsEnabled()) {
|
||||
WrappedWatchableObject watch = ReflectionManager.createWatchable(0,
|
||||
WrappedDataWatcher.getEntityWatcher(entity).getByte(0));
|
||||
|
||||
@ -1173,18 +1174,4 @@ public class PacketsManager {
|
||||
|
||||
return packets;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this disguise type doesn't have changing metadata.
|
||||
*
|
||||
* @param disguise
|
||||
* @return
|
||||
*/
|
||||
public static boolean isStaticMetadataDisguiseType(Disguise disguise) {
|
||||
return false;
|
||||
/* 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 || disguise.getType() == DisguiseType.ENDER_CRYSTAL);*/
|
||||
}
|
||||
}
|
||||
|
@ -21,16 +21,13 @@ import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.utilities.PacketsManager;
|
||||
import me.libraryaddict.disguise.utilities.PacketsManager.LibsPackets;
|
||||
|
||||
public class PacketListenerMain extends PacketAdapter
|
||||
{
|
||||
public PacketListenerMain(LibsDisguises plugin, ArrayList<PacketType> packetsToListen)
|
||||
{
|
||||
public class PacketListenerMain extends PacketAdapter {
|
||||
public PacketListenerMain(LibsDisguises plugin, ArrayList<PacketType> packetsToListen) {
|
||||
super(plugin, ListenerPriority.HIGH, packetsToListen);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketSending(final PacketEvent event)
|
||||
{
|
||||
public void onPacketSending(final PacketEvent event) {
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
|
||||
@ -56,19 +53,16 @@ public class PacketListenerMain extends PacketAdapter
|
||||
|
||||
LibsPackets packets;
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
packets = PacketsManager.transformPacket(event.getPacket(), disguise, observer, entity);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (packets.isUnhandled())
|
||||
{
|
||||
if (packets.isUnhandled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -76,17 +70,14 @@ public class PacketListenerMain extends PacketAdapter
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
try
|
||||
{
|
||||
for (PacketContainer packet : packets.getPackets())
|
||||
{
|
||||
try {
|
||||
for (PacketContainer packet : packets.getPackets()) {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false);
|
||||
}
|
||||
|
||||
packets.sendDelayed(observer);
|
||||
}
|
||||
catch (InvocationTargetException ex)
|
||||
{
|
||||
catch (InvocationTargetException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user