From bfb996c9bcb2e36811838db84b4170dae64fa86e Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 22 Apr 2023 22:17:53 +0200 Subject: [PATCH] Add Config --- src/de/steamwar/towerrun/Config.java | 88 ++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 src/de/steamwar/towerrun/Config.java diff --git a/src/de/steamwar/towerrun/Config.java b/src/de/steamwar/towerrun/Config.java new file mode 100644 index 0000000..e822baa --- /dev/null +++ b/src/de/steamwar/towerrun/Config.java @@ -0,0 +1,88 @@ +package de.steamwar.towerrun; + +import lombok.Getter; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; + +public class Config { + + private Config() { + } + + public static final World world = Bukkit.getWorlds().get(0); + + public static final int TOWER_MIN_X; + public static final int TOWER_FLOOR_Y; + public static final int TOWER_MIN_Z; + + public static final int TOWER_MIN_HEIGHT; + public static final int TOWER_MAX_HEIGHT; + + public static final List TOWER_GENERATORS = new ArrayList<>(); + + public static final List TOWER_DOORS = new ArrayList<>(); + + static { + File worldConfigFile = new File(world.getWorldFolder(), "config.yml"); + if (!worldConfigFile.exists()) { + Bukkit.getLogger().log(Level.SEVERE, "Weltconfig fehlt!"); + Bukkit.shutdown(); + } + FileConfiguration worldconfig = YamlConfiguration.loadConfiguration(worldConfigFile); + + ConfigurationSection tower = worldconfig.getConfigurationSection("tower"); + TOWER_MIN_X = tower.getInt("minX"); + TOWER_FLOOR_Y = tower.getInt("floorY"); + TOWER_MIN_Z = tower.getInt("minZ"); + + TOWER_MIN_HEIGHT = tower.getInt("minHeight"); + TOWER_MAX_HEIGHT = tower.getInt("maxHeight"); + + for (String key : tower.getConfigurationSection("generators").getKeys(false)) { + TOWER_GENERATORS.add(new Generator(tower.getConfigurationSection("generators." + key))); + } + + for (String key : tower.getConfigurationSection("doors").getKeys(false)) { + TOWER_DOORS.add(new Door(tower.getConfigurationSection("doors." + key))); + } + } + + @Getter + public static final class Generator { + public final int minX; + public final int maxX; + public final int minZ; + public final int maxZ; + public final Material type; + + private Generator(ConfigurationSection generator) { + minX = generator.getInt("minX"); + maxX = generator.getInt("maxX"); + minZ = generator.getInt("minZ"); + maxZ = generator.getInt("maxZ"); + type = Material.valueOf(generator.getString("type")); + } + } + + @Getter + public static final class Door { + public final int x; + public final int offsetY; + public final int z; + + private Door(ConfigurationSection door) { + x = door.getInt("x"); + offsetY = door.getInt("offsetY"); + z = door.getInt("z"); + } + } +}