feat: add example mine config, &#RRGGBB color support, up to 100 selection points

This commit is contained in:
loki5512344 2026-06-01 11:38:53 +02:00
parent 0f2735f171
commit f2be6d6ece
6 changed files with 445 additions and 28 deletions

View file

@ -17,32 +17,17 @@ public final class RegionConfigLoader {
/**
* Parses region configuration from YAML.
* Supports up to 100 selection points (50 regions).
*/
public RegionConfig parse(YamlConfiguration yaml) {
List<Location> selections = new ArrayList<>();
// Try new format first
for (int i = 1; i <= 10; i++) {
String key = "region.selection." + i;
if (yaml.contains(key)) {
String locStr = yaml.getString(key);
if (locStr != null && !locStr.isBlank()) {
selections.add(parseLocation(locStr));
}
}
}
// Try new format first (region.selection.X)
selections.addAll(parseSelections(yaml, "region.selection.", 100));
// Legacy fallback
// Legacy fallback (selection.X)
if (selections.isEmpty()) {
for (int i = 1; i <= 10; i++) {
String key = "selection." + i;
if (yaml.contains(key)) {
String locStr = yaml.getString(key);
if (locStr != null && !locStr.isBlank()) {
selections.add(parseLocation(locStr));
}
}
}
selections.addAll(parseSelections(yaml, "selection.", 100));
}
if (selections.size() < 2) {
@ -52,6 +37,43 @@ public final class RegionConfigLoader {
return RegionConfig.fromSelections(selections);
}
/**
* Parses selection points from YAML with given prefix.
* Supports indexed format: prefix.1, prefix.2, etc.
*/
private List<Location> parseSelections(YamlConfiguration yaml, String prefix, int maxPoints) {
List<Location> selections = new ArrayList<>();
for (int i = 1; i <= maxPoints; i++) {
String key = prefix + i;
if (yaml.contains(key)) {
String locStr = yaml.getString(key);
if (locStr != null && !locStr.isBlank()) {
try {
selections.add(parseLocation(locStr));
} catch (IllegalArgumentException e) {
// Skip invalid locations but continue parsing
}
}
} else {
// Stop at first missing index (assuming sequential)
// But check at least a few more for gaps
if (i > 20) {
boolean hasMore = false;
for (int j = i + 1; j <= Math.min(i + 5, maxPoints); j++) {
if (yaml.contains(prefix + j)) {
hasMore = true;
break;
}
}
if (!hasMore) break;
}
}
}
return selections;
}
/**
* Saves region configuration to YAML.
*/

View file

@ -1,6 +1,6 @@
package dev.loki.lomines.data.config.ui;
import net.kyori.adventure.text.minimessage.MiniMessage;
import dev.loki.lomines.util.format.ColorUtils;
import net.kyori.adventure.text.Component;
import java.util.Objects;
@ -36,6 +36,7 @@ public record UIConfig(
/**
* Parses the action bar format with placeholders.
* Placeholders: {mine}, {percent}, {time}, {blocks}, {total}
* Supports colors: &#RRGGBB, &a..&f, <color>
*/
public Component formatActionBar(String mineName, double percent, String timeStr, int blocks, int total) {
String parsed = actionBarFormat
@ -45,7 +46,7 @@ public record UIConfig(
.replace("{blocks}", String.valueOf(blocks))
.replace("{total}", String.valueOf(total));
return MiniMessage.miniMessage().deserialize(parsed);
return ColorUtils.format(parsed);
}
/**