From 18ef3c6fc9ee31cebd5a37f040a6b74d718b9ada Mon Sep 17 00:00:00 2001 From: LOOHP Date: Thu, 30 Mar 2023 15:42:51 +0100 Subject: [PATCH 1/3] Folia support --- plugin.yml | 1 + pom.xml | 11 ++++++ src/net/milkbowl/vault/Vault.java | 57 +++++++++++++++++++++++-------- 3 files changed, 54 insertions(+), 15 deletions(-) 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..ef66efad 100644 --- a/src/net/milkbowl/vault/Vault.java +++ b/src/net/milkbowl/vault/Vault.java @@ -15,14 +15,6 @@ */ package net.milkbowl.vault; -import java.io.BufferedReader; -import java.io.InputStreamReader; -import java.net.URL; -import java.net.URLConnection; -import java.util.Collection; -import java.util.concurrent.Callable; -import java.util.logging.Logger; - import net.milkbowl.vault.chat.Chat; import net.milkbowl.vault.chat.plugins.Chat_DroxPerms; import net.milkbowl.vault.chat.plugins.Chat_GroupManager; @@ -30,6 +22,7 @@ import net.milkbowl.vault.chat.plugins.Chat_Permissions3; import net.milkbowl.vault.chat.plugins.Chat_PermissionsEx; import net.milkbowl.vault.chat.plugins.Chat_Privileges; +import net.milkbowl.vault.chat.plugins.Chat_TotalPermissions; import net.milkbowl.vault.chat.plugins.Chat_bPermissions; import net.milkbowl.vault.chat.plugins.Chat_bPermissions2; import net.milkbowl.vault.chat.plugins.Chat_iChat; @@ -40,6 +33,7 @@ import net.milkbowl.vault.permission.Permission; import net.milkbowl.vault.permission.plugins.Permission_DroxPerms; import net.milkbowl.vault.permission.plugins.Permission_GroupManager; +import net.milkbowl.vault.permission.plugins.Permission_KPerms; import net.milkbowl.vault.permission.plugins.Permission_OverPermissions; import net.milkbowl.vault.permission.plugins.Permission_Permissions3; import net.milkbowl.vault.permission.plugins.Permission_PermissionsBukkit; @@ -48,13 +42,11 @@ import net.milkbowl.vault.permission.plugins.Permission_SimplyPerms; import net.milkbowl.vault.permission.plugins.Permission_Starburst; import net.milkbowl.vault.permission.plugins.Permission_SuperPerms; +import net.milkbowl.vault.permission.plugins.Permission_TotalPermissions; import net.milkbowl.vault.permission.plugins.Permission_Xperms; import net.milkbowl.vault.permission.plugins.Permission_bPermissions; import net.milkbowl.vault.permission.plugins.Permission_bPermissions2; -import net.milkbowl.vault.permission.plugins.Permission_TotalPermissions; import net.milkbowl.vault.permission.plugins.Permission_rscPermissions; -import net.milkbowl.vault.permission.plugins.Permission_KPerms; - import org.bstats.bukkit.Metrics; import org.bstats.charts.SimplePie; import org.bukkit.Bukkit; @@ -76,7 +68,14 @@ import org.json.simple.JSONObject; import org.json.simple.JSONValue; -import net.milkbowl.vault.chat.plugins.Chat_TotalPermissions; +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.net.URL; +import java.net.URLConnection; +import java.util.Collection; +import java.util.concurrent.Callable; +import java.util.concurrent.TimeUnit; +import java.util.logging.Logger; public class Vault extends JavaPlugin { @@ -89,12 +88,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 +104,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 +119,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 +133,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 +423,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 From 20cc002215211ff57f9272a247e233bef969f4d9 Mon Sep 17 00:00:00 2001 From: LOOHP Date: Thu, 30 Mar 2023 15:47:57 +0100 Subject: [PATCH 2/3] Try not to create a lot of diff from imports --- src/net/milkbowl/vault/Vault.java | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/net/milkbowl/vault/Vault.java b/src/net/milkbowl/vault/Vault.java index ef66efad..286c2e53 100644 --- a/src/net/milkbowl/vault/Vault.java +++ b/src/net/milkbowl/vault/Vault.java @@ -15,6 +15,15 @@ */ package net.milkbowl.vault; +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.net.URL; +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; import net.milkbowl.vault.chat.plugins.Chat_DroxPerms; import net.milkbowl.vault.chat.plugins.Chat_GroupManager; @@ -22,7 +31,6 @@ import net.milkbowl.vault.chat.plugins.Chat_Permissions3; import net.milkbowl.vault.chat.plugins.Chat_PermissionsEx; import net.milkbowl.vault.chat.plugins.Chat_Privileges; -import net.milkbowl.vault.chat.plugins.Chat_TotalPermissions; import net.milkbowl.vault.chat.plugins.Chat_bPermissions; import net.milkbowl.vault.chat.plugins.Chat_bPermissions2; import net.milkbowl.vault.chat.plugins.Chat_iChat; @@ -33,7 +41,6 @@ import net.milkbowl.vault.permission.Permission; import net.milkbowl.vault.permission.plugins.Permission_DroxPerms; import net.milkbowl.vault.permission.plugins.Permission_GroupManager; -import net.milkbowl.vault.permission.plugins.Permission_KPerms; import net.milkbowl.vault.permission.plugins.Permission_OverPermissions; import net.milkbowl.vault.permission.plugins.Permission_Permissions3; import net.milkbowl.vault.permission.plugins.Permission_PermissionsBukkit; @@ -42,11 +49,13 @@ import net.milkbowl.vault.permission.plugins.Permission_SimplyPerms; import net.milkbowl.vault.permission.plugins.Permission_Starburst; import net.milkbowl.vault.permission.plugins.Permission_SuperPerms; -import net.milkbowl.vault.permission.plugins.Permission_TotalPermissions; import net.milkbowl.vault.permission.plugins.Permission_Xperms; import net.milkbowl.vault.permission.plugins.Permission_bPermissions; import net.milkbowl.vault.permission.plugins.Permission_bPermissions2; +import net.milkbowl.vault.permission.plugins.Permission_TotalPermissions; import net.milkbowl.vault.permission.plugins.Permission_rscPermissions; +import net.milkbowl.vault.permission.plugins.Permission_KPerms; + import org.bstats.bukkit.Metrics; import org.bstats.charts.SimplePie; import org.bukkit.Bukkit; @@ -68,14 +77,7 @@ import org.json.simple.JSONObject; import org.json.simple.JSONValue; -import java.io.BufferedReader; -import java.io.InputStreamReader; -import java.net.URL; -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.plugins.Chat_TotalPermissions; public class Vault extends JavaPlugin { From fc7b94d999f488b9d831a2353660418cc81d9a22 Mon Sep 17 00:00:00 2001 From: LOOHP Date: Thu, 30 Mar 2023 15:51:36 +0100 Subject: [PATCH 3/3] Git ignore .idea --- .gitignore | 1 + 1 file changed, 1 insertion(+) 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