refactor(config): complete rewrite of configuration system

BREAKING CHANGE: New section-based configuration format

New Features:
- Type-safe BlockKey sealed interface (Vanilla, Oraxen, ItemsAdder)
- Section-based config: RegionConfig, BlockConfig, ResetConfig, RewardConfig, UIConfig, TeleportConfig
- Human-readable durations: 5m, 30s, 2h, 1d
- YAML inheritance from defaults.yml
- MiniMessage support for action bar and item names
- Immutable config records with validation

Removed:
- Legacy MineConfig (17-field god object)
- ConfigParser, ConfigValidator, ConfigSerializer split classes
- Legacy FillMode enum (replaced with better version)
- Old ConfigLoader with complex parsing logic

New Files:
- data/config/block/BlockKey.java - sealed interface for block types
- data/config/block/BlockConfig.java - type-safe block weights
- data/config/block/FillMode.java - fill strategies
- data/config/region/RegionConfig.java - region management
- data/config/reset/ResetConfig.java - reset behavior with Duration
- data/config/reward/RewardConfig.java - rewards with ItemReward
- data/config/teleport/TeleportConfig.java - teleport on reset
- data/config/ui/UIConfig.java - action bar and messages
- data/config/MineConfig.java - composed from sections
- data/config/ConfigLoader.java - clean loader with defaults inheritance
- defaults.yml - default configuration template

Tests:
- BlockKeyTest.java - serialization/deserialization
- BlockConfigTest.java - weight normalization, validation
- ResetConfigTest.java - duration parsing, defaults
- UIConfigTest.java - timer formatting, action bar
- MineConfigTest.java - builder, defaults, validation
This commit is contained in:
loki5512344 2026-05-31 21:57:10 +02:00
parent f4e9458544
commit f1060f34d4
22 changed files with 2012 additions and 896 deletions

View file

@ -0,0 +1,99 @@
package dev.loki.lomines.data.config.region;
import dev.loki.lomines.util.location.Cuboid;
import org.bukkit.Location;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
/**
* Configuration for mine regions.
* Immutable, validates regions on construction.
*/
public record RegionConfig(List<Cuboid> regions) {
public RegionConfig {
if (regions == null || regions.isEmpty()) {
throw new IllegalArgumentException("Mine must have at least one region");
}
// Defensive copy and validate
List<Cuboid> copy = List.copyOf(regions);
// Check all regions are in same world
String worldName = copy.get(0).getWorld().getName();
for (Cuboid region : copy) {
if (!region.getWorld().getName().equals(worldName)) {
throw new IllegalArgumentException(
"All regions must be in the same world. Expected: " + worldName
);
}
}
regions = Collections.unmodifiableList(copy);
}
/**
* Creates a single-region config.
*/
public static RegionConfig single(Cuboid region) {
return new RegionConfig(List.of(region));
}
/**
* Creates from paired locations (selection.1 + selection.2 = region 1).
* Selections must be even number.
*/
public static RegionConfig fromSelections(List<Location> selections) {
if (selections.size() % 2 != 0) {
throw new IllegalArgumentException(
"Selections must be in pairs (even number). Got: " + selections.size()
);
}
var regions = new java.util.ArrayList<Cuboid>();
for (int i = 0; i < selections.size(); i += 2) {
Location loc1 = selections.get(i);
Location loc2 = selections.get(i + 1);
if (!Objects.equals(loc1.getWorld(), loc2.getWorld())) {
throw new IllegalArgumentException(
"Selection pair " + (i / 2 + 1) + " has locations in different worlds"
);
}
regions.add(new Cuboid(loc1, loc2));
}
return new RegionConfig(regions);
}
/**
* Total volume of all regions.
*/
public int totalVolume() {
return regions.stream().mapToInt(Cuboid::getVolume).sum();
}
/**
* World name (all regions share the same world).
*/
public String worldName() {
return regions.get(0).getWorld().getName();
}
/**
* Checks if location is within any region.
*/
public boolean contains(Location location) {
return regions.stream().anyMatch(r -> r.contains(location));
}
/**
* Number of regions.
*/
public int regionCount() {
return regions.size();
}
}