From 301d4bc25e1c450fa55a39d0ccf6e19d981ca50a Mon Sep 17 00:00:00 2001 From: Emmanuel Lampe Date: Wed, 14 Feb 2024 23:25:16 +0100 Subject: [PATCH 1/2] fix: use async scheduler instead of BukkitScheduler for folia --- .../simplyadmin/SimplyAdminPlugin.java | 5 ----- .../cron/CronScheduleExecutor.java | 22 +++++-------------- 2 files changed, 6 insertions(+), 21 deletions(-) diff --git a/src/main/java/net/simplyvanilla/simplyadmin/SimplyAdminPlugin.java b/src/main/java/net/simplyvanilla/simplyadmin/SimplyAdminPlugin.java index f97d759..026cef9 100644 --- a/src/main/java/net/simplyvanilla/simplyadmin/SimplyAdminPlugin.java +++ b/src/main/java/net/simplyvanilla/simplyadmin/SimplyAdminPlugin.java @@ -40,11 +40,6 @@ public void onEnable() { manager.registerEvents(new NewPlayerListener(this), this); } - @Override - public void onDisable() { - this.cronScheduleExecutor.cancel(); - } - public Component getMessage(String key, TagResolver... tagResolvers) { String string = this.getConfig().getString("messages." + key); if (string == null) { diff --git a/src/main/java/net/simplyvanilla/simplyadmin/cron/CronScheduleExecutor.java b/src/main/java/net/simplyvanilla/simplyadmin/cron/CronScheduleExecutor.java index 31a56d7..32dbc57 100644 --- a/src/main/java/net/simplyvanilla/simplyadmin/cron/CronScheduleExecutor.java +++ b/src/main/java/net/simplyvanilla/simplyadmin/cron/CronScheduleExecutor.java @@ -1,10 +1,9 @@ package net.simplyvanilla.simplyadmin.cron; -import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.TimeUnit; import net.simplyvanilla.simplyadmin.SimplyAdminPlugin; import org.bukkit.configuration.ConfigurationSection; @@ -14,8 +13,7 @@ record CronEntry(int interval, List commands) { private final SimplyAdminPlugin plugin; - private final Map currentCommandIndex = new HashMap<>(); - private final Set taskIds = new HashSet<>(); + private final Map currentCommandIndex = new ConcurrentHashMap<>(); public CronScheduleExecutor(SimplyAdminPlugin plugin, ConfigurationSection section) { this.plugin = plugin; @@ -37,8 +35,8 @@ private void parseEntries(ConfigurationSection section) { } private void schedule(CronEntry entry) { - int taskId = - this.plugin.getServer().getScheduler().scheduleSyncRepeatingTask(this.plugin, () -> { + this.plugin.getServer().getAsyncScheduler() + .runAtFixedRate(this.plugin, scheduledTask -> { int currentIndex = this.currentCommandIndex.getOrDefault(entry, 0); if (currentIndex >= entry.commands.size()) { currentIndex = 0; @@ -48,14 +46,6 @@ private void schedule(CronEntry entry) { this.plugin.getServer() .dispatchCommand(this.plugin.getServer().getConsoleSender(), command); this.currentCommandIndex.put(entry, currentIndex + 1); - }, 0L, entry.interval * 20L); - - this.taskIds.add(taskId); - } - - public void cancel() { - for (int taskId : this.taskIds) { - this.plugin.getServer().getScheduler().cancelTask(taskId); - } + }, 0, entry.interval, TimeUnit.SECONDS); } } From 42c6f3fc35347328a425c31694eb51af2ba69114 Mon Sep 17 00:00:00 2001 From: Netherwhal Date: Wed, 14 Feb 2024 23:27:17 +0100 Subject: [PATCH 2/2] bump 0.2.1 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index add5661..bdf2e4e 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { } group = 'net.simplyvanilla' -version = '0.2.0' +version = '0.2.1' repositories { mavenCentral()