Implement Tectonic for master config.

This commit is contained in:
dfsek
2020-11-25 01:57:02 -07:00
parent c46161fc87
commit dbbe7dbd0d
20 changed files with 150 additions and 88 deletions

View File

@@ -56,6 +56,8 @@ dependencies {
implementation("net.jafama:jafama:2.3.2")
implementation(name = "Tectonic-0.1.0", group = "")
// JUnit.
testImplementation("org.junit.jupiter:junit-jupiter-api:5.7.0")
@@ -107,6 +109,7 @@ tasks.named<ShadowJar>("shadowJar") {
relocate("parsii", "com.dfsek.terra.lib.parsii")
relocate("io.papermc.lib", "com.dfsek.terra.lib.paperlib")
relocate("net.jafama", "com.dfsek.terra.lib.jafama")
relocate("com.dfsek.tectonic", "com.dfsek.terra.lib.tectonic")
minimize()
}

BIN
lib/Tectonic-0.1.0.jar Normal file

Binary file not shown.

View File

@@ -1,6 +1,6 @@
package com.dfsek.terra;
import com.dfsek.terra.config.base.ConfigUtil;
import com.dfsek.terra.config.base.PluginConfig;
import org.bukkit.plugin.java.JavaPlugin;
public class Debug {
@@ -11,18 +11,18 @@ public class Debug {
}
public static void info(String message) {
if(ConfigUtil.debug) main.getLogger().info(message);
if(PluginConfig.isDebug()) main.getLogger().info(message);
}
public static void warn(String message) {
if(ConfigUtil.debug) main.getLogger().warning(message);
if(PluginConfig.isDebug()) main.getLogger().warning(message);
}
public static void error(String message) {
if(ConfigUtil.debug) main.getLogger().severe(message);
if(PluginConfig.isDebug()) main.getLogger().severe(message);
}
public static void stack(Exception e) {
if(ConfigUtil.debug) e.printStackTrace();
if(PluginConfig.isDebug()) e.printStackTrace();
}
}

View File

@@ -2,7 +2,8 @@ package com.dfsek.terra;
import com.dfsek.terra.command.TerraCommand;
import com.dfsek.terra.command.structure.LocateCommand;
import com.dfsek.terra.config.base.ConfigUtil;
import com.dfsek.terra.config.base.ConfigPack;
import com.dfsek.terra.config.base.PluginConfig;
import com.dfsek.terra.config.base.WorldConfig;
import com.dfsek.terra.config.lang.LangUtil;
import com.dfsek.terra.generation.TerraChunkGenerator;
@@ -39,10 +40,17 @@ public class Terra extends GaeaPlugin {
@Override
public void onEnable() {
instance = this;
saveDefaultConfig();
Metrics metrics = new Metrics(this, 9017);
metrics.addCustomChart(new Metrics.SingleLineChart("worlds", TerraWorld::numWorlds));
Debug.setMain(this);
ConfigUtil.loadConfig(this);
PluginConfig.load(this);
LangUtil.load(PluginConfig.getLanguage(), this); // Load language.
ConfigPack.loadAll(this);
TerraWorld.invalidate();
PluginCommand c = Objects.requireNonNull(getCommand("terra"));
TerraCommand command = new TerraCommand(this);
@@ -54,8 +62,9 @@ public class Terra extends GaeaPlugin {
locatePl.setExecutor(locate);
locatePl.setTabCompleter(locate);
saveDefaultConfig();
Bukkit.getScheduler().scheduleAsyncRepeatingTask(this, TerraChunkGenerator::saveAll, ConfigUtil.dataSave, ConfigUtil.dataSave);
long save = PluginConfig.getDataSaveInterval();
Bukkit.getScheduler().scheduleAsyncRepeatingTask(this, TerraChunkGenerator::saveAll, save, save);
Bukkit.getPluginManager().registerEvents(new EventListener(this), this);
PaperUtil.checkPaper(this);
}
@@ -71,7 +80,7 @@ public class Terra extends GaeaPlugin {
@Override
public boolean isDebug() {
return ConfigUtil.debug;
return PluginConfig.isDebug();
}
@Override

View File

@@ -1,7 +1,7 @@
package com.dfsek.terra.async;
import com.dfsek.terra.biome.grid.TerraBiomeGrid;
import com.dfsek.terra.config.base.ConfigUtil;
import com.dfsek.terra.config.base.PluginConfig;
import org.bukkit.Location;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;
@@ -28,11 +28,12 @@ public class AsyncBiomeFinder extends AsyncFeatureFinder<Biome> {
*/
@Override
public boolean isValid(int x, int z, Biome target) {
return getGrid().getBiome(x * ConfigUtil.biomeSearchRes, z * ConfigUtil.biomeSearchRes, GenerationPhase.POST_GEN).equals(target);
int res = PluginConfig.getBiomeSearchResolution();
return getGrid().getBiome(x * res, z * res, GenerationPhase.POST_GEN).equals(target);
}
@Override
public Vector finalizeVector(Vector orig) {
return orig.multiply(ConfigUtil.biomeSearchRes);
return orig.multiply(PluginConfig.getBiomeSearchResolution());
}
}

View File

@@ -5,7 +5,7 @@ import com.dfsek.terra.biome.UserDefinedBiome;
import com.dfsek.terra.biome.postprocessing.CoordinatePerturb;
import com.dfsek.terra.biome.postprocessing.ErosionNoise;
import com.dfsek.terra.config.base.ConfigPack;
import com.dfsek.terra.config.base.ConfigUtil;
import com.dfsek.terra.config.base.PluginConfig;
import com.dfsek.terra.config.lang.LangUtil;
import com.dfsek.terra.procgen.math.Vector2;
import org.bukkit.Location;
@@ -53,7 +53,7 @@ public class TerraBiomeGrid extends BiomeGrid {
try {
b = (UserDefinedBiome) zone.getGrid(xp, zp).getBiome(xp, zp, phase);
} catch(NullPointerException e) {
if(ConfigUtil.debug) e.printStackTrace();
if(PluginConfig.isDebug()) e.printStackTrace();
if(failNum % 256 == 0)
LangUtil.log("error.severe-config", Level.SEVERE, String.valueOf(x), String.valueOf(z));
failNum++;

View File

@@ -1,7 +1,8 @@
package com.dfsek.terra.command;
import com.dfsek.terra.Terra;
import com.dfsek.terra.config.base.ConfigUtil;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.config.base.ConfigPack;
import com.dfsek.terra.config.base.PluginConfig;
import com.dfsek.terra.config.lang.LangUtil;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
@@ -28,7 +29,10 @@ public class ReloadCommand extends Command implements DebugCommand {
@Override
public boolean execute(@NotNull CommandSender sender, org.bukkit.command.@NotNull Command command, @NotNull String label, @NotNull String[] args) {
ConfigUtil.loadConfig(Terra.getInstance());
PluginConfig.load(getMain());
LangUtil.load(PluginConfig.getLanguage(), getMain()); // Load language.
ConfigPack.loadAll(getMain());
TerraWorld.invalidate();
LangUtil.send("command.reload", sender);
return true;
}

View File

@@ -1,7 +1,7 @@
package com.dfsek.terra.command.image.gui;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.config.base.ConfigUtil;
import com.dfsek.terra.config.base.PluginConfig;
import com.dfsek.terra.config.lang.LangUtil;
import com.dfsek.terra.image.ImageLoader;
import org.bukkit.World;
@@ -21,7 +21,7 @@ public class RawGUICommand extends WorldCommand {
@Override
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
if(!ConfigUtil.debug) {
if(!PluginConfig.isDebug()) {
LangUtil.send("command.image.gui.debug", sender);
return true;
}

View File

@@ -1,7 +1,7 @@
package com.dfsek.terra.command.image.gui;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.config.base.ConfigUtil;
import com.dfsek.terra.config.base.PluginConfig;
import com.dfsek.terra.config.lang.LangUtil;
import com.dfsek.terra.image.ImageLoader;
import org.bukkit.World;
@@ -21,7 +21,7 @@ public class StepGUICommand extends WorldCommand {
@Override
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) {
if(!ConfigUtil.debug) {
if(!PluginConfig.isDebug()) {
LangUtil.send("command.image.gui.debug", sender);
return true;
}

View File

@@ -1,7 +1,7 @@
package com.dfsek.terra.config;
import com.dfsek.terra.config.base.ConfigPack;
import com.dfsek.terra.config.base.ConfigUtil;
import com.dfsek.terra.config.base.PluginConfig;
import com.dfsek.terra.config.lang.LangUtil;
import org.apache.commons.io.FilenameUtils;
@@ -40,7 +40,7 @@ public class ConfigLoader {
e.printStackTrace();
LangUtil.log("config.error.generic", Level.SEVERE, path.toString());
} catch(IllegalArgumentException | InvocationTargetException e) {
if(ConfigUtil.debug) e.printStackTrace();
if(PluginConfig.isDebug()) e.printStackTrace();
LangUtil.log("config.error.file", Level.SEVERE, path.toString(), e.getMessage());
}
});

View File

@@ -1,65 +1,17 @@
package com.dfsek.terra.config.base;
import com.dfsek.terra.Debug;
import com.dfsek.terra.Terra;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.config.exception.ConfigException;
import com.dfsek.terra.config.lang.LangUtil;
import com.dfsek.terra.util.TagUtil;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import org.polydev.gaea.util.JarUtil;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.time.Duration;
import java.util.EnumSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.jar.JarFile;
import java.util.logging.Logger;
public final class ConfigUtil {
public static boolean debug;
public static long dataSave; // Period of population data saving, in ticks.
public static boolean masterDisableCaves;
public static int biomeSearchRes;
public static int cacheSize;
public static void loadConfig(JavaPlugin main) {
main.saveDefaultConfig();
main.reloadConfig();
FileConfiguration config = main.getConfig();
LangUtil.load(config.getString("language", "en_us"), main);
debug = config.getBoolean("debug", false);
dataSave = Duration.parse(Objects.requireNonNull(config.getString("data-save", "PT6M"))).toMillis() / 20L;
masterDisableCaves = config.getBoolean("master-disable.caves", false);
biomeSearchRes = config.getInt("biome-search-resolution", 4);
cacheSize = config.getInt("cache-size", 384);
if(config.getBoolean("dump-default", true)) {
try(JarFile jar = new JarFile(new File(Terra.class.getProtectionDomain().getCodeSource().getLocation().toURI()))) {
JarUtil.copyResourcesToDirectory(jar, "packs", new File(main.getDataFolder(), "packs").toString());
} catch(IOException | URISyntaxException e) {
Debug.error("Failed to dump default config files!");
e.printStackTrace();
Debug.error("Report this to Terra!");
}
}
Logger logger = main.getLogger();
logger.info("Loading config values");
ConfigPack.loadAll(main);
TerraWorld.invalidate();
}
public static Set<Material> toBlockData(List<String> list, String phase, String id) throws InvalidConfigurationException {
Set<Material> bl = EnumSet.noneOf(Material.class);
for(String s : list) {

View File

@@ -0,0 +1,93 @@
package com.dfsek.terra.config.base;
import com.dfsek.tectonic.annotations.Default;
import com.dfsek.tectonic.annotations.Value;
import com.dfsek.tectonic.config.ConfigTemplate;
import com.dfsek.tectonic.exception.ConfigException;
import com.dfsek.tectonic.loading.ConfigLoader;
import com.dfsek.terra.Debug;
import com.dfsek.terra.Terra;
import org.polydev.gaea.GaeaPlugin;
import org.polydev.gaea.util.JarUtil;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URISyntaxException;
import java.time.Duration;
import java.util.jar.JarFile;
import java.util.logging.Logger;
@SuppressWarnings("FieldMayBeFinal")
public class PluginConfig implements ConfigTemplate {
private static final PluginConfig singleton = new PluginConfig();
private static boolean loaded = false;
@Value("debug")
@Default
private boolean debug = false;
@Value("language")
@Default
private String language = "en_us";
@Value("data-save")
@Default
private Duration dataSave = Duration.parse("PT6M");
@Value("biome-search-resolution")
@Default
private int biomeSearch = 4;
@Value("cache-size")
@Default
private int cacheSize = 384;
@Value("dump-default")
@Default
private boolean dumpDefaultConfig = true;
private PluginConfig() {
}
public static void load(GaeaPlugin main) {
Logger logger = main.getLogger();
logger.info("Loading config values");
try(FileInputStream file = new FileInputStream(new File(main.getDataFolder(), "config.yml"))) {
ConfigLoader loader = new ConfigLoader();
loader.load(singleton, file);
if(singleton.dumpDefaultConfig && !loaded) { // Don't dump default config if already loaded.
try(JarFile jar = new JarFile(new File(Terra.class.getProtectionDomain().getCodeSource().getLocation().toURI()))) {
JarUtil.copyResourcesToDirectory(jar, "packs", new File(main.getDataFolder(), "packs").toString());
} catch(IOException | URISyntaxException e) {
Debug.error("Failed to dump default config files!");
e.printStackTrace();
Debug.error("Report this to Terra!");
}
}
loaded = true;
} catch(ConfigException | IOException e) {
e.printStackTrace();
}
}
public static String getLanguage() {
return singleton.language;
}
public static boolean isDebug() {
return singleton.debug;
}
public static long getDataSaveInterval() {
return singleton.dataSave.toMillis() / 20L;
}
public static int getBiomeSearchResolution() {
return singleton.biomeSearch;
}
public static int getCacheSize() {
return singleton.cacheSize;
}
}

View File

@@ -4,6 +4,7 @@ import com.dfsek.terra.Debug;
import com.dfsek.terra.config.TerraConfig;
import com.dfsek.terra.config.base.ConfigPack;
import com.dfsek.terra.config.base.ConfigUtil;
import com.dfsek.terra.config.base.PluginConfig;
import com.dfsek.terra.config.exception.ConfigException;
import com.dfsek.terra.config.exception.NotFoundException;
import com.dfsek.terra.procgen.math.Vector2;
@@ -54,7 +55,7 @@ public class TreeConfig extends TerraConfig implements Tree {
}
}
} catch(IOException | NullPointerException e) {
if(ConfigUtil.debug) {
if(PluginConfig.isDebug()) {
e.printStackTrace();
}
throw new NotFoundException("Tree Structure", getString("file"), getID());

View File

@@ -2,7 +2,7 @@ package com.dfsek.terra.config.genconfig.biome;
import com.dfsek.terra.config.TerraConfig;
import com.dfsek.terra.config.TerraConfigSection;
import com.dfsek.terra.config.base.ConfigUtil;
import com.dfsek.terra.config.base.PluginConfig;
import com.dfsek.terra.config.exception.ConfigException;
import com.dfsek.terra.config.exception.NotFoundException;
import com.dfsek.terra.config.genconfig.OreConfig;
@@ -30,7 +30,7 @@ public class BiomeOreConfig extends TerraConfigSection {
oreHeights.put(ore, new Range(((ConfigurationSection) m.getValue()).getInt("min-height"), ((ConfigurationSection) m.getValue()).getInt("max-height")));
}
} catch(ClassCastException e) {
if(ConfigUtil.debug) e.printStackTrace();
if(PluginConfig.isDebug()) e.printStackTrace();
throw new ConfigException("Unable to parse Flora configuration! Check YAML syntax.", parent.getID());
}
}

View File

@@ -2,7 +2,7 @@ package com.dfsek.terra.config.genconfig.biome;
import com.dfsek.terra.config.TerraConfig;
import com.dfsek.terra.config.TerraConfigSection;
import com.dfsek.terra.config.base.ConfigUtil;
import com.dfsek.terra.config.base.PluginConfig;
import com.dfsek.terra.config.exception.ConfigException;
import org.bukkit.configuration.InvalidConfigurationException;
import org.polydev.gaea.math.Range;
@@ -31,7 +31,7 @@ public class BiomeSnowConfig extends TerraConfigSection {
}
}
} catch(ClassCastException e) {
if(ConfigUtil.debug) e.printStackTrace();
if(PluginConfig.isDebug()) e.printStackTrace();
throw new ConfigException("Unable to parse Snow configuration! Check YAML syntax.", parent.getID());
}
}

View File

@@ -3,7 +3,7 @@ package com.dfsek.terra.config.genconfig.structure;
import com.dfsek.terra.Debug;
import com.dfsek.terra.config.TerraConfig;
import com.dfsek.terra.config.base.ConfigPack;
import com.dfsek.terra.config.base.ConfigUtil;
import com.dfsek.terra.config.base.PluginConfig;
import com.dfsek.terra.config.exception.ConfigException;
import com.dfsek.terra.config.exception.NotFoundException;
import com.dfsek.terra.procgen.GridSpawn;
@@ -55,7 +55,7 @@ public class StructureConfig extends TerraConfig {
}
}
} catch(IOException | NullPointerException e) {
if(ConfigUtil.debug) {
if(PluginConfig.isDebug()) {
e.printStackTrace();
}
throw new NotFoundException("Structure", getString("file"), getID());

View File

@@ -3,7 +3,7 @@ package com.dfsek.terra.image;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.biome.BiomeZone;
import com.dfsek.terra.biome.grid.TerraBiomeGrid;
import com.dfsek.terra.config.base.ConfigUtil;
import com.dfsek.terra.config.base.PluginConfig;
import com.dfsek.terra.debug.gui.DebugGUI;
import net.jafama.FastMath;
import org.bukkit.World;
@@ -26,7 +26,7 @@ public class ImageLoader {
}
public static void debugWorld(boolean genStep, World w) {
if(!ConfigUtil.debug) return;
if(!PluginConfig.isDebug()) return;
BufferedImage newImg = new WorldImageGenerator(w, 1024, 1024).drawWorld(0, 0).getDraw();
if(genStep) newImg = redrawStepped(newImg, w, Align.CENTER);
DebugGUI debugGUI = new DebugGUI(newImg);
@@ -61,7 +61,7 @@ public class ImageLoader {
}
public void debug(boolean genStep, World w) {
if(!ConfigUtil.debug) return;
if(!PluginConfig.isDebug()) return;
BufferedImage newImg = copyImage(image);
if(genStep) {
newImg = redrawStepped(image, w, align);

View File

@@ -1,6 +1,6 @@
package com.dfsek.terra.math;
import com.dfsek.terra.config.base.ConfigUtil;
import com.dfsek.terra.config.base.PluginConfig;
import com.dfsek.terra.generation.config.NoiseBuilder;
import com.dfsek.terra.util.hash.HashMapDoubleDouble;
import org.polydev.gaea.math.FastNoiseLite;
@@ -43,7 +43,7 @@ public class NoiseFunction2 implements NoiseFunction {
private static class Cache extends HashMapDoubleDouble {
private static final long serialVersionUID = 8915092734723467010L;
private static final int cacheSize = ConfigUtil.cacheSize;
private static final int cacheSize = PluginConfig.getCacheSize();
public double get(FastNoiseLite noise, double x, double z) {
double xx = x >= 0 ? x * 2 : x * -2 - 1;

View File

@@ -3,7 +3,6 @@ package com.dfsek.terra.population;
import com.dfsek.terra.TerraProfiler;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.config.base.ConfigPack;
import com.dfsek.terra.config.base.ConfigUtil;
import com.dfsek.terra.config.genconfig.CarverConfig;
import com.dfsek.terra.util.PopulationUtil;
import org.bukkit.Chunk;
@@ -32,7 +31,7 @@ public class CavePopulator extends BlockPopulator {
@SuppressWarnings("try")
@Override
public void populate(@NotNull World world, @NotNull Random r, @NotNull Chunk chunk) {
if(ConfigUtil.masterDisableCaves) return;
//if(ConfigUtil.masterDisableCaves) return;
try(ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("CaveTime")) {
Random random = PopulationUtil.getRandom(chunk);
TerraWorld tw = TerraWorld.getWorld(world);

View File

@@ -4,7 +4,7 @@ import com.dfsek.terra.TerraProfiler;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.biome.UserDefinedBiome;
import com.dfsek.terra.biome.grid.TerraBiomeGrid;
import com.dfsek.terra.config.base.ConfigUtil;
import com.dfsek.terra.config.base.PluginConfig;
import com.dfsek.terra.config.genconfig.biome.BiomeConfig;
import com.dfsek.terra.util.DataUtil;
import org.bukkit.Bukkit;
@@ -43,7 +43,7 @@ public class SnowPopulator extends GaeaBlockPopulator {
|| name.equals("pane")) blacklistSpawn.add(m);
}
blacklistSpawn.add(Material.END_STONE);
if(ConfigUtil.debug)
if(PluginConfig.isDebug())
Bukkit.getLogger().info("Added " + blacklistSpawn.size() + " materials to snow blacklist");
}