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:
@@ -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");
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -4,7 +4,7 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
public record CommandLoop (
|
||||
String command,
|
||||
int interval,
|
||||
long interval,
|
||||
TimeUnit unit
|
||||
) {}
|
||||
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user