From 1dbe7ad0566996d597605f31c8a4bf18075fe656 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Mon, 24 Mar 2014 01:45:02 +1300 Subject: [PATCH] Check if the packets from transformPackets are null before attempting to use them --- .../disguise/utilities/DisguiseUtilities.java | 6 ++- .../disguise/utilities/PacketsManager.java | 49 ++++++++++--------- 2 files changed, 31 insertions(+), 24 deletions(-) diff --git a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index cf164405..f3158f16 100644 --- a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -295,7 +295,8 @@ public class DisguiseUtilities { } /** - * @param A convidence method for me to refresh trackers in other plugins + * @param A + * convidence method for me to refresh trackers in other plugins */ public static void refreshTrackers(Entity entity) { try { @@ -530,6 +531,9 @@ public class DisguiseUtilities { private static void sendSelfPacket(Player player, PacketContainer packet, int fakeId) { PacketContainer[] packets = PacketsManager.transformPacket(packet, player, player); try { + if (packets == null) { + packets = new PacketContainer[] { packet }; + } for (PacketContainer p : packets) { p = p.deepClone(); p.getIntegers().write(0, fakeId); diff --git a/src/me/libraryaddict/disguise/utilities/PacketsManager.java b/src/me/libraryaddict/disguise/utilities/PacketsManager.java index 43d527cb..9a83169d 100644 --- a/src/me/libraryaddict/disguise/utilities/PacketsManager.java +++ b/src/me/libraryaddict/disguise/utilities/PacketsManager.java @@ -711,35 +711,38 @@ public class PacketsManager { if (fakeId > 0) { // Here I grab the packets to convert them to, So I can display them as if the disguise sent them. PacketContainer[] packets = transformPacket(event.getPacket(), observer, observer); - final PacketContainer[] delayedPackets = new PacketContainer[packets.length > 0 ? packets.length - 1 : 0]; - for (int i = 0; i < packets.length; i++) { - PacketContainer packet = packets[i]; - if (packet.equals(event.getPacket())) { - packet = packet.deepClone(); - } - packet.getModifier().write(0, fakeId); - if (i == 0) { - try { - ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false); - } catch (InvocationTargetException e) { - e.printStackTrace(); + if (packets != null) { + final PacketContainer[] delayedPackets = new PacketContainer[packets.length > 0 ? packets.length - 1 + : 0]; + for (int i = 0; i < packets.length; i++) { + PacketContainer packet = packets[i]; + if (packet.equals(event.getPacket())) { + packet = packet.deepClone(); } - } else { - delayedPackets[i - 1] = packet; - } - } - if (delayedPackets.length > 0) { - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { - public void run() { + packet.getModifier().write(0, fakeId); + if (i == 0) { try { - for (PacketContainer packet : delayedPackets) { - ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false); - } + ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false); } catch (InvocationTargetException e) { e.printStackTrace(); } + } else { + delayedPackets[i - 1] = packet; } - }); + } + if (delayedPackets.length > 0) { + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + public void run() { + try { + for (PacketContainer packet : delayedPackets) { + ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false); + } + } catch (InvocationTargetException e) { + e.printStackTrace(); + } + } + }); + } } if (event.getPacketType() == PacketType.Play.Server.ENTITY_METADATA) { event.setPacket(event.getPacket().deepClone());