Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Folia support #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ dependencies {
compileOnly("com.github.MilkBowl", "VaultAPI", "1.7")
compileOnly("me.clip", "placeholderapi", "2.10.8")
compileOnly("org.jetbrains", "annotations", "22.0.0")
compileOnly("io.papermc.paper", "paper-api", "1.18.1-R0.1-SNAPSHOT")
compileOnly("dev.folia", "folia-api", "1.19.4-R0.1-SNAPSHOT")
}

// Set the default value to the current time as an ISO-8601 string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import pw.chew.transmuteit.guis.TransmuteTakeGUI;
import pw.chew.transmuteit.objects.TransmutableItem;
import pw.chew.transmuteit.utils.ChatHelper;
import pw.chew.transmuteit.utils.Compatibility;
import pw.chew.transmuteit.utils.DataManager;

import java.io.IOException;
Expand Down Expand Up @@ -376,7 +377,7 @@ public boolean handleVersion(CommandSender sender) {
sender.sendMessage("Checking for new updates...");

int finalCbuild = cbuild;
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
Compatibility.runTaskAsync(plugin, () -> {
String[] response = getLatestVersion();
int lbuild = Integer.parseInt(response[0]);
String lversion = response[1];
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/pw/chew/transmuteit/utils/Compatibility.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package pw.chew.transmuteit.utils;

import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;

public class Compatibility {

public static Boolean IS_FOLIA = null;

private static boolean methodExists(Class<?> clazz, String methodName, Class<?>... parameterTypes) {
try {
clazz.getDeclaredMethod(methodName, parameterTypes);
return true;
} catch (Throwable dontcare) {
return false;
}
}

public static Boolean isFolia() {
if (IS_FOLIA == null) {
IS_FOLIA = methodExists(Bukkit.class, "getGlobalRegionScheduler");
}
return IS_FOLIA;
}

public static void runTaskAsync(Plugin plugin, Runnable runnable) {
if (isFolia()) {
Bukkit.getAsyncScheduler().runNow(plugin, (task) -> runnable.run());
return;
}
Bukkit.getScheduler().runTaskAsynchronously(plugin, runnable);
}
}
1 change: 1 addition & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version: 0.5.0-b${build}
api-version: "1.15"
description: It's just ProjectE Transmutation for Spigot
author: Chewsterchew
folia-supported: true
website: https://github.com/ChewMC/TransmuteIt
softdepend: [Vault, PlaceholderAPI]
commands:
Expand Down