From 47f496133c83182965751dea15d316c00f3cb27e Mon Sep 17 00:00:00 2001 From: Stijn Bannink Date: Sun, 12 Nov 2023 13:35:44 +0100 Subject: [PATCH] Bumped GuardianBeam to 2.3.5 (fixes Spot), fixed time combinations --- pom.xml | 10 ++-- .../showcontrol/commands/ShowCMD.java | 2 +- .../showcontrol/utils/TimeUtil.java | 55 ++++++++----------- 3 files changed, 30 insertions(+), 37 deletions(-) diff --git a/pom.xml b/pom.xml index 10ad049..45fc5b6 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ tech.sbdevelopment ShowControl - 1.6 + 1.6.1 jar ShowControl https://sbdevelopment.tech @@ -157,7 +157,7 @@ org.spigotmc spigot-api - 1.20.1-R0.1-SNAPSHOT + 1.20.2-R0.1-SNAPSHOT provided @@ -177,9 +177,9 @@ compile - io.github.skytasul - guardianbeam - 2.3.4 + com.github.SkytAsul + GuardianBeam + 97b0078aba compile diff --git a/src/main/java/tech/sbdevelopment/showcontrol/commands/ShowCMD.java b/src/main/java/tech/sbdevelopment/showcontrol/commands/ShowCMD.java index 3fb2fbd..534a53f 100644 --- a/src/main/java/tech/sbdevelopment/showcontrol/commands/ShowCMD.java +++ b/src/main/java/tech/sbdevelopment/showcontrol/commands/ShowCMD.java @@ -61,7 +61,7 @@ public class ShowCMD extends BaseCommand { Long timeMilli; try { - timeMilli = TimeUtil.toMilis(time); + timeMilli = TimeUtil.toMillis(time); } catch (Exception e) { sender.sendMessage(ChatColor.RED + "Provide a valid time, for example 5s (5 seconds) or 10m (10 minutes)."); return; diff --git a/src/main/java/tech/sbdevelopment/showcontrol/utils/TimeUtil.java b/src/main/java/tech/sbdevelopment/showcontrol/utils/TimeUtil.java index ac3001a..5674fe9 100644 --- a/src/main/java/tech/sbdevelopment/showcontrol/utils/TimeUtil.java +++ b/src/main/java/tech/sbdevelopment/showcontrol/utils/TimeUtil.java @@ -3,54 +3,47 @@ package tech.sbdevelopment.showcontrol.utils; import java.time.LocalTime; import java.time.format.DateTimeFormatter; import java.util.concurrent.TimeUnit; +import java.util.regex.Matcher; +import java.util.regex.Pattern; -/* - * Source from: - * https://github.com/Mindgamesnl/OpenAudioMc/blob/master/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/show/util/TimeParser.java - */ public class TimeUtil { - - public static Long toMilis(String input) { + public static Long toMillis(String input) { long time = 0L; - // ITS A TIMECODE if (input.contains(":")) { return LocalTime.parse(input, DateTimeFormatter.ofPattern("HH:mm:ss")).toSecondOfDay() * 1000L; } input = input.toLowerCase() + "-"; - String[] milisSplit = input.split("ms"); - if (isValid(milisSplit)) { - time += Long.parseLong(milisSplit[0]); - return time; - } + Pattern pattern = Pattern.compile("(\\d+)([a-z]+)"); + Matcher matcher = pattern.matcher(input); - String[] secondsSplit = input.split("s"); - if (isValid(secondsSplit)) { - time += Math.round(Double.parseDouble(secondsSplit[0]) * 1000); - return time; - } + while (matcher.find()) { + String value = matcher.group(1); + String unit = matcher.group(2); - String[] minutesSplit = input.split("m"); - if (isValid(minutesSplit)) { - time += Math.round(Double.parseDouble(minutesSplit[0]) * 60000); - return time; - } - - String[] tickSplit = input.split("t"); - if (isValid(tickSplit)) { - time += Integer.parseInt(tickSplit[0]) * 50L; - return time; + switch (unit) { + case "ms": + time += Long.parseLong(value); + break; + case "s": + time += Math.round(Double.parseDouble(value) * 1000); + break; + case "m": + time += Math.round(Double.parseDouble(value) * 60000); + break; + case "t": + time += Integer.parseInt(value) * 50L; + break; + default: + throw new IllegalArgumentException("Unknown time unit: " + unit); + } } return time; } - private static boolean isValid(String[] array) { - return array.length > 1 && !array[0].isEmpty(); - } - public static String makeReadable(Long time) { return String.format("%02d:%02d:%02d", TimeUnit.MILLISECONDS.toHours(time), TimeUnit.MILLISECONDS.toMinutes(time) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(time)),