Skip to content

Commit 4cac880

Browse files
committed
Added missing placeholder transcription for [label]
1 parent 6c78e2d commit 4cac880

File tree

1 file changed

+31
-30
lines changed

1 file changed

+31
-30
lines changed

src/main/java/world/bentobox/challenges/panel/CommonPanel.java

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -120,69 +120,70 @@ public static void reopen(CommonPanel panel) {
120120
* @return List of strings that will be used in challenges description.
121121
*/
122122
protected List<String> generateChallengeDescription(Challenge challenge, @Nullable User target) {
123-
// Some values to avoid over checking.
124-
final boolean isCompletedOnce = target != null
123+
// Determine if the challenge has been completed at least once
124+
boolean isCompletedOnce = target != null
125125
&& this.manager.isChallengeComplete(target.getUniqueId(), this.world, challenge);
126126

127-
final long doneTimes = target != null && challenge.isRepeatable()
127+
// Calculate how many times the challenge has been completed
128+
long doneTimes = (target != null && challenge.isRepeatable())
128129
? this.manager.getChallengeTimes(target, this.world, challenge)
129130
: (isCompletedOnce ? 0 : 1);
130131

132+
// Determine if the challenge has been fully completed (non-repeatable or reached max times)
131133
boolean isCompletedAll = isCompletedOnce
132-
&& (!challenge.isRepeatable() || challenge.getMaxTimes() > 0 && doneTimes >= challenge.getMaxTimes());
134+
&& (!challenge.isRepeatable() || (challenge.getMaxTimes() > 0 && doneTimes >= challenge.getMaxTimes()));
133135

134-
final String reference = Constants.DESCRIPTIONS + "challenge.";
136+
// Build a reference key for translation lookups
137+
final String referenceKey = Constants.DESCRIPTIONS + "challenge.";
135138

136-
// Get description from custom translations
139+
// Fetch a custom description translation; if empty, fallback to challenge's own description
137140
String description = this.user
138141
.getTranslationOrNothing("challenges.challenges." + challenge.getUniqueId() + ".description");
139-
140142
if (description.isEmpty()) {
141-
// Get data from object in single string.
143+
// Combine the challenge description list into a single string and translate color codes
142144
description = Util.translateColorCodes(String.join("\n", challenge.getDescription()));
143145
}
146+
// Replace any [label] placeholder with the actual top label
147+
description = description.replace("[label]", this.topLabel);
144148

145-
// Non-memory optimal code used for easier debugging and nicer code layout for
146-
// my eye :)
147-
// Get status in single string
149+
// Generate dynamic sections of the challenge lore
148150
String status = this.generateChallengeStatus(isCompletedOnce, isCompletedAll, doneTimes,
149151
challenge.getMaxTimes());
150-
// Get requirements in single string
151152
String requirements = isCompletedAll ? "" : this.generateRequirements(challenge, target);
152-
// Get rewards in single string
153153
String rewards = isCompletedAll ? "" : this.generateRewards(challenge, isCompletedOnce);
154-
// Get coolDown in single string
155-
String coolDown = isCompletedAll || challenge.getTimeout() <= 0 ? "" : this.generateCoolDown(challenge, target);
154+
String coolDown = (isCompletedAll || challenge.getTimeout() <= 0) ? ""
155+
: this.generateCoolDown(challenge, target);
156156

157+
String returnString;
158+
// Check if the description (after removing blank lines) is not empty
157159
if (!description.replaceAll("(?m)^[ \\t]*\\r?\\n", "").isEmpty()) {
158-
String returnString = this.user.getTranslationOrNothing(reference + "lore", "[requirements]", requirements,
160+
// Retrieve the lore translation without the description placeholder
161+
returnString = this.user.getTranslationOrNothing(referenceKey + "lore", "[requirements]", requirements,
159162
"[rewards]", rewards, "[status]", status, "[cooldown]", coolDown);
160163

161-
// remove empty lines from the generated text.
162-
List<String> collect = Arrays.stream(returnString.replaceAll("(?m)^[ \\t]*\\r?\\n", "").split("\n"))
163-
.collect(Collectors.toList());
164+
// Remove any empty lines from the translated text and split it into individual lines
165+
final String finalDescription = description; // ensure it's effectively final
164166

165-
// find and replace description from collected blocks.
166-
167-
for (int i = 0; i < collect.size(); i++) {
168-
if (collect.get(i).contains(Constants.PARAMETER_DESCRIPTION)) {
169-
collect.set(i, collect.get(i).replace(Constants.PARAMETER_DESCRIPTION, description));
170-
}
171-
}
167+
List<String> lines = Arrays.stream(returnString.replaceAll("(?m)^[ \\t]*\\r?\\n", "").split("\n"))
168+
.map(line -> line.contains(Constants.PARAMETER_DESCRIPTION)
169+
? line.replace(Constants.PARAMETER_DESCRIPTION, finalDescription)
170+
: line)
171+
.collect(Collectors.toList());
172172

173-
return collect;
173+
return lines;
174174
} else {
175-
String returnString = this.user.getTranslationOrNothing(reference + "lore", Constants.PARAMETER_DESCRIPTION,
175+
// If description is empty, pass it directly as a parameter to the translation
176+
returnString = this.user.getTranslationOrNothing(referenceKey + "lore", Constants.PARAMETER_DESCRIPTION,
176177
description, "[requirements]", requirements, "[rewards]", rewards, "[status]", status, "[cooldown]",
177178
coolDown);
178179

179-
// Remove empty lines and returns as a list.
180-
180+
// Remove empty lines and return the resulting lines as a list
181181
return Arrays.stream(returnString.replaceAll("(?m)^[ \\t]*\\r?\\n", "").split("\n"))
182182
.collect(Collectors.toList());
183183
}
184184
}
185185

186+
186187
/**
187188
* Generate cool down string.
188189
*

0 commit comments

Comments
 (0)