From 63c5cd0381fb66cfce260a7bdd0234c4f7636bdf Mon Sep 17 00:00:00 2001 From: Krakenied Date: Wed, 28 Aug 2024 12:16:08 +0200 Subject: [PATCH] Do not return null for a negative cooldown placeholder Fixes https://github.com/LMBishop/Quests/issues/669 --- .../quests/bukkit/hook/papi/QuestsPlaceholders.java | 10 ++++++++-- .../leonardobishop/quests/bukkit/util/Messages.java | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/papi/QuestsPlaceholders.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/papi/QuestsPlaceholders.java index 6ada4e2a5..7c988cba8 100644 --- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/papi/QuestsPlaceholders.java +++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/papi/QuestsPlaceholders.java @@ -181,8 +181,14 @@ public String onPlaceholderRequest(Player p, String params) { break; case "cooldown": if (qPlayer.getQuestProgressFile().getQuestProgress(quest).isCompleted()) { - final String time = FormatUtils.time(TimeUnit.SECONDS.convert(qPlayer.getQuestProgressFile().getCooldownFor(quest), TimeUnit.MILLISECONDS)); - if (!time.startsWith("-")) result = time; + final long questCooldown = qPlayer.getQuestProgressFile().getCooldownFor(quest); + if (questCooldown > 0) { + final long questCooldownMillis = TimeUnit.SECONDS.convert(questCooldown, TimeUnit.MILLISECONDS); + result = FormatUtils.time(questCooldownMillis); + } else { + // TODO handle it in a more proper way after storage rework + result = Messages.PLACEHOLDERAPI_NO_COOLDOWN.getMessage(); + } } else { result = "0"; } diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/util/Messages.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/util/Messages.java index fc0035c9c..a6ce007e6 100644 --- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/util/Messages.java +++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/util/Messages.java @@ -76,6 +76,7 @@ public enum Messages { PLACEHOLDERAPI_FALSE("messages.placeholderapi-false", "false"), PLACEHOLDERAPI_NO_TRACKED_QUEST("messages.placeholderapi-no-tracked-quest", "No tracked quest"), PLACEHOLDERAPI_QUEST_NOT_STARTED("messages.placeholderapi-quest-not-started", "Quest not started"), + PLACEHOLDERAPI_NO_COOLDOWN("messages.placeholderapi-no-cooldown", "No cooldown"), PLACEHOLDERAPI_NO_TIME_LIMIT("messages.placeholderapi-no-time-limit", "No time limit"), PLACEHOLDERAPI_DATA_NOT_LOADED("messages.placeholderapi-data-not-loaded", "Data not loaded");