refactor: use long in cloop interval instead of int

feat: `getLong` in CommandContext (i didn't know it doesn't exist lol)
This commit is contained in:
ChomeNS
2025-03-19 09:39:16 +07:00
parent 07b61540ef
commit 04b0377bd9
5 changed files with 16 additions and 4 deletions

View File

@@ -184,6 +184,18 @@ public class CommandContext {
}
}
public Long getLong (boolean required) throws CommandException {
final String string = getString(false, required, "long");
if (string.isEmpty()) return null;
try {
return Long.parseLong(string);
} catch (NumberFormatException e) {
throw new CommandException(Component.text("Invalid long"));
}
}
public Double getDouble (boolean required, boolean allowInfinite) throws CommandException {
final String string = getString(false, required, "double");

View File

@@ -35,7 +35,7 @@ public class CloopCommand extends Command {
switch (action) {
case "add" -> {
int interval = context.getInteger(true);
long interval = context.getLong(true);
if (interval < 1) interval = 1;
final TimeUnit unit = context.getEnum(TimeUnit.class);

View File

@@ -4,7 +4,7 @@ import java.util.concurrent.TimeUnit;
public record CommandLoop (
String command,
int interval,
long interval,
TimeUnit unit
) {}

View File

@@ -18,7 +18,7 @@ public class CloopPlugin {
this.bot = bot;
}
public void add (TimeUnit unit, int interval, String command) {
public void add (TimeUnit unit, long interval, String command) {
Runnable loopTask = () -> bot.core.run(command);
loops.add(new CommandLoop(command, interval, unit));