From 3d60fe3c4931546b4da5616084cb08a137c330ca Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sat, 12 Apr 2014 17:07:27 +1200 Subject: [PATCH] Allow players to retain their skins if they disguised as theirselves --- pom.xml | 6 ++--- .../disguise/utilities/DisguiseUtilities.java | 2 +- .../disguise/utilities/PacketsManager.java | 16 ++++++++--- .../disguise/utilities/ReflectionManager.java | 27 ++++++++++++++++--- 4 files changed, 39 insertions(+), 12 deletions(-) diff --git a/pom.xml b/pom.xml index c31b5ef7..c9ed8f01 100644 --- a/pom.xml +++ b/pom.xml @@ -74,9 +74,9 @@ - org.spigotmc - spigot-api - 1.7.2-R0.3-SNAPSHOT + org.bukkit + craftbukkit + 1.7.8-R0.1-SNAPSHOT com.comphenix.protocol diff --git a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index 24c1c70b..f6e30a75 100644 --- a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -300,7 +300,7 @@ public class DisguiseUtilities { } public static UUID getUUID() { - if (LibVersion.getGameVersion() == LibVersion.V1_7) { + if (LibVersion.is1_7()) { EthernetAddress addr = EthernetAddress.fromInterface(); TimeBasedGenerator uuidGenerator = Generators.timeBasedGenerator(addr); return uuidGenerator.generate(); diff --git a/src/me/libraryaddict/disguise/utilities/PacketsManager.java b/src/me/libraryaddict/disguise/utilities/PacketsManager.java index 9478c315..ae414742 100644 --- a/src/me/libraryaddict/disguise/utilities/PacketsManager.java +++ b/src/me/libraryaddict/disguise/utilities/PacketsManager.java @@ -121,7 +121,7 @@ public class PacketsManager { /** * Construct the packets I need to spawn in the disguise */ - public static PacketContainer[] constructSpawnPackets(Disguise disguise, Entity disguisedEntity) { + public static PacketContainer[] constructSpawnPackets(Disguise disguise, Entity disguisedEntity, Player observer) { if (disguise.getEntity() == null) disguise.setEntity(disguisedEntity); Object nmsEntity = ReflectionManager.getNmsEntity(disguisedEntity); @@ -200,8 +200,16 @@ public class PacketsManager { stringMods.write(i, ((PlayerDisguise) disguise).getName()); } } else { - spawnPackets[0].getModifier().write(1, - ReflectionManager.getGameProfile(DisguiseUtilities.getUUID(), ((PlayerDisguise) disguise).getName())); + Object gameProfile = null; + if (disguisedEntity instanceof Player + && ((Player) disguisedEntity).getName().equals(((PlayerDisguise) disguise).getName()) + && disguisedEntity != observer) { + gameProfile = ReflectionManager.getGameProfile((Player) disguisedEntity); + } else { + gameProfile = ReflectionManager.getGameProfile(DisguiseUtilities.getUUID(), + ((PlayerDisguise) disguise).getName()); + } + spawnPackets[0].getModifier().write(1, gameProfile); } StructureModifier intMods = spawnPackets[0].getIntegers(); intMods.write(0, disguisedEntity.getEntityId()); @@ -1137,7 +1145,7 @@ public class PacketsManager { || sentPacket.getType() == PacketType.Play.Server.SPAWN_ENTITY_EXPERIENCE_ORB || sentPacket.getType() == PacketType.Play.Server.SPAWN_ENTITY || sentPacket.getType() == PacketType.Play.Server.SPAWN_ENTITY_PAINTING) { - packets = constructSpawnPackets(disguise, entity); + packets = constructSpawnPackets(disguise, entity, observer); } // Else if the disguise is attempting to send players a forbidden packet diff --git a/src/me/libraryaddict/disguise/utilities/ReflectionManager.java b/src/me/libraryaddict/disguise/utilities/ReflectionManager.java index 89725369..467b3c40 100644 --- a/src/me/libraryaddict/disguise/utilities/ReflectionManager.java +++ b/src/me/libraryaddict/disguise/utilities/ReflectionManager.java @@ -16,14 +16,18 @@ import org.bukkit.inventory.ItemStack; public class ReflectionManager { public enum LibVersion { - V1_6, V1_7; + V1_6, V1_7, V1_7_3; private static LibVersion currentVersion; static { if (getBukkitVersion().startsWith("v1_")) { try { int version = Integer.parseInt(getBukkitVersion().split("_")[1]); if (version == 7) { - currentVersion = LibVersion.V1_7; + if (Integer.parseInt(getBukkitVersion().split("_")[1]) < 3) { + currentVersion = LibVersion.V1_7; + } else { + currentVersion = LibVersion.V1_7_3; + } } else { if (version < 7) { currentVersion = LibVersion.V1_6; @@ -32,7 +36,7 @@ public class ReflectionManager { } } } catch (Exception ex) { - + ex.printStackTrace(); } } } @@ -46,7 +50,11 @@ public class ReflectionManager { } public static boolean is1_7() { - return getGameVersion() == V1_7; + return getGameVersion() == V1_7 || getGameVersion() == V1_7_3; + } + + public static boolean is1_7_3() { + return getGameVersion() == V1_7_3; } } @@ -206,6 +214,17 @@ public class ReflectionManager { return null; } + public static Object getGameProfile(Player player) { + if (LibVersion.is1_7_3()) { + try { + return getNmsClass("EntityHuman").getMethod("getProfile").invoke(getNmsEntity(player)); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + return null; + } + public static Object getGameProfile(UUID uuid, String playerName) { try { try {