From 89220d67d34a2ef4748ff0b884fd40cfe2ed9a99 Mon Sep 17 00:00:00 2001 From: Tastybento Date: Sat, 21 Apr 2018 10:45:40 -0700 Subject: [PATCH] Added challenge descriptions. --- locales/en-US.yml | 23 +++-- .../challenges/panel/ChallengesPanels.java | 91 ++++++++++++++++++- 2 files changed, 103 insertions(+), 11 deletions(-) diff --git a/locales/en-US.yml b/locales/en-US.yml index 5c88e25..ad1cf6a 100755 --- a/locales/en-US.yml +++ b/locales/en-US.yml @@ -6,24 +6,29 @@ ### Credits ### # Tastybento: maintainer -challenges: +challenges: + completed-times: "Completed [donetimes] out of [maxtimes]" + max-reached: "Max reached [donetimes] out of [maxtimes]" + challenge: + format: "[description]" parameters: "[Level]" description: "Open the challenges menu" - complete: "Complete" - exp-reward: "Exp reward" - first-time-rewards: "First time reward(s)" + complete: "&BComplete" + exp-reward: "&6Exp reward: [reward]" + first-time-rewards: "&6First time reward(s)" gui-title: "BSkyBlock Challenges" incomplete: "Incomplete" - itemTakeWarning: "All required items are taken when you complete this challenge!" - level: "Level" + item-take-warning: "&cAll required items are|&ctaken when you complete|&cthis challenge!" + items-closeby: "&cAll required items|&cmust be close to you|&con your island!" + level: "&FLevel: [level]" max-reached: "Max reached [donetimes] out of [maxtimes]" - money-reward: "Money reward" + money-reward: "&6Money reward: $[reward]" name: "Challenge Name" name-has-completed: "[name] has completed the [challenge] challenge!" navigation: "Click to see [level] challenges!" not-repeatable: "This Challenge is not repeatable!" - repeat-rewards: "Repeat reward(s)" - rewards: "Reward(s)" + repeat-rewards: "&6Repeat reward(s)" + rewards: "&FReward(s)" to-complete: "Complete [challengesToDo] more [thisLevel] challenges to unlock this level!" you-completed: "You completed the [challenge] challenge!" you-repeated: "You repeated the [challenge] challenge!" diff --git a/src/main/java/bskyblock/addon/challenges/panel/ChallengesPanels.java b/src/main/java/bskyblock/addon/challenges/panel/ChallengesPanels.java index eb02c65..17bfaed 100644 --- a/src/main/java/bskyblock/addon/challenges/panel/ChallengesPanels.java +++ b/src/main/java/bskyblock/addon/challenges/panel/ChallengesPanels.java @@ -1,5 +1,8 @@ package bskyblock.addon.challenges.panel; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; import java.util.Set; import org.bukkit.Material; @@ -11,6 +14,7 @@ import bskyblock.addon.challenges.LevelStatus; import bskyblock.addon.challenges.commands.ChallengesCommand; import bskyblock.addon.challenges.database.object.Challenges; import bskyblock.addon.challenges.database.object.Challenges.ChallengeType; +import us.tastybento.bskyblock.Constants; import us.tastybento.bskyblock.api.panels.Panel; import us.tastybento.bskyblock.api.panels.PanelItem; import us.tastybento.bskyblock.api.panels.builders.PanelBuilder; @@ -86,8 +90,7 @@ public class ChallengesPanels { PanelItem item = new PanelItemBuilder() .icon(challenge.getIcon()) .name(challenge.getFriendlyName().isEmpty() ? challenge.getUniqueId() : challenge.getFriendlyName()) - .description(challenge.getDescription()) - // TODO Complete the description + .description(challengeDescription(challenge, user)) .glow(completed) .clickHandler((player,c) -> { if (!challenge.getChallengeType().equals(ChallengeType.ICON)) { @@ -147,4 +150,88 @@ public class ChallengesPanels { } } + /** + * Creates the challenge description for the "item" in the inventory + * + * @param challenge + * @param player + * @return List of strings splitting challenge string into 25 chars long + */ + private List challengeDescription(Challenges challenge, User user) { + List result = new ArrayList(); + String level = challenge.getLevel(); + if (!level.isEmpty()) { + result.addAll(splitTrans(user, "challenges.level", "[level]", level)); + } + // Check if completed or not + + boolean complete = addon.getChallengesManager().isChallengeComplete(user, challenge.getUniqueId()); + int maxTimes = challenge.getMaxTimes(); + long doneTimes = addon.getChallengesManager().checkChallengeTimes(user, challenge); + if (complete) { + result.add(user.getTranslation("challenges.complete")); + } + if (challenge.isRepeatable()) { + if (maxTimes == 0) { + + // Check if the player has maxed out the challenge + if (doneTimes < maxTimes) { + result.addAll(splitTrans(user, "challenges.completed-times","[donetimes]", String.valueOf(doneTimes),"[maxtimes]", String.valueOf(maxTimes))); + } else { + result.addAll(splitTrans(user, "challenges.maxed-reached","[donetimes]", String.valueOf(doneTimes),"[maxtimes]", String.valueOf(maxTimes))); + } + } + } + if (!complete || (complete && challenge.isRepeatable())) { + result.addAll(challenge.getDescription()); + if (challenge.getChallengeType().equals(ChallengeType.INVENTORY)) { + if (challenge.isTakeItems()) { + result.addAll(splitTrans(user, "challenges.item-take-warning")); + } + } else if (challenge.getChallengeType().equals(ChallengeType.ISLAND)) { + result.addAll(splitTrans(user, "challenges.items-closeby")); + } + } + if (complete && (!challenge.getChallengeType().equals(ChallengeType.INVENTORY) || !challenge.isRepeatable())) { + result.addAll(splitTrans(user, "challenges.not-repeatable")); + return result; + } + double moneyReward = 0; + int expReward = 0; + String rewardText = ""; + if (!complete) { + // First time + moneyReward = challenge.getMoneyReward(); + rewardText = challenge.getRewardText(); + expReward = challenge.getExpReward(); + if (!rewardText.isEmpty()) { + result.addAll(splitTrans(user, "challenges.first-time-rewards")); + } + } else { + // Repeat challenge + moneyReward = challenge.getRepeatMoneyReward(); + rewardText = challenge.getRepeatRewardText(); + expReward = challenge.getRepeatExpReward(); + if (!rewardText.isEmpty()) { + result.addAll(splitTrans(user, "challenges.repeat-rewards")); + } + + } + if (!rewardText.isEmpty()) { + result.addAll(splitTrans(user,rewardText)); + } + if (expReward > 0) { + result.addAll(splitTrans(user,"challenges.exp-reward", "[reward]", String.valueOf(expReward))); + } + if (addon.getBSkyBlock().getSettings().isUseEconomy() && moneyReward > 0) { + result.addAll(splitTrans(user,"challenges.money-reward", "[reward]", String.valueOf(moneyReward))); + } + // Final placeholder change for [label] + result.replaceAll(x -> x.replace("[label]", Constants.ISLANDCOMMAND)); + return result; + } + + private Collection splitTrans(User user, String string, String...strings) { + return addon.getChallengesManager().stringSplit(user.getTranslation(string, strings)); + } }