Abstracted parts of config loading

This commit is contained in:
dfsek 2020-09-20 14:39:53 -07:00
parent d0e7f535bb
commit 2424b907be
17 changed files with 201 additions and 337 deletions

View File

@ -2,9 +2,9 @@ package com.dfsek.terra;
import com.dfsek.terra.biome.TerraBiomeGrid;
import com.dfsek.terra.biome.UserDefinedBiome;
import com.dfsek.terra.config.BiomeConfig;
import com.dfsek.terra.config.genconfig.BiomeConfig;
import com.dfsek.terra.config.ConfigUtil;
import com.dfsek.terra.config.OreConfig;
import com.dfsek.terra.config.genconfig.OreConfig;
import org.bukkit.block.Block;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
@ -12,7 +12,6 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.polydev.gaea.profiler.WorldProfiler;
import org.polydev.gaea.structures.NMSStructure;
import java.util.Random;

View File

@ -1,19 +1,10 @@
package com.dfsek.terra.biome;
import com.dfsek.terra.TerraTree;
import com.dfsek.terra.config.BiomeConfig;
import com.dfsek.terra.config.ConfigUtil;
import org.bukkit.Bukkit;
import org.bukkit.block.Biome;
import org.bukkit.configuration.InvalidConfigurationException;
import org.polydev.gaea.biome.Decorator;
import org.polydev.gaea.math.ProbabilityCollection;
import org.polydev.gaea.tree.Tree;
import org.polydev.gaea.tree.TreeType;
import org.polydev.gaea.world.Fauna;
import org.polydev.gaea.world.FaunaType;
import java.util.Map;
public class UserDefinedDecorator extends Decorator {

View File

@ -1,6 +1,6 @@
package com.dfsek.terra.biome;
import com.dfsek.terra.config.BiomeGridConfig;
import com.dfsek.terra.config.genconfig.BiomeGridConfig;
import org.bukkit.World;
import org.polydev.gaea.biome.BiomeGrid;

View File

@ -3,16 +3,13 @@ package com.dfsek.terra.carving;
import com.dfsek.terra.MaxMin;
import com.dfsek.terra.biome.TerraBiomeGrid;
import com.dfsek.terra.biome.UserDefinedBiome;
import com.dfsek.terra.config.BiomeConfig;
import com.dfsek.terra.config.CarverConfig;
import org.bukkit.Material;
import com.dfsek.terra.config.genconfig.BiomeConfig;
import org.bukkit.World;
import org.bukkit.util.Vector;
import org.polydev.gaea.world.BlockPalette;
import org.polydev.gaea.world.carving.Carver;
import org.polydev.gaea.world.carving.Worm;
import java.util.List;
import java.util.Random;
public class UserDefinedCarver extends Carver {

View File

@ -0,0 +1,46 @@
package com.dfsek.terra.config;
import org.bukkit.plugin.java.JavaPlugin;
import org.polydev.gaea.commons.io.FilenameUtils;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Stream;
public class ConfigLoader {
private final String path;
public ConfigLoader(String path) {
this.path = path;
}
public <T extends TerraConfigObject> void load(JavaPlugin main, Class<T> clazz) {
File folder = new File(main.getDataFolder() + File.separator + path);
folder.mkdirs();
try (Stream<Path> paths = Files.walk(folder.toPath())) {
paths
.filter(path -> FilenameUtils.wildcardMatch(path.toFile().getName(), "*.yml"))
.forEach(path -> {
try {
Constructor<T> c = clazz.getConstructor(File.class);
T o = c.newInstance(path.toFile());
main.getLogger().info("Loaded " + o.toString() + " from file " + path.toString());
} catch(IllegalAccessException | InstantiationException | NoSuchMethodException e) {
e.printStackTrace();
} catch(IllegalArgumentException | InvocationTargetException e) {
e.printStackTrace();
main.getLogger().severe("Configuration error for Terra object. File: " + path.toString());
main.getLogger().severe(((e instanceof InvocationTargetException) ? "INVOCATION: " + e.getCause().getMessage() : e.getMessage()));
main.getLogger().severe("Correct this before proceeding!");
}
});
} catch(IOException e) {
e.printStackTrace();
}
}
}

View File

@ -1,5 +1,11 @@
package com.dfsek.terra.config;
import com.dfsek.terra.config.genconfig.BiomeConfig;
import com.dfsek.terra.config.genconfig.BiomeGridConfig;
import com.dfsek.terra.config.genconfig.CarverConfig;
import com.dfsek.terra.config.genconfig.FaunaConfig;
import com.dfsek.terra.config.genconfig.OreConfig;
import com.dfsek.terra.config.genconfig.PaletteConfig;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.List;
@ -11,17 +17,17 @@ public class ConfigUtil {
Logger logger = main.getLogger();
logger.info("Loading config values");
OreConfig.loadOres(main);
new ConfigLoader("ores").load(main, OreConfig.class);
PaletteConfig.loadPalettes(main);
new ConfigLoader("palettes").load(main, PaletteConfig.class);
CarverConfig.loadCaves(main);
new ConfigLoader("carving").load(main, CarverConfig.class);
FaunaConfig.loadFauna(main);
new ConfigLoader("fauna").load(main, FaunaConfig.class);
BiomeConfig.loadBiomes(main);
new ConfigLoader("biomes").load(main, BiomeConfig.class);
BiomeGridConfig.loadBiomeGrids(main);
new ConfigLoader("grids").load(main, BiomeGridConfig.class);
WorldConfig.reloadAll();
}

View File

@ -1,41 +0,0 @@
package com.dfsek.terra.config;
import com.dfsek.terra.Terra;
import org.bukkit.Location;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.jetbrains.annotations.NotNull;
import org.polydev.gaea.structures.NMSStructure;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public class StructureConfig extends YamlConfiguration {
private String id;
private String name;
private Object structure;
private int offset;
public StructureConfig(File file) throws IOException, InvalidConfigurationException {
this.load(file);
}
@Override
public void load(@NotNull File file) throws IOException, InvalidConfigurationException {
super.load(file);
if(!contains("id")) throw new InvalidConfigurationException("Structure ID unspecified!");
this.id = getString("id");
if(!contains("name")) throw new InvalidConfigurationException("Biome Name unspecified!");
this.name = getString("name");
this.offset = getInt("offset", 0);
try {
structure = NMSStructure.getAsTag(new FileInputStream(new File(Terra.getInstance().getDataFolder() + File.separator + "structures" + File.separator + "nbt" + File.separator + getString("file"))));
} catch(FileNotFoundException e) {
throw new InvalidConfigurationException("Unable to locate structure file Terra/structures/nbt/" + getString("file"));
}
}
public NMSStructure getInstance(Location origin) {
return new NMSStructure(origin, structure);
}
}

View File

@ -0,0 +1,16 @@
package com.dfsek.terra.config;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.io.IOException;
public abstract class TerraConfigObject extends YamlConfiguration {
public TerraConfigObject(File file) throws IOException, InvalidConfigurationException {
super.load(file);
init();
}
public abstract void init() throws InvalidConfigurationException;
public abstract String getID();
}

View File

@ -3,6 +3,8 @@ package com.dfsek.terra.config;
import com.dfsek.terra.Terra;
import com.dfsek.terra.biome.UserDefinedBiome;
import com.dfsek.terra.biome.UserDefinedGrid;
import com.dfsek.terra.config.genconfig.BiomeConfig;
import com.dfsek.terra.config.genconfig.BiomeGridConfig;
import org.bukkit.World;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration;

View File

@ -1,4 +1,4 @@
package com.dfsek.terra.config;
package com.dfsek.terra.config.genconfig;
import com.dfsek.terra.MaxMin;
import com.dfsek.terra.TerraTree;
@ -6,14 +6,13 @@ import com.dfsek.terra.biome.UserDefinedBiome;
import com.dfsek.terra.biome.UserDefinedDecorator;
import com.dfsek.terra.biome.UserDefinedGenerator;
import com.dfsek.terra.carving.UserDefinedCarver;
import com.dfsek.terra.config.ConfigLoader;
import com.dfsek.terra.config.TerraConfigObject;
import org.bukkit.Bukkit;
import org.bukkit.block.data.BlockData;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import org.polydev.gaea.commons.io.FilenameUtils;
import org.polydev.gaea.math.ProbabilityCollection;
import org.polydev.gaea.math.parsii.tokenizer.ParseException;
import org.polydev.gaea.tree.Tree;
@ -24,40 +23,35 @@ import org.polydev.gaea.world.FaunaType;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.TreeMap;
import java.util.logging.Logger;
import java.util.stream.Stream;
public class BiomeConfig extends YamlConfiguration {
public class BiomeConfig extends TerraConfigObject {
private static final Map<String, BiomeConfig> biomes = new HashMap<>();
private UserDefinedBiome biome;
private String biomeID;
private String friendlyName;
private org.bukkit.block.Biome vanillaBiome;
private boolean isEnabled = false;
private final Map<OreConfig, MaxMin> ores = new HashMap<>();
private final Map<OreConfig, MaxMin> oreHeights = new HashMap<>();
private final Map<CarverConfig, Integer> carvers = new HashMap<>();
private final ProbabilityCollection<Fauna> fauna = new ProbabilityCollection<>();
private final ProbabilityCollection<Tree> trees = new ProbabilityCollection<>();
private Map<OreConfig, MaxMin> ores;
private Map<OreConfig, MaxMin> oreHeights;
private Map<CarverConfig, Integer> carvers;
public BiomeConfig(File file) throws InvalidConfigurationException, IOException {
super();
load(file);
super(file);
}
@Override
public void load(@NotNull File file) throws InvalidConfigurationException, IOException {
public void init() throws InvalidConfigurationException {
isEnabled = false;
super.load(file);
oreHeights = new HashMap<>();
ores = new HashMap<>();
carvers = new HashMap<>();
ProbabilityCollection<Fauna> fauna = new ProbabilityCollection<>();
ProbabilityCollection<Tree> trees = new ProbabilityCollection<>();
if(!contains("id")) throw new InvalidConfigurationException("Biome ID unspecified!");
this.biomeID = getString("id");
if(!contains("name")) throw new InvalidConfigurationException("Biome Name unspecified!");
@ -83,7 +77,7 @@ public class BiomeConfig extends YamlConfiguration {
}
}
} catch(ClassCastException ex) {
throw new InvalidConfigurationException("SEVERE configuration error for BlockPalettes in biome" + getFriendlyName() + ", ID: " + biomeID);
throw new InvalidConfigurationException("SEVERE configuration error for BlockPalettes in biome " + getFriendlyName() + ", ID: " + biomeID);
}
}
}
@ -93,9 +87,13 @@ public class BiomeConfig extends YamlConfiguration {
for(Map.Entry<?, ?> entry : e.entrySet()) {
try {
//carvers.add(new UserDefinedCarver((Integer) entry.getValue(), ConfigUtil.getCarver((String) entry.getKey())));
carvers.put(CarverConfig.fromID((String) entry.getKey()), (Integer) entry.getValue());
CarverConfig c = CarverConfig.fromID((String) entry.getKey());
Bukkit.getLogger().info("Got carver " + c + ". Adding with weight " + entry.getValue());
carvers.put(c, (Integer) entry.getValue());
} catch(ClassCastException ex) {
throw new InvalidConfigurationException("SEVERE configuration error for Carvers in biome" + getFriendlyName() + ", ID: " + biomeID);
throw new InvalidConfigurationException("SEVERE configuration error for Carvers in biome " + getFriendlyName() + ", ID: " + biomeID);
} catch(NullPointerException ex) {
throw new InvalidConfigurationException("SEVERE configuration error for Carvers in biome " + getFriendlyName() + ", ID: " + biomeID + "\n\n" + "No such carver " + entry.getKey());
}
}
}
@ -112,7 +110,7 @@ public class BiomeConfig extends YamlConfiguration {
Fauna faunaCustom = FaunaConfig.fromID(e.getKey());
fauna.add(faunaCustom, (Integer) e.getValue());
} catch(NullPointerException ex2) {
throw new IllegalArgumentException("SEVERE configuration error for fauna in biome " + getFriendlyName() + ", ID " + getBiomeID() + "\n\nFauna with ID " + e.getKey() + " cannot be found!");
throw new IllegalArgumentException("SEVERE configuration error for fauna in biome " + getFriendlyName() + ", ID " + getID() + "\n\nFauna with ID " + e.getKey() + " cannot be found!");
}
}
}
@ -156,6 +154,7 @@ public class BiomeConfig extends YamlConfiguration {
if(!contains("palette")) throw new InvalidConfigurationException("Palette unspecified!");
isEnabled = true;
biomes.put(biomeID, this);
}
public MaxMin getOreHeight(OreConfig c) {
@ -170,7 +169,7 @@ public class BiomeConfig extends YamlConfiguration {
return biome;
}
public String getBiomeID() {
public String getID() {
return biomeID;
}
@ -197,32 +196,9 @@ public class BiomeConfig extends YamlConfiguration {
return biomes.get(id);
}
protected static void loadBiomes(JavaPlugin main) {
// TODO: Merge all load methods
Logger logger = main.getLogger();
biomes.clear();
File biomeFolder = new File(main.getDataFolder() + File.separator + "biomes");
biomeFolder.mkdirs();
try (Stream<Path> paths = Files.walk(biomeFolder.toPath())) {
paths
.filter(path -> FilenameUtils.wildcardMatch(path.toFile().getName(), "*.yml"))
.forEach(path -> {
try {
BiomeConfig biome = new BiomeConfig(path.toFile());
biomes.put(biome.getBiomeID(), biome);
logger.info("Loaded Biome with name " + biome.getFriendlyName() + ", ID " + biome.getBiomeID() + " and noise equation " + biome.get("noise-equation") + " from " + path.toString());
} catch(IOException e) {
e.printStackTrace();
} catch(InvalidConfigurationException | IllegalArgumentException e) {
logger.severe("Configuration error for Biome. File: " + path.toString());
logger.severe(e.getMessage());
logger.severe("Correct this before proceeding!");
}
});
} catch(IOException e) {
e.printStackTrace();
}
main.getLogger().info("Loaded " + biomes.size() + " biomes.");
@Override
public String toString() {
return "Biome with name " + getFriendlyName() + ", ID " + getID() + " and noise equation " + get("noise-equation");
}
public int getCarverChance(UserDefinedCarver c) {

View File

@ -1,26 +1,22 @@
package com.dfsek.terra.config;
package com.dfsek.terra.config.genconfig;
import com.dfsek.terra.biome.UserDefinedBiome;
import com.dfsek.terra.biome.UserDefinedGrid;
import org.bukkit.Bukkit;
import com.dfsek.terra.config.ConfigLoader;
import com.dfsek.terra.config.TerraConfigObject;
import com.dfsek.terra.config.WorldConfig;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import org.polydev.gaea.commons.io.FilenameUtils;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
import java.util.Objects;
public class BiomeGridConfig extends YamlConfiguration {
public class BiomeGridConfig extends TerraConfigObject {
private static final Map<String, BiomeGridConfig> biomeGrids = new HashMap<>();
private String gridID;
private String friendlyName;
@ -30,19 +26,18 @@ public class BiomeGridConfig extends YamlConfiguration {
private int sizeZ;
public BiomeGridConfig(File file) throws IOException, InvalidConfigurationException {
super();
load(file);
super(file);
}
@Override
public void load(@NotNull File file) throws IOException, InvalidConfigurationException {
public void init() throws 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!");
this.sizeX = ((List<List<String>>) getList("grid")).size();
this.sizeX = Objects.requireNonNull(getList("grid")).size();
this.sizeZ = ((List<List<String>>) getList("grid")).get(0).size();
gridRaw = new UserDefinedBiome[sizeX][sizeZ];
try {
@ -51,7 +46,7 @@ public class BiomeGridConfig extends YamlConfiguration {
try {
gridRaw[x][z] = BiomeConfig.fromID(((List<List<String>>) 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<List<String>>) getList("grid")).get(x).get(z));
throw new InvalidConfigurationException("SEVERE configuration error for BiomeGrid " + getFriendlyName() + ", ID: " + getID() + "\n\nNo such biome " + ((List<List<String>>) getList("grid")).get(x).get(z));
}
}
}
@ -59,6 +54,7 @@ public class BiomeGridConfig extends YamlConfiguration {
throw new InvalidConfigurationException("Malformed grid!");
}
isEnabled = true;
biomeGrids.put(gridID, this);
}
public int getSizeX() {
@ -81,7 +77,7 @@ public class BiomeGridConfig extends YamlConfiguration {
return isEnabled;
}
public String getGridID() {
public String getID() {
return gridID;
}
@ -90,28 +86,9 @@ public class BiomeGridConfig extends YamlConfiguration {
return new UserDefinedGrid(w, c.freq1, c.freq2, this);
}
protected static void loadBiomeGrids(JavaPlugin main) {
File biomeGridFolder = new File(main.getDataFolder() + File.separator + "grids");
biomeGridFolder.mkdirs();
try (Stream<Path> paths = Files.walk(biomeGridFolder.toPath())) {
paths
.filter(path -> FilenameUtils.wildcardMatch(path.toFile().getName(), "*.yml"))
.forEach(path -> {
try {
BiomeGridConfig grid = new BiomeGridConfig(path.toFile());
biomeGrids.put(grid.getGridID(), grid);
main.getLogger().info("Loaded BiomeGrid with name " + grid.getFriendlyName() + ", ID " + grid.getGridID() + " Size: " + grid.getSizeX() + ", " + grid.getSizeZ() + " from " + path.toString());
} catch(IOException e) {
e.printStackTrace();
} catch(InvalidConfigurationException | IllegalArgumentException e) {
Bukkit.getLogger().severe("[Terra] Configuration error for BiomeGrid. File: " + path.toString());
Bukkit.getLogger().severe("[Terra] " + e.getMessage());
Bukkit.getLogger().severe("[Terra] Correct this before proceeding!");
}
});
} catch(IOException e) {
e.printStackTrace();
}
@Override
public String toString() {
return "BiomeGrid with ID " + getID() + ", name " + getFriendlyName() + ", dimensions " + getSizeX() + ":" + getSizeZ();
}
public static Map<String, BiomeGridConfig> getBiomeGrids() {

View File

@ -1,51 +1,42 @@
package com.dfsek.terra.config;
package com.dfsek.terra.config.genconfig;
import com.dfsek.terra.MaxMin;
import com.dfsek.terra.carving.UserDefinedCarver;
import com.dfsek.terra.config.ConfigLoader;
import com.dfsek.terra.config.TerraConfigObject;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.data.BlockData;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;
import org.jetbrains.annotations.NotNull;
import org.polydev.gaea.commons.io.FilenameUtils;
import org.polydev.gaea.math.ProbabilityCollection;
import org.polydev.gaea.world.BlockPalette;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.TreeMap;
import java.util.logging.Logger;
import java.util.stream.Stream;
public class CarverConfig extends YamlConfiguration {
public class CarverConfig extends TerraConfigObject {
private static final Map<String, CarverConfig> caveConfig = new HashMap<>();
private UserDefinedCarver carver;
private String id;
private final Set<Material> replaceableInner = new HashSet<>();
private final Set<Material> replaceableOuter = new HashSet<>();
private final Map<Material, Set<Material>> shift = new HashMap<>();
private Set<Material> replaceableInner;
private Set<Material> replaceableOuter;
private Map<Material, Set<Material>> shift;
private Map<Integer, ProbabilityCollection<BlockData>> inner;
private Map<Integer, ProbabilityCollection<BlockData>> outer;
private boolean replaceIsBlacklistInner;
private boolean replaceIsBlacklistOuter;
public CarverConfig(File file) throws IOException, InvalidConfigurationException {
super();
this.load(file);
}
public CarverConfig(File file) throws IOException, InvalidConfigurationException {
super(file);
}
public String getID() {
return id;
@ -56,19 +47,31 @@ public class CarverConfig extends YamlConfiguration {
}
@Override
public void load(@NotNull File file) throws IOException, InvalidConfigurationException {
super.load(file);
public void init() throws InvalidConfigurationException {
inner = getBlocks("palette.inner.blocks");
outer = getBlocks("palette.outer.blocks");
replaceableInner = new HashSet<>();
replaceableOuter = new HashSet<>();
for(String s : getStringList("palette.inner.replace")) {
replaceableInner.add(Bukkit.createBlockData(s).getMaterial());
try {
if(replaceableInner.contains(Bukkit.createBlockData(s).getMaterial())) Bukkit.getLogger().warning("Duplicate material in replaceable list: " + s);
replaceableInner.add(Bukkit.createBlockData(s).getMaterial());
} catch(NullPointerException | IllegalArgumentException e) {
throw new InvalidConfigurationException("Could not load data for " + s);
}
}
for(String s : getStringList("palette.outer.replace")) {
replaceableOuter.add(Bukkit.createBlockData(s).getMaterial());
try {
if(replaceableOuter.contains(Bukkit.createBlockData(s).getMaterial())) Bukkit.getLogger().warning("Duplicate material in replaceable list: " + s);
replaceableOuter.add(Bukkit.createBlockData(s).getMaterial());
} catch(NullPointerException | IllegalArgumentException e) {
throw new InvalidConfigurationException("Could not load data for " + s);
}
}
shift = new HashMap<>();
for(Map.Entry<String, Object> e : getConfigurationSection("shift").getValues(false).entrySet()) {
Set<Material> l = new HashSet<>();
for(String s : (List<String>) e.getValue()) {
@ -90,6 +93,7 @@ public class CarverConfig extends YamlConfiguration {
MaxMin height = new MaxMin(getInt("start.height.min"), getInt("start.height.max"));
id = getString("id");
carver = new UserDefinedCarver(height, radius, length, start, mutate, radiusMultiplier);
caveConfig.put(id, this);
}
private Map<Integer, ProbabilityCollection<BlockData>> getBlocks(String key) throws InvalidConfigurationException {
@ -143,37 +147,21 @@ public class CarverConfig extends YamlConfiguration {
return null;
}
protected static void loadCaves(JavaPlugin main) {
// TODO: Merge all load methods
Logger logger = main.getLogger();
caveConfig.clear();
File oreFolder = new File(main.getDataFolder() + File.separator + "carving");
oreFolder.mkdirs();
try (Stream<Path> paths = Files.walk(oreFolder.toPath())) {
paths
.filter(path -> FilenameUtils.wildcardMatch(path.toFile().getName(), "*.yml"))
.forEach(path -> {
try {
CarverConfig cave = new CarverConfig(path.toFile());
caveConfig.put(cave.getID(), cave);
logger.info("Loaded Carver with ID " + cave.getID() + " from " + path.toString());
} catch(IOException e) {
e.printStackTrace();
} catch(InvalidConfigurationException | IllegalArgumentException e) {
logger.severe("Configuration error for Carver. File: " + path.toString());
logger.severe(e.getMessage());
logger.severe("Correct this before proceeding!");
}
});
} catch(IOException e) {
e.printStackTrace();
}
main.getLogger().info("Loaded " + caveConfig.size() + " carvers.");
@Override
public String toString() {
return "Carver with ID " + getID();
}
public static List<CarverConfig> getCarvers() {
return new ArrayList<>(caveConfig.values());
}
public static CarverConfig fromID(String id) {
Bukkit.getLogger().info("Accessing carvers...");
for(Map.Entry<String, CarverConfig> e : caveConfig.entrySet()) {
Bukkit.getLogger().info("Carver ID " + e.getKey() + ", carver: " + e.getValue());
}
Bukkit.getLogger().info("ID requested: " + id);
Bukkit.getLogger().info("Fetched " + caveConfig.get(id));
return caveConfig.get(id);
}

View File

@ -1,46 +1,38 @@
package com.dfsek.terra.config;
package com.dfsek.terra.config.genconfig;
import com.dfsek.terra.config.ConfigLoader;
import com.dfsek.terra.config.ConfigUtil;
import com.dfsek.terra.config.TerraConfigObject;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.data.BlockData;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import org.polydev.gaea.commons.io.FilenameUtils;
import org.polydev.gaea.math.ProbabilityCollection;
import org.polydev.gaea.world.BlockPalette;
import org.polydev.gaea.world.Fauna;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.logging.Logger;
import java.util.stream.Stream;
public class FaunaConfig extends YamlConfiguration implements Fauna {
public class FaunaConfig extends TerraConfigObject implements Fauna {
private static final Map<String, FaunaConfig> faunaConfig = new HashMap<>();
private BlockPalette faunaPalette = new BlockPalette();
private BlockPalette faunaPalette;
private String id;
private String friendlyName;
List<Material> spawnable;
public FaunaConfig(File file) throws IOException, InvalidConfigurationException {
super();
load(file);
super(file);
}
@Override
public void load(@NotNull File file) throws IOException, InvalidConfigurationException {
super.load(file);
public void init() throws InvalidConfigurationException {
if(!contains("blocks")) throw new InvalidConfigurationException("No blocks defined in custom fauna!");
if(!contains("id")) throw new InvalidConfigurationException("Fauna ID unspecified!");
if(!contains("name")) throw new InvalidConfigurationException("Fauna name unspecified!");
@ -58,6 +50,7 @@ public class FaunaConfig extends YamlConfiguration implements Fauna {
this.id = getString("id");
if(!contains("name")) throw new InvalidConfigurationException("Fauna Name unspecified!");
this.friendlyName = getString("name");
faunaConfig.put(id, this);
}
public String getFriendlyName() {
@ -88,33 +81,11 @@ public class FaunaConfig extends YamlConfiguration implements Fauna {
return true;
}
protected static void loadFauna(JavaPlugin main) {
// TODO: Merge all load methods
Logger logger = main.getLogger();
faunaConfig.clear();
File faunaFolder = new File(main.getDataFolder() + File.separator + "fauna");
faunaFolder.mkdirs();
try (Stream<Path> paths = Files.walk(faunaFolder.toPath())) {
paths
.filter(path -> FilenameUtils.wildcardMatch(path.toFile().getName(), "*.yml"))
.forEach(path -> {
try {
FaunaConfig fauna = new FaunaConfig(path.toFile());
faunaConfig.put(fauna.getID(), fauna);
logger.info("Loaded Fauna with name " + fauna.getFriendlyName() + ", ID " + fauna.getID() + " from " + path.toString());
} catch(IOException e) {
e.printStackTrace();
} catch(InvalidConfigurationException | IllegalArgumentException e) {
logger.severe("Configuration error for Fauna. File: " + path.toString());
logger.severe(e.getMessage());
logger.severe("Correct this before proceeding!");
}
});
} catch(IOException e) {
e.printStackTrace();
}
main.getLogger().info("Loaded " + faunaConfig.size() + " fauna objects.");
@Override
public String toString() {
return "Fauna with name " + getFriendlyName() + ", ID " + getID();
}
public static FaunaConfig fromID(String id) {
return faunaConfig.get(id);
}

View File

@ -1,32 +1,26 @@
package com.dfsek.terra.config;
package com.dfsek.terra.config.genconfig;
import com.dfsek.terra.config.ConfigLoader;
import com.dfsek.terra.config.ConfigUtil;
import com.dfsek.terra.config.TerraConfigObject;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.data.BlockData;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;
import org.polydev.gaea.commons.io.FilenameUtils;
import org.polydev.gaea.math.FastNoise;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Random;
import java.util.logging.Logger;
import java.util.stream.Stream;
public class OreConfig extends YamlConfiguration {
public class OreConfig extends TerraConfigObject {
private static final Map<String, OreConfig> ores = new HashMap<>();
private BlockData oreData;
private int min;
@ -38,12 +32,11 @@ public class OreConfig extends YamlConfiguration {
private int h;
List<Material> replaceable;
public OreConfig(File file) throws IOException, InvalidConfigurationException {
this.load(file);
super(file);
}
@Override
public void load(@NotNull File file) throws IOException, InvalidConfigurationException {
super.load(file);
public void init() throws InvalidConfigurationException {
if(!contains("material")) throw new InvalidConfigurationException("Ore material not found!");
if(!contains("deform")) throw new InvalidConfigurationException("Ore vein deformation not found!");
if(!contains("id")) throw new InvalidConfigurationException("Ore ID not found!");
@ -66,6 +59,7 @@ public class OreConfig extends YamlConfiguration {
} catch(NullPointerException | IllegalArgumentException e) {
throw new InvalidConfigurationException("Invalid ore material: " + getString("material"));
}
ores.put(id, this);
}
private int randomInRange(Random r) {
return r.nextInt(max-min+1)+min;
@ -87,6 +81,11 @@ public class OreConfig extends YamlConfiguration {
}
}
@Override
public String toString() {
return "Ore with name " + getFriendlyName() + ", ID " + getID();
}
public String getID() {
return id;
}
@ -95,33 +94,6 @@ public class OreConfig extends YamlConfiguration {
return friendlyName;
}
protected static void loadOres(JavaPlugin main) {
// TODO: Merge all load methods
Logger logger = main.getLogger();
ores.clear();
File oreFolder = new File(main.getDataFolder() + File.separator + "ores");
oreFolder.mkdirs();
try (Stream<Path> paths = Files.walk(oreFolder.toPath())) {
paths
.filter(path -> FilenameUtils.wildcardMatch(path.toFile().getName(), "*.yml"))
.forEach(path -> {
try {
OreConfig ore = new OreConfig(path.toFile());
ores.put(ore.getID(), ore);
logger.info("Loaded ore with ID " + ore.getID() + " from " + path.toString());
} catch(IOException e) {
e.printStackTrace();
} catch(InvalidConfigurationException | IllegalArgumentException e) {
logger.severe("Configuration error for Ore. File: " + path.toString());
logger.severe(e.getMessage());
logger.severe("Correct this before proceeding!");
}
});
} catch(IOException e) {
e.printStackTrace();
}
main.getLogger().info("Loaded " + ores.size() + " ores.");
}
public static OreConfig fromID(String id) {
return ores.get(id);
}

View File

@ -1,45 +1,39 @@
package com.dfsek.terra.config;
package com.dfsek.terra.config.genconfig;
import com.dfsek.terra.config.ConfigLoader;
import com.dfsek.terra.config.TerraConfigObject;
import org.bukkit.Bukkit;
import org.bukkit.block.data.BlockData;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import org.polydev.gaea.commons.io.FilenameUtils;
import org.polydev.gaea.math.ProbabilityCollection;
import org.polydev.gaea.world.BlockPalette;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import java.util.stream.Stream;
public class PaletteConfig extends YamlConfiguration {
public class PaletteConfig extends TerraConfigObject {
private static final Map<String, PaletteConfig> palettes = new HashMap<>();
private BlockPalette palette;
private String paletteID;
private boolean isEnabled = false;
private String friendlyName;
public PaletteConfig(File file) throws IOException, InvalidConfigurationException {
load(file);
super(file);
}
@Override
public void load(@NotNull File file) throws IOException, InvalidConfigurationException {
super.load(file);
public void init() throws InvalidConfigurationException {
palette = getPalette(getMapList("blocks"));
if(!contains("id")) throw new InvalidConfigurationException("Grid ID unspecified!");
this.paletteID = getString("id");
if(!contains("name")) throw new InvalidConfigurationException("Grid Name unspecified!");
this.friendlyName = getString("name");
isEnabled = true;
palettes.put(paletteID, this);
}
public BlockPalette getPalette() {
@ -54,7 +48,7 @@ public class PaletteConfig extends YamlConfiguration {
return friendlyName;
}
public String getPaletteID() {
public String getID() {
return paletteID;
}
@ -74,32 +68,9 @@ public class PaletteConfig extends YamlConfiguration {
return p;
}
protected static void loadPalettes(JavaPlugin main) {
// TODO: Merge all load methods
Logger logger = main.getLogger();
palettes.clear();
File paletteFolder = new File(main.getDataFolder() + File.separator + "palettes");
paletteFolder.mkdirs();
try (Stream<Path> paths = Files.walk(paletteFolder.toPath())) {
paths
.filter(path -> FilenameUtils.wildcardMatch(path.toFile().getName(), "*.yml"))
.forEach(path -> {
try {
PaletteConfig palette = new PaletteConfig(path.toFile());
palettes.put(palette.getPaletteID(), palette);
logger.info("Loaded BlockPalette with name: " + palette.getFriendlyName() + ", ID " + palette.getPaletteID() + "with " + palette.getPalette().getSize() + " layers from " + path.toString());
} catch(IOException e) {
e.printStackTrace();
} catch(InvalidConfigurationException | IllegalArgumentException e) {
logger.severe("Configuration error for BlockPalette. File: " + path.toString());
logger.severe(e.getMessage());
logger.severe("Correct this before proceeding!");
}
});
} catch(IOException e) {
e.printStackTrace();
}
main.getLogger().info("Loaded " + palettes.size() + " palettes.");
@Override
public String toString() {
return "BlockPalette with name: " + getFriendlyName() + ", ID " + getID() + " with " + getPalette().getSize() + " layers";
}
public static PaletteConfig fromID(String id) {

View File

@ -1,26 +1,21 @@
package com.dfsek.terra.population;
import com.dfsek.terra.TerraProfiler;
import com.dfsek.terra.config.CarverConfig;
import com.dfsek.terra.config.genconfig.CarverConfig;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.generator.BlockPopulator;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;
import org.polydev.gaea.generation.GenerationPopulator;
import org.polydev.gaea.profiler.ProfileFuture;
import org.polydev.gaea.world.carving.CarvingData;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
public class CavePopulator extends BlockPopulator {
@Override

View File

@ -1,15 +1,13 @@
package com.dfsek.terra.population;
import com.dfsek.terra.MaxMin;
import com.dfsek.terra.biome.BiomeZone;
import com.dfsek.terra.biome.TerraBiomeGrid;
import com.dfsek.terra.biome.UserDefinedBiome;
import com.dfsek.terra.config.BiomeConfig;
import com.dfsek.terra.config.OreConfig;
import com.dfsek.terra.config.genconfig.BiomeConfig;
import com.dfsek.terra.config.genconfig.OreConfig;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.generator.BlockPopulator;
import org.jetbrains.annotations.NotNull;
import org.polydev.gaea.biome.Biome;
import org.polydev.gaea.population.GaeaBlockPopulator;