From 306b246f76522a6633c5a83011698a6ff02ed92a Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Fri, 7 Feb 2014 13:50:40 +1300 Subject: [PATCH] Minor performance cleanup. --- src/me/libraryaddict/disguise/DisguiseAPI.java | 2 +- .../disguise/utilities/DisguiseUtilities.java | 2 +- .../disguise/utilities/PacketsManager.java | 10 +++------- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/me/libraryaddict/disguise/DisguiseAPI.java b/src/me/libraryaddict/disguise/DisguiseAPI.java index 73615bfa..d0183b2b 100644 --- a/src/me/libraryaddict/disguise/DisguiseAPI.java +++ b/src/me/libraryaddict/disguise/DisguiseAPI.java @@ -126,7 +126,7 @@ public class DisguiseAPI { * Get the disguise of a entity */ public static Disguise getDisguise(Player observer, Entity disguised) { - if (disguised == null) + if (disguised == null || observer == null) return null; return DisguiseUtilities.getDisguise(observer, disguised.getEntityId()); } diff --git a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index 220dbfc1..3980f9a3 100644 --- a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -390,7 +390,7 @@ public class DisguiseUtilities { * Method to send a packet to the self disguise, translate his entity ID to the fake id. */ private static void sendSelfPacket(Player player, PacketContainer packet, int fakeId) { - PacketContainer[] packets = PacketsManager.transformPacket(packet, player); + PacketContainer[] packets = PacketsManager.transformPacket(packet, player, player); try { for (PacketContainer p : packets) { p = p.deepClone(); diff --git a/src/me/libraryaddict/disguise/utilities/PacketsManager.java b/src/me/libraryaddict/disguise/utilities/PacketsManager.java index ac9b5753..18d60911 100644 --- a/src/me/libraryaddict/disguise/utilities/PacketsManager.java +++ b/src/me/libraryaddict/disguise/utilities/PacketsManager.java @@ -83,7 +83,7 @@ public class PacketsManager { // Prevents problems and there is no advantage to be gained. if (entity == observer) return; - PacketContainer[] packets = transformPacket(event.getPacket(), event.getPlayer()); + PacketContainer[] packets = transformPacket(event.getPacket(), event.getPlayer(), entity); if (packets.length == 0) event.setCancelled(true); else { @@ -719,7 +719,7 @@ public class PacketsManager { int fakeId = DisguiseAPI.getFakeDisguise(observer.getEntityId()); 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); + 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]; @@ -1118,13 +1118,9 @@ public class PacketsManager { /** * Transform the packet magically into the one I have always dreamed off. My true luv!!! */ - public static PacketContainer[] transformPacket(PacketContainer sentPacket, Player observer) { + public static PacketContainer[] transformPacket(PacketContainer sentPacket, Player observer, Entity entity) { PacketContainer[] packets = new PacketContainer[] { sentPacket }; try { - // First get the entity, the one sending this packet - StructureModifier entityModifer = sentPacket.getEntityModifier(observer.getWorld()); - org.bukkit.entity.Entity entity = entityModifer - .read((PacketType.Play.Server.COLLECT == sentPacket.getType() ? 1 : 0)); Disguise disguise = DisguiseAPI.getDisguise(observer, entity); // If disguised. if (disguise != null) {