SHARE
TWEET

Untitled

a guest Sep 28th, 2019 126 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package me.leluckyy.localsystem.utils;
  2.  
  3. import me.leluckyy.localsystem.main.Config;
  4. import me.leluckyy.localsystem.main.Main;
  5. import org.apache.commons.io.FileUtils;
  6. import org.bukkit.Bukkit;
  7. import org.bukkit.World;
  8. import org.bukkit.WorldCreator;
  9. import org.bukkit.WorldType;
  10. import org.bukkit.entity.Player;
  11. import org.bukkit.generator.ChunkGenerator;
  12.  
  13. import java.io.File;
  14. import java.io.IOException;
  15.  
  16. public class WorldManager {
  17.  
  18.     public static boolean worldExists(String worldName) {
  19.         World world = Bukkit.getWorld(worldName);
  20.         return(world == null ? false : true);
  21.     }
  22.  
  23.     public void createWorld(String worldName, Long seed, World.Environment worldtype, WorldType type, Boolean structures) {
  24.         WorldCreator creator = new WorldCreator(worldName).environment(worldtype).type(type);
  25.         if (!worldExists(worldName)) {
  26.             if (seed != null) {
  27.                 creator.seed(seed);
  28.             }
  29.             if (structures != null) {
  30.                 if (structures == true) {
  31.                     creator.generateStructures(true);
  32.                 } else creator.generateStructures(false);
  33.             } else creator.generateStructures(true);
  34.             creator.createWorld();
  35.             Bukkit.getServer().getWorlds().add(Bukkit.getWorld(worldName));
  36.             Bukkit.broadcastMessage("Welt '§c" + worldName + "§r' wurde generiert!");
  37.         }
  38.     }
  39.  
  40.     public void generateSkyWorld(String worldName) {
  41.         WorldCreator creator = new WorldCreator(worldName).generator(getSkyWorld());
  42.         creator.createWorld();
  43.         Bukkit.getServer().getWorlds().add(Bukkit.getWorld(worldName));
  44.         Bukkit.broadcastMessage("SkyWelt '§c" + worldName + "§r' wurde generiert!");
  45.     }
  46.  
  47.     public void deleteWorld(String worldName) {
  48.         if (worldExists(worldName)) {
  49.             World world = Bukkit.getWorld(worldName);
  50.             for (Player player : world.getPlayers()) {
  51.                 if (worldName != "world") {
  52.                     World backupWorld = Bukkit.getWorld("world");
  53.                     player.teleport(backupWorld.getSpawnLocation());
  54.                 } else player.kickPlayer("Die Welt wird momentan geändert!");
  55.             }
  56.             Bukkit.unloadWorld(world, false);
  57.             try {
  58.                 FileUtils.deleteDirectory(new File(worldName));
  59.             } catch (IOException e) { e.printStackTrace(); }
  60.             Bukkit.broadcastMessage("Welt '§c" + worldName + "§r' wurde §cgelöscht!");
  61.         }
  62.     }
  63.  
  64.     private ChunkGenerator getSkyWorld() {
  65.         return new GenerateSkyWorld();
  66.     }
  67. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top