Allow players to retain their skins if they disguised as theirselves

This commit is contained in:
libraryaddict 2014-04-12 17:07:27 +12:00
parent 5a4ac21f10
commit 3d60fe3c49
4 changed files with 39 additions and 12 deletions

View File

@ -74,9 +74,9 @@
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.bukkit</groupId>
<artifactId>spigot-api</artifactId> <artifactId>craftbukkit</artifactId>
<version>1.7.2-R0.3-SNAPSHOT</version> <version>1.7.8-R0.1-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.comphenix.protocol</groupId> <groupId>com.comphenix.protocol</groupId>

View File

@ -300,7 +300,7 @@ public class DisguiseUtilities {
} }
public static UUID getUUID() { public static UUID getUUID() {
if (LibVersion.getGameVersion() == LibVersion.V1_7) { if (LibVersion.is1_7()) {
EthernetAddress addr = EthernetAddress.fromInterface(); EthernetAddress addr = EthernetAddress.fromInterface();
TimeBasedGenerator uuidGenerator = Generators.timeBasedGenerator(addr); TimeBasedGenerator uuidGenerator = Generators.timeBasedGenerator(addr);
return uuidGenerator.generate(); return uuidGenerator.generate();

View File

@ -121,7 +121,7 @@ public class PacketsManager {
/** /**
* Construct the packets I need to spawn in the disguise * 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) if (disguise.getEntity() == null)
disguise.setEntity(disguisedEntity); disguise.setEntity(disguisedEntity);
Object nmsEntity = ReflectionManager.getNmsEntity(disguisedEntity); Object nmsEntity = ReflectionManager.getNmsEntity(disguisedEntity);
@ -200,8 +200,16 @@ public class PacketsManager {
stringMods.write(i, ((PlayerDisguise) disguise).getName()); stringMods.write(i, ((PlayerDisguise) disguise).getName());
} }
} else { } else {
spawnPackets[0].getModifier().write(1, Object gameProfile = null;
ReflectionManager.getGameProfile(DisguiseUtilities.getUUID(), ((PlayerDisguise) disguise).getName())); 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<Integer> intMods = spawnPackets[0].getIntegers(); StructureModifier<Integer> intMods = spawnPackets[0].getIntegers();
intMods.write(0, disguisedEntity.getEntityId()); 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_EXPERIENCE_ORB
|| sentPacket.getType() == PacketType.Play.Server.SPAWN_ENTITY || sentPacket.getType() == PacketType.Play.Server.SPAWN_ENTITY
|| sentPacket.getType() == PacketType.Play.Server.SPAWN_ENTITY_PAINTING) { || 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 // Else if the disguise is attempting to send players a forbidden packet

View File

@ -16,14 +16,18 @@ import org.bukkit.inventory.ItemStack;
public class ReflectionManager { public class ReflectionManager {
public enum LibVersion { public enum LibVersion {
V1_6, V1_7; V1_6, V1_7, V1_7_3;
private static LibVersion currentVersion; private static LibVersion currentVersion;
static { static {
if (getBukkitVersion().startsWith("v1_")) { if (getBukkitVersion().startsWith("v1_")) {
try { try {
int version = Integer.parseInt(getBukkitVersion().split("_")[1]); int version = Integer.parseInt(getBukkitVersion().split("_")[1]);
if (version == 7) { if (version == 7) {
if (Integer.parseInt(getBukkitVersion().split("_")[1]) < 3) {
currentVersion = LibVersion.V1_7; currentVersion = LibVersion.V1_7;
} else {
currentVersion = LibVersion.V1_7_3;
}
} else { } else {
if (version < 7) { if (version < 7) {
currentVersion = LibVersion.V1_6; currentVersion = LibVersion.V1_6;
@ -32,7 +36,7 @@ public class ReflectionManager {
} }
} }
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace();
} }
} }
} }
@ -46,7 +50,11 @@ public class ReflectionManager {
} }
public static boolean is1_7() { 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; 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) { public static Object getGameProfile(UUID uuid, String playerName) {
try { try {
try { try {