|
16 | 16 | import org.bukkit.Material; |
17 | 17 | import org.bukkit.inventory.ItemStack; |
18 | 18 |
|
| 19 | +import com.bencodez.simpleapi.time.ParsedDuration; |
| 20 | + |
19 | 21 | import lombok.Getter; |
20 | 22 | import lombok.Setter; |
21 | 23 |
|
@@ -51,15 +53,33 @@ public abstract class SkullCacheHandler { |
51 | 53 |
|
52 | 54 | private final AtomicInteger rateLimitHitCount = new AtomicInteger(0); |
53 | 55 |
|
54 | | - public SkullCacheHandler() { |
55 | | - this.currentDelayMs = clamp(skullDelayTime, minDelayMs, maxDelayMs); |
56 | | - } |
57 | | - |
| 56 | + /** |
| 57 | + * Legacy constructor (milliseconds). |
| 58 | + */ |
58 | 59 | public SkullCacheHandler(int skullDelayTime) { |
59 | 60 | this.skullDelayTime = skullDelayTime; |
60 | 61 | this.currentDelayMs = clamp(skullDelayTime, minDelayMs, maxDelayMs); |
61 | 62 | } |
62 | 63 |
|
| 64 | + /** |
| 65 | + * Duration-based constructor (ParsedDuration). |
| 66 | + * |
| 67 | + * @param skullDelayTime duration string (e.g. 4s, 4000ms, 1m) |
| 68 | + */ |
| 69 | + public SkullCacheHandler(String skullDelayTime) { |
| 70 | + this.skullDelayTime = clamp(parseMs(skullDelayTime, 4000), minDelayMs, maxDelayMs); |
| 71 | + this.currentDelayMs = this.skullDelayTime; |
| 72 | + } |
| 73 | + |
| 74 | + private static int parseMs(String duration, int fallback) { |
| 75 | + try { |
| 76 | + long ms = ParsedDuration.parse(duration).getMillis(); |
| 77 | + return ms > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) ms; |
| 78 | + } catch (Exception e) { |
| 79 | + return fallback; |
| 80 | + } |
| 81 | + } |
| 82 | + |
63 | 83 | public void addToCache(UUID uuid, String name) { |
64 | 84 | if (uuid == null || name == null) { |
65 | 85 | return; |
|
0 commit comments