package com.dfsek.terra.config; import com.dfsek.terra.biome.UserDefinedBiome; import com.dfsek.terra.biome.UserDefinedGrid; import org.bukkit.World; import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.file.YamlConfiguration; import org.jetbrains.annotations.NotNull; import java.io.File; import java.io.IOException; import java.util.List; public class BiomeGridConfig extends YamlConfiguration { private UserDefinedGrid grid; private String gridID; private String friendlyName; private boolean isEnabled = false; private final World world; private final UserDefinedBiome[][] gridRaw = new UserDefinedBiome[16][16]; public BiomeGridConfig(File file, World w) throws IOException, InvalidConfigurationException { super(); this.world = w; load(file); } @Override public void load(@NotNull File file) throws IOException, InvalidConfigurationException { isEnabled = false; super.load(file); if(!contains("id")) throw new InvalidConfigurationException("Grid ID unspecified!"); this.gridID = getString("id"); if(!contains("name")) throw new InvalidConfigurationException("Grid Name unspecified!"); this.friendlyName = getString("name"); if(!contains("grid")) throw new InvalidConfigurationException("Grid not found!"); try { for(int x = 0; x < 16; x++) { for(int z = 0; z < 16; z++) { try { gridRaw[x][z] = BiomeConfig.fromID(((List>) getList("grid")).get(x).get(z)).getBiome(); } catch(NullPointerException e) { throw new InvalidConfigurationException("SEVERE configuration error for BiomeGrid " + getFriendlyName() + ", ID: " + getGridID() + "\n\nNo such biome " + ((List>) getList("grid")).get(x).get(z)); } } } } catch(ClassCastException e) { throw new InvalidConfigurationException("Malformed grid!"); } this.grid = new UserDefinedGrid(world, 1f/512, 1f/1024, this);// TODO: custom frequency isEnabled = true; } public String getFriendlyName() { return friendlyName; } public UserDefinedBiome[][] getBiomeGrid() { return gridRaw; } public boolean isEnabled() { return isEnabled; } public String getGridID() { return gridID; } public UserDefinedGrid getGrid() { return grid; } }