Skip to content

Commit

Permalink
Implement changing Timeout in the Challenge Edit GUI.
Browse files Browse the repository at this point in the history
Relates #71
  • Loading branch information
BONNe committed Sep 24, 2021
1 parent bb5e861 commit 99a3e3f
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package world.bentobox.challenges.panel.admin;


import java.time.Duration;
import java.util.*;
import java.util.function.Consumer;

Expand Down Expand Up @@ -272,6 +273,8 @@ private void buildRewardsPanel(PanelBuilder panelBuilder)

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));
Expand Down Expand Up @@ -1511,6 +1514,34 @@ private PanelItem createRewardButton(RewardButton button)
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<Number> 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);

Expand Down Expand Up @@ -1815,6 +1846,7 @@ private enum RewardButton

REPEATABLE,
REPEAT_COUNT,
COOL_DOWN,

REPEAT_REWARD_TEXT,
REPEAT_REWARD_ITEMS,
Expand Down
17 changes: 14 additions & 3 deletions src/main/resources/locales/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |-
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
17 changes: 14 additions & 3 deletions src/main/resources/locales/lv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |-
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 99a3e3f

Please sign in to comment.