Archiviert
13
0

Fix a ClassNotFoundException with PlayerInfoData

Fixes #59
Dieser Commit ist enthalten in:
Dan Mulloy 2015-03-15 13:10:36 -04:00
Ursprung ac14843d96
Commit c7b9600c21
2 geänderte Dateien mit 49 neuen und 59 gelöschten Zeilen

Datei anzeigen

@ -67,13 +67,13 @@ class CachedPackage {
if (result == null) { if (result == null) {
// Look up the class dynamically // Look up the class dynamically
result = source.loadClass(combine(packageName, className)); result = source.loadClass(combine(packageName, className));
if (result == null) if (result == null)
throw new IllegalArgumentException("Source " + source + " returned NULL for " + className); throw new IllegalArgumentException("Source " + source + " returned NULL for " + className);
cache.put(className, result); cache.put(className, result);
} }
return result;
return result;
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
throw new RuntimeException("Cannot find class " + className, e); throw new RuntimeException("Cannot find class " + className, e);
} }

Datei anzeigen

@ -420,10 +420,8 @@ public class MinecraftReflection {
/** /**
* Determine if a given object is a ChunkPosition. * Determine if a given object is a ChunkPosition.
* @param obj - the object to test. * @param obj - the object to test.
* @deprecated ChunkPosition no longer exists
* @return TRUE if it can, FALSE otherwise. * @return TRUE if it can, FALSE otherwise.
*/ */
@Deprecated
public static boolean isChunkPosition(Object obj) { public static boolean isChunkPosition(Object obj) {
Class<?> chunkPosition = getChunkPositionClass(); Class<?> chunkPosition = getChunkPositionClass();
return obj != null && chunkPosition != null && chunkPosition.isAssignableFrom(obj.getClass()); return obj != null && chunkPosition != null && chunkPosition.isAssignableFrom(obj.getClass());
@ -567,16 +565,15 @@ public class MinecraftReflection {
return getMinecraftClass("EntityPlayer"); return getMinecraftClass("EntityPlayer");
} catch (RuntimeException e) { } catch (RuntimeException e) {
try { try {
// A fairly stable method // Grab CraftPlayer's handle
Method detect = FuzzyReflection.fromClass(getCraftBukkitClass("CraftServer")). Method getHandle = FuzzyReflection
getMethodByName("detectListNameConflict"); .fromClass(getCraftBukkitClass("entity.CraftPlayer"))
.getMethodByName("getHandle");
// EntityPlayer is then the first parameter // EntityPlayer is the return type
return detect.getParameterTypes()[0]; return setMinecraftClass("EntityPlayer", getHandle.getReturnType());
} catch (IllegalArgumentException e1) {
} catch (IllegalArgumentException ex) { throw new RuntimeException("Could not find EntityPlayer class.", e1);
// Last resort
return fallbackMethodReturn("EntityPlayer", "entity.CraftPlayer", "getHandle");
} }
} }
} }
@ -609,7 +606,7 @@ public class MinecraftReflection {
*/ */
public static Class<?> getEntityClass() { public static Class<?> getEntityClass() {
try { try {
return getMinecraftClass("Entity"); return getMinecraftClass("Entity");
} catch (RuntimeException e) { } catch (RuntimeException e) {
return fallbackMethodReturn("Entity", "entity.CraftEntity", "getHandle"); return fallbackMethodReturn("Entity", "entity.CraftEntity", "getHandle");
} }
@ -828,13 +825,14 @@ public class MinecraftReflection {
} catch (RuntimeException e) { } catch (RuntimeException e) {
Class<?> serverPing = getServerPingClass(); Class<?> serverPing = getServerPingClass();
// Find a server ping object for (Field field : FuzzyReflection.fromClass(serverPing, true).getFields()) {
AbstractFuzzyMatcher<Class<?>> serverDataContract = FuzzyClassContract.newBuilder(). Class<?> clazz = field.getType();
constructor(FuzzyMethodContract.newBuilder().parameterExactArray(String.class, int.class)). if (clazz.getName().contains("ServerData")) {
build(). return setMinecraftClass("ServerData", clazz);
and(getMinecraftObjectMatcher()); }
}
return setMinecraftClass("ServerPingServerData", getTypeFromField(serverPing, serverDataContract)); throw new IllegalStateException("Could not find ServerData class.");
} }
} }
@ -1173,29 +1171,26 @@ public class MinecraftReflection {
/** /**
* Retrieves the ChunkPosition class. * Retrieves the ChunkPosition class.
* *
* @deprecated ChunkPosition no longer exists. Replaced by BlockPosition.
* @return The ChunkPosition class. * @return The ChunkPosition class.
*/ */
@Deprecated
public static Class<?> getChunkPositionClass() { public static Class<?> getChunkPositionClass() {
try { try {
return getMinecraftClass("ChunkPosition"); return getMinecraftClass("ChunkPosition");
} catch (RuntimeException e) { } catch (RuntimeException e) {
return null; Class<?> normalChunkGenerator = getCraftBukkitClass("generator.NormalChunkGenerator");
// Class<?> normalChunkGenerator = getCraftBukkitClass("generator.NormalChunkGenerator");
// // ChunkPosition a(net.minecraft.server.World world, String string, int i, int i1, int i2) {
// // ChunkPosition a(net.minecraft.server.World world, String string, int i, int i1, int i2) { FuzzyMethodContract selected = FuzzyMethodContract.newBuilder()
// FuzzyMethodContract selected = FuzzyMethodContract.newBuilder() .banModifier(Modifier.STATIC)
// .banModifier(Modifier.STATIC) .parameterMatches(getMinecraftObjectMatcher(), 0)
// .parameterMatches(getMinecraftObjectMatcher(), 0) .parameterExactType(String.class, 1)
// .parameterExactType(String.class, 1) .parameterExactType(int.class, 2)
// .parameterExactType(int.class, 2) .parameterExactType(int.class, 3)
// .parameterExactType(int.class, 3) .parameterExactType(int.class, 4)
// .parameterExactType(int.class, 4) .build();
// .build();
// return setMinecraftClass("ChunkPosition",
// return setMinecraftClass("ChunkPosition", FuzzyReflection.fromClass(normalChunkGenerator).getMethod(selected).getReturnType());
// FuzzyReflection.fromClass(normalChunkGenerator).getMethod(selected).getReturnType());
} }
} }
@ -1223,8 +1218,8 @@ public class MinecraftReflection {
} }
/** /**
* Retrieves the Vec3d class. * Retrieves the Vec3D class.
* @return The Vec3d class. * @return The Vec3D class.
*/ */
public static Class<?> getVec3DClass() { public static Class<?> getVec3DClass() {
try { try {
@ -1239,7 +1234,6 @@ public class MinecraftReflection {
* Retrieve the ChunkCoordinates class. * Retrieve the ChunkCoordinates class.
* @return The ChunkPosition class. * @return The ChunkPosition class.
*/ */
@Deprecated
public static Class<?> getChunkCoordinatesClass() { public static Class<?> getChunkCoordinatesClass() {
try { try {
return getMinecraftClass("ChunkCoordinates"); return getMinecraftClass("ChunkCoordinates");
@ -1886,7 +1880,7 @@ public class MinecraftReflection {
* @return The PlayerInfoData class * @return The PlayerInfoData class
*/ */
public static Class<?> getPlayerInfoDataClass() { public static Class<?> getPlayerInfoDataClass() {
return getMinecraftClass("PlayerInfoData"); return getMinecraftClass("PacketPlayOutPlayerInfo$PlayerInfoData", "PlayerInfoData");
} }
/** /**
@ -1936,8 +1930,7 @@ public class MinecraftReflection {
* @return Class object. * @return Class object.
* @throws RuntimeException If we are unable to find the given class. * @throws RuntimeException If we are unable to find the given class.
*/ */
@SuppressWarnings("rawtypes") public static Class<?> getCraftBukkitClass(String className) {
public static Class getCraftBukkitClass(String className) {
if (craftbukkitPackage == null) if (craftbukkitPackage == null)
craftbukkitPackage = new CachedPackage(getCraftBukkitPackage(), getClassSource()); craftbukkitPackage = new CachedPackage(getCraftBukkitPackage(), getClassSource());
return craftbukkitPackage.getPackageClass(className); return craftbukkitPackage.getPackageClass(className);
@ -1990,6 +1983,7 @@ public class MinecraftReflection {
// Just use the default class loader // Just use the default class loader
classSource = ClassSource.fromClassLoader(); classSource = ClassSource.fromClassLoader();
} }
return classSource; return classSource;
} }
@ -2004,7 +1998,7 @@ public class MinecraftReflection {
try { try {
// Try the main class first // Try the main class first
return getMinecraftClass(className); return getMinecraftClass(className);
} catch (RuntimeException e1) { } catch (RuntimeException e) {
Class<?> success = null; Class<?> success = null;
// Try every alias too // Try every alias too
@ -2012,8 +2006,8 @@ public class MinecraftReflection {
try { try {
success = getMinecraftClass(alias); success = getMinecraftClass(alias);
break; break;
} catch (RuntimeException e2) { } catch (RuntimeException e1) {
// Swallov // Just swallow it...
} }
} }
@ -2023,11 +2017,7 @@ public class MinecraftReflection {
return success; return success;
} else { } else {
// Hack failed // Hack failed
throw new RuntimeException( throw new RuntimeException(String.format("Unable to find %s (%s)", className, Joiner.on(", ").join(aliases)));
String.format("Unable to find %s (%s)",
className,
Joiner.on(", ").join(aliases))
);
} }
} }
} }