Added config reader for generator settings

This commit is contained in:
Daniel 2019-05-02 20:46:47 +02:00
parent d7ea8e3ade
commit 679ee5e8f9
7 changed files with 81 additions and 76 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>de.butzlabben.world</groupId>
<artifactId>WorldSystem</artifactId>
<version>2.4.5</version>
<version>2.4.6</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.build.number>-</project.build.number>

View File

@ -220,16 +220,6 @@ public class WorldSettingsCommands {
// For fast worldcreating after reset
WorldCreator creator = new WorldCreator(worldname);
long seed = PluginConfig.getSeed();
World.Environment env = PluginConfig.getEnvironment();
WorldType type = PluginConfig.getWorldType();
if (seed != 0)
creator.seed(seed);
creator.type(type);
creator.environment(env);
String generator = PluginConfig.getGenerator();
if (!generator.trim().isEmpty())
creator.generator(generator);
sw.setCreating(true);
// For #16

View File

@ -176,38 +176,6 @@ public class PluginConfig {
return PlayerPositions.getInstance().injectPlayersLocation(player, location);
}
public static long getSeed() {
return getConfig().getLong("worldgeneration.seed");
}
public static Environment getEnvironment() {
YamlConfiguration cfg = getConfig();
String t = cfg.getString("worldgeneration.environment");
Environment e = Environment.NORMAL;
try {
e = Environment.valueOf(t.toUpperCase());
} catch (Exception ex) {
System.out.println("'" + t + "' is not a valid environment");
}
return e;
}
public static String getGenerator() {
return getConfig().getString("worldgeneration.generator");
}
public static WorldType getWorldType() {
YamlConfiguration cfg = getConfig();
String t = cfg.getString("worldgeneration.type");
WorldType wt = WorldType.NORMAL;
try {
wt = WorldType.valueOf(t.toUpperCase());
} catch (Exception e) {
System.err.println("'" + t + "' is not a valid worldtype");
}
return wt;
}
public static int getRequestExpire() {
return getConfig().getInt("request_expires", 20);
}
@ -238,21 +206,6 @@ public class PluginConfig {
return getConfig().getLong("delete_after");
}
public static WorldCreator getWorldCreator(String worldname) {
WorldCreator creator = new WorldCreator(worldname);
long seed = PluginConfig.getSeed();
Environment env = PluginConfig.getEnvironment();
WorldType type = PluginConfig.getWorldType();
if (seed != 0)
creator.seed(seed);
creator.type(type);
creator.environment(env);
String generator = PluginConfig.getGenerator();
if (!generator.trim().isEmpty())
creator.generator(generator);
return creator;
}
public static boolean useWorldSpawnLastLocation() {
return getConfig().getBoolean("worldspawn.use_last_location");
}

View File

@ -0,0 +1,29 @@
package de.butzlabben.world.wrapper;
import lombok.AllArgsConstructor;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.bukkit.WorldType;
@AllArgsConstructor
public class GeneratorSettings {
final long seed;
final World.Environment environment;
final WorldType type;
final String generator;
public WorldCreator asWorldCreator(String name) {
WorldCreator creator = new WorldCreator(name);
if (type != null)
creator.type(type);
if (environment != null)
creator.environment(environment);
if (seed != 0)
creator.seed(seed);
if (generator != null && !generator.trim().isEmpty())
creator.generator(generator);
return creator;
}
}

View File

@ -14,11 +14,13 @@ public class WorldTemplate {
private final OrcItem icon;
private final int slot;
private final int cost;
private final GeneratorSettings generatorSettings;
public WorldTemplate(String name, String permission, int cost) {
public WorldTemplate(String name, String permission, int cost, GeneratorSettings generatorSettings) {
this.name = name;
this.permission = permission;
this.cost = cost;
this.generatorSettings = generatorSettings;
this.icon = GuiConfig.getItem("worldchoose." + name);
this.slot = GuiConfig.getSlot("worldchoose." + name);

View File

@ -1,6 +1,8 @@
package de.butzlabben.world.wrapper;
import de.butzlabben.world.config.PluginConfig;
import org.bukkit.World;
import org.bukkit.WorldType;
import org.bukkit.configuration.ConfigurationSection;
import java.util.Collection;
@ -26,14 +28,24 @@ public class WorldTemplateProvider {
String name = section.getString(key + ".name");
String permission = null;
if (section.isString(key + ".permission"))
permission = section.getString(key + ".permission");
permission = section.getString(key + ".permission");
int cost = -1;
// Get money for #15 if needed
if (section.isInt(key + ".cost"))
cost = section.getInt(key + ".cost");
templates.put(name, new WorldTemplate(name, permission, cost));
GeneratorSettings settings = null;
if (section.contains(key + ".generator")) {
ConfigurationSection gSection = section.getConfigurationSection(key + ".generator");
long seed = gSection.getLong("seed", 0);
String env = gSection.getString("environment");
String type = gSection.getString("type");
String generator = gSection.getString("generator");
settings = new GeneratorSettings(seed, getEnvironment(env), getWorldType(type), generator);
}
templates.put(name, new WorldTemplate(name, permission, cost, settings));
}
}
@ -44,4 +56,22 @@ public class WorldTemplateProvider {
public Collection<WorldTemplate> getTemplates() {
return templates.values();
}
private World.Environment getEnvironment(String env) {
if (env == null)
return null;
try {
return World.Environment.valueOf(env);
} catch (Exception ignored) {}
return null;
}
private WorldType getWorldType(String type) {
if (type == null)
return null;
try {
return WorldType.valueOf(type);
} catch (Exception ignored) {}
return null;
}
}

View File

@ -33,6 +33,22 @@ worldtemplates:
# This amount will then with withdrawn from the player
cost: 100
# Options for random world generation
# Here you can configure the world generator of a template
generator:
# A seed for worldgeneration
# Set it to 0 for no seed-useage
seed: 0
# Environment for the world
# Valid inputs are 'NORMAL', 'NETHER' and 'THE_END'
environment: NORMAL
# Type of the world eg. flat, amplified, ...
# Valid types are 'NORMAL', 'VERSION_1_1', 'FLAT', 'AMPLIFIED', 'CUSTOMIZED' or 'LARGE_BIOMES'
type: NORMAL
# Put in here the name of a generator
# If you have one from one plugin
generator: ''
# If a confirm is needed before auto-update
need_confirm: true
@ -95,21 +111,6 @@ lagsystem:
garbagecollector:
use: false
period_in_minutes: 5
# Options for random world generation
worldgeneration:
# A seed for worldgeneration
# Set it to 0 for no seed-useage
seed: 0
# Environment for the world
# Valid inputs are 'NORMAL', 'NETHER' and 'THE_END'
environment: NORMAL
# Type of the world eg. flat, amplified, ...
# Valid types are 'NORMAL', 'VERSION_1_1', 'FLAT', 'AMPLIFIED', 'CUSTOMIZED' or 'LARGE_BIOMES'
type: NORMAL
# Put in here the name of a generator
# If you have one from one plugin
generator: ''
# Location where you will be teleported when you leave you world
spawn: