!Added IDs to WorldGenTemplates

This commit is contained in:
Indyuce 2020-04-29 20:29:30 +02:00
parent 503857569e
commit e529ab7139
2 changed files with 24 additions and 20 deletions

View File

@ -10,6 +10,7 @@ import org.bukkit.block.Biome;
import org.bukkit.configuration.ConfigurationSection;
public class WorldGenTemplate {
private final String id;
private final double chunkChance;
private final int minDepth, maxDepth, veinSize, veinCount;
@ -21,6 +22,7 @@ public class WorldGenTemplate {
public WorldGenTemplate(ConfigurationSection config) {
Validate.notNull(config, "Could not read gen template config");
id = config.getName().toLowerCase().replace(" ", "-").replace("_", "-");
config.getStringList("replace").forEach(str -> replaceable.add(Material.valueOf(str.toUpperCase().replace("-", "_").replace(" ", "_"))));
for (String world : config.getStringList("worlds"))
@ -43,6 +45,10 @@ public class WorldGenTemplate {
veinCount = config.getInt("vein-count");
}
public String getId() {
return id;
}
public double getChunkChance() {
return chunkChance;
}

View File

@ -57,9 +57,7 @@ public class WorldGenManager implements Listener {
@EventHandler
public void a(ChunkLoadEvent event) {
if (!event.isNewChunk())
return;
if (event.isNewChunk())
assigned.forEach((block, template) -> {
if (random.nextDouble() < template.getChunkChance())
for (int i = 0; i < template.getVeinCount(); i++) {
@ -89,10 +87,10 @@ public class WorldGenManager implements Listener {
FileConfiguration config = new ConfigFile("gen-templates").getConfig();
for (String key : config.getKeys(false))
try {
templates.put(key, new WorldGenTemplate(config.getConfigurationSection(key)));
WorldGenTemplate template = new WorldGenTemplate(config.getConfigurationSection(key));
templates.put(template.getId(), template);
} catch (IllegalArgumentException exception) {
MMOItems.plugin.getLogger().log(Level.WARNING, "An error occured when loading gen template '" + key + "': " + exception.getMessage());
}
}
}