diff --git a/src/main/java/com/denizenscript/denizencore/objects/core/DurationTag.java b/src/main/java/com/denizenscript/denizencore/objects/core/DurationTag.java index 739302e1..c6bc5fc8 100644 --- a/src/main/java/com/denizenscript/denizencore/objects/core/DurationTag.java +++ b/src/main/java/com/denizenscript/denizencore/objects/core/DurationTag.java @@ -33,7 +33,7 @@ public class DurationTag implements ObjectTag { // Durations are a unified and convenient way to get a 'unit of time' throughout Denizen. // Many commands and features that require a duration can be satisfied by specifying a number and unit of time, especially command arguments that are prefixed 'duration:', etc. // The unit of time can be specified by using one of the following: - // t=ticks (0.05 seconds), s=seconds, m=minutes (60 seconds), h=hours (60 minutes), d=days (24 hours), w=weeks (7 days), y=years (365 days). + // ms=milliseconds (0.001 seconds), t=ticks (0.05 seconds), s=seconds, m=minutes (60 seconds), h=hours (60 minutes), d=days (24 hours), w=weeks (7 days), y=years (365 days). // Not using a unit will imply seconds. // Examples: 10s, 50m, 1d, 20. // @@ -93,7 +93,8 @@ public static DurationTag valueOf(String string, TagContext context) { } } } - String numericString = Character.isDigit(string.charAt(string.length() - 1)) ? string : string.substring(0, string.length() - 1); + int len = string.length(); + String numericString = Character.isDigit(string.charAt(len - 1)) ? string : string.substring(0, len - (string.endsWith("ms") ? 2 : 1)); // Standard DurationTag. Check the type and create new DurationTag object accordingly. try { double numVal = Double.parseDouble(numericString); @@ -112,6 +113,9 @@ else if (string.endsWith("h")) { else if (string.endsWith("m")) { return new DurationTag(numVal * 60); } + else if (string.endsWith("ms")) { + return new DurationTag(numVal * 0.001); + } else if (string.endsWith("s")) { // seconds return new DurationTag(numVal); @@ -195,6 +199,9 @@ public DurationTag(long ticks) { * @return the number of ticks. */ public long getTicks() { + if (seconds < 0.05 && seconds > 0) { + return 1; + } return (long) (seconds * 20); } @@ -205,6 +212,9 @@ public long getTicks() { * @return the number of ticks. */ public int getTicksAsInt() { + if (seconds < 0.05 && seconds > 0) { + return 1; + } return (int) (seconds * 20); } @@ -410,7 +420,7 @@ public static void register() { // Returns this duration minus another. // --> tagProcessor.registerStaticTag(DurationTag.class, DurationTag.class, "sub", (attribute, object, secondVal) -> { - return new DurationTag(object.getTicks() - secondVal.getTicks()); + return new DurationTag(java.math.BigDecimal.valueOf(object.seconds).subtract(java.math.BigDecimal.valueOf(secondVal.seconds)).doubleValue()); }); // <--[tag] @@ -420,7 +430,7 @@ public static void register() { // Returns this duration plus another. // --> tagProcessor.registerStaticTag(DurationTag.class, DurationTag.class, "add", (attribute, object, secondVal) -> { - return new DurationTag(object.getTicks() + secondVal.getTicks()); + return new DurationTag(java.math.BigDecimal.valueOf(object.seconds).add(java.math.BigDecimal.valueOf(secondVal.seconds)).doubleValue()); }); // <--[tag] @@ -550,10 +560,18 @@ public String formatted(boolean words) { if (seconds > 0 && minutes < 10 && hours == 0 && days == 0 && years == 0) { timeString += seconds + (words ? " second" + autoS(seconds) : "s "); } + long millis = Math.round(secondsCopy * 1000) % 1000; + if (millis > 0 && (millis % 50 != 0) && minutes < 10 && hours == 0 && days == 0 && years == 0) { + timeString += millis + (words ? " millisecond" + autoS(millis) : "ms "); + } if (timeString.isEmpty()) { if (secondsCopy == 0) { timeString = "forever"; } + else if (Math.round(secondsCopy * 1000) % 50 != 0) { + long ms = Math.round(secondsCopy * 1000); + timeString = ms + (words ? " millisecond" + autoS(ms) : "ms"); + } else { timeString = ((double) ((long) (secondsCopy * 100)) / 100d) + "s"; } diff --git a/src/main/java/com/denizenscript/denizencore/utilities/scheduling/RepeatingSchedulable.java b/src/main/java/com/denizenscript/denizencore/utilities/scheduling/RepeatingSchedulable.java index 7657165a..ae846086 100644 --- a/src/main/java/com/denizenscript/denizencore/utilities/scheduling/RepeatingSchedulable.java +++ b/src/main/java/com/denizenscript/denizencore/utilities/scheduling/RepeatingSchedulable.java @@ -4,6 +4,9 @@ public class RepeatingSchedulable extends Schedulable { public RepeatingSchedulable(Runnable runnable, float fireRate) { run = runnable; + if (fireRate > 0 && fireRate < 0.05f) { + fireRate = 0.05f; + } fireEverySeconds = fireRate; secondsLeft = fireRate; }