fix args parser?

totally didn't ask chatgpt but idk i only stole part of the fix cuz it added random shits
This commit is contained in:
Chayapak 2023-09-19 16:26:42 +07:00
parent 824697879d
commit 7c15ea84a2
2 changed files with 9 additions and 3 deletions

View file

@ -34,7 +34,7 @@ public class CommandContext {
public String getString (boolean greedy, boolean required) throws CommandException { return getString(greedy, required, "string"); }
private String getString (boolean greedy, boolean required, String type) throws CommandException {
if (args.length == 0 || args[Math.min(argsPosition, args.length - 1)] == null) {
if (argsPosition >= args.length || args[argsPosition] == null) {
if (required) {
throw new CommandException(
Component.translatable(
@ -47,7 +47,13 @@ public class CommandContext {
}
}
return greedy ? String.join(" ", Arrays.copyOfRange(args, argsPosition++, args.length)) : args[Math.min(argsPosition++, args.length - 1)];
final String string = greedy ?
String.join(" ", Arrays.copyOfRange(args, argsPosition, args.length)) :
args[argsPosition];
argsPosition++;
return string;
}
public Integer getInteger (boolean required) throws CommandException {

View file

@ -73,7 +73,7 @@ public class MailCommand extends Command {
bot.mail.send(
new Mail(
sender.profile.getName(),
context.getString(true, true),
context.getString(false, true),
Instant.now().toEpochMilli(),
bot.host + ":" + bot.port,
context.getString(true, true)