1
0

Hotfix PunishmentCommand.parseTime

Dieser Commit ist enthalten in:
yoyosource 2022-11-01 23:22:24 +01:00
Ursprung 24a3885e2f
Commit ef11620e2f

Datei anzeigen

@ -29,10 +29,12 @@ import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.time.Duration;
import java.time.Instant; import java.time.Instant;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
import java.util.Date; import java.util.Date;
import java.util.regex.MatchResult; import java.util.regex.MatchResult;
import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
public class PunishmentCommand { public class PunishmentCommand {
@ -105,15 +107,18 @@ public class PunishmentCommand {
if (arg.equalsIgnoreCase("perma")) { if (arg.equalsIgnoreCase("perma")) {
return Punishment.PERMA_TIME; return Punishment.PERMA_TIME;
} else { } else {
MatchResult matchResult = RELATIVE_PATTERN.matcher(arg).toMatchResult(); if (RELATIVE_PATTERN.matcher(arg).matches()) {
if (matchResult.groupCount() > 0) {
Instant instant = Instant.now(); Instant instant = Instant.now();
for (int i = 1; i < matchResult.groupCount(); i++) { StringBuilder st = new StringBuilder();
String group = matchResult.group(i); for (int i = 0; i < arg.length(); i++) {
int amount = Integer.parseInt(group.substring(0, group.length() - 1)); char c = arg.charAt(i);
char unit = Character.toLowerCase(group.charAt(group.length() - 1)); if (Character.isDigit(c)) {
System.out.println("Amount: " + amount + " Unit: " + unit); st.append(c);
switch (unit) { continue;
}
int amount = Integer.parseInt(st.toString());
st = new StringBuilder();
switch (c) {
case 'h': case 'h':
instant = instant.plus(amount, ChronoUnit.HOURS); instant = instant.plus(amount, ChronoUnit.HOURS);
break; break;
@ -121,13 +126,13 @@ public class PunishmentCommand {
instant = instant.plus(amount, ChronoUnit.DAYS); instant = instant.plus(amount, ChronoUnit.DAYS);
break; break;
case 'w': case 'w':
instant = instant.plus(amount, ChronoUnit.WEEKS); instant = instant.plus(Duration.ofSeconds(amount * ChronoUnit.WEEKS.getDuration().getSeconds()));
break; break;
case 'm': case 'm':
instant = instant.plus(amount, ChronoUnit.MONTHS); instant = instant.plus(Duration.ofSeconds(amount * ChronoUnit.MONTHS.getDuration().getSeconds()));
break; break;
case 'y': case 'y':
instant = instant.plus(amount, ChronoUnit.YEARS); instant = instant.plus(Duration.ofSeconds(amount * ChronoUnit.YEARS.getDuration().getSeconds()));
break; break;
} }
} }