2020-09-08 18:40:43 +00:00
|
|
|
package net.seanomik.tamablefoxes.versions;
|
|
|
|
|
2020-09-10 16:29:47 +00:00
|
|
|
import net.seanomik.tamablefoxes.Utils;
|
|
|
|
import net.seanomik.tamablefoxes.io.LanguageConfig;
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
|
2020-09-08 18:40:43 +00:00
|
|
|
import java.lang.invoke.MethodHandles;
|
2021-06-07 05:36:46 +00:00
|
|
|
//import java.lang.invoke.VarHandle;
|
2020-09-08 18:40:43 +00:00
|
|
|
import java.lang.reflect.Field;
|
|
|
|
import java.lang.reflect.Modifier;
|
|
|
|
|
|
|
|
public final class FieldHelper {
|
|
|
|
public static void makeNonFinal(Field field) {
|
2021-06-07 05:36:46 +00:00
|
|
|
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);
|
2020-09-10 16:29:47 +00:00
|
|
|
}
|
2021-06-07 05:36:46 +00:00
|
|
|
} catch (NoSuchFieldException | IllegalAccessException e) {
|
|
|
|
Bukkit.getServer().getConsoleSender().sendMessage(Utils.getPrefix() + ChatColor.RED + LanguageConfig.getFailureReplace());
|
|
|
|
e.printStackTrace();
|
2020-09-08 18:40:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setField(Field field, Object obj, Object value) throws IllegalAccessException {
|
|
|
|
makeNonFinal(field);
|
|
|
|
field.setAccessible(true);
|
|
|
|
field.set(obj, value);
|
|
|
|
field.setAccessible(false);
|
|
|
|
}
|
|
|
|
}
|