feat: use ChronoUnit for cloop (forever cloop now real!!!)

This commit is contained in:
ChomeNS
2025-03-18 19:05:31 +07:00
parent f882c15d39
commit 04a8d10e1f
4 changed files with 9 additions and 8 deletions

View File

@@ -1 +1 @@
1913
1916

View File

@@ -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);

View File

@@ -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
) {}

View File

@@ -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) {