From 620dc01fc91789e153438e62a06a2653cc9edb42 Mon Sep 17 00:00:00 2001 From: "max." Date: Sat, 8 Jun 2024 13:02:34 +0200 Subject: [PATCH] Fix more issues with duration wrapper (whitespace in between units is now optional, amounts are now correctly summed together) Fixes #814 --- .../dev/latvian/mods/kubejs/util/UtilsJS.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/common/src/main/java/dev/latvian/mods/kubejs/util/UtilsJS.java b/common/src/main/java/dev/latvian/mods/kubejs/util/UtilsJS.java index e173a3b94..9f2e4e9ea 100644 --- a/common/src/main/java/dev/latvian/mods/kubejs/util/UtilsJS.java +++ b/common/src/main/java/dev/latvian/mods/kubejs/util/UtilsJS.java @@ -105,7 +105,7 @@ public class UtilsJS { public static MinecraftServer staticServer = null; public static final ResourceLocation UNKNOWN_ID = new ResourceLocation("unknown", "unknown"); public static final Predicate ALWAYS_TRUE = o -> true; - public static final Pattern TEMPORAL_AMOUNT_PATTERN = Pattern.compile("(\\d+)\\s*(y|M|d|w|h|m|s|ms|ns|t)\\b"); + public static final Pattern TEMPORAL_AMOUNT_PATTERN = Pattern.compile("(\\d+)\\s*(y|M|d|w|h|m|s|ms|ns|t)\\b?"); private static Collection ALL_STATE_CACHE = null; private static final Map ENTITY_SELECTOR_CACHE = new HashMap<>(); @@ -909,13 +909,13 @@ public static TemporalAmount getTemporalAmount(Object o) { case "ns" -> nanos += (long) amount; case "ms" -> millis += (long) amount; - case "s" -> millis = (long) (amount * 1000D); - case "m" -> millis = (long) (amount * 60000D); - case "h" -> millis = (long) (amount * 60000D) * 60L; - case "d" -> millis = (long) (amount * 86400L) * 1000L; - case "w" -> millis = (long) (amount * 86400L) * 7000L; - case "M" -> millis = (long) (amount * 31556952D / 12D) * 1000L; - case "y" -> millis = (long) (amount * 31556952D) * 1000L; + case "s" -> millis += (long) (amount * 1000D); + case "m" -> millis += (long) (amount * 60000D); + case "h" -> millis += (long) (amount * 60000D) * 60L; + case "d" -> millis += (long) (amount * 86400L) * 1000L; + case "w" -> millis += (long) (amount * 86400L) * 7000L; + case "M" -> millis += (long) (amount * 31556952D / 12D) * 1000L; + case "y" -> millis += (long) (amount * 31556952D) * 1000L; default -> throw new IllegalArgumentException("Invalid temporal unit: " + matcher.group(2)); } }