Check if the packets from transformPackets are null before attempting to use them

This commit is contained in:
libraryaddict 2014-03-24 01:45:02 +13:00
parent e7bee27319
commit 1dbe7ad056
2 changed files with 31 additions and 24 deletions

View File

@ -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) { public static void refreshTrackers(Entity entity) {
try { try {
@ -530,6 +531,9 @@ public class DisguiseUtilities {
private static void sendSelfPacket(Player player, PacketContainer packet, int fakeId) { private static void sendSelfPacket(Player player, PacketContainer packet, int fakeId) {
PacketContainer[] packets = PacketsManager.transformPacket(packet, player, player); PacketContainer[] packets = PacketsManager.transformPacket(packet, player, player);
try { try {
if (packets == null) {
packets = new PacketContainer[] { packet };
}
for (PacketContainer p : packets) { for (PacketContainer p : packets) {
p = p.deepClone(); p = p.deepClone();
p.getIntegers().write(0, fakeId); p.getIntegers().write(0, fakeId);

View File

@ -711,35 +711,38 @@ public class PacketsManager {
if (fakeId > 0) { if (fakeId > 0) {
// Here I grab the packets to convert them to, So I can display them as if the disguise sent them. // 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); PacketContainer[] packets = transformPacket(event.getPacket(), observer, observer);
final PacketContainer[] delayedPackets = new PacketContainer[packets.length > 0 ? packets.length - 1 : 0]; if (packets != null) {
for (int i = 0; i < packets.length; i++) { final PacketContainer[] delayedPackets = new PacketContainer[packets.length > 0 ? packets.length - 1
PacketContainer packet = packets[i]; : 0];
if (packet.equals(event.getPacket())) { for (int i = 0; i < packets.length; i++) {
packet = packet.deepClone(); PacketContainer packet = packets[i];
} if (packet.equals(event.getPacket())) {
packet.getModifier().write(0, fakeId); packet = packet.deepClone();
if (i == 0) {
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false);
} catch (InvocationTargetException e) {
e.printStackTrace();
} }
} else { packet.getModifier().write(0, fakeId);
delayedPackets[i - 1] = packet; if (i == 0) {
}
}
if (delayedPackets.length > 0) {
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
public void run() {
try { try {
for (PacketContainer packet : delayedPackets) { ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false);
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false);
}
} catch (InvocationTargetException e) { } catch (InvocationTargetException e) {
e.printStackTrace(); 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) { if (event.getPacketType() == PacketType.Play.Server.ENTITY_METADATA) {
event.setPacket(event.getPacket().deepClone()); event.setPacket(event.getPacket().deepClone());