From 99a3e3f165cfa81147ff7a4ceafc5ba6c31578a6 Mon Sep 17 00:00:00 2001 From: BONNe Date: Fri, 24 Sep 2021 16:16:48 +0300 Subject: [PATCH] Implement changing Timeout in the Challenge Edit GUI. Relates #71 --- .../panel/admin/EditChallengePanel.java | 32 +++++++++++++++++++ src/main/resources/locales/en-US.yml | 17 ++++++++-- src/main/resources/locales/lv.yml | 17 ++++++++-- 3 files changed, 60 insertions(+), 6 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/panel/admin/EditChallengePanel.java b/src/main/java/world/bentobox/challenges/panel/admin/EditChallengePanel.java index 6377a31..96edbfb 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/EditChallengePanel.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/EditChallengePanel.java @@ -1,6 +1,7 @@ package world.bentobox.challenges.panel.admin; +import java.time.Duration; import java.util.*; import java.util.function.Consumer; @@ -272,6 +273,8 @@ public class EditChallengePanel extends CommonPanel if (this.challenge.isRepeatable()) { + panelBuilder.item(13, this.createRewardButton(RewardButton.COOL_DOWN)); + panelBuilder.item(31, this.createRewardButton(RewardButton.REPEAT_COUNT)); panelBuilder.item(15, this.createRewardButton(RewardButton.REPEAT_REWARD_TEXT)); @@ -1511,6 +1514,34 @@ public class EditChallengePanel extends CommonPanel description.add(""); description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); } + case COOL_DOWN -> { + description.add(this.user.getTranslation(reference + "value", + "[time]", + Utils.parseDuration(Duration.ofMillis(this.challenge.getTimeout()), this.user))); + icon = new ItemStack(Material.CLOCK); + clickHandler = (panel, user, clickType, i) -> { + Consumer numberConsumer = number -> { + if (number != null) + { + this.challenge.setTimeout(number.longValue() * 1000); + } + + // reopen panel + this.build(); + }; + ConversationUtils.createNumericInput(numberConsumer, + this.user, + this.user.getTranslation(Constants.CONVERSATIONS + "input-seconds"), + 0, + Integer.MAX_VALUE); + + return true; + }; + glow = false; + + description.add(""); + description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); + } case REPEAT_REWARD_TEXT -> { icon = new ItemStack(Material.WRITTEN_BOOK); @@ -1815,6 +1846,7 @@ public class EditChallengePanel extends CommonPanel REPEATABLE, REPEAT_COUNT, + COOL_DOWN, REPEAT_REWARD_TEXT, REPEAT_REWARD_ITEMS, diff --git a/src/main/resources/locales/en-US.yml b/src/main/resources/locales/en-US.yml index d5e904f..4ca469f 100755 --- a/src/main/resources/locales/en-US.yml +++ b/src/main/resources/locales/en-US.yml @@ -522,6 +522,15 @@ challenges: &7 number of repeats &7 for the challenge. value: "&7 Current value: &e [number]" + cool_down: + name: "&f&l Cool Down" + description: |- + &7 Allows to change the + &7 cool down seconds that + &7 must be waited between + &7 repeatable challenge + &7 completions. + value: "&7 Current value: &e [time]" challenges: name: "&f&l Challenges" description: |- @@ -852,11 +861,11 @@ challenges: # Text message that shows challenges wait time if it is larger than 0. wait-time: "&c&l Available after: &r&c [time]" # Text message that replaces days if number > 1 - in-days: "[number] d, " + in-days: "[number] d " # Text message that replaces hours if number > 1 - in-hours: "[number] h, " + in-hours: "[number] h " # Text message that replaces minutes if number > 1 - in-minutes: "[number] min, " + in-minutes: "[number] min " # Text message that replaces seconds if number > 1 in-seconds: "[number] s" # Contains a text generated inside [requirements] lore @@ -1035,6 +1044,8 @@ challenges: cancelled: "&c Conversation cancelled!" # Message that appears when admin clicks on number editing button. input-number: "&e Please enter a number in chat." + # Message that appears when admin clicks on seconds editing button. + input-seconds: "&e Please enter a seconds in chat." # Error message that is showed if user input a value that is not a number. numeric-only: "&c The given [value] is not a number!" # Error message that is showed if user input a number that is smaller or larger that allowed. diff --git a/src/main/resources/locales/lv.yml b/src/main/resources/locales/lv.yml index 9067b46..5790911 100644 --- a/src/main/resources/locales/lv.yml +++ b/src/main/resources/locales/lv.yml @@ -511,6 +511,15 @@ challenges: &7 daudz reižu uzdevumu &7 varēs izpildīt. value: "&7 Vērtība: &e [number]" + cool_down: + name: "&f&l Taimouts" + description: |- + &7 Ļauj uzstādīt sekunžu + &7 daudzumu, kas jānogaida + &7 starp sekunžu izpildīšanu + &7 starp atkārtojamajiem + &7 uzdevumiem. + value: "&7 Current value: &e [time]" challenges: name: "&f&l Uzdevumi" description: |- @@ -872,11 +881,11 @@ challenges: # Text message that shows challenges wait time if it is larger than 0. wait-time: "&c&l Jānogaida: &r&c [time]" # Text message that replaces days if number > 1 - in-days: "[number] d, " + in-days: "[number] d " # Text message that replaces hours if number > 1 - in-hours: "[number] h, " + in-hours: "[number] h " # Text message that replaces minutes if number > 1 - in-minutes: "[number] min, " + in-minutes: "[number] min " # Text message that replaces seconds if number > 1 in-seconds: "[number] s" # Contains a text generated inside [requirements] lore @@ -1058,6 +1067,8 @@ challenges: cancelled: "&c Saruna pārtraukta!" # Message that appears when admin clicks on number editing button. input-number: "&e Lūdzu ieraksti skaitli sarakstē!" + # Message that appears when admin clicks on seconds editing button. + input-seconds: "&e Lūdzu ieraksti sekunžu skaitu sarakstē!" # Error message that is showed if user input a value that is not a number. numeric-only: "&c Šis `[value]` nav skaitlis!" # Error message that is showed if user input a number that is smaller or larger that allowed.