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>
|
<groupId>net.seanomik</groupId>
|
||||||
<artifactId>tamablefoxes</artifactId>
|
<artifactId>tamablefoxes</artifactId>
|
||||||
<version>1.9.2-SNAPSHOT</version>
|
<version>1.9.2.1-SNAPSHOT</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>Tamablefoxes</name>
|
<name>Tamablefoxes</name>
|
||||||
|
|
|
@ -6,12 +6,33 @@ import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
|
||||||
import java.lang.invoke.MethodHandles;
|
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.Field;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
|
|
||||||
public final class FieldHelper {
|
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) {
|
public static void makeNonFinal(Field field) {
|
||||||
|
// Check if we're running a supported java version for this new method.
|
||||||
|
if (MODIFIERS == null) {
|
||||||
try {
|
try {
|
||||||
if ((field.getModifiers() & Modifier.FINAL) == Modifier.FINAL) {
|
if ((field.getModifiers() & Modifier.FINAL) == Modifier.FINAL) {
|
||||||
Field fieldMutable = field.getClass().getDeclaredField("modifiers");
|
Field fieldMutable = field.getClass().getDeclaredField("modifiers");
|
||||||
|
@ -23,6 +44,12 @@ public final class FieldHelper {
|
||||||
Bukkit.getServer().getConsoleSender().sendMessage(Utils.getPrefix() + ChatColor.RED + LanguageConfig.getFailureReplace());
|
Bukkit.getServer().getConsoleSender().sendMessage(Utils.getPrefix() + ChatColor.RED + LanguageConfig.getFailureReplace());
|
||||||
e.printStackTrace();
|
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 {
|
public static void setField(Field field, Object obj, Object value) throws IllegalAccessException {
|
||||||
|
|
Loading…
Reference in New Issue