From 2c7a6e2b43123fe86617caa63f6c2b8d39362b91 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Tue, 25 Jul 2017 06:58:58 +1200 Subject: [PATCH] Add check for null watchable object --- .../disguise/utilities/PacketsManager.java | 3 +- .../disguise/utilities/ReflectionManager.java | 4 ++- .../PacketListenerViewDisguises.java | 28 +++++++++---------- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/me/libraryaddict/disguise/utilities/PacketsManager.java b/src/me/libraryaddict/disguise/utilities/PacketsManager.java index a56631f2..b527268d 100644 --- a/src/me/libraryaddict/disguise/utilities/PacketsManager.java +++ b/src/me/libraryaddict/disguise/utilities/PacketsManager.java @@ -1058,7 +1058,8 @@ public class PacketsManager { WrappedWatchableObject watch = ReflectionManager .createWatchable(0, WrappedDataWatcher.getEntityWatcher(entity).getByte(0)); - list.add(watch); + if (watch != null) + list.add(watch); list = disguise.getWatcher().convert(list); } else { diff --git a/src/me/libraryaddict/disguise/utilities/ReflectionManager.java b/src/me/libraryaddict/disguise/utilities/ReflectionManager.java index e5a91a6b..93aa6ab9 100644 --- a/src/me/libraryaddict/disguise/utilities/ReflectionManager.java +++ b/src/me/libraryaddict/disguise/utilities/ReflectionManager.java @@ -887,7 +887,9 @@ public class ReflectionManager { } public static WrappedWatchableObject createWatchable(int index, Object obj) { - return new WrappedWatchableObject(createDataWatcherItem(index, obj)); + Object watcherItem = createDataWatcherItem(index, obj); + + return new WrappedWatchableObject(watcherItem); } public static int getCombinedId(int id, int data) { diff --git a/src/me/libraryaddict/disguise/utilities/packetlisteners/PacketListenerViewDisguises.java b/src/me/libraryaddict/disguise/utilities/packetlisteners/PacketListenerViewDisguises.java index 454f2306..e0df570e 100644 --- a/src/me/libraryaddict/disguise/utilities/packetlisteners/PacketListenerViewDisguises.java +++ b/src/me/libraryaddict/disguise/utilities/packetlisteners/PacketListenerViewDisguises.java @@ -118,8 +118,7 @@ public class PacketListenerViewDisguises extends PacketAdapter { watch.setValue(a); } } - } - else if (event.getPacketType() == Server.NAMED_ENTITY_SPAWN) { + } else if (event.getPacketType() == Server.NAMED_ENTITY_SPAWN) { event.setCancelled(true); PacketContainer packet = new PacketContainer(Server.ENTITY_METADATA); @@ -136,7 +135,9 @@ public class PacketListenerViewDisguises extends PacketAdapter { WrappedWatchableObject watch = ReflectionManager.createWatchable(0, b); - watchableList.add(watch); + if (watch != null) + watchableList.add(watch); + packet.getWatchableCollectionModifier().write(0, watchableList); try { @@ -145,21 +146,20 @@ public class PacketListenerViewDisguises extends PacketAdapter { catch (InvocationTargetException e) { e.printStackTrace(); } - } - else if (event.getPacketType() == Server.ANIMATION) { + } else if (event.getPacketType() == Server.ANIMATION) { if (event.getPacket().getIntegers().read(1) != 2) { event.setCancelled(true); } - } - else if (event.getPacketType() == Server.ATTACH_ENTITY || event.getPacketType() == Server.REL_ENTITY_MOVE - || event.getPacketType() == Server.REL_ENTITY_MOVE_LOOK || event.getPacketType() == Server.ENTITY_LOOK - || event.getPacketType() == Server.ENTITY_TELEPORT || event.getPacketType() == Server.ENTITY_HEAD_ROTATION - || event.getPacketType() == Server.ENTITY_EQUIPMENT) { + } else if (event.getPacketType() == Server.ATTACH_ENTITY || event + .getPacketType() == Server.REL_ENTITY_MOVE || event + .getPacketType() == Server.REL_ENTITY_MOVE_LOOK || event + .getPacketType() == Server.ENTITY_LOOK || event.getPacketType() == Server.ENTITY_TELEPORT || event + .getPacketType() == Server.ENTITY_HEAD_ROTATION || event + .getPacketType() == Server.ENTITY_EQUIPMENT) { event.setCancelled(true); - } - else if (event.getPacketType() == Server.ENTITY_STATUS) { - if (disguise.isSelfDisguiseSoundsReplaced() && !disguise.getType().isPlayer() - && event.getPacket().getBytes().read(0) == 2) { + } else if (event.getPacketType() == Server.ENTITY_STATUS) { + if (disguise.isSelfDisguiseSoundsReplaced() && !disguise.getType().isPlayer() && event.getPacket() + .getBytes().read(0) == 2) { event.setCancelled(true); } }