mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 10:30:42 +00:00
Config errors now failover to Vanilla, refactored configs, begin work on wiki.
This commit is contained in:
@@ -2,6 +2,7 @@ package com.dfsek.terra;
|
||||
|
||||
import com.dfsek.terra.command.TerraCommand;
|
||||
import com.dfsek.terra.config.base.ConfigUtil;
|
||||
import com.dfsek.terra.config.base.WorldConfig;
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import com.dfsek.terra.generation.TerraChunkGenerator;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
@@ -15,10 +16,14 @@ import org.polydev.gaea.GaeaPlugin;
|
||||
import org.polydev.gaea.generation.GaeaChunkGenerator;
|
||||
import org.polydev.gaea.lang.Language;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
public class Terra extends GaeaPlugin {
|
||||
private static Terra instance;
|
||||
private static final Set<String> loadedWorlds = new HashSet<>();
|
||||
|
||||
public static Terra getInstance() {
|
||||
return instance;
|
||||
@@ -49,9 +54,15 @@ public class Terra extends GaeaPlugin {
|
||||
|
||||
@Override
|
||||
public @Nullable ChunkGenerator getDefaultWorldGenerator(@NotNull String worldName, @Nullable String id) {
|
||||
if(!loadedWorlds.contains(worldName)) TerraWorld.loadWorld(new WorldConfig(worldName, this));
|
||||
loadedWorlds.add(worldName); // Ensure world config is only loaded once for world.
|
||||
return new TerraChunkGenerator();
|
||||
}
|
||||
|
||||
public static void invalidate() {
|
||||
loadedWorlds.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebug() {
|
||||
return ConfigUtil.debug;
|
||||
|
||||
@@ -18,6 +18,7 @@ import java.util.Objects;
|
||||
|
||||
public class TerraWorld {
|
||||
private static final Map<World, TerraWorld> map = new HashMap<>();
|
||||
private static final Map<String, WorldConfig> loaded = new HashMap<>();
|
||||
private final TerraBiomeGrid grid;
|
||||
private final BiomeZone zone;
|
||||
private final ConfigPack config;
|
||||
@@ -26,7 +27,7 @@ public class TerraWorld {
|
||||
|
||||
private TerraWorld(World w) {
|
||||
safe = true;
|
||||
worldConfig = new WorldConfig(w, Terra.getInstance());
|
||||
worldConfig = loaded.get(w.getName());
|
||||
config = worldConfig.getConfig();
|
||||
UserDefinedGrid[] definedGrids = new UserDefinedGrid[config.biomeList.size()];
|
||||
for(int i = 0; i < config.biomeList.size(); i++) {
|
||||
@@ -77,7 +78,10 @@ public class TerraWorld {
|
||||
}
|
||||
zone = new BiomeZone(w, worldConfig, definedGrids);
|
||||
grid = new TerraBiomeGrid(w, config.freq1, config.freq2, zone, config, erosion);
|
||||
}
|
||||
|
||||
public static void loadWorld(WorldConfig w) {
|
||||
loaded.put(w.getWorldID(), w);
|
||||
}
|
||||
|
||||
public static synchronized TerraWorld getWorld(World w) {
|
||||
@@ -102,6 +106,7 @@ public class TerraWorld {
|
||||
|
||||
public static synchronized void invalidate() {
|
||||
map.clear();
|
||||
loaded.clear();
|
||||
}
|
||||
|
||||
public static int numWorlds() {
|
||||
|
||||
@@ -11,7 +11,7 @@ public class ErosionNoise {
|
||||
public ErosionNoise(float freq1, double thresh, long seed) {
|
||||
FastNoise main = new FastNoise((int) (seed+1));
|
||||
main.setNoiseType(FastNoise.NoiseType.SimplexFractal);
|
||||
main.setFractalOctaves(2);
|
||||
main.setFractalOctaves(3);
|
||||
main.setFrequency(freq1);
|
||||
this.thresh = thresh;
|
||||
this.noise = main;
|
||||
|
||||
@@ -69,7 +69,7 @@ public class ConfigPack extends YamlConfiguration {
|
||||
|
||||
public ConfigPack(File file) throws IOException, InvalidConfigurationException {
|
||||
long l = System.nanoTime();
|
||||
load(new File(file, "config.yml"));
|
||||
load(new File(file, "pack.yml"));
|
||||
dataFolder = file;
|
||||
|
||||
if(!contains("id")) throw new ConfigException("No ID specified!", "null");
|
||||
@@ -110,6 +110,12 @@ public class ConfigPack extends YamlConfiguration {
|
||||
// Load BiomeGrids from BiomeZone
|
||||
biomeList = getStringList("grids");
|
||||
|
||||
for(String biome : biomeList) {
|
||||
if(getBiomeGrid(biome) == null) {
|
||||
throw new ConfigException("No such BiomeGrid: " + biome, getID());
|
||||
}
|
||||
}
|
||||
|
||||
configs.put(id, this);
|
||||
|
||||
for(BiomeConfig b : getBiomes().values()) {
|
||||
@@ -137,9 +143,11 @@ public class ConfigPack extends YamlConfiguration {
|
||||
|
||||
public static synchronized void loadAll(JavaPlugin main) {
|
||||
configs.clear();
|
||||
File file = new File(main.getDataFolder(), "packs");
|
||||
file.mkdirs();
|
||||
List<Path> subfolder;
|
||||
try {
|
||||
subfolder = Files.walk(new File(main.getDataFolder(), "config").toPath(), 1)
|
||||
subfolder = Files.walk(file.toPath(), 1)
|
||||
.filter(Files::isDirectory)
|
||||
.collect(Collectors.toList());
|
||||
} catch(IOException e) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.dfsek.terra.config.base;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.TerraWorld;
|
||||
import com.dfsek.terra.biome.failsafe.FailType;
|
||||
import com.dfsek.terra.config.exception.ConfigException;
|
||||
@@ -44,6 +45,7 @@ public final class ConfigUtil {
|
||||
logger.info("Loading config values");
|
||||
|
||||
ConfigPack.loadAll(main);
|
||||
Terra.invalidate();
|
||||
TerraWorld.invalidate();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.dfsek.terra.config.base;
|
||||
|
||||
import com.dfsek.terra.config.exception.ConfigException;
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import com.dfsek.terra.image.ImageLoader;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
@@ -29,26 +30,32 @@ public class WorldConfig {
|
||||
|
||||
private ConfigPack tConfig;
|
||||
|
||||
private final String worldID;
|
||||
|
||||
public WorldConfig(World w, JavaPlugin main) {
|
||||
|
||||
public WorldConfig(String w, JavaPlugin main) {
|
||||
long start = System.nanoTime();
|
||||
LangUtil.log("world-config.load", Level.INFO, w.getName());
|
||||
this.worldID = w;
|
||||
LangUtil.log("world-config.load", Level.INFO, w);
|
||||
FileConfiguration config = new YamlConfiguration();
|
||||
try { // Load/create world config file
|
||||
File configFile = new File(main.getDataFolder() + File.separator + "worlds", w.getName() + ".yml");
|
||||
File configFile = new File(main.getDataFolder() + File.separator + "worlds", w + ".yml");
|
||||
if(! configFile.exists()) {
|
||||
configFile.getParentFile().mkdirs();
|
||||
LangUtil.log("world-config.not-found", Level.SEVERE, w.getName());
|
||||
LangUtil.log("world-config.not-found", Level.WARNING, w);
|
||||
FileUtils.copyInputStreamToFile(Objects.requireNonNull(main.getResource("world.yml")), configFile);
|
||||
}
|
||||
config.load(configFile);
|
||||
|
||||
|
||||
// Get values from config.
|
||||
fromImage = config.getBoolean("image.use-image", false);
|
||||
fromImage = config.getBoolean("image.enable", false);
|
||||
|
||||
String packID = config.getString("config");
|
||||
|
||||
|
||||
tConfig = ConfigPack.fromID(config.getString("config"));
|
||||
tConfig = ConfigPack.fromID(packID);
|
||||
|
||||
if(tConfig == null) throw new ConfigException("No such config pack: \"" + packID + "\"", worldID);
|
||||
|
||||
// Load image stuff
|
||||
try {
|
||||
@@ -61,8 +68,8 @@ public class WorldConfig {
|
||||
throw new InvalidConfigurationException("2 objects share the same image channels: zone and biome-x/z");
|
||||
if(fromImage) {
|
||||
try {
|
||||
imageLoader = new ImageLoader(new File(Objects.requireNonNull(config.getString("image.image-location"))), ImageLoader.Align.valueOf(config.getString("image.align", "center").toUpperCase()));
|
||||
LangUtil.log("world-config.using-image", Level.INFO, w.getName());
|
||||
imageLoader = new ImageLoader(new File(Objects.requireNonNull(config.getString("image.file"))), ImageLoader.Align.valueOf(config.getString("image.align", "center").toUpperCase()));
|
||||
LangUtil.log("world-config.using-image", Level.INFO, w);
|
||||
} catch(IOException | NullPointerException e) {
|
||||
e.printStackTrace();
|
||||
fromImage = false;
|
||||
@@ -75,9 +82,14 @@ public class WorldConfig {
|
||||
|
||||
} catch(IOException | InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
LangUtil.log("world-config.error", Level.SEVERE, w.getName());
|
||||
LangUtil.log("world-config.error", Level.SEVERE, w);
|
||||
throw new IllegalStateException("Unable to proceed due to fatal configuration error.");
|
||||
}
|
||||
LangUtil.log("world-config.done", Level.INFO, w.getName(), String.valueOf(((double) (System.nanoTime() - start)) / 1000000));
|
||||
LangUtil.log("world-config.done", Level.INFO, w, String.valueOf(((double) (System.nanoTime() - start)) / 1000000));
|
||||
}
|
||||
|
||||
public String getWorldID() {
|
||||
return worldID;
|
||||
}
|
||||
|
||||
public ConfigPack getConfig() {
|
||||
|
||||
Reference in New Issue
Block a user