-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use 'sun.misc.Unsafe' to change the 'final field flagsList from World…
…Guard' at 1.7.10 Add several warnings in case it does not work (as it might not work on java after 2025) Now it will try things on this order: 1- Check if is a modified WorldGuard version with the extra method 'addFlag' 2- If not, try the normal reflection way (should work on java 8) 3- Try using UNSAFE to change the field, should work on java 21 (for now) 4- If no one works, warn the player about the problem.
- Loading branch information
Showing
3 changed files
with
76 additions
and
13 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
...ionedPlugins/src/main/java/br/com/finalcraft/evernifecore/unsafereflecton/UnsafeUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package br.com.finalcraft.evernifecore.unsafereflecton; | ||
|
||
import sun.misc.Unsafe; | ||
|
||
import java.lang.reflect.Field; | ||
|
||
public class UnsafeUtil { | ||
|
||
static Field theUnsafe; | ||
static Unsafe UNSAFE; | ||
static { | ||
try { | ||
theUnsafe = Unsafe.class.getDeclaredField("theUnsafe"); | ||
theUnsafe.setAccessible(true); | ||
UNSAFE = (Unsafe) theUnsafe.get(null); // Cache this | ||
}catch (Throwable e){ | ||
|
||
} | ||
} | ||
|
||
// As noted here https://github.com/GTNewHorizons/lwjgl3ify?tab=readme-ov-file#javabasejavalangreflect-classes-are-protected-from-reflective-access | ||
// this method 'MIGHT' work until java 2025 | ||
public static void setField(Field data, Object object, Object value) { | ||
if (object == null) { | ||
long offset = UNSAFE.staticFieldOffset(data); | ||
Object base = UNSAFE.staticFieldBase(data); | ||
UNSAFE.putObject(base, offset, value); | ||
} else { | ||
long offset = UNSAFE.objectFieldOffset(data); | ||
UNSAFE.putObject(object, offset, value); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters