mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 10:30:42 +00:00
Actually load configs on startup
This commit is contained in:
Binary file not shown.
@@ -6,6 +6,7 @@ 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;
|
||||
import com.dfsek.terra.registry.ConfigRegistry;
|
||||
import com.dfsek.terra.util.PaperUtil;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -49,6 +50,7 @@ public class Terra extends GaeaPlugin {
|
||||
PluginConfig.load(this);
|
||||
LangUtil.load(PluginConfig.getLanguage(), this); // Load language.
|
||||
TerraWorld.invalidate();
|
||||
ConfigRegistry.loadAll(this);
|
||||
|
||||
PluginCommand c = Objects.requireNonNull(getCommand("terra"));
|
||||
TerraCommand command = new TerraCommand(this);
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.dfsek.terra.config.base;
|
||||
import com.dfsek.tectonic.abstraction.AbstractConfigLoader;
|
||||
import com.dfsek.tectonic.exception.ConfigException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.terra.Debug;
|
||||
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.carving.UserDefinedCarver;
|
||||
import com.dfsek.terra.config.builder.BiomeGridBuilder;
|
||||
@@ -35,7 +36,6 @@ import java.util.logging.Level;
|
||||
* Represents a Terra configuration pack.
|
||||
*/
|
||||
public class ConfigPack {
|
||||
private static final Map<String, ConfigPack> configs = new HashMap<>();
|
||||
private final ConfigPackTemplate template = new ConfigPackTemplate();
|
||||
private final Map<String, UserDefinedBiome> biomes = new HashMap<>();
|
||||
private final Map<String, BiomeGridBuilder> biomeGrids = new HashMap<>();
|
||||
@@ -60,31 +60,35 @@ public class ConfigPack {
|
||||
AbstractConfigLoader abstractConfigLoader = new AbstractConfigLoader();
|
||||
|
||||
List<StructureTemplate> structureTemplates = abstractConfigLoader.load(ConfigUtil.loadFromPath(new File(folder, "structures/single").toPath()), StructureTemplate::new);
|
||||
structureTemplates.forEach(structure -> structures.put(structure.getId(), structure));
|
||||
structureTemplates.forEach(structure -> {
|
||||
structures.put(structure.getID(), structure);
|
||||
Debug.info("Loaded structure " + structure.getID());
|
||||
});
|
||||
|
||||
List<CarverTemplate> carverTemplates = abstractConfigLoader.load(ConfigUtil.loadFromPath(new File(folder, "carving").toPath()), CarverTemplate::new);
|
||||
CarverFactory carverFactory = new CarverFactory();
|
||||
carverTemplates.forEach(carver -> carvers.put(carver.getId(), carverFactory.build(carver)));
|
||||
carverTemplates.forEach(carver -> {
|
||||
carvers.put(carver.getID(), carverFactory.build(carver));
|
||||
Debug.info("Loaded carver " + carver.getID());
|
||||
});
|
||||
|
||||
List<BiomeTemplate> biomeTemplates = abstractConfigLoader.load(ConfigUtil.loadFromPath(new File(folder, "biomes").toPath()), () -> new BiomeTemplate(this));
|
||||
BiomeFactory biomeFactory = new BiomeFactory();
|
||||
biomeTemplates.forEach(biome -> biomes.put(biome.getID(), biomeFactory.build(biome)));
|
||||
biomeTemplates.forEach(biome -> {
|
||||
biomes.put(biome.getID(), biomeFactory.build(biome));
|
||||
Debug.info("Loaded biome " + biome.getID());
|
||||
});
|
||||
|
||||
List<BiomeGridTemplate> biomeGridTemplates = abstractConfigLoader.load(ConfigUtil.loadFromPath(new File(folder, "grids").toPath()), BiomeGridTemplate::new);
|
||||
BiomeGridFactory biomeGridFactory = new BiomeGridFactory();
|
||||
biomeGridTemplates.forEach(grid -> biomeGrids.put(grid.getID(), biomeGridFactory.build(grid)));
|
||||
|
||||
|
||||
configs.put(template.getID(), this);
|
||||
|
||||
biomeGridTemplates.forEach(grid -> {
|
||||
biomeGrids.put(grid.getID(), biomeGridFactory.build(grid));
|
||||
Debug.info("Loaded BiomeGrid " + grid.getID());
|
||||
});
|
||||
|
||||
LangUtil.log("config-pack.loaded", Level.INFO, template.getID(), String.valueOf((System.nanoTime() - l) / 1000000D));
|
||||
}
|
||||
|
||||
public static ConfigPack fromID(String id) {
|
||||
return configs.get(id);
|
||||
}
|
||||
|
||||
public UserDefinedBiome getBiome(String id) {
|
||||
return biomes.get(id);
|
||||
}
|
||||
|
||||
@@ -69,6 +69,7 @@ public class PluginConfig implements ConfigTemplate {
|
||||
} catch(ConfigException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
logger.info("Debug: " + isDebug());
|
||||
}
|
||||
|
||||
public static String getLanguage() {
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
import com.dfsek.terra.Debug;
|
||||
import com.dfsek.terra.config.lang.LangUtil;
|
||||
import com.dfsek.terra.image.ImageLoader;
|
||||
import com.dfsek.terra.registry.ConfigRegistry;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
@@ -54,7 +55,7 @@ public class WorldConfig implements ConfigTemplate {
|
||||
// Get values from config.
|
||||
fromImage = config.getBoolean("image.enable", false);
|
||||
|
||||
tConfig = ConfigPack.fromID(configID);
|
||||
tConfig = ConfigRegistry.getRegistry().get(configID);
|
||||
|
||||
// Load image stuff
|
||||
try {
|
||||
|
||||
@@ -9,7 +9,7 @@ public class CarverFactory implements TerraFactory<CarverTemplate, UserDefinedCa
|
||||
double[] start = new double[] {config.getStartX(), config.getStartY(), config.getStartZ()};
|
||||
double[] mutate = new double[] {config.getMutateX(), config.getMutateY(), config.getMutateZ(), config.getMutateRadius()};
|
||||
double[] radius = new double[] {config.getRadMX(), config.getRadMY(), config.getRadMZ()};
|
||||
int hash = config.getId().hashCode();
|
||||
int hash = config.getID().hashCode();
|
||||
return new UserDefinedCarver(config.getHeight(), config.getRadius(), config.getLength(), start, mutate, radius, hash, config.getCutTop(), config.getCutBottom(), config);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ public class CarverTemplate implements ConfigTemplate {
|
||||
@Default
|
||||
private Set<Material> update = new HashSet<>();
|
||||
|
||||
public String getId() {
|
||||
public String getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ public class StructureTemplate implements ConfigTemplate {
|
||||
return loot;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
public String getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.dfsek.terra.registry;
|
||||
|
||||
import com.dfsek.tectonic.exception.ConfigException;
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.config.base.ConfigPack;
|
||||
|
||||
import java.io.File;
|
||||
@@ -9,8 +10,30 @@ import java.io.File;
|
||||
* Class to hold config packs
|
||||
*/
|
||||
public class ConfigRegistry extends TerraRegistry<ConfigPack> {
|
||||
private static ConfigRegistry singleton;
|
||||
|
||||
private ConfigRegistry() {
|
||||
|
||||
}
|
||||
|
||||
public static ConfigRegistry getRegistry() {
|
||||
if(singleton == null) singleton = new ConfigRegistry();
|
||||
return singleton;
|
||||
}
|
||||
|
||||
public void load(File folder) throws ConfigException {
|
||||
ConfigPack pack = new ConfigPack(folder);
|
||||
add(pack.getTemplate().getID(), pack);
|
||||
}
|
||||
|
||||
public static void loadAll(Terra main) {
|
||||
File packsFolder = new File(main.getDataFolder(), "packs");
|
||||
for(File dir : packsFolder.listFiles(File::isDirectory)) {
|
||||
try {
|
||||
getRegistry().load(dir);
|
||||
} catch(ConfigException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,8 +13,9 @@ import java.util.stream.Stream;
|
||||
public final class ConfigUtil {
|
||||
public static List<InputStream> loadFromPath(Path folder) {
|
||||
List<InputStream> streams = new ArrayList<>();
|
||||
folder.toFile().mkdirs();
|
||||
try(Stream<Path> paths = Files.walk(folder)) {
|
||||
paths.filter(Files::isRegularFile).filter(file -> file.endsWith(".yml")).forEach(file -> {
|
||||
paths.filter(Files::isRegularFile).filter(file -> file.toString().toLowerCase().endsWith(".yml")).forEach(file -> {
|
||||
try {
|
||||
streams.add(new FileInputStream(file.toFile()));
|
||||
} catch(FileNotFoundException e) {
|
||||
|
||||
Reference in New Issue
Block a user