Skip to content

Commit 45692bf

Browse files
authored
Merge pull request #384 from BentoBoxWorld/develop
Release 1.5.1
2 parents 7231113 + f6b8eec commit 45692bf

File tree

6 files changed

+1175
-485
lines changed

6 files changed

+1175
-485
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
<!-- Revision variable removes warning about dynamic version -->
5252
<revision>${build.version}-SNAPSHOT</revision>
5353
<!-- This allows to change between versions and snapshots. -->
54-
<build.version>1.5.0</build.version>
54+
<build.version>1.5.1</build.version>
5555
<build.number>-LOCAL</build.number>
5656
<!-- Sonar Cloud -->
5757
<sonar.projectKey>BentoBoxWorld_Challenges</sonar.projectKey>

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
*

src/main/java/world/bentobox/challenges/utils/Utils.java

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import org.bukkit.inventory.meta.ItemMeta;
2222
import org.bukkit.inventory.meta.PotionMeta;
2323
import org.bukkit.inventory.meta.SkullMeta;
24-
import org.bukkit.potion.PotionData;
2524
import org.bukkit.potion.PotionType;
2625
import org.eclipse.jdt.annotation.Nullable;
2726

@@ -745,7 +744,7 @@ public static String prettifyObject(PotionType type, User user)
745744
* @param user the user
746745
* @return the string
747746
*/
748-
public static String prettifyObject(ItemStack item, @Nullable PotionMeta potionMeta, User user)
747+
public static String prettifyObject(ItemStack item, @Nullable PotionMeta potionMeta, User user)
749748
{
750749
if (potionMeta == null)
751750
{
@@ -757,39 +756,36 @@ public static String prettifyObject(ItemStack item, @Nullable PotionMeta potionM
757756
final String itemReference = Constants.ITEM_STACKS + itemType.name().toLowerCase() + ".";
758757
final String metaReference = Constants.ITEM_STACKS + "meta.";
759758

760-
PotionData potionData = potionMeta.getBasePotionData();
759+
PotionType potionData = potionMeta.getBasePotionType();
761760

762761
// Check custom translation for potions.
763-
String type = user.getTranslationOrNothing(itemReference + potionData.getType().name().toLowerCase());
764-
762+
String type = user.getTranslationOrNothing(itemReference + potionData.name().toLowerCase());
765763
if (type.isEmpty())
766764
{
767765
// Check potion types translation.
768-
type = prettifyObject(potionData.getType(), user);
766+
type = prettifyObject(potionData, user);
769767
}
770-
771-
String upgraded = user.getTranslationOrNothing(metaReference + "upgraded");
772-
String extended = user.getTranslationOrNothing(metaReference + "extended");
773-
774768
// Get item specific translation.
775769
String specific = user.getTranslationOrNothing(itemReference + "name",
776770
"[type]", type,
777-
"[upgraded]", (potionData.isUpgraded() ? upgraded : ""),
778-
"[extended]", (potionData.isExtended() ? extended : ""));
771+
"[upgraded]", "", "[extended]", "");
779772

780773
if (specific.isEmpty())
781774
{
782775
// Use generic translation.
783776
String meta = user.getTranslationOrNothing(metaReference + "potion-meta",
784777
"[type]", type,
785-
"[upgraded]", (potionData.isUpgraded() ? upgraded : ""),
786-
"[extended]", (potionData.isExtended() ? extended : ""));
787-
778+
"[upgraded]", "", "[extended]", "");
779+
BentoBox.getInstance().logDebug("Generic ref: " + Constants.ITEM_STACKS + "generic");
788780
specific = user.getTranslationOrNothing(Constants.ITEM_STACKS + "generic",
789781
"[type]", prettifyObject(itemType, user),
790782
"[meta]", meta);
791783
}
792-
784+
if (specific.isEmpty()) {
785+
// Last ditch
786+
specific = prettifyObject(itemType, user) + ": " + type;
787+
}
788+
BentoBox.getInstance().logDebug(specific);
793789
return specific;
794790
}
795791

0 commit comments

Comments
 (0)