Created
February 24, 2018 00:24
-
-
Save johannvonissou/10bb462f24c7fb0c3cc189a7bc82dfc7 to your computer and use it in GitHub Desktop.
Minecraft Spigot Reflection class (1.8.8)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package fr.glowstoner.firehub; | |
import java.lang.reflect.Field; | |
public class FireReflection { | |
public static final String VERSION = "v1_8_R3"; | |
public static final String PATH = "net.minecraft.server.v1_8_R3"; | |
public static Class<?> getClass(String cname) { | |
String path = PATH+"."+cname; | |
try { | |
return Class.forName(path); | |
} catch (ClassNotFoundException e) { | |
e.printStackTrace(); | |
} | |
return null; | |
} | |
public static Object getFieldValueByName(Object instance, String fname) { | |
try { | |
Field f = instance.getClass().getDeclaredField(fname); | |
f.setAccessible(true); | |
return f.get(instance); | |
} catch (NoSuchFieldException | SecurityException | | |
IllegalArgumentException | IllegalAccessException e) { | |
e.printStackTrace(); | |
} | |
return null; | |
} | |
public static Field getField(Class<?> clazz, String fname) { | |
Field f = null; | |
try { | |
f = clazz.getDeclaredField(fname); | |
} catch (NoSuchFieldException | SecurityException e) { | |
e.printStackTrace(); | |
} | |
f.setAccessible(true); | |
return f; | |
} | |
@SuppressWarnings("unchecked") | |
public static <T> T getFieldValue(Field f, Object instance) { | |
try { | |
return (T) f.get(instance); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
return null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment