From 7f65d8c8f1422de68dffcec82a8de12f5c2859f2 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Wed, 22 Apr 2020 14:06:04 +1200 Subject: [PATCH] Fixed disguiseNextEntity --- .../packethandlers/PacketHandlerSpawn.java | 4 ---- .../packetlisteners/PacketListenerMain.java | 18 +++++++++++++++++- .../packetlisteners/PacketListenerSounds.java | 2 +- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/main/java/me/libraryaddict/disguise/utilities/packets/packethandlers/PacketHandlerSpawn.java b/src/main/java/me/libraryaddict/disguise/utilities/packets/packethandlers/PacketHandlerSpawn.java index 292a3758..b2b40fa4 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/packets/packethandlers/PacketHandlerSpawn.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/packets/packethandlers/PacketHandlerSpawn.java @@ -70,10 +70,6 @@ public class PacketHandlerSpawn implements IPacketHandler { private void constructSpawnPackets(final Player observer, LibsPackets packets, Entity disguisedEntity) { Disguise disguise = packets.getDisguise(); - if (disguise.getEntity() == null) { - disguise.setEntity(disguisedEntity); - } - if (DisguiseConfig.isMiscDisguisesForLivingEnabled()) { if (disguise.getWatcher() instanceof LivingWatcher) { diff --git a/src/main/java/me/libraryaddict/disguise/utilities/packets/packetlisteners/PacketListenerMain.java b/src/main/java/me/libraryaddict/disguise/utilities/packets/packetlisteners/PacketListenerMain.java index 82ed08ff..82a029ef 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/packets/packetlisteners/PacketListenerMain.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/packets/packetlisteners/PacketListenerMain.java @@ -12,6 +12,7 @@ import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.packets.LibsPackets; import me.libraryaddict.disguise.utilities.packets.PacketsManager; +import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import java.lang.reflect.InvocationTargetException; @@ -38,10 +39,25 @@ public class PacketListenerMain extends PacketAdapter { final Disguise disguise = DisguiseUtilities.getDisguise(observer, entityId); + if (disguise == null) { + return; + } + + if (disguise.getEntity() == null) { + for (Entity e : observer.getWorld().getEntities()) { + if (e.getEntityId() != entityId) { + continue; + } + + disguise.setEntity(e); + break; + } + } + // If the entity is the same as the sender. Don't disguise! // Prevents problems and there is no advantage to be gained. // Or if they are null and there's no disguise - if (disguise == null || disguise.getEntity() == observer) { + if (disguise.getEntity() == observer) { return; } diff --git a/src/main/java/me/libraryaddict/disguise/utilities/packets/packetlisteners/PacketListenerSounds.java b/src/main/java/me/libraryaddict/disguise/utilities/packets/packetlisteners/PacketListenerSounds.java index 09a6f588..166f8cf6 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/packets/packetlisteners/PacketListenerSounds.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/packets/packetlisteners/PacketListenerSounds.java @@ -73,7 +73,7 @@ public class PacketListenerSounds extends PacketAdapter { for (TargetedDisguise entityDisguise : disguises) { Entity entity = entityDisguise.getEntity(); - if (entity.getWorld() != observer.getWorld()) { + if (entity == null || entity.getWorld() != observer.getWorld()) { continue; }