mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-06-12 20:43:54 +00:00
Fix paperweight changes (#1364)
This commit is contained in:
committed by
GitHub
parent
74486fc8c9
commit
c7a490fa03
@ -1,5 +1,7 @@
|
||||
package com.fastasyncworldedit.core.util;
|
||||
|
||||
import sun.misc.Unsafe;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.reflect.AccessibleObject;
|
||||
@ -12,6 +14,18 @@ import java.util.Comparator;
|
||||
|
||||
public class ReflectionUtils {
|
||||
|
||||
private static Unsafe UNSAFE;
|
||||
|
||||
static {
|
||||
try {
|
||||
Field unsafeField = Unsafe.class.getDeclaredField("theUnsafe");
|
||||
unsafeField.setAccessible(true);
|
||||
UNSAFE = (Unsafe) unsafeField.get(null);
|
||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T as(Class<T> t, Object o) {
|
||||
return t.isInstance(o) ? t.cast(o) : null;
|
||||
}
|
||||
@ -112,4 +126,13 @@ public class ReflectionUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static void unsafeSet(Object base, long offset, Object value) {
|
||||
UNSAFE.putObject(base, offset, value);
|
||||
}
|
||||
|
||||
public static void unsafeSet(Field field, Object base, Object value) {
|
||||
UNSAFE.putObject(base, UNSAFE.objectFieldOffset(field), value);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user