Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.IOException;
- import java.nio.file.FileVisitResult;
- import java.nio.file.Files;
- import java.nio.file.Path;
- import java.nio.file.SimpleFileVisitor;
- import java.nio.file.attribute.BasicFileAttributes;
- import java.util.List;
- import java.util.logging.Logger;
- import org.bukkit.Bukkit;
- import org.bukkit.Server;
- import org.bukkit.World;
- import org.bukkit.WorldCreator;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.configuration.file.YamlConfiguration;
- import org.bukkit.entity.Player;
- import org.bukkit.plugin.Plugin;
- import org.bukkit.plugin.PluginManager;
- import org.bukkit.plugin.java.JavaPlugin;
- public class Caves
- extends JavaPlugin
- {
- public void onEnable()
- {
- try
- {
- if (!Bukkit.getServer().getPluginManager().getPlugin("TerrainControl").isEnabled()) {
- Bukkit.getServer().getPluginManager().enablePlugin(Bukkit.getServer().getPluginManager().getPlugin("TerrainControl"));
- }
- FileConfiguration config = YamlConfiguration.loadConfiguration(new File("bukkit.yml"));
- config.set("worlds.uhc_world.generator", "TerrainControl");
- Bukkit.getLogger().info("The world 'uhc_world' is now being generated.");
- Bukkit.getServer().createWorld(new WorldCreator("uhc_world").generator("TerrainControl"));
- try
- {
- config.save(new File("bukkit.yml"));
- }
- catch (IOException localIOException) {}
- return;
- }
- catch (Exception localException) {}
- }
- public void onDisable()
- {
- if (Bukkit.getWorld("uhc_world").getPlayers().size() > 0)
- {
- for (Player player : Bukkit.getWorld("uhc_world").getPlayers())
- {
- player.teleport(Bukkit.getWorld("world").getSpawnLocation());
- player.sendMessage("�c?You have been teleported out of the world since it is being re-generated.");
- }
- return;
- }
- Bukkit.unloadWorld("uhc_world", false);
- File file = Bukkit.getWorld("uhc_world").getWorldFolder();
- deleteFileOrFolder(file.toPath());
- }
- public void delete(File file)
- {
- file.delete();
- }
- public static void deleteFileOrFolder(Path path)
- {
- try
- {
- Files.walkFileTree(path, new SimpleFileVisitor()
- {
- public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
- throws IOException
- {
- Files.delete(file);
- return FileVisitResult.CONTINUE;
- }
- public FileVisitResult visitFileFailed(Path file, IOException e)
- {
- return handleException(e);
- }
- private FileVisitResult handleException(IOException e)
- {
- e.printStackTrace();
- return FileVisitResult.TERMINATE;
- }
- public FileVisitResult postVisitDirectory(Path dir, IOException e)
- throws IOException
- {
- if (e != null) {
- return handleException(e);
- }
- Files.delete(dir);
- return FileVisitResult.CONTINUE;
- }
- });
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement