Fix a skin broken bug I hope while fixed the other previous bug

This commit is contained in:
libraryaddict 2017-03-20 01:14:45 +13:00
parent 80dff148ff
commit e0fffdaa14
2 changed files with 139 additions and 148 deletions

@ -705,6 +705,8 @@ public class DisguiseUtilities {
} }
} }
}); });
return null;
} }
} }

@ -58,8 +58,8 @@ public class ReflectionManager {
static { static {
for (Method method : getNmsClass("EntityLiving").getDeclaredMethods()) { for (Method method : getNmsClass("EntityLiving").getDeclaredMethods()) {
try { try {
if (method.getReturnType() == float.class && Modifier.isProtected(method.getModifiers()) if (method.getReturnType() == float.class && Modifier.isProtected(
&& method.getParameterTypes().length == 0) { method.getModifiers()) && method.getParameterTypes().length == 0) {
Object entity = createEntityInstance("Cow"); Object entity = createEntityInstance("Cow");
method.setAccessible(true); method.setAccessible(true);
@ -86,8 +86,8 @@ public class ReflectionManager {
ihmGet = getNmsMethod("IntHashMap", "get", int.class); ihmGet = getNmsMethod("IntHashMap", "get", int.class);
boundingBoxConstructor = getNmsConstructor("AxisAlignedBB", double.class, double.class, double.class, double.class, boundingBoxConstructor = getNmsConstructor("AxisAlignedBB", double.class, double.class, double.class,
double.class, double.class); double.class, double.class, double.class);
setBoundingBoxMethod = getNmsMethod("Entity", "a", getNmsClass("AxisAlignedBB")); setBoundingBoxMethod = getNmsMethod("Entity", "a", getNmsClass("AxisAlignedBB"));
@ -102,8 +102,9 @@ public class ReflectionManager {
String id = (String) response.get("id"); String id = (String) response.get("id");
if (!id.contains("-")) { if (!id.contains("-")) {
id = Pattern.compile("([0-9a-fA-F]{8})([0-9a-fA-F]{4})([0-9a-fA-F]{4})([0-9a-fA-F]{4})([0-9a-fA-F]+)").matcher(id) id = Pattern.compile(
.replaceFirst("$1-$2-$3-$4-$5"); "([0-9a-fA-F]{8})([0-9a-fA-F]{4})([0-9a-fA-F]{4})([0-9a-fA-F]{4})([0-9a-fA-F]+)").matcher(
id).replaceFirst("$1-$2-$3-$4-$5");
} }
WrappedGameProfile gameProfile = new WrappedGameProfile(UUID.fromString(id), (String) response.get("name")); WrappedGameProfile gameProfile = new WrappedGameProfile(UUID.fromString(id), (String) response.get("name"));
@ -142,29 +143,28 @@ public class ReflectionManager {
case "Player": case "Player":
Object minecraftServer = getNmsMethod("MinecraftServer", "getServer").invoke(null); Object minecraftServer = getNmsMethod("MinecraftServer", "getServer").invoke(null);
Object playerinteractmanager = getNmsClass("PlayerInteractManager").getDeclaredConstructor(getNmsClass("World")) Object playerinteractmanager = getNmsClass("PlayerInteractManager").getDeclaredConstructor(
.newInstance(world); getNmsClass("World")).newInstance(world);
WrappedGameProfile gameProfile = getGameProfile(null, "Steve"); WrappedGameProfile gameProfile = getGameProfile(null, "Steve");
entityObject = entityClass entityObject = entityClass.getDeclaredConstructor(getNmsClass("MinecraftServer"),
.getDeclaredConstructor(getNmsClass("MinecraftServer"), getNmsClass("WorldServer"), getNmsClass("WorldServer"), gameProfile.getHandleType(),
gameProfile.getHandleType(), playerinteractmanager.getClass()) playerinteractmanager.getClass()).newInstance(minecraftServer, world,
.newInstance(minecraftServer, world, gameProfile.getHandle(), playerinteractmanager); gameProfile.getHandle(), playerinteractmanager);
break; break;
case "EnderPearl": case "EnderPearl":
entityObject = entityClass.getDeclaredConstructor(getNmsClass("World"), getNmsClass("EntityLiving")) entityObject = entityClass.getDeclaredConstructor(getNmsClass("World"),
.newInstance(world, createEntityInstance("Cow")); getNmsClass("EntityLiving")).newInstance(world, createEntityInstance("Cow"));
break; break;
case "Potion": case "Potion":
entityObject = entityClass entityObject = entityClass.getDeclaredConstructor(getNmsClass("World"), Double.TYPE, Double.TYPE,
.getDeclaredConstructor(getNmsClass("World"), Double.TYPE, Double.TYPE, Double.TYPE, Double.TYPE, getNmsClass("ItemStack")).newInstance(world, 0d, 0d, 0d,
getNmsClass("ItemStack")) getNmsItem(new ItemStack(Material.SPLASH_POTION)));
.newInstance(world, 0d, 0d, 0d, getNmsItem(new ItemStack(Material.SPLASH_POTION)));
break; break;
case "FishingHook": case "FishingHook":
entityObject = entityClass.getDeclaredConstructor(getNmsClass("World"), getNmsClass("EntityHuman")) entityObject = entityClass.getDeclaredConstructor(getNmsClass("World"),
.newInstance(world, createEntityInstance("Player")); getNmsClass("EntityHuman")).newInstance(world, createEntityInstance("Player"));
break; break;
default: default:
entityObject = entityClass.getDeclaredConstructor(getNmsClass("World")).newInstance(world); entityObject = entityClass.getDeclaredConstructor(getNmsClass("World")).newInstance(world);
@ -194,15 +194,15 @@ public class ReflectionManager {
} }
public static Object createMobEffect(PotionEffect effect) { public static Object createMobEffect(PotionEffect effect) {
return createMobEffect(effect.getType().getId(), effect.getDuration(), effect.getAmplifier(), effect.isAmbient(), return createMobEffect(effect.getType().getId(), effect.getDuration(), effect.getAmplifier(),
effect.hasParticles()); effect.isAmbient(), effect.hasParticles());
} }
public static Object createMobEffect(int id, int duration, int amplification, boolean ambient, boolean particles) { public static Object createMobEffect(int id, int duration, int amplification, boolean ambient, boolean particles) {
try { try {
return getNmsClass("MobEffect") return getNmsClass("MobEffect").getDeclaredConstructor(getNmsClass("MobEffectList"), Integer.TYPE,
.getDeclaredConstructor(getNmsClass("MobEffectList"), Integer.TYPE, Integer.TYPE, Boolean.TYPE, Boolean.TYPE) Integer.TYPE, Boolean.TYPE, Boolean.TYPE).newInstance(getMobEffectList(id), duration, amplification,
.newInstance(getMobEffectList(id), duration, amplification, ambient, particles); ambient, particles);
} }
catch (Exception e) { catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@ -357,7 +357,8 @@ public class ReflectionManager {
public static Object getBlockPosition(int x, int y, int z) { public static Object getBlockPosition(int x, int y, int z) {
try { try {
return getNmsClass("BlockPosition").getDeclaredConstructor(int.class, int.class, int.class).newInstance(x, y, z); return getNmsClass("BlockPosition").getDeclaredConstructor(int.class, int.class, int.class).newInstance(x,
y, z);
} }
catch (Exception ex) { catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
@ -390,14 +391,13 @@ public class ReflectionManager {
public static Object getPlayerInfoData(Object playerInfoPacket, WrappedGameProfile gameProfile) { public static Object getPlayerInfoData(Object playerInfoPacket, WrappedGameProfile gameProfile) {
try { try {
Object playerListName = getNmsClass("ChatComponentText").getDeclaredConstructor(String.class) Object playerListName = getNmsClass("ChatComponentText").getDeclaredConstructor(String.class).newInstance(
.newInstance(gameProfile.getName()); gameProfile.getName());
return getNmsClass("PacketPlayOutPlayerInfo$PlayerInfoData") return getNmsClass("PacketPlayOutPlayerInfo$PlayerInfoData").getDeclaredConstructor(
.getDeclaredConstructor(getNmsClass("PacketPlayOutPlayerInfo"), gameProfile.getHandleType(), int.class, getNmsClass("PacketPlayOutPlayerInfo"), gameProfile.getHandleType(), int.class,
getNmsClass("EnumGamemode"), getNmsClass("IChatBaseComponent")) getNmsClass("EnumGamemode"), getNmsClass("IChatBaseComponent")).newInstance(playerInfoPacket,
.newInstance(playerInfoPacket, gameProfile.getHandle(), 0, getNmsClass("EnumGamemode").getEnumConstants()[1], gameProfile.getHandle(), 0, getNmsClass("EnumGamemode").getEnumConstants()[1], playerListName);
playerListName);
} }
catch (Exception ex) { catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
@ -427,8 +427,10 @@ public class ReflectionManager {
public static WrappedGameProfile getGameProfileWithThisSkin(UUID uuid, String playerName, public static WrappedGameProfile getGameProfileWithThisSkin(UUID uuid, String playerName,
WrappedGameProfile profileWithSkin) { WrappedGameProfile profileWithSkin) {
try { try {
WrappedGameProfile gameProfile = new WrappedGameProfile(uuid != null ? uuid : UUID.randomUUID(), playerName); WrappedGameProfile gameProfile = new WrappedGameProfile(uuid != null ? uuid : UUID.randomUUID(),
playerName);
if (profileWithSkin != null)
gameProfile.getProperties().putAll(profileWithSkin.getProperties()); gameProfile.getProperties().putAll(profileWithSkin.getProperties());
return gameProfile; return gameProfile;
@ -561,9 +563,7 @@ public class ReflectionManager {
float width = getNmsField("Entity", "width").getFloat(getNmsEntity(entity)); float width = getNmsField("Entity", "width").getFloat(getNmsEntity(entity));
float height = (Float) getNmsMethod("Entity", "getHeadHeight").invoke(getNmsEntity(entity)); float height = (Float) getNmsMethod("Entity", "getHeadHeight").invoke(getNmsEntity(entity));
return new float[] { return new float[]{length, width, height};
length, width, height
};
} }
catch (Exception ex) { catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
@ -580,9 +580,9 @@ public class ReflectionManager {
if (method.getReturnType().getSimpleName().equals("MinecraftSessionService")) { if (method.getReturnType().getSimpleName().equals("MinecraftSessionService")) {
Object session = method.invoke(minecraftServer); Object session = method.invoke(minecraftServer);
return WrappedGameProfile.fromHandle(session.getClass() return WrappedGameProfile.fromHandle(
.getDeclaredMethod("fillProfileProperties", gameProfile.getHandleType(), boolean.class) session.getClass().getDeclaredMethod("fillProfileProperties", gameProfile.getHandleType(),
.invoke(session, gameProfile.getHandle(), true)); boolean.class).invoke(session, gameProfile.getHandle(), true));
} }
} }
} }
@ -616,12 +616,9 @@ public class ReflectionManager {
LibsProfileLookupCaller callback = new LibsProfileLookupCaller(); LibsProfileLookupCaller callback = new LibsProfileLookupCaller();
profileRepo.getClass() profileRepo.getClass().getDeclaredMethod("findProfilesByNames", String[].class, agent.getClass(),
.getDeclaredMethod("findProfilesByNames", String[].class, agent.getClass(), Class.forName("com.mojang.authlib.ProfileLookupCallback")).invoke(profileRepo,
Class.forName("com.mojang.authlib.ProfileLookupCallback")) new String[]{playername}, agent, callback);
.invoke(profileRepo, new String[] {
playername
}, agent, callback);
if (callback.getGameProfile() != null) { if (callback.getGameProfile() != null) {
return callback.getGameProfile(); return callback.getGameProfile();
@ -646,9 +643,9 @@ public class ReflectionManager {
try { try {
Location loc = entity.getLocation(); Location loc = entity.getLocation();
Object boundingBox = boundingBoxConstructor.newInstance(loc.getX() - newBox.getX(), loc.getY() - newBox.getY(), Object boundingBox = boundingBoxConstructor.newInstance(loc.getX() - newBox.getX(),
loc.getZ() - newBox.getZ(), loc.getX() + newBox.getX(), loc.getY() + newBox.getY(), loc.getY() - newBox.getY(), loc.getZ() - newBox.getZ(), loc.getX() + newBox.getX(),
loc.getZ() + newBox.getZ()); loc.getY() + newBox.getY(), loc.getZ() + newBox.getZ());
setBoundingBoxMethod.invoke(getNmsEntity(entity), boundingBox); setBoundingBoxMethod.invoke(getNmsEntity(entity), boundingBox);
} }
@ -831,14 +828,14 @@ public class ReflectionManager {
BlockPosition pos = (BlockPosition) val; BlockPosition pos = (BlockPosition) val;
try { try {
return Optional.of(getNmsConstructor("BlockPosition", int.class, int.class, int.class).newInstance(pos.getX(), return Optional.of(
getNmsConstructor("BlockPosition", int.class, int.class, int.class).newInstance(pos.getX(),
pos.getY(), pos.getZ())); pos.getY(), pos.getZ()));
} }
catch (Exception ex) { catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
} } else if (val instanceof WrappedBlockData) {
else if (val instanceof WrappedBlockData) {
try { try {
return Optional.of(((WrappedBlockData) val).getHandle()); return Optional.of(((WrappedBlockData) val).getHandle());
} }
@ -846,8 +843,7 @@ public class ReflectionManager {
ex.printStackTrace(); ex.printStackTrace();
} }
} }
} } else if (value instanceof Vector3F) {
else if (value instanceof Vector3F) {
Vector3F angle = (Vector3F) value; Vector3F angle = (Vector3F) value;
try { try {
@ -857,27 +853,25 @@ public class ReflectionManager {
catch (Exception ex) { catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
} } else if (value instanceof Direction) {
else if (value instanceof Direction) {
try { try {
return (Enum) getNmsMethod("EnumDirection", "fromType1", int.class).invoke(null, ((Direction) value).ordinal()); return (Enum) getNmsMethod("EnumDirection", "fromType1", int.class).invoke(null,
((Direction) value).ordinal());
} }
catch (Exception ex) { catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
} } else if (value instanceof BlockPosition) {
else if (value instanceof BlockPosition) {
BlockPosition pos = (BlockPosition) value; BlockPosition pos = (BlockPosition) value;
try { try {
return getNmsConstructor("BlockPosition", int.class, int.class, int.class).newInstance(pos.getX(), pos.getY(), return getNmsConstructor("BlockPosition", int.class, int.class, int.class).newInstance(pos.getX(),
pos.getZ()); pos.getY(), pos.getZ());
} }
catch (Exception ex) { catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
} } else if (value instanceof ItemStack) {
else if (value instanceof ItemStack) {
return getNmsItem((ItemStack) value); return getNmsItem((ItemStack) value);
} }
@ -902,19 +896,15 @@ public class ReflectionManager {
if (value instanceof Optional) { if (value instanceof Optional) {
Optional opt = (Optional) value; Optional opt = (Optional) value;
serializer = Registry.get((opt.isPresent() serializer = Registry.get((opt.isPresent() ? getNmsClass("IBlockData").isInstance(opt.get()) ? getNmsClass(
? getNmsClass("IBlockData").isInstance(opt.get()) ? getNmsClass("IBlockData") : opt.get().getClass() "IBlockData") : opt.get().getClass() : UUID.class), true);
: UUID.class), true); } else {
}
else {
serializer = Registry.get(value.getClass()); serializer = Registry.get(value.getClass());
} }
if (serializer == null) { if (serializer == null) {
throw new IllegalArgumentException("Unable to find Serializer for " + value throw new IllegalArgumentException(
+ (value instanceof Optional && ((Optional) value).isPresent() "Unable to find Serializer for " + value + (value instanceof Optional && ((Optional) value).isPresent() ? " (" + ((Optional) value).get().getClass().getName() + ")" : "") + "! Are you running the latest version of ProtocolLib?");
? " (" + ((Optional) value).get().getClass().getName() + ")" : "")
+ "! Are you running the latest version of ProtocolLib?");
} }
WrappedDataWatcherObject watcherObject = new WrappedDataWatcherObject(id, serializer); WrappedDataWatcherObject watcherObject = new WrappedDataWatcherObject(id, serializer);
@ -969,5 +959,4 @@ public class ReflectionManager {
return null; return null;
} }
} }