feat: use ChronoUnit for cloop (forever cloop now real!!!)
This commit is contained in:
@@ -1 +1 @@
|
||||
1913
|
||||
1916
|
||||
@@ -11,16 +11,16 @@ import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.JoinConfiguration;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class CloopCommand extends Command {
|
||||
public CloopCommand () {
|
||||
super(
|
||||
"cloop",
|
||||
"Loops commands",
|
||||
new String[] { "add <interval> <TimeUnit> <command>", "remove <index>", "clear", "list" },
|
||||
new String[] { "add <interval> <ChronoUnit> <command>", "remove <index>", "clear", "list" },
|
||||
new String[] { "commandloop" },
|
||||
TrustLevel.TRUSTED,
|
||||
false
|
||||
@@ -38,7 +38,7 @@ public class CloopCommand extends Command {
|
||||
int interval = context.getInteger(true);
|
||||
if (interval < 1) interval = 1;
|
||||
|
||||
final TimeUnit unit = context.getEnum(TimeUnit.class);
|
||||
final ChronoUnit unit = context.getEnum(ChronoUnit.class);
|
||||
|
||||
final String command = context.getString(true, true);
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package me.chayapak1.chomens_bot.data.cloop;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
public record CommandLoop (
|
||||
String command,
|
||||
int interval,
|
||||
TimeUnit unit
|
||||
ChronoUnit unit
|
||||
) {}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package me.chayapak1.chomens_bot.plugins;
|
||||
import me.chayapak1.chomens_bot.Bot;
|
||||
import me.chayapak1.chomens_bot.data.cloop.CommandLoop;
|
||||
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
@@ -18,11 +19,11 @@ public class CloopPlugin {
|
||||
this.bot = bot;
|
||||
}
|
||||
|
||||
public void add (TimeUnit unit, int interval, String command) {
|
||||
public void add (ChronoUnit unit, int interval, String command) {
|
||||
Runnable loopTask = () -> bot.core.run(command);
|
||||
|
||||
loops.add(new CommandLoop(command, interval, unit));
|
||||
loopTasks.add(bot.executor.scheduleAtFixedRate(loopTask, 0, interval, unit));
|
||||
loopTasks.add(bot.executor.scheduleAtFixedRate(loopTask, 0, interval, TimeUnit.of(unit)));
|
||||
}
|
||||
|
||||
public CommandLoop remove (int index) {
|
||||
|
||||
Reference in New Issue
Block a user