diff --git a/src/me/libraryaddict/disguise/DisguiseAPI.java b/src/me/libraryaddict/disguise/DisguiseAPI.java index ee2aa3de..41860bf7 100644 --- a/src/me/libraryaddict/disguise/DisguiseAPI.java +++ b/src/me/libraryaddict/disguise/DisguiseAPI.java @@ -3,6 +3,7 @@ package me.libraryaddict.disguise; import java.lang.reflect.Field; import java.util.Arrays; import java.util.List; +import java.util.UUID; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.TargetedDisguise; @@ -142,7 +143,7 @@ public class DisguiseAPI { /** * Get the ID of a fake disguise for a entityplayer */ - public static int getFakeDisguise(int entityId) { + public static int getFakeDisguise(UUID entityId) { if (DisguiseUtilities.getSelfDisguisesIds().containsKey(entityId)) return DisguiseUtilities.getSelfDisguisesIds().get(entityId); return -1; diff --git a/src/me/libraryaddict/disguise/disguisetypes/Disguise.java b/src/me/libraryaddict/disguise/disguisetypes/Disguise.java index 25b3ef13..36935ade 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/Disguise.java +++ b/src/me/libraryaddict/disguise/disguisetypes/Disguise.java @@ -4,6 +4,7 @@ import java.lang.reflect.InvocationTargetException; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; +import java.util.UUID; import me.libraryaddict.disguise.DisguiseAPI; import me.libraryaddict.disguise.DisguiseConfig; @@ -33,6 +34,7 @@ public abstract class Disguise { private static JavaPlugin plugin; private DisguiseType disguiseType; private Entity entity; + private UUID disguiseUUID; private boolean hearSelfDisguise = DisguiseConfig.isSelfDisguisesSoundsReplaced(); private boolean hideArmorFromSelf = DisguiseConfig.isHidingArmorFromSelf(); private boolean hideHeldItemFromSelf = DisguiseConfig.isHidingHeldItemFromSelf(); @@ -229,7 +231,7 @@ public abstract class Disguise { (byte) Math.floor(loc.getPitch() * 256.0F / 360.0F))); if (isSelfDisguiseVisible() && getEntity() instanceof Player) { PacketContainer selfLookPacket = lookPacket.shallowClone(); - selfLookPacket.getModifier().write(0, DisguiseAPI.getFakeDisguise(getEntity().getEntityId())); + selfLookPacket.getModifier().write(0, DisguiseAPI.getFakeDisguise(getEntity().getUniqueId())); try { ProtocolLibrary.getProtocolManager().sendServerPacket((Player) getEntity(), selfLookPacket, false); @@ -248,7 +250,7 @@ public abstract class Disguise { if (!isSelfDisguiseVisible()) { continue; } - mods.write(0, DisguiseAPI.getFakeDisguise(getEntity().getEntityId())); + mods.write(0, DisguiseAPI.getFakeDisguise(getEntity().getUniqueId())); } else { mods.write(0, getEntity().getEntityId()); } @@ -274,7 +276,7 @@ public abstract class Disguise { ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false); } else if (isSelfDisguiseVisible()) { PacketContainer selfPacket = packet.shallowClone(); - selfPacket.getModifier().write(0, DisguiseAPI.getFakeDisguise(getEntity().getEntityId())); + selfPacket.getModifier().write(0, DisguiseAPI.getFakeDisguise(getEntity().getUniqueId())); try { ProtocolLibrary.getProtocolManager().sendServerPacket((Player) getEntity(), selfPacket, false); diff --git a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index f3158f16..9ef2e9f5 100644 --- a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -8,6 +8,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.UUID; import me.libraryaddict.disguise.DisguiseAPI; import me.libraryaddict.disguise.LibsDisguises; @@ -39,7 +40,7 @@ public class DisguiseUtilities { private static LibsDisguises libsDisguises; // A internal storage of fake entity ID's I can use. // Realistically I could probably use a ID like "4" for everyone, seeing as no one shares the ID - private static HashMap selfDisguisesIds = new HashMap(); + private static HashMap selfDisguisesIds = new HashMap(); // Store the entity IDs instead of entitys because then I can disguise entitys even before they exist private static HashMap> targetedDisguises = new HashMap>(); @@ -247,7 +248,7 @@ public class DisguiseUtilities { return dis; } - public static HashMap getSelfDisguisesIds() { + public static HashMap getSelfDisguisesIds() { return selfDisguisesIds; } @@ -377,17 +378,17 @@ public class DisguiseUtilities { } public static void removeSelfDisguise(Player player) { - if (selfDisguisesIds.containsKey(player.getEntityId())) { + if (selfDisguisesIds.containsKey(player.getUniqueId())) { // Send a packet to destroy the fake entity PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_DESTROY); - packet.getModifier().write(0, new int[] { selfDisguisesIds.get(player.getEntityId()) }); + packet.getModifier().write(0, new int[] { selfDisguisesIds.get(player.getUniqueId()) }); try { ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet); } catch (Exception ex) { ex.printStackTrace(); } // Remove the fake entity ID from the disguise bin - selfDisguisesIds.remove(player.getEntityId()); + selfDisguisesIds.remove(player.getUniqueId()); // Get the entity tracker try { Object world = ReflectionManager.getWorld(player.getWorld()); @@ -444,7 +445,7 @@ public class DisguiseUtilities { }); return; } - int fakeId = selfDisguisesIds.get(player.getEntityId()); + int fakeId = selfDisguisesIds.get(player.getUniqueId()); // Add himself to his own entity tracker ((HashSet) entityTrackerEntry.getClass().getField("trackedPlayers").get(entityTrackerEntry)).add(ReflectionManager .getNmsEntity(player)); @@ -572,7 +573,7 @@ public class DisguiseUtilities { int id = field.getInt(null); // Set the entitycount plus one so we don't have the id being reused field.set(null, id + 1); - selfDisguisesIds.put(player.getEntityId(), id); + selfDisguisesIds.put(player.getUniqueId(), id); } catch (Exception ex) { ex.printStackTrace(); } diff --git a/src/me/libraryaddict/disguise/utilities/PacketsManager.java b/src/me/libraryaddict/disguise/utilities/PacketsManager.java index 2f694964..2714369d 100644 --- a/src/me/libraryaddict/disguise/utilities/PacketsManager.java +++ b/src/me/libraryaddict/disguise/utilities/PacketsManager.java @@ -707,7 +707,7 @@ public class PacketsManager { public void onPacketSending(PacketEvent event) { final Player observer = event.getPlayer(); if (event.getPacket().getIntegers().read(0) == observer.getEntityId()) { - int fakeId = DisguiseAPI.getFakeDisguise(observer.getEntityId()); + int fakeId = DisguiseAPI.getFakeDisguise(observer.getUniqueId()); 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);