From 4934e1b68b82eaaab20b3a784ae4d7a50c713cde Mon Sep 17 00:00:00 2001 From: BuildTools Date: Tue, 1 May 2018 17:57:16 +0200 Subject: [PATCH] Worlds on all server statistics + WorldGenerator settings added to config.yml --- WorldSystem/bin/config.yml | 12 +++++++ WorldSystem/bin/plugin.yml | 2 +- WorldSystem/src/config.yml | 12 +++++++ .../src/de/butzlabben/world/WorldSystem.java | 6 ++-- .../world/command/TabCompleter.java | 12 +++++++ .../butzlabben/world/config/PluginConfig.java | 33 +++++++++++++++++++ .../butzlabben/world/wrapper/SystemWorld.java | 24 +++++++++++--- WorldSystem/src/plugin.yml | 2 +- 8 files changed, 95 insertions(+), 8 deletions(-) create mode 100644 WorldSystem/src/de/butzlabben/world/command/TabCompleter.java diff --git a/WorldSystem/bin/config.yml b/WorldSystem/bin/config.yml index 7915924..8097bab 100644 --- a/WorldSystem/bin/config.yml +++ b/WorldSystem/bin/config.yml @@ -41,6 +41,18 @@ 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 # Location where you will be teleported when you leave you world spawn: diff --git a/WorldSystem/bin/plugin.yml b/WorldSystem/bin/plugin.yml index 1d50940..15aca1d 100644 --- a/WorldSystem/bin/plugin.yml +++ b/WorldSystem/bin/plugin.yml @@ -1,5 +1,5 @@ name: WorldSystem -version: 2.0.1 +version: 2.0.2 author: Butzlabben main: de.butzlabben.world.WorldSystem diff --git a/WorldSystem/src/config.yml b/WorldSystem/src/config.yml index 7915924..8097bab 100644 --- a/WorldSystem/src/config.yml +++ b/WorldSystem/src/config.yml @@ -41,6 +41,18 @@ 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 # Location where you will be teleported when you leave you world spawn: diff --git a/WorldSystem/src/de/butzlabben/world/WorldSystem.java b/WorldSystem/src/de/butzlabben/world/WorldSystem.java index 1bb644b..3f77cea 100644 --- a/WorldSystem/src/de/butzlabben/world/WorldSystem.java +++ b/WorldSystem/src/de/butzlabben/world/WorldSystem.java @@ -29,6 +29,7 @@ import de.butzlabben.world.command.WSToggleBuildCommand; import de.butzlabben.world.command.WSToggleGMCommand; import de.butzlabben.world.command.WSToggleTPCommand; import de.butzlabben.world.config.DependenceConfig; +import de.butzlabben.world.config.Entry; import de.butzlabben.world.config.GuiConfig; import de.butzlabben.world.config.MessageConfig; import de.butzlabben.world.config.PluginConfig; @@ -125,11 +126,12 @@ public class WorldSystem extends JavaPlugin { getCommand("ws delete").setExecutor(new WSDeleteCommand()); getCommand("ws gui").setExecutor(new GuiCommand()); - + mainGUI = new WorldSystemGUI(); - + System.setProperty("bstats.relocatecheck", "false"); Metrics m = new Metrics(this); + m.addCustomChart(new Metrics.SingleLineChart("worlds", Entry::entrys)); m.getPluginData(); Bukkit.getConsoleSender().sendMessage(PluginConfig.getPrefix() + "Succesfully enabled WorldSystem v" + version); diff --git a/WorldSystem/src/de/butzlabben/world/command/TabCompleter.java b/WorldSystem/src/de/butzlabben/world/command/TabCompleter.java new file mode 100644 index 0000000..434d1bf --- /dev/null +++ b/WorldSystem/src/de/butzlabben/world/command/TabCompleter.java @@ -0,0 +1,12 @@ +package de.butzlabben.world.command; + +/** + * @author Butzlabben + * @since 01.05.2018 + */ +public class TabCompleter { + + private TabCompleter() { + + } +} diff --git a/WorldSystem/src/de/butzlabben/world/config/PluginConfig.java b/WorldSystem/src/de/butzlabben/world/config/PluginConfig.java index 00aa65a..4a89516 100644 --- a/WorldSystem/src/de/butzlabben/world/config/PluginConfig.java +++ b/WorldSystem/src/de/butzlabben/world/config/PluginConfig.java @@ -12,6 +12,8 @@ import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.World; +import org.bukkit.World.Environment; +import org.bukkit.WorldType; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.plugin.java.JavaPlugin; @@ -36,6 +38,9 @@ public class PluginConfig { cfg.isInt("lagsystem.period_in_seconds") && cfg.isInt("lagsystem.entities_per_world") && cfg.isBoolean("lagsystem.garbagecollector.use") && cfg.isInt("lagsystem.garbagecollector.period_in_minutes") && + + cfg.isString("worldgeneration.type") && cfg.isString("worldgeneration.environment") + && (cfg.isLong("worldgeneration.seed") || cfg.isInt("worldgeneration.seed")) && cfg.isString("spawn.spawnpoint.world") && cfg.isInt("spawn.gamemode") && (cfg.isDouble("spawn.spawnpoint.x") || cfg.isInt("spawn.spawnpoint.x")) @@ -141,6 +146,34 @@ public class PluginConfig { return getLocation(cfg, "spawn.spawnpoint", Bukkit.getWorld(cfg.getString("spawn.spawnpoint.world", "world"))); } + 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 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.out.println("'" + t + "' is not a valid worldtype"); + } + return wt; + } + public static int getRequestExpire() { return getConfig().getInt("request_expires", 20); } diff --git a/WorldSystem/src/de/butzlabben/world/wrapper/SystemWorld.java b/WorldSystem/src/de/butzlabben/world/wrapper/SystemWorld.java index f2eba5d..4f89159 100644 --- a/WorldSystem/src/de/butzlabben/world/wrapper/SystemWorld.java +++ b/WorldSystem/src/de/butzlabben/world/wrapper/SystemWorld.java @@ -2,6 +2,7 @@ package de.butzlabben.world.wrapper; import java.io.File; import java.io.IOException; +import java.util.HashMap; import org.apache.commons.io.FileUtils; import org.bukkit.Bukkit; @@ -33,6 +34,8 @@ public class SystemWorld { private World w; private String worldname; private boolean unloading = false; + + private static HashMap cached = new HashMap<>(); /** * This method is the online way to get a system world instance @@ -45,9 +48,13 @@ public class SystemWorld { */ public static SystemWorld getSystemWorld(String worldname) { Preconditions.checkNotNull(worldname, "worldname must not be null"); + if(cached.containsKey(worldname)) + return cached.get(worldname); SystemWorld sw = new SystemWorld(worldname); - if (sw.exists()) + if(sw != null && sw.exists()) { + cached.put(worldname, sw); return sw; + } return null; } @@ -201,6 +208,7 @@ public class SystemWorld { worldname = myName.toString(); } // Teleport the Player + World worldinserver = Bukkit.createWorld(new WorldCreator(worldname)); Bukkit.getServer().getWorlds().add(worldinserver); w = worldinserver; @@ -251,8 +259,8 @@ public class SystemWorld { System.err.println("Couldn't create world for " + p.getName()); e.printStackTrace(); } - WorldConfig2 wc = new WorldConfig2(); - wc.createConfig(p); + WorldConfig2 wc2 = new WorldConfig2(); + wc2.createConfig(p); if (PluginConfig.getExampleWorldName() == null || PluginConfig.getExampleWorldName().equals("") || !exampleworld.exists()) { // Move World into Server dir @@ -275,7 +283,15 @@ public class SystemWorld { e.printStackTrace(); } } - World worldinserver = Bukkit.createWorld(new WorldCreator(worldname)); + WorldCreator wc = new WorldCreator(worldname); + System.out.println(PluginConfig.getEnvironment().name()); + wc.environment(PluginConfig.getEnvironment()); + System.out.println(PluginConfig.getWorldType().name()); + wc.type(PluginConfig.getWorldType()); + long seed = PluginConfig.getSeed(); + if(seed != 0) + wc.seed(seed); + World worldinserver = Bukkit.createWorld(wc); Bukkit.getServer().getWorlds().add(worldinserver); } return true; diff --git a/WorldSystem/src/plugin.yml b/WorldSystem/src/plugin.yml index 1d50940..15aca1d 100644 --- a/WorldSystem/src/plugin.yml +++ b/WorldSystem/src/plugin.yml @@ -1,5 +1,5 @@ name: WorldSystem -version: 2.0.1 +version: 2.0.2 author: Butzlabben main: de.butzlabben.world.WorldSystem