Skip to content

Commit d83bc55

Browse files
sebampuerohyperdefined
authored andcommitted
feat: fix function for several placeholders. It was appending wrongly. Use version11 class for updater.
1 parent 3196223 commit d83bc55

File tree

2 files changed

+17
-28
lines changed

2 files changed

+17
-28
lines changed

src/main/java/lol/hyper/toolstats/tools/config/ConfigTools.java

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -152,39 +152,28 @@ public Component formatLoreMultiplePlaceholders(String configName, Map<String, S
152152
return null;
153153
}
154154

155-
Pattern pattern = Pattern.compile("\\{([^}]+)\\}");
155+
Pattern pattern = Pattern.compile("\\{([^}]+)\\}(\\S*)\\s*");
156156
Matcher matcher = pattern.matcher(lore);
157157

158-
StringBuffer result = new StringBuffer();
159-
158+
StringBuilder result = new StringBuilder();
159+
int lastEnd = 0;
160+
160161
while (matcher.find()) {
161162
String placeholder = matcher.group(1);
163+
String unit = matcher.group(2);
164+
165+
result.append(lore, lastEnd, matcher.start());
166+
162167
if (placeHoldersValues.containsKey(placeholder)) {
163-
matcher.appendReplacement(result, placeHoldersValues.get(placeholder));
164-
} else {
165-
// Placeholder not found in our time values, so remove it and any unit suffix
166-
// Find the next non-alphanumeric character after this placeholder to remove the unit
167-
int end = matcher.end();
168-
while (end < lore.length() &&
169-
!Character.isWhitespace(lore.charAt(end)) &&
170-
!lore.substring(end, end + 1).matches("[^a-zA-Z]")) {
171-
end++;
172-
}
173-
174-
matcher.appendReplacement(result, "");
175-
176-
// Remove trailing space if there is one
177-
if (end < lore.length() && Character.isWhitespace(lore.charAt(end))) {
178-
// Skip this space in the next append
179-
end++;
180-
}
181-
182-
// Adjust region to char after skipped placeholder
183-
matcher.region(end, lore.length());
168+
result.append(placeHoldersValues.get(placeholder)).append(unit).append(" ");
184169
}
170+
171+
// Update lastEnd to end of the match
172+
lastEnd = matcher.end();
173+
}
174+
if (lastEnd < lore.length()) {
175+
result.append(lore.substring(lastEnd));
185176
}
186-
187-
matcher.appendTail(result);
188177

189178
Component component;
190179
// Clean output text

src/main/java/lol/hyper/toolstats/tools/config/versions/Version11.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ public void update() {
8686
toolStats.logger.info("Adding enabled.damage-done.bow to config.yml");
8787
toolStats.logger.info("Adding enabled.damage-done.mace to config.yml");
8888

89-
toolStats.logger.info("Changing messages.flight-time to new format");
89+
toolStats.logger.info("Updating entry for messages.flight-time");
9090
toolStats.config.set("messages.flight-time", "&7Flight time: &8{years}y {months}m {days}d {hours}h {minutes}m {seconds}s");
91-
91+
9292
// save the config and reload it
9393
try {
9494
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config.yml");

0 commit comments

Comments
 (0)