diff --git a/.gitignore b/.gitignore
index 41b5f437..968fafef 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,6 +10,7 @@ javadoc
Vault.jar
/Vault.iml
/target
+.idea
#added by LRFLEW
#feel free to remove
diff --git a/plugin.yml b/plugin.yml
index 8591ddcc..d20495a4 100644
--- a/plugin.yml
+++ b/plugin.yml
@@ -4,6 +4,7 @@ description: ${project.description}
authors: [cereal, Sleaker, mung3r]
website: ${project.url}
api-version: 1.13
+folia-supported: true
main: ${mainClass}
load: startup
diff --git a/pom.xml b/pom.xml
index f91cfd6a..b3b3bcaa 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,6 +5,7 @@
UTF-8
1.13.1-R0.1-SNAPSHOT
+ 1.19.4-R0.1-SNAPSHOT
${project.groupId}.${project.artifactId}
1.7
@@ -59,6 +60,10 @@
spigot-repo
https://hub.spigotmc.org/nexus/content/groups/public/
+
+ papermc
+ https://repo.papermc.io/repository/maven-public/
+
escapecraft-repo
http://dev.escapecraft.com/maven
@@ -70,6 +75,12 @@
+
+ dev.folia
+ folia-api
+ ${foliaVersion}
+ provided
+
org.bukkit
bukkit
diff --git a/src/net/milkbowl/vault/Vault.java b/src/net/milkbowl/vault/Vault.java
index f085f0e5..286c2e53 100644
--- a/src/net/milkbowl/vault/Vault.java
+++ b/src/net/milkbowl/vault/Vault.java
@@ -21,6 +21,7 @@
import java.net.URLConnection;
import java.util.Collection;
import java.util.concurrent.Callable;
+import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
import net.milkbowl.vault.chat.Chat;
@@ -89,12 +90,13 @@ public class Vault extends JavaPlugin {
private String currentVersionTitle = "";
private ServicesManager sm;
private Vault plugin;
+ private boolean folia;
@Override
public void onDisable() {
// Remove all Service Registrations
getServer().getServicesManager().unregisterAll(this);
- Bukkit.getScheduler().cancelTasks(this);
+ schedulerCancelTasks(this);
}
@Override
@@ -104,6 +106,8 @@ public void onEnable() {
currentVersionTitle = getDescription().getVersion().split("-")[0];
currentVersion = Double.valueOf(currentVersionTitle.replaceFirst("\\.", ""));
sm = getServer().getServicesManager();
+ folia = packagesExists("io.papermc.paper.threadedregions.scheduler.AsyncScheduler");
+
// set defaults
getConfig().addDefault("update-check", true);
getConfig().options().copyDefaults(true);
@@ -117,7 +121,7 @@ public void onEnable() {
getServer().getPluginManager().registerEvents(new VaultListener(), this);
// Schedule to check the version every 30 minutes for an update. This is to update the most recent
// version so if an admin reconnects they will be warned about newer versions.
- this.getServer().getScheduler().runTask(this, new Runnable() {
+ schedulerRunTask(this, new Runnable() {
@Override
public void run() {
@@ -131,7 +135,7 @@ public void run() {
}
perm.setDescription("Allows a user or the console to check for vault updates");
- getServer().getScheduler().runTaskTimerAsynchronously(plugin, new Runnable() {
+ schedulerRunTaskTimerAsynchronously(plugin, new Runnable() {
@Override
public void run() {
@@ -421,6 +425,31 @@ private void infoCommand(CommandSender sender) {
sender.sendMessage(String.format("[%s] Chat: %s [%s]", getDescription().getName(), chat == null ? "None" : chat.getName(), registeredChats));
}
+ private void schedulerRunTask(Plugin plugin, Runnable runnable) {
+ if (folia) {
+ Bukkit.getGlobalRegionScheduler().execute(plugin, runnable);
+ } else {
+ Bukkit.getScheduler().runTask(plugin, runnable);
+ }
+ }
+
+ private void schedulerRunTaskTimerAsynchronously(Plugin plugin, Runnable runnable, long delay, long period) {
+ if (folia) {
+ Bukkit.getAsyncScheduler().runAtFixedRate(plugin, st -> runnable.run(), delay, period * 50L, TimeUnit.MILLISECONDS);
+ } else {
+ Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, runnable, delay, period);
+ }
+ }
+
+ private void schedulerCancelTasks(Plugin plugin) {
+ if (folia) {
+ Bukkit.getAsyncScheduler().cancelTasks(plugin);
+ Bukkit.getGlobalRegionScheduler().cancelTasks(plugin);
+ } else {
+ Bukkit.getScheduler().cancelTasks(plugin);
+ }
+ }
+
/**
* Determines if all packages in a String array are within the Classpath
* This is the best way to determine if a specific plugin exists and will be