-
Notifications
You must be signed in to change notification settings - Fork 4
How it works
Folia Phantom uses advanced bytecode manipulation to ensure compatibility between standard Bukkit APIs and Folia's multi-threaded environment.
We use the ASM Library to read, analyze, and rewrite .class files inside plugin JARs.
Before applying heavy transformations, the engine performs a "Fast Scan" using ScanningClassVisitor. It looks for keywords like BukkitScheduler, BukkitRunnable, and setType. If none are found, the class is skipped, drastically increasing patching speed.
The engine intercepts method calls and redirects them to a "Bridge" class (FoliaPatcher) that is automatically bundled into the resulting JAR.
-
Original Code:
Bukkit.getScheduler().runTask(plugin, runnable); -
Patched Code:
FoliaPatcher.runTask(null, plugin, runnable);
The FoliaPatcher then determines whether to use:
-
RegionScheduler(if a location context is found) -
GlobalRegionScheduler(for global tasks) -
AsyncScheduler(for async tasks)
Certain methods like Block.setType are inherently thread-unsafe in Folia if called from the wrong thread. Folia Phantom automatically wraps these calls to ensure they execute on the correct Folia tick/region thread.
In addition to bytecode transformation, Folia Phantom performs:
-
plugin.ymlUpdate: Automatically addsfolia-supported: true. -
Signature Removal: Deletes
META-INF/*.SF,DSA, andRSAfiles to avoid security exceptions after modification. -
Runtime Injection: Bundles the
FoliaPatcherclasses so the patched plugin can run on any Folia server without external dependencies.