Folia support added by ZhangYuheng (#3617)

* folia support finished
* add Contributors
* try to use reflection to load class
* finish the compatible for java11 and java 17+ (folia)
* change pal version to 5.2.0, due to the merge of folia-layer.
now this can be compiled by CI-CD(workflow)
* separate folia pal to standalone gradle module
so javadoc gen may success
* made folia module skip javadoc compile
* take advise from AnttiMK. Thank u :)
* make folia pal with runtimeOnly
* extend FileWatcherTest time await up to 5 sec

Affects issues:
- Close #2962
This commit is contained in:
张宇衡 2024-05-18 23:52:39 +08:00 committed by GitHub
parent 5e0780be1a
commit fefbd9ae23
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 42 additions and 4 deletions

View File

@ -71,7 +71,7 @@ subprojects {
ext {
daggerVersion = "2.51.1"
palVersion = "5.1.0"
palVersion = "5.2.0"
bukkitVersion = "1.13.2-R0.1-SNAPSHOT"
spigotVersion = "1.13.2-R0.1-SNAPSHOT"

View File

@ -36,6 +36,7 @@ import org.bukkit.command.PluginCommand;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import java.lang.reflect.Constructor;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
@ -62,7 +63,18 @@ public class Plan extends JavaPlugin implements PlanPlugin {
@Override
public void onLoad() {
abstractionLayer = new BukkitPlatformLayer(this);
if (isFolia()) {
try {
// Attempt to load and use the Folia library for Java 17+
Class<?> foliaPlatformLayer = Class.forName("net.playeranalytics.plugin.FoliaPlatformLayer");
abstractionLayer = (PlatformAbstractionLayer) foliaPlatformLayer.getConstructor(JavaPlugin.class).newInstance(this);
} catch (Exception e) {
this.getLogger().log(Level.SEVERE, "Failed to load FoliaPlatformLayer", e);
abstractionLayer = new BukkitPlatformLayer(this);
}
} else {
abstractionLayer = new BukkitPlatformLayer(this);
}
pluginLogger = abstractionLayer.getPluginLogger();
runnableFactory = abstractionLayer.getRunnableFactory();
}
@ -167,7 +179,18 @@ public class Plan extends JavaPlugin implements PlanPlugin {
public void cancelAllTasks() {
runnableFactory.cancelAllKnownTasks();
Bukkit.getScheduler().cancelTasks(this);
if (!isFolia()) {
Bukkit.getScheduler().cancelTasks(this);
}
}
private static boolean isFolia() {
try {
Class.forName("io.papermc.paper.threadedregions.RegionizedServer");
return true;
} catch (ClassNotFoundException e) {
return false;
}
}
@Override

View File

@ -114,6 +114,7 @@ public class Contributors {
new Contributor("liuzhen932", LANG),
new Contributor("Sniper_TVmc", LANG),
new Contributor("mcmdev", CODE),
new Contributor("ZhangYuheng", CODE)
};
private Contributors() {

View File

@ -3,6 +3,7 @@ author: AuroraLS3
main: com.djrapitops.plan.Plan
version: @version@
api-version: 1.13
folia-supported: true
softdepend:
- AAC
- ASkyBlock

View File

@ -60,7 +60,7 @@ class FileWatcherTest {
createAndModifyFile(modified);
Awaitility.await()
.atMost(1, TimeUnit.SECONDS)
.atMost(5, TimeUnit.SECONDS)
.until(methodWasCalled::get);
assertTrue(methodWasCalled.get());

11
Plan/folia/build.gradle Normal file
View File

@ -0,0 +1,11 @@
tasks.withType(JavaCompile).configureEach {
options.release.set(17)
}
dependencies {
runtimeOnly "net.playeranalytics:platform-abstraction-layer-folia:$palVersion"
}
shadowJar {
configurations = [project.configurations.shadow]
}

View File

@ -8,6 +8,7 @@ dependencies {
shadow project(path: ":sponge")
shadow project(path: ":bungeecord")
shadow project(path: ":velocity")
shadow project(path: ":folia")
testImplementation project(path: ":common", configuration: 'testArtifacts')
testImplementation project(path: ":bukkit", configuration: 'testArtifacts')
testImplementation project(path: ":nukkit", configuration: 'testArtifacts')

View File

@ -26,3 +26,4 @@ include 'plugin'
include 'extensions'
include 'extensions:adventure'
include 'fabric'
include 'folia'