mirror of
https://github.com/songoda/SongodaCore.git
synced 2024-10-22 20:30:41 +02:00
Add option to customize delay and period
This commit is contained in:
parent
6abaeb4cf8
commit
b44504efed
@ -8,12 +8,33 @@ import java.util.Map;
|
|||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
public abstract class TaskScheduler {
|
public abstract class TaskScheduler {
|
||||||
|
|
||||||
private final SongodaPlugin plugin;
|
private final SongodaPlugin plugin;
|
||||||
private final Map<TaskWrapper, Long> tasks = new ConcurrentHashMap<>();
|
private final Map<TaskWrapper, Long> tasks = new ConcurrentHashMap<>();
|
||||||
private BukkitRunnable runnable;
|
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) {
|
public TaskScheduler(SongodaPlugin plugin) {
|
||||||
this.plugin = 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() {
|
private void startScheduler() {
|
||||||
@ -24,7 +45,7 @@ public abstract class TaskScheduler {
|
|||||||
executeTasks();
|
executeTasks();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
this.runnable.runTaskTimerAsynchronously(this.plugin, 20L, 20L);
|
this.runnable.runTaskTimerAsynchronously(this.plugin, this.delay, this.period);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user