mirror of
https://github.com/trainerlord/WorldSystem.git
synced 2024-12-10 14:33:33 +01:00
Added config reader for generator settings
This commit is contained in:
parent
d7ea8e3ade
commit
679ee5e8f9
2
pom.xml
2
pom.xml
@ -3,7 +3,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>de.butzlabben.world</groupId>
|
<groupId>de.butzlabben.world</groupId>
|
||||||
<artifactId>WorldSystem</artifactId>
|
<artifactId>WorldSystem</artifactId>
|
||||||
<version>2.4.5</version>
|
<version>2.4.6</version>
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<project.build.number>-</project.build.number>
|
<project.build.number>-</project.build.number>
|
||||||
|
@ -220,16 +220,6 @@ public class WorldSettingsCommands {
|
|||||||
|
|
||||||
// For fast worldcreating after reset
|
// For fast worldcreating after reset
|
||||||
WorldCreator creator = new WorldCreator(worldname);
|
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);
|
sw.setCreating(true);
|
||||||
// For #16
|
// For #16
|
||||||
|
@ -176,38 +176,6 @@ public class PluginConfig {
|
|||||||
return PlayerPositions.getInstance().injectPlayersLocation(player, location);
|
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() {
|
public static int getRequestExpire() {
|
||||||
return getConfig().getInt("request_expires", 20);
|
return getConfig().getInt("request_expires", 20);
|
||||||
}
|
}
|
||||||
@ -238,21 +206,6 @@ public class PluginConfig {
|
|||||||
return getConfig().getLong("delete_after");
|
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() {
|
public static boolean useWorldSpawnLastLocation() {
|
||||||
return getConfig().getBoolean("worldspawn.use_last_location");
|
return getConfig().getBoolean("worldspawn.use_last_location");
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -14,11 +14,13 @@ public class WorldTemplate {
|
|||||||
private final OrcItem icon;
|
private final OrcItem icon;
|
||||||
private final int slot;
|
private final int slot;
|
||||||
private final int cost;
|
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.name = name;
|
||||||
this.permission = permission;
|
this.permission = permission;
|
||||||
this.cost = cost;
|
this.cost = cost;
|
||||||
|
this.generatorSettings = generatorSettings;
|
||||||
|
|
||||||
this.icon = GuiConfig.getItem("worldchoose." + name);
|
this.icon = GuiConfig.getItem("worldchoose." + name);
|
||||||
this.slot = GuiConfig.getSlot("worldchoose." + name);
|
this.slot = GuiConfig.getSlot("worldchoose." + name);
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package de.butzlabben.world.wrapper;
|
package de.butzlabben.world.wrapper;
|
||||||
|
|
||||||
import de.butzlabben.world.config.PluginConfig;
|
import de.butzlabben.world.config.PluginConfig;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.WorldType;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@ -33,7 +35,17 @@ public class WorldTemplateProvider {
|
|||||||
if (section.isInt(key + ".cost"))
|
if (section.isInt(key + ".cost"))
|
||||||
cost = section.getInt(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() {
|
public Collection<WorldTemplate> getTemplates() {
|
||||||
return templates.values();
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,22 @@ worldtemplates:
|
|||||||
# This amount will then with withdrawn from the player
|
# This amount will then with withdrawn from the player
|
||||||
cost: 100
|
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
|
# If a confirm is needed before auto-update
|
||||||
need_confirm: true
|
need_confirm: true
|
||||||
|
|
||||||
@ -96,21 +112,6 @@ lagsystem:
|
|||||||
use: false
|
use: false
|
||||||
period_in_minutes: 5
|
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
|
# Location where you will be teleported when you leave you world
|
||||||
spawn:
|
spawn:
|
||||||
gamemode: 2
|
gamemode: 2
|
||||||
|
Loading…
Reference in New Issue
Block a user