package de.skeletoneye.bungee.scale;

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import org.apache.commons.io.FileUtils;

import lombok.Getter;
import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.config.Configuration;
import net.md_5.bungee.config.ConfigurationProvider;
import net.md_5.bungee.config.YamlConfiguration;

public class BungeeScale extends Plugin
{
    private static @Getter BungeeScale instance;

    // TODO To be moved somewhere else
    public Configuration checkConfig(Path path) throws IOException
    {
        if (!Files.exists(path)) {
            this.getLogger().info("Unable to find " + path.getFileName().toString() + ", creating it.");

            try (InputStream stream = this.getResourceAsStream("templates/" + path.getFileName().toString())) {
                Files.copy(stream, path);
            }
        }

        return ConfigurationProvider.getProvider(YamlConfiguration.class).load(path.toFile());
    }

    @Override
    public void onEnable()
    {
        try {
            // Check whether servers directory exists
            final Path serversDir = Paths.get("servers");
            Files.createDirectories(serversDir);

            // Check whether configuration file exists and read it
            final Configuration networkCfg = this.checkConfig(serversDir.resolve("network.yml"));

            // Check whether other required directories exist
            final Path staticDir = serversDir.resolve("static");
            Files.createDirectories(staticDir);

            final Path imagesDir = serversDir.resolve("images");
            Files.createDirectories(imagesDir);

            final Path includesDir = serversDir.resolve("includes");
            Files.createDirectories(includesDir);

            // Make sure runtime/ is existing and empty
            final Path runtimeDir = serversDir.resolve("runtime");

            if (Files.exists(runtimeDir)) {
                this.getLogger().info("Clearing runtime directory");
                FileUtils.deleteDirectory(runtimeDir.toFile());
            }

            Files.createDirectory(runtimeDir);

            // Singleton
            BungeeScale.instance = this;
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }
}

@@ -424,16 +424,24 @@
 ation;%0A%0A
+@Getter%0A
 public c
@@ -524,16 +524,87 @@
 tance;%0A%0A
+    private Configuration networkConfig;%0A    private Path runtimeDir;%0A%0A
     // T
@@ -1435,36 +1435,21 @@
     
-final Configuration 
+this.
 networkC
 fg =
@@ -1444,17 +1444,20 @@
 networkC
-f
+onfi
 g = this
@@ -1984,27 +1984,21 @@
         
-final Path 
+this.
 runtimeD
@@ -2063,16 +2063,21 @@
 .exists(
+this.
 runtimeD
@@ -2186,32 +2186,37 @@
 deleteDirectory(
+this.
 runtimeDir.toFil
@@ -2270,16 +2270,21 @@
 rectory(
+this.
 runtimeD

Transform some variables to attributes