SteamWar/BungeeCore
Archiviert
13
2

Hotfix PunishmentCommand.parseTime
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

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