From 8e2165bb8a5d12e93d8653090ba2299418b99c98 Mon Sep 17 00:00:00 2001 From: anon8281 Date: Mon, 26 Jun 2023 03:07:55 +0300 Subject: [PATCH 1/3] Folia support --- build.gradle.kts | 2 ++ .../placeholderapi/PlaceholderAPIPlugin.java | 16 +++++++++++++--- .../updatechecker/UpdateChecker.java | 4 ++-- .../me/clip/placeholderapi/util/Futures.java | 4 +++- src/main/resources/plugin.yml | 1 + 5 files changed, 21 insertions(+), 6 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 1810fa6..8f9ee4f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -25,6 +25,7 @@ repositories { dependencies { implementation("org.bstats:bstats-bukkit:3.0.1") implementation("net.kyori:adventure-platform-bukkit:4.3.1") + implementation("com.github.Anon8281:UniversalScheduler:0.1.3") compileOnly("org.spigotmc:spigot-api:1.20-R0.1-SNAPSHOT") compileOnlyApi("org.jetbrains:annotations:23.0.0") @@ -88,6 +89,7 @@ tasks { relocate("org.bstats", "me.clip.placeholderapi.metrics") relocate("net.kyori", "me.clip.placeholderapi.libs.kyori") + relocate("com.github.Anon8281.universalScheduler", "me.clip.placeholderapi.libs.universalScheduler") } test { diff --git a/src/main/java/me/clip/placeholderapi/PlaceholderAPIPlugin.java b/src/main/java/me/clip/placeholderapi/PlaceholderAPIPlugin.java index 1fc84bf..162ea0c 100644 --- a/src/main/java/me/clip/placeholderapi/PlaceholderAPIPlugin.java +++ b/src/main/java/me/clip/placeholderapi/PlaceholderAPIPlugin.java @@ -23,6 +23,9 @@ package me.clip.placeholderapi; import java.text.SimpleDateFormat; import java.util.HashMap; import java.util.Map; + +import com.github.Anon8281.universalScheduler.UniversalScheduler; +import com.github.Anon8281.universalScheduler.scheduling.schedulers.TaskScheduler; import me.clip.placeholderapi.commands.PlaceholderCommandRouter; import me.clip.placeholderapi.configuration.PlaceholderAPIConfig; import me.clip.placeholderapi.expansion.PlaceholderExpansion; @@ -52,6 +55,7 @@ public final class PlaceholderAPIPlugin extends JavaPlugin { @NotNull private static final Version VERSION; + private static TaskScheduler SCHEDULER; private static PlaceholderAPIPlugin instance; static { @@ -140,6 +144,8 @@ public final class PlaceholderAPIPlugin extends JavaPlugin { @Override public void onEnable() { + SCHEDULER = UniversalScheduler.getScheduler(this); + setupCommand(); setupMetrics(); setupExpansions(); @@ -162,7 +168,7 @@ public final class PlaceholderAPIPlugin extends JavaPlugin { HandlerList.unregisterAll(this); - Bukkit.getScheduler().cancelTasks(this); + PlaceholderAPIPlugin.getScheduler().cancelTasks(this); adventure.close(); adventure = null; @@ -213,6 +219,10 @@ public final class PlaceholderAPIPlugin extends JavaPlugin { return config; } + public static TaskScheduler getScheduler() { + return SCHEDULER; + } + private void setupCommand() { final PluginCommand pluginCommand = getCommand("placeholderapi"); if (pluginCommand == null) { @@ -250,8 +260,8 @@ public final class PlaceholderAPIPlugin extends JavaPlugin { Class.forName("org.bukkit.event.server.ServerLoadEvent"); new ServerLoadEventListener(this); } catch (final ClassNotFoundException ignored) { - Bukkit.getScheduler() - .runTaskLater(this, () -> getLocalExpansionManager().load(Bukkit.getConsoleSender()), 1); + PlaceholderAPIPlugin.getScheduler() + .runTaskLater(() -> getLocalExpansionManager().load(Bukkit.getConsoleSender()), 1); } } diff --git a/src/main/java/me/clip/placeholderapi/updatechecker/UpdateChecker.java b/src/main/java/me/clip/placeholderapi/updatechecker/UpdateChecker.java index 8001d61..d9ae407 100644 --- a/src/main/java/me/clip/placeholderapi/updatechecker/UpdateChecker.java +++ b/src/main/java/me/clip/placeholderapi/updatechecker/UpdateChecker.java @@ -55,7 +55,7 @@ public class UpdateChecker implements Listener { } public void fetch() { - Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { + PlaceholderAPIPlugin.getScheduler().runTaskAsynchronously(() -> { try { HttpsURLConnection con = (HttpsURLConnection) new URL( "https://api.spigotmc.org/legacy/update.php?resource=" + RESOURCE_ID).openConnection(); @@ -76,7 +76,7 @@ public class UpdateChecker implements Listener { return; } - Bukkit.getScheduler().runTask(plugin, () -> { + PlaceholderAPIPlugin.getScheduler().runTask(() -> { plugin.getLogger() .info("An update for PlaceholderAPI (v" + getSpigotVersion() + ") is available at:"); plugin.getLogger() diff --git a/src/main/java/me/clip/placeholderapi/util/Futures.java b/src/main/java/me/clip/placeholderapi/util/Futures.java index c29892f..94d3dd8 100644 --- a/src/main/java/me/clip/placeholderapi/util/Futures.java +++ b/src/main/java/me/clip/placeholderapi/util/Futures.java @@ -27,6 +27,8 @@ import java.util.function.BiConsumer; import java.util.stream.Collector; import java.util.stream.Collectors; import java.util.stream.Stream; + +import me.clip.placeholderapi.PlaceholderAPIPlugin; import org.bukkit.Bukkit; import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; @@ -43,7 +45,7 @@ public final class Futures { if (Bukkit.isPrimaryThread()) { consumer.accept(value, exception); } else { - Bukkit.getScheduler().runTask(plugin, () -> consumer.accept(value, exception)); + PlaceholderAPIPlugin.getScheduler().runTask(() -> consumer.accept(value, exception)); } }); } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 84c3f5f..1c50d32 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -6,6 +6,7 @@ author: HelpChat api-version: "1.13" description: "An awesome placeholder provider!" +folia-supported: true commands: placeholderapi: From 2b53e3913fc339166dd50cf9508ca620ae07d675 Mon Sep 17 00:00:00 2001 From: Sevastjan Date: Mon, 17 Jul 2023 07:27:43 +0300 Subject: [PATCH 2/3] Ecloud fix --- .../java/me/clip/placeholderapi/PlaceholderAPIPlugin.java | 6 +++--- .../expansion/manager/CloudExpansionManager.java | 4 +--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main/java/me/clip/placeholderapi/PlaceholderAPIPlugin.java b/src/main/java/me/clip/placeholderapi/PlaceholderAPIPlugin.java index 162ea0c..77d6387 100644 --- a/src/main/java/me/clip/placeholderapi/PlaceholderAPIPlugin.java +++ b/src/main/java/me/clip/placeholderapi/PlaceholderAPIPlugin.java @@ -55,7 +55,7 @@ public final class PlaceholderAPIPlugin extends JavaPlugin { @NotNull private static final Version VERSION; - private static TaskScheduler SCHEDULER; + private static TaskScheduler scheduler; private static PlaceholderAPIPlugin instance; static { @@ -144,7 +144,7 @@ public final class PlaceholderAPIPlugin extends JavaPlugin { @Override public void onEnable() { - SCHEDULER = UniversalScheduler.getScheduler(this); + scheduler = UniversalScheduler.getScheduler(this); setupCommand(); setupMetrics(); @@ -220,7 +220,7 @@ public final class PlaceholderAPIPlugin extends JavaPlugin { } public static TaskScheduler getScheduler() { - return SCHEDULER; + return scheduler; } private void setupCommand() { diff --git a/src/main/java/me/clip/placeholderapi/expansion/manager/CloudExpansionManager.java b/src/main/java/me/clip/placeholderapi/expansion/manager/CloudExpansionManager.java index 19dc77c..7bfc7e3 100644 --- a/src/main/java/me/clip/placeholderapi/expansion/manager/CloudExpansionManager.java +++ b/src/main/java/me/clip/placeholderapi/expansion/manager/CloudExpansionManager.java @@ -201,11 +201,9 @@ public final class CloudExpansionManager { } // loop through what's left on the main thread - plugin - .getServer() + PlaceholderAPIPlugin .getScheduler() .runTask( - plugin, () -> { try { for (Map.Entry entry : values.entrySet()) { From c6aed73f888a2c75f4b045174499d02c368bdab1 Mon Sep 17 00:00:00 2001 From: Sevastjan <80479533+Anon8281@users.noreply.github.com> Date: Sun, 21 Jan 2024 20:40:00 +0300 Subject: [PATCH 3/3] Added repository and update scheduling lib --- build.gradle.kts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 8f9ee4f..f55c9ef 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -20,12 +20,13 @@ repositories { maven("https://repo.codemc.org/repository/maven-public/") maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") + maven ("https://jitpack.io" ) } dependencies { implementation("org.bstats:bstats-bukkit:3.0.1") implementation("net.kyori:adventure-platform-bukkit:4.3.1") - implementation("com.github.Anon8281:UniversalScheduler:0.1.3") + implementation("com.github.Anon8281:UniversalScheduler:0.1.6") compileOnly("org.spigotmc:spigot-api:1.20-R0.1-SNAPSHOT") compileOnlyApi("org.jetbrains:annotations:23.0.0")