153 lines
6.7 KiB
Java
153 lines
6.7 KiB
Java
package com.alttd.hunger_games.config;
|
|
|
|
import com.alttd.hunger_games.data_objects.GameStage;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.bukkit.Location;
|
|
import org.bukkit.configuration.ConfigurationSection;
|
|
|
|
import java.io.File;
|
|
import java.time.Duration;
|
|
import java.util.*;
|
|
|
|
@Slf4j
|
|
public class Config extends AbstractConfig {
|
|
|
|
static Config config;
|
|
|
|
Config() {
|
|
super(
|
|
new File(File.separator
|
|
+ "mnt" + File.separator
|
|
+ "configs" + File.separator
|
|
+ "HungerGames"),
|
|
"config.yml");
|
|
}
|
|
|
|
public static void reload() {
|
|
log.info("Reloading config");
|
|
config = new Config();
|
|
config.readConfig(Config.class, null);
|
|
}
|
|
|
|
public static class SETTINGS {
|
|
private static final String prefix = "settings.";
|
|
|
|
@SuppressWarnings("unused")
|
|
private static void load() {
|
|
}
|
|
}
|
|
|
|
public static class ROUND {
|
|
private static final String prefix = "round.";
|
|
|
|
public static Duration COUNTDOWN = Duration.ofSeconds(10);
|
|
public static Duration SAFE_PHASE = Duration.ofSeconds(30);
|
|
public static Duration TIME_TO_FINALE = Duration.ofMinutes(5);
|
|
public static int INITIAL_BORDER_SIZE = 5000;
|
|
public static List<GameStage> STAGES = List.of(
|
|
GameStage.builder().duration(Duration.ofMinutes(5)).worldBorderSize(1000).build(),
|
|
GameStage.builder().duration(Duration.ofMinutes(5)).worldBorderSize(750).build(),
|
|
GameStage.builder().duration(Duration.ofMinutes(5)).worldBorderSize(500).build()
|
|
);
|
|
|
|
@SuppressWarnings("unused")
|
|
private static void load() {
|
|
int countdownSeconds = config.getInt(prefix, "countdown-seconds", Math.toIntExact(COUNTDOWN.toSeconds()));
|
|
COUNTDOWN = Duration.ofSeconds(countdownSeconds);
|
|
int safePhaseSeconds = config.getInt(prefix, "safe-phase-seconds", Math.toIntExact(SAFE_PHASE.toSeconds()));
|
|
SAFE_PHASE = Duration.ofSeconds(safePhaseSeconds);
|
|
int killPhaseSeconds = config.getInt(prefix, "time-to-finale-seconds", Math.toIntExact(TIME_TO_FINALE.toSeconds()));
|
|
TIME_TO_FINALE = Duration.ofSeconds(killPhaseSeconds);
|
|
INITIAL_BORDER_SIZE = config.getInt(prefix, "initial-border-size", INITIAL_BORDER_SIZE);
|
|
|
|
ConfigurationSection configurationSection = config.getConfigurationSection(prefix + "stages");
|
|
if (configurationSection == null) {
|
|
configurationSection = config.createSection(prefix + "stages");
|
|
}
|
|
Set<String> keys = configurationSection.getKeys(false);
|
|
STAGES = getGameStages(keys, configurationSection);
|
|
}
|
|
|
|
private static List<GameStage> getGameStages(Set<String> keys, ConfigurationSection configurationSection) {
|
|
if (keys.isEmpty()) {
|
|
int key = 0;
|
|
for (GameStage stage : STAGES) {
|
|
ConfigurationSection section = configurationSection.createSection(String.valueOf(key++));
|
|
section.set("duration-seconds", stage.getDuration().toSeconds());
|
|
section.set("world-border-size", stage.getWorldBorderSize());
|
|
}
|
|
return STAGES;
|
|
}
|
|
List<GameStage> gameStageList = new ArrayList<>();
|
|
|
|
for (String key : keys) {
|
|
ConfigurationSection section = configurationSection.getConfigurationSection(key);
|
|
if (section == null) {
|
|
throw new IllegalStateException("Stage section is null for key [" + key + "] but is in the list of retrieved keys");
|
|
}
|
|
if (!section.contains("duration-seconds")) {
|
|
log.error("Missing duration-seconds in stage {}.", key);
|
|
continue;
|
|
}
|
|
if (!section.contains("world-border-size")) {
|
|
log.error("Missing world-border-size in stage {}.", key);
|
|
continue;
|
|
}
|
|
int durationSeconds = section.getInt("duration-seconds");
|
|
int worldBorderSize = section.getInt("world-border-size");
|
|
gameStageList.add(GameStage.builder()
|
|
.duration(Duration.ofSeconds(durationSeconds))
|
|
.worldBorderSize(worldBorderSize)
|
|
.build());
|
|
}
|
|
return gameStageList;
|
|
}
|
|
}
|
|
|
|
public static class DESTINATION {
|
|
private static final String prefix = "destination.";
|
|
public static Location START_CENTER = null;
|
|
public static int START_RADIUS = 15;
|
|
public static Location FINALE_CENTER = null;
|
|
public static int FINALE_RADIUS = 10;
|
|
public static Location SPECTATOR_AREA = null;
|
|
|
|
public static int STUCK_MIN_HEIGHT = 64;
|
|
public static int STUCK_FIREWORK_COUNT = 3;
|
|
public static Duration STUCK_COOLDOWN = Duration.ofMinutes(2);
|
|
public static Duration STUCK_WARMUP = Duration.ofSeconds(5);
|
|
|
|
@SuppressWarnings("unused")
|
|
private static void load() {
|
|
Config.DESTINATION.START_RADIUS = config.getInt(prefix, "start-radius", START_RADIUS);
|
|
config.getLocation(prefix, "start-center")
|
|
.ifPresent(location -> DESTINATION.START_CENTER = location);
|
|
|
|
config.getLocation(prefix, "spectator-area")
|
|
.ifPresent(location -> DESTINATION.SPECTATOR_AREA = location);
|
|
|
|
DESTINATION.FINALE_RADIUS = config.getInt(prefix, "finale-radius", FINALE_RADIUS);
|
|
config.getLocation(prefix, "finale-center")
|
|
.ifPresent(location -> DESTINATION.FINALE_CENTER = location);
|
|
|
|
STUCK_MIN_HEIGHT = config.getInt(prefix, "stuck-min-height", STUCK_MIN_HEIGHT);
|
|
STUCK_FIREWORK_COUNT = config.getInt(prefix, "stuck-firework-count", STUCK_FIREWORK_COUNT);
|
|
STUCK_COOLDOWN = Duration.ofSeconds(config.getInt(prefix, "stuck-cooldown-seconds", (int) STUCK_COOLDOWN.toSeconds()));
|
|
STUCK_WARMUP = Duration.ofSeconds(config.getInt(prefix, "stuck-warmup-seconds", (int) STUCK_WARMUP.toSeconds()));
|
|
}
|
|
}
|
|
|
|
public static class COMMAND_WHITELIST {
|
|
private static final String prefix = "command-whitelist";
|
|
|
|
public static final List<String> PREFIXES = new ArrayList<>(List.of("msg", "ac", "gac", "tell", "r", "server", "lobby", "hub", "bayou", "creative", "hg", "lp"));
|
|
|
|
@SuppressWarnings("unused")
|
|
private static void load() {
|
|
List<String> stringList = config.getStringList(prefix, "prefix-list", PREFIXES);
|
|
PREFIXES.clear();
|
|
PREFIXES.addAll(stringList);
|
|
}
|
|
}
|
|
}
|