Fix plugin for Java 1.16
This commit is contained in:
parent
90f1c58670
commit
3c79bb028d
2
pom.xml
2
pom.xml
|
@ -6,7 +6,7 @@
|
|||
|
||||
<groupId>net.seanomik</groupId>
|
||||
<artifactId>tamablefoxes</artifactId>
|
||||
<version>1.9.2-SNAPSHOT</version>
|
||||
<version>1.9.2.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Tamablefoxes</name>
|
||||
|
|
|
@ -6,12 +6,33 @@ import org.bukkit.Bukkit;
|
|||
import org.bukkit.ChatColor;
|
||||
|
||||
import java.lang.invoke.MethodHandles;
|
||||
//import java.lang.invoke.VarHandle;
|
||||
import java.lang.invoke.MethodType;
|
||||
import java.lang.invoke.VarHandle;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
public final class FieldHelper {
|
||||
|
||||
private static final VarHandle MODIFIERS;
|
||||
|
||||
static {
|
||||
String version = System.getProperty("java.version");
|
||||
if (!version.startsWith("1.8")) {
|
||||
try {
|
||||
MethodHandles.Lookup lookup = MethodHandles.privateLookupIn(Field.class, MethodHandles.lookup());
|
||||
MODIFIERS = lookup.findVarHandle(Field.class, "modifiers", int.class);
|
||||
} catch (IllegalAccessException | NoSuchFieldException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
} else {
|
||||
MODIFIERS = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void makeNonFinal(Field field) {
|
||||
// Check if we're running a supported java version for this new method.
|
||||
if (MODIFIERS == null) {
|
||||
try {
|
||||
if ((field.getModifiers() & Modifier.FINAL) == Modifier.FINAL) {
|
||||
Field fieldMutable = field.getClass().getDeclaredField("modifiers");
|
||||
|
@ -23,6 +44,12 @@ public final class FieldHelper {
|
|||
Bukkit.getServer().getConsoleSender().sendMessage(Utils.getPrefix() + ChatColor.RED + LanguageConfig.getFailureReplace());
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
int mods = field.getModifiers();
|
||||
if (Modifier.isFinal(mods)) {
|
||||
MODIFIERS.set(field, mods & ~Modifier.FINAL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void setField(Field field, Object obj, Object value) throws IllegalAccessException {
|
||||
|
|
Loading…
Reference in New Issue