mirror of
https://github.com/hyperdefined/ToolStats.git
synced 2025-12-05 22:31:45 +00:00
feat: fix function for several placeholders. It was appending wrongly. Use version11 class for updater.
This commit is contained in:
@@ -152,39 +152,28 @@ public class ConfigTools {
|
||||
return null;
|
||||
}
|
||||
|
||||
Pattern pattern = Pattern.compile("\\{([^}]+)\\}");
|
||||
Pattern pattern = Pattern.compile("\\{([^}]+)\\}(\\S*)\\s*");
|
||||
Matcher matcher = pattern.matcher(lore);
|
||||
|
||||
StringBuffer result = new StringBuffer();
|
||||
|
||||
StringBuilder result = new StringBuilder();
|
||||
int lastEnd = 0;
|
||||
|
||||
while (matcher.find()) {
|
||||
String placeholder = matcher.group(1);
|
||||
String unit = matcher.group(2);
|
||||
|
||||
result.append(lore, lastEnd, matcher.start());
|
||||
|
||||
if (placeHoldersValues.containsKey(placeholder)) {
|
||||
matcher.appendReplacement(result, placeHoldersValues.get(placeholder));
|
||||
} else {
|
||||
// Placeholder not found in our time values, so remove it and any unit suffix
|
||||
// Find the next non-alphanumeric character after this placeholder to remove the unit
|
||||
int end = matcher.end();
|
||||
while (end < lore.length() &&
|
||||
!Character.isWhitespace(lore.charAt(end)) &&
|
||||
!lore.substring(end, end + 1).matches("[^a-zA-Z]")) {
|
||||
end++;
|
||||
}
|
||||
|
||||
matcher.appendReplacement(result, "");
|
||||
|
||||
// Remove trailing space if there is one
|
||||
if (end < lore.length() && Character.isWhitespace(lore.charAt(end))) {
|
||||
// Skip this space in the next append
|
||||
end++;
|
||||
}
|
||||
|
||||
// Adjust region to char after skipped placeholder
|
||||
matcher.region(end, lore.length());
|
||||
result.append(placeHoldersValues.get(placeholder)).append(unit).append(" ");
|
||||
}
|
||||
|
||||
// Update lastEnd to end of the match
|
||||
lastEnd = matcher.end();
|
||||
}
|
||||
if (lastEnd < lore.length()) {
|
||||
result.append(lore.substring(lastEnd));
|
||||
}
|
||||
|
||||
matcher.appendTail(result);
|
||||
|
||||
Component component;
|
||||
// Clean output text
|
||||
|
||||
@@ -86,9 +86,9 @@ public class Version11 {
|
||||
toolStats.logger.info("Adding enabled.damage-done.bow to config.yml");
|
||||
toolStats.logger.info("Adding enabled.damage-done.mace to config.yml");
|
||||
|
||||
toolStats.logger.info("Changing messages.flight-time to new format");
|
||||
toolStats.logger.info("Updating entry for messages.flight-time");
|
||||
toolStats.config.set("messages.flight-time", "&7Flight time: &8{years}y {months}m {days}d {hours}h {minutes}m {seconds}s");
|
||||
|
||||
|
||||
// save the config and reload it
|
||||
try {
|
||||
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config.yml");
|
||||
|
||||
Reference in New Issue
Block a user