diff --git a/pom.xml b/pom.xml
index 97cdbc8..c2d5afb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
4.0.0
de.butzlabben.world
WorldSystem
- 2.4.5
+ 2.4.6
UTF-8
-
diff --git a/src/main/java/de/butzlabben/world/command/WorldSettingsCommands.java b/src/main/java/de/butzlabben/world/command/WorldSettingsCommands.java
index ae947fc..8cc1abb 100644
--- a/src/main/java/de/butzlabben/world/command/WorldSettingsCommands.java
+++ b/src/main/java/de/butzlabben/world/command/WorldSettingsCommands.java
@@ -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
diff --git a/src/main/java/de/butzlabben/world/config/PluginConfig.java b/src/main/java/de/butzlabben/world/config/PluginConfig.java
index 3c5947e..6510230 100644
--- a/src/main/java/de/butzlabben/world/config/PluginConfig.java
+++ b/src/main/java/de/butzlabben/world/config/PluginConfig.java
@@ -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");
}
diff --git a/src/main/java/de/butzlabben/world/wrapper/GeneratorSettings.java b/src/main/java/de/butzlabben/world/wrapper/GeneratorSettings.java
new file mode 100644
index 0000000..c4adcd6
--- /dev/null
+++ b/src/main/java/de/butzlabben/world/wrapper/GeneratorSettings.java
@@ -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;
+ }
+}
diff --git a/src/main/java/de/butzlabben/world/wrapper/WorldTemplate.java b/src/main/java/de/butzlabben/world/wrapper/WorldTemplate.java
index 9c7303c..8686efe 100644
--- a/src/main/java/de/butzlabben/world/wrapper/WorldTemplate.java
+++ b/src/main/java/de/butzlabben/world/wrapper/WorldTemplate.java
@@ -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);
diff --git a/src/main/java/de/butzlabben/world/wrapper/WorldTemplateProvider.java b/src/main/java/de/butzlabben/world/wrapper/WorldTemplateProvider.java
index 305b041..4290452 100644
--- a/src/main/java/de/butzlabben/world/wrapper/WorldTemplateProvider.java
+++ b/src/main/java/de/butzlabben/world/wrapper/WorldTemplateProvider.java
@@ -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 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;
+ }
}
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
index 8c6192f..7023b9a 100644
--- a/src/main/resources/config.yml
+++ b/src/main/resources/config.yml
@@ -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: