From b44504efed0a44c91913fd1bf71d532dddae0fcb Mon Sep 17 00:00:00 2001 From: ceze88 Date: Mon, 15 Apr 2024 14:09:34 +0200 Subject: [PATCH] Add option to customize delay and period --- .../craftaro/core/thread/TaskScheduler.java | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/Core/src/main/java/com/craftaro/core/thread/TaskScheduler.java b/Core/src/main/java/com/craftaro/core/thread/TaskScheduler.java index a46299f9..52272ca6 100644 --- a/Core/src/main/java/com/craftaro/core/thread/TaskScheduler.java +++ b/Core/src/main/java/com/craftaro/core/thread/TaskScheduler.java @@ -8,12 +8,33 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; public abstract class TaskScheduler { + private final SongodaPlugin plugin; private final Map tasks = new ConcurrentHashMap<>(); private BukkitRunnable runnable; + private long delay; + private long period; + /** + * Constructor for TaskScheduler with default delay and period. + * @param plugin The plugin instance. + */ public TaskScheduler(SongodaPlugin plugin) { this.plugin = plugin; + this.delay = 20L; + this.period = 20L; + } + + /** + * Constructor for TaskScheduler with a custom delay and period. + * @param plugin The plugin instance. + * @param delay The delay in ticks. + * @param period The period in ticks. + */ + public TaskScheduler(SongodaPlugin plugin, long delay, long period) { + this.plugin = plugin; + this.delay = delay; + this.period = period; } private void startScheduler() { @@ -24,7 +45,7 @@ public abstract class TaskScheduler { executeTasks(); } }; - this.runnable.runTaskTimerAsynchronously(this.plugin, 20L, 20L); + this.runnable.runTaskTimerAsynchronously(this.plugin, this.delay, this.period); } }