Update message formatting for Hunger Games and improve configuration validation methods

This commit is contained in:
akastijn 2026-05-31 17:59:27 +02:00
parent 02228f570d
commit d7160b86cd
2 changed files with 12 additions and 7 deletions

View File

@ -111,18 +111,23 @@ abstract class AbstractConfig {
return yaml.getDouble(path, yaml.getDouble(path));
}
boolean contains(String prefix, String path) {
boolean isValidSection(String prefix, String path) {
return getConfigurationSection(prefix + path) != null;
}
boolean isEmpty(String prefix, String path) {
path = prefix + path;
return !yaml.contains(path);
return yaml.get(path) == null;
}
Optional<Location> getLocation(String prefix, String path) {
if (contains(prefix, path)) {
if (!isValidSection(prefix, path)) {
log.warn("No location configuration for {}", prefix + path);
return Optional.empty();
}
//destination.start-center.world
String rootPath = prefix + path + ".";
if (contains(rootPath, "world") || contains(rootPath, path + "x") || contains(rootPath, path + "y") || contains(rootPath, path + "z")) {
if (isEmpty(rootPath, "world") || isEmpty(rootPath, "x") || isEmpty(rootPath, "y") || isEmpty(rootPath, "z")) {
ConfigurationSection configurationSection = getConfigurationSection(prefix + path);
log.error("Invalid location configuration for:\n\t{}", configurationSection.getKeys(false).stream().map(key -> rootPath + key).collect(Collectors.joining("\n\t")));
return Optional.empty();

View File

@ -73,8 +73,8 @@ public class Messages extends AbstractConfig {
public static class GAME {
private static final String prefix = "game.";
public static String WARMUP = "<gold>The Hunger Game is starting soon! Get ready!</gold>";
public static String STARTED = "<green><bold>The Hunger Game has begun! Good luck!</bold></green>";
public static String WARMUP = "<gold>The Hunger Games are starting soon! Get ready!</gold>";
public static String STARTED = "<green><bold>The Hunger Games has begun! Good luck!</bold></green>";
public static String BORDER_SHRINK = "<red>The border is shrinking to <size> blocks!</red>";
@SuppressWarnings("unused")