mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 10:30:42 +00:00
hold PluginConfig instance in Terra plugin instance
This commit is contained in:
@@ -25,7 +25,7 @@ java {
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
val versionObj = Version("2", "0", "2", true)
|
||||
val versionObj = Version("2", "1", "0", true)
|
||||
|
||||
version = versionObj
|
||||
|
||||
|
||||
@@ -69,6 +69,7 @@ public class Terra extends GaeaPlugin {
|
||||
private final Map<World, TerraWorld> worldMap = new HashMap<>();
|
||||
private final Map<String, ConfigPack> worlds = new HashMap<>();
|
||||
private final ConfigRegistry registry = new ConfigRegistry();
|
||||
private final PluginConfig config = new PluginConfig();
|
||||
|
||||
public void invalidate() {
|
||||
worldMap.clear();
|
||||
@@ -90,8 +91,9 @@ public class Terra extends GaeaPlugin {
|
||||
Metrics metrics = new Metrics(this, 9017); // Set up bStats.
|
||||
metrics.addCustomChart(new Metrics.SingleLineChart("worlds", worldMap::size)); // World number chart.
|
||||
|
||||
PluginConfig.load(this); // Load master config.yml
|
||||
LangUtil.load(PluginConfig.getLanguage(), this); // Load language.
|
||||
config.load(this); // Load master config.yml
|
||||
LangUtil.load(config.getLanguage(), this); // Load language.
|
||||
Debug.setDebug(isDebug());
|
||||
|
||||
registry.loadAll(this); // Load all config packs.
|
||||
|
||||
@@ -106,7 +108,7 @@ public class Terra extends GaeaPlugin {
|
||||
locatePl.setTabCompleter(locate);
|
||||
|
||||
|
||||
long save = PluginConfig.getDataSaveInterval();
|
||||
long save = config.getDataSaveInterval();
|
||||
Bukkit.getScheduler().runTaskTimerAsynchronously(this, TerraChunkGenerator::saveAll, save, save); // Schedule population data saving
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(new EventListener(this), this); // Register master event listener
|
||||
@@ -126,7 +128,7 @@ public class Terra extends GaeaPlugin {
|
||||
|
||||
@Override
|
||||
public boolean isDebug() {
|
||||
return PluginConfig.isDebug();
|
||||
return config.isDebug();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -171,6 +173,16 @@ public class Terra extends GaeaPlugin {
|
||||
}
|
||||
|
||||
public TerraWorld getWorld(World w) {
|
||||
if(!(w.getGenerator() instanceof TerraChunkGenerator)) throw new IllegalArgumentException("Not a Terra world!");
|
||||
if(!worlds.containsKey(w.getName())) {
|
||||
getLogger().warning("Unexpected world load detected: \"" + w.getName() + "\"");
|
||||
return new TerraWorld(w, ((TerraChunkGenerator) w.getGenerator()).getConfigPack());
|
||||
}
|
||||
return worldMap.computeIfAbsent(w, world -> new TerraWorld(w, worlds.get(w.getName())));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public PluginConfig getTerraConfig() {
|
||||
return config;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.dfsek.terra.async;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.biome.grid.master.TerraBiomeGrid;
|
||||
import com.dfsek.terra.config.base.PluginConfig;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -29,12 +28,12 @@ public class AsyncBiomeFinder extends AsyncFeatureFinder<Biome> {
|
||||
*/
|
||||
@Override
|
||||
public boolean isValid(int x, int z, Biome target) {
|
||||
int res = PluginConfig.getBiomeSearchResolution();
|
||||
int res = main.getTerraConfig().getBiomeSearchResolution();
|
||||
return getGrid().getBiome(x * res, z * res, GenerationPhase.POST_GEN).equals(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector finalizeVector(Vector orig) {
|
||||
return orig.multiply(PluginConfig.getBiomeSearchResolution());
|
||||
return orig.multiply(main.getTerraConfig().getBiomeSearchResolution());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.dfsek.terra.carving;
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.biome.grid.master.TerraBiomeGrid;
|
||||
import com.dfsek.terra.config.base.PluginConfig;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.polydev.gaea.biome.Biome;
|
||||
@@ -30,7 +29,7 @@ public class CarverCache {
|
||||
}
|
||||
|
||||
public List<Worm.WormPoint> getPoints(int chunkX, int chunkZ, UserDefinedCarver carver) {
|
||||
if(carvers.size() > PluginConfig.getCacheSize() * 2) carvers.clear();
|
||||
if(carvers.size() > main.getTerraConfig().getCacheSize() * 2) carvers.clear();
|
||||
return carvers.computeIfAbsent((((long) chunkX) << 32) | (chunkZ & 0xffffffffL), key -> {
|
||||
TerraBiomeGrid grid = main.getWorld(w).getGrid();
|
||||
if(carver.isChunkCarved(w, chunkX, chunkZ, new FastRandom(MathUtil.getCarverChunkSeed(chunkX, chunkZ, w.getSeed() + carver.hashCode())))) {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.dfsek.terra.command;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
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,8 +27,8 @@ 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) {
|
||||
PluginConfig.load(getMain());
|
||||
LangUtil.load(PluginConfig.getLanguage(), getMain()); // Load language.
|
||||
((Terra) getMain()).getTerraConfig().load(getMain());
|
||||
LangUtil.load(((Terra) getMain()).getTerraConfig().getLanguage(), getMain()); // Load language.
|
||||
if(!((Terra) getMain()).getRegistry().loadAll((Terra) getMain())) LangUtil.send("command.reload-error", sender);
|
||||
((Terra) getMain()).invalidate();
|
||||
LangUtil.send("command.reload", sender);
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.dfsek.terra.command.biome;
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.async.AsyncBiomeFinder;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.config.base.PluginConfig;
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import com.dfsek.terra.generation.TerraChunkGenerator;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -44,7 +43,7 @@ public class BiomeLocateCommand extends WorldCommand {
|
||||
LangUtil.send("command.biome.invalid", sender, id);
|
||||
return true;
|
||||
}
|
||||
Bukkit.getScheduler().runTaskAsynchronously(getMain(), new AsyncBiomeFinder(((Terra) getMain()).getWorld(world).getGrid(), b, sender.getLocation().clone().multiply((1D / PluginConfig.getBiomeSearchResolution())), 0, maxRadius, location -> {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(getMain(), new AsyncBiomeFinder(((Terra) getMain()).getWorld(world).getGrid(), b, sender.getLocation().clone().multiply((1D / ((Terra) getMain()).getTerraConfig().getBiomeSearchResolution())), 0, maxRadius, location -> {
|
||||
if(location != null) {
|
||||
LangUtil.send("command.biome.biome-found", sender, String.valueOf(location.getBlockX()), String.valueOf(location.getBlockZ()));
|
||||
if(tp) {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.dfsek.terra.command.image.gui;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
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 +20,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(!PluginConfig.isDebug()) {
|
||||
if(!getMain().isDebug()) {
|
||||
LangUtil.send("command.image.gui.debug", sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.dfsek.terra.command.image.gui;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
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 +20,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(!PluginConfig.isDebug()) {
|
||||
if(!getMain().isDebug()) {
|
||||
LangUtil.send("command.image.gui.debug", sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -20,9 +20,6 @@ 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;
|
||||
@@ -47,16 +44,13 @@ public class PluginConfig implements ConfigTemplate {
|
||||
@Default
|
||||
private boolean dumpDefaultConfig = true;
|
||||
|
||||
private PluginConfig() {
|
||||
}
|
||||
|
||||
public static void load(GaeaPlugin main) {
|
||||
public 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.
|
||||
loader.load(this, file);
|
||||
if(dumpDefaultConfig) { // 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) {
|
||||
@@ -65,30 +59,29 @@ public class PluginConfig implements ConfigTemplate {
|
||||
Debug.error("Report this to Terra!");
|
||||
}
|
||||
}
|
||||
loaded = true;
|
||||
} catch(ConfigException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
logger.info("Debug: " + isDebug());
|
||||
}
|
||||
|
||||
public static String getLanguage() {
|
||||
return singleton.language;
|
||||
public String getLanguage() {
|
||||
return language;
|
||||
}
|
||||
|
||||
public static boolean isDebug() {
|
||||
return singleton.debug;
|
||||
public boolean isDebug() {
|
||||
return debug;
|
||||
}
|
||||
|
||||
public static long getDataSaveInterval() {
|
||||
return singleton.dataSave.toMillis() / 20L;
|
||||
public long getDataSaveInterval() {
|
||||
return dataSave.toMillis() / 20L;
|
||||
}
|
||||
|
||||
public static int getBiomeSearchResolution() {
|
||||
return singleton.biomeSearch;
|
||||
public int getBiomeSearchResolution() {
|
||||
return biomeSearch;
|
||||
}
|
||||
|
||||
public static int getCacheSize() {
|
||||
return singleton.cacheSize;
|
||||
public int getCacheSize() {
|
||||
return cacheSize;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,29 +1,36 @@
|
||||
package com.dfsek.terra.debug;
|
||||
|
||||
import com.dfsek.terra.config.base.PluginConfig;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class Debug {
|
||||
public static Logger logger;
|
||||
private static Logger logger;
|
||||
private static boolean debug = false;
|
||||
|
||||
public static boolean isDebug() {
|
||||
return debug;
|
||||
}
|
||||
|
||||
public static void setDebug(boolean debug) {
|
||||
Debug.debug = debug;
|
||||
}
|
||||
|
||||
public static void setLogger(Logger logger) {
|
||||
Debug.logger = logger;
|
||||
}
|
||||
|
||||
public static void info(String message) {
|
||||
if(PluginConfig.isDebug()) logger.info(message);
|
||||
if(debug) logger.info(message);
|
||||
}
|
||||
|
||||
public static void warn(String message) {
|
||||
if(PluginConfig.isDebug()) logger.warning(message);
|
||||
if(debug) logger.warning(message);
|
||||
}
|
||||
|
||||
public static void error(String message) {
|
||||
if(PluginConfig.isDebug()) logger.severe(message);
|
||||
if(debug) logger.severe(message);
|
||||
}
|
||||
|
||||
public static void stack(Exception e) {
|
||||
if(PluginConfig.isDebug()) e.printStackTrace();
|
||||
if(debug) e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,11 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
|
||||
private boolean needsLoad = true;
|
||||
private final Terra main;
|
||||
|
||||
public ConfigPack getConfigPack() {
|
||||
return configPack;
|
||||
}
|
||||
|
||||
|
||||
public TerraChunkGenerator(ConfigPack c, Terra main) {
|
||||
super(ChunkInterpolator.InterpolationType.TRILINEAR);
|
||||
popMan = new PopulationManager(main);
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.dfsek.terra.image;
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.biome.BiomeZone;
|
||||
import com.dfsek.terra.biome.grid.master.TerraBiomeGrid;
|
||||
import com.dfsek.terra.config.base.PluginConfig;
|
||||
import com.dfsek.terra.debug.gui.DebugGUI;
|
||||
import net.jafama.FastMath;
|
||||
import org.bukkit.World;
|
||||
@@ -26,7 +25,7 @@ public class ImageLoader {
|
||||
}
|
||||
|
||||
public static void debugWorld(boolean genStep, World w, Terra main) {
|
||||
if(!PluginConfig.isDebug()) return;
|
||||
if(!main.isDebug()) return;
|
||||
BufferedImage newImg = new WorldImageGenerator(w, 1024, 1024, main).drawWorld(0, 0).getDraw();
|
||||
if(genStep) newImg = redrawStepped(newImg, w, Align.CENTER, main);
|
||||
DebugGUI debugGUI = new DebugGUI(newImg, main);
|
||||
@@ -61,7 +60,7 @@ public class ImageLoader {
|
||||
}
|
||||
|
||||
public void debug(boolean genStep, World w, Terra main) {
|
||||
if(!PluginConfig.isDebug()) return;
|
||||
if(!main.isDebug()) return;
|
||||
BufferedImage newImg = copyImage(image);
|
||||
if(genStep) {
|
||||
newImg = redrawStepped(image, w, align, main);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.dfsek.terra.math;
|
||||
|
||||
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 +42,7 @@ public class NoiseFunction2 implements NoiseFunction {
|
||||
|
||||
private static class Cache extends HashMapDoubleDouble {
|
||||
private static final long serialVersionUID = 8915092734723467010L;
|
||||
private static final int cacheSize = PluginConfig.getCacheSize();
|
||||
private static final int cacheSize = 384;
|
||||
|
||||
public double get(FastNoiseLite noise, double x, double z) {
|
||||
double xx = x >= 0 ? x * 2 : x * -2 - 1;
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
Reference in New Issue
Block a user