diff --git a/pom.xml b/pom.xml
index 9edc7c8..c7b6f92 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,13 +6,13 @@
net.seanomik
tamablefoxes
- 1.7.5-SNAPSHOT
+ 1.7.6-SNAPSHOT
jar
Tamablefoxes
- 1.14
+ 8
UTF-8
@@ -24,8 +24,8 @@
maven-compiler-plugin
3.7.0
-
- 9
+
+ ${java.version}
@@ -41,9 +41,10 @@
- D:\Code\java\spigotPlugins\_TEST_SERVER_PAPER_1.16.1_\plugins\TamableFoxes_v${project.version}.jar
+
+ D:\Code\java\spigotPlugins\_TEST_SERVER_PAPER_1.16.2_\plugins\TamableFoxes_v${project.version}.jar
false
diff --git a/src/main/java/net/seanomik/tamablefoxes/versions/FieldHelper.java b/src/main/java/net/seanomik/tamablefoxes/versions/FieldHelper.java
index 5f907cc..fdd80e4 100644
--- a/src/main/java/net/seanomik/tamablefoxes/versions/FieldHelper.java
+++ b/src/main/java/net/seanomik/tamablefoxes/versions/FieldHelper.java
@@ -1,6 +1,12 @@
package net.seanomik.tamablefoxes.versions;
+import net.seanomik.tamablefoxes.Utils;
+import net.seanomik.tamablefoxes.io.LanguageConfig;
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+
import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
import java.lang.invoke.VarHandle;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
@@ -10,18 +16,38 @@ public final class FieldHelper {
private static final VarHandle MODIFIERS;
static {
- 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);
+ 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) {
- int mods = field.getModifiers();
- if (Modifier.isFinal(mods)) {
- MODIFIERS.set(field, mods & ~Modifier.FINAL);
+ // 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");
+ fieldMutable.setAccessible(true);
+ fieldMutable.set(field, fieldMutable.getInt(field) & ~Modifier.FINAL);
+ fieldMutable.setAccessible(false);
+ }
+ } catch (NoSuchFieldException | IllegalAccessException e) {
+ 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);
+ }
}
}