Fix compatibility with JDK 13
This commit is contained in:
parent
3ccdfb7abb
commit
8bb2987e57
@ -20,10 +20,9 @@ public class LocalLoader implements TabooLibLoader.Loader {
|
||||
if (annotation == null) {
|
||||
continue;
|
||||
}
|
||||
Ref.forcedAccess(field);
|
||||
for (Object instance : TInjectHelper.getInstance(field, pluginClass, plugin)) {
|
||||
try {
|
||||
field.set(instance, Local.get(plugin.getName()).get(annotation.value()));
|
||||
Ref.putField(instance, field, Local.get(plugin.getName()).get(annotation.value()));
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
|
@ -32,8 +32,7 @@ public abstract class EventNormal<T extends EventNormal> extends Event {
|
||||
public T async(boolean value) {
|
||||
try {
|
||||
Field asyncField = Reflection.getField(Event.class, true, "async");
|
||||
Ref.forcedAccess(asyncField);
|
||||
asyncField.setBoolean(this, value);
|
||||
Ref.putField(this, asyncField, value);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
|
@ -27,10 +27,9 @@ public class THookLoader implements TabooLibLoader.Loader {
|
||||
if (Plugin.class.isAssignableFrom(declaredField.getType()) && declaredField.isAnnotationPresent(THook.class)) {
|
||||
THook hook = declaredField.getAnnotation(THook.class);
|
||||
if (Strings.nonEmpty(hook.plugin())) {
|
||||
Ref.forcedAccess(declaredField);
|
||||
for (Object instance : TInjectHelper.getInstance(declaredField, pluginClass, plugin)) {
|
||||
try {
|
||||
declaredField.set(instance, Bukkit.getPluginManager().getPlugin(hook.plugin()));
|
||||
Ref.putField(instance, declaredField, Bukkit.getPluginManager().getPlugin(hook.plugin()));
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
|
@ -20,10 +20,9 @@ public class TInjectAsm implements TabooLibLoader.Loader {
|
||||
if (annotation == null || annotation.asm().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
Ref.forcedAccess(declaredField);
|
||||
for (Object instance : TInjectHelper.getInstance(declaredField, pluginClass, plugin)) {
|
||||
try {
|
||||
declaredField.set(instance, SimpleVersionControl.createNMS(annotation.asm()).useCache().translate(plugin).newInstance());
|
||||
Ref.putField(instance, declaredField, SimpleVersionControl.createNMS(annotation.asm()).useCache().translate(plugin).newInstance());
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
|
@ -58,10 +58,9 @@ public class TInjectCreator implements TabooLibLoader.Loader {
|
||||
if (instance.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
Ref.forcedAccess(declaredField);
|
||||
try {
|
||||
InstanceData instanceData = new InstanceData(declaredField.getType().newInstance(), annotation);
|
||||
declaredField.set(instance, instanceData.getInstance());
|
||||
Ref.putField(instance, declaredField, instanceData.getInstance());
|
||||
instanceMap.put(new ClassData(loadClass, declaredField.getType()), instanceData);
|
||||
} catch (Throwable t) {
|
||||
TLogger.getGlobalLogger().error(declaredField.getName() + " instantiation failed: " + t.getMessage());
|
||||
|
@ -32,7 +32,6 @@ public class Ref {
|
||||
public static final int ACC_SYNTHETIC = 0x1000;
|
||||
private static final Unsafe UNSAFE;
|
||||
private static final MethodHandles.Lookup LOOKUP;
|
||||
private static final long modifiersOffset;
|
||||
|
||||
static {
|
||||
try {
|
||||
@ -41,7 +40,6 @@ public class Ref {
|
||||
Object lookupBase = UNSAFE.staticFieldBase(lookupField);
|
||||
long lookupOffset = UNSAFE.staticFieldOffset(lookupField);
|
||||
LOOKUP = (MethodHandles.Lookup) UNSAFE.getObject(lookupBase, lookupOffset);
|
||||
modifiersOffset = UNSAFE.objectFieldOffset(Field.class.getDeclaredField("modifiers"));
|
||||
} catch (Throwable t) {
|
||||
throw new IllegalStateException("Unsafe not found");
|
||||
}
|
||||
@ -55,6 +53,17 @@ public class Ref {
|
||||
return LOOKUP;
|
||||
}
|
||||
|
||||
public static void putField(Object src, Field field, Object value) {
|
||||
if (Modifier.isStatic(field.getModifiers())) {
|
||||
Object base = getUnsafe().staticFieldBase(field);
|
||||
long offset = getUnsafe().staticFieldOffset(field);
|
||||
getUnsafe().putObject(base, offset, value);
|
||||
} else {
|
||||
long offset = getUnsafe().objectFieldOffset(field);
|
||||
getUnsafe().putObject(src, offset, value);
|
||||
}
|
||||
}
|
||||
|
||||
public static List<Field> getDeclaredFields(Class<?> clazz) {
|
||||
return getDeclaredFields(clazz, 0, true);
|
||||
}
|
||||
@ -210,7 +219,6 @@ public class Ref {
|
||||
public static void forcedAccess(Field field) {
|
||||
try {
|
||||
field.setAccessible(true);
|
||||
getUnsafe().putInt(field, modifiersOffset, field.getModifiers() & ~Modifier.FINAL);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user