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