Search in sources :

Example 26 with Configuration

use of net.md_5.bungee.config.Configuration in project ChangeSkin by games647.

the class ChangeSkinCore method loadFile.

private Configuration loadFile(String fileName) throws IOException {
    Configuration defaults;
    ConfigurationProvider configProvider = ConfigurationProvider.getProvider(YamlConfiguration.class);
    try (InputStream defaultStream = getClass().getClassLoader().getResourceAsStream(fileName)) {
        defaults = configProvider.load(defaultStream);
    }
    Path file = plugin.getPluginFolder().resolve(fileName);
    try (Reader reader = Files.newBufferedReader(file)) {
        return configProvider.load(reader, defaults);
    }
}
Also used : Path(java.nio.file.Path) YamlConfiguration(net.md_5.bungee.config.YamlConfiguration) Configuration(net.md_5.bungee.config.Configuration) ConfigurationProvider(net.md_5.bungee.config.ConfigurationProvider) InputStream(java.io.InputStream) Reader(java.io.Reader)

Example 27 with Configuration

use of net.md_5.bungee.config.Configuration in project Parties by AlessioDP.

the class BungeeMetrics method loadConfig.

/**
 * Loads the bStats configuration.
 *
 * @throws IOException If something did not work :(
 */
private void loadConfig() throws IOException {
    Path configPath = plugin.getDataFolder().toPath().getParent().resolve("bStats");
    configPath.toFile().mkdirs();
    File configFile = new File(configPath.toFile(), "config.yml");
    if (!configFile.exists()) {
        writeFile(configFile, "#bStats collects some data for plugin authors like how many servers are using their plugins.", "#To honor their work, you should not disable it.", "#This has nearly no effect on the server performance!", "#Check out https://bStats.org/ to learn more :)", "enabled: true", "serverUuid: \"" + UUID.randomUUID().toString() + "\"", "logFailedRequests: false");
    }
    Configuration configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile);
    // Load configuration
    enabled = configuration.getBoolean("enabled", true);
    serverUUID = configuration.getString("serverUuid");
    logFailedRequests = configuration.getBoolean("logFailedRequests", false);
}
Also used : Path(java.nio.file.Path) Configuration(net.md_5.bungee.config.Configuration) YamlConfiguration(net.md_5.bungee.config.YamlConfiguration) YamlConfiguration(net.md_5.bungee.config.YamlConfiguration) File(java.io.File)

Example 28 with Configuration

use of net.md_5.bungee.config.Configuration in project Parties by AlessioDP.

the class ConfigurationManager method reloadConfig.

public void reloadConfig() {
    File cfgFile = new File(plugin.getDataFolder(), "config_bungee.yml");
    if (!cfgFile.exists()) {
        try {
            InputStream in = plugin.getResourceAsStream("config_bungee.yml");
            byte[] buffer = new byte[in.available()];
            in.read(buffer);
            in.close();
            cfgFile.getParentFile().mkdirs();
            OutputStream out = new FileOutputStream(cfgFile);
            out.write(buffer);
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    Configuration cfg;
    try {
        cfg = ConfigurationProvider.getProvider(YamlConfiguration.class).load(cfgFile);
    } catch (IOException e) {
        return;
    }
    if (cfg.getInt("dont-edit-this.config-version") < Constants.VERSION_CONFIG_MAIN)
        plugin.log(ConsoleColor.RED.getCode() + "Configuration file outdated");
    if (cfg.get("follow-party.enable") != null)
        ConfigMain.follow_enable = cfg.getBoolean("follow-party.enable");
    if (cfg.get("follow-party.needed-rank") != null)
        ConfigMain.follow_neededrank = cfg.getInt("follow-party.needed-rank");
    if (cfg.get("follow-party.minimum-rank") != null)
        ConfigMain.follow_minimumrank = cfg.getInt("follow-party.minimum-rank");
    ConfigMain.follow_listserver = cfg.getStringList("follow-party.list-server");
}
Also used : YamlConfiguration(net.md_5.bungee.config.YamlConfiguration) Configuration(net.md_5.bungee.config.Configuration) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File)

Example 29 with Configuration

use of net.md_5.bungee.config.Configuration in project ViaCheckConnection by x9nico.

the class Metrics method loadConfig.

/**
 * Loads the bStats configuration.
 *
 * @throws IOException If something did not work :(
 */
private void loadConfig() throws IOException {
    Path configPath = plugin.getDataFolder().toPath().getParent().resolve("bStats");
    configPath.toFile().mkdirs();
    File configFile = new File(configPath.toFile(), "config.yml");
    if (!configFile.exists()) {
        writeFile(configFile, "#bStats collects some data for plugin authors like how many servers are using their plugins.", "#To honor their work, you should not disable it.", "#This has nearly no effect on the server performance!", "#Check out https://bStats.org/ to learn more :)", "enabled: true", "serverUuid: \"" + UUID.randomUUID().toString() + "\"", "logFailedRequests: false");
    }
    Configuration configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile);
    // Load configuration
    enabled = configuration.getBoolean("enabled", true);
    serverUUID = configuration.getString("serverUuid");
    logFailedRequests = configuration.getBoolean("logFailedRequests", false);
}
Also used : Path(java.nio.file.Path) Configuration(net.md_5.bungee.config.Configuration) YamlConfiguration(net.md_5.bungee.config.YamlConfiguration) YamlConfiguration(net.md_5.bungee.config.YamlConfiguration) File(java.io.File)

Example 30 with Configuration

use of net.md_5.bungee.config.Configuration in project CloudNet by Dytanic.

the class CloudGameServer method bootstrap.

@Override
public boolean bootstrap() throws Exception {
    long startupTime = System.currentTimeMillis();
    for (ServerInstallablePlugin url : cloudServerMeta.getPlugins()) {
        switch(url.getPluginResourceType()) {
            case URL:
                {
                    if (!Files.exists(Paths.get("local/cache/web_plugins/" + url.getName() + ".jar"))) {
                        try {
                            URLConnection urlConnection = new java.net.URL(url.getUrl()).openConnection();
                            urlConnection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11");
                            Files.copy(urlConnection.getInputStream(), Paths.get("local/cache/web_plugins/" + url.getName() + ".jar"));
                        } catch (Exception ex) {
                            ex.printStackTrace();
                        }
                    }
                }
                break;
            case MASTER:
                {
                    if (!Files.exists(Paths.get("local/cache/web_plugins/" + url.getName() + ".jar")) && CloudNetWrapper.getInstance().getSimpledUser() != null) {
                        try {
                            URLConnection urlConnection = new java.net.URL(new StringBuilder(CloudNetWrapper.getInstance().getOptionSet().has("ssl") ? "https://" : "http://").append(CloudNetWrapper.getInstance().getWrapperConfig().getCloudnetHost()).append(":").append(CloudNetWrapper.getInstance().getWrapperConfig().getWebPort()).append("/cloudnet/api/v1/download").substring(0)).openConnection();
                            urlConnection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11");
                            SimpledUser simpledUser = CloudNetWrapper.getInstance().getSimpledUser();
                            urlConnection.setRequestProperty("-Xcloudnet-user", simpledUser.getUserName());
                            urlConnection.setRequestProperty("-Xcloudnet-token", simpledUser.getApiToken());
                            urlConnection.setRequestProperty("-Xmessage", "plugin");
                            urlConnection.setRequestProperty("-Xvalue", url.getName());
                            urlConnection.connect();
                            System.out.println("Downloading " + url.getName() + ".jar");
                            Files.copy(urlConnection.getInputStream(), Paths.get("local/cache/web_plugins/" + url.getName() + ".jar"));
                            System.out.println("Download was completed successfully!");
                        } catch (Exception ex) {
                            ex.printStackTrace();
                        }
                    }
                }
                break;
            default:
                break;
        }
    }
    Files.createDirectories(this.dir);
    // Template
    MasterTemplateLoader templateLoader = new MasterTemplateLoader(new StringBuilder(CloudNetWrapper.getInstance().getOptionSet().has("ssl") ? "https://" : "http://").append(CloudNetWrapper.getInstance().getWrapperConfig().getCloudnetHost()).append(":").append(CloudNetWrapper.getInstance().getWrapperConfig().getWebPort()).append("/cloudnet/api/v1/download").toString(), dir.toString() + "/template.zip", CloudNetWrapper.getInstance().getSimpledUser(), null, null, cloudServerMeta.getTemplateName());
    System.out.println("Downloading cloud server for " + this.cloudServerMeta.getServiceId());
    templateLoader.load();
    templateLoader.unZip(dir.toString());
    FileCopy.copyFilesInDirectory(new File(dir.toString()), new File(path));
    if (cloudServerMeta.getServerGroupType().equals(ServerGroupType.CAULDRON)) {
        try {
            System.out.println("Downloading cauldron.zip...");
            File file = new File(path + "/cauldron.zip");
            URLConnection connection = new URL("https://yivesmirror.com/files/cauldron/cauldron-1.7.10-2.1403.1.54.zip").openConnection();
            connection.setUseCaches(false);
            connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11");
            connection.connect();
            Files.copy(connection.getInputStream(), Paths.get(path + "/cauldron.zip"));
            ((HttpURLConnection) connection).disconnect();
            System.out.println("Download was completed successfully!");
            ZipFile zip = new ZipFile(file);
            Enumeration<? extends ZipEntry> entryEnumeration = zip.entries();
            while (entryEnumeration.hasMoreElements()) {
                ZipEntry entry = entryEnumeration.nextElement();
                if (!entry.isDirectory()) {
                    extractEntry(zip, entry, path);
                }
            }
            zip.close();
            file.delete();
            new File(path + "/cauldron-1.7.10-2.1403.1.54-server.jar").renameTo(new File(path + "/cauldron.jar"));
            try (FileWriter fileWriter = new FileWriter(path + "/eula.txt")) {
                fileWriter.write("eula=true");
                fileWriter.flush();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    if (cloudServerMeta.getServerGroupType().equals(ServerGroupType.GLOWSTONE)) {
        Path path = Paths.get(this.path + "/glowstone.jar");
        if (!Files.exists(path)) {
            try {
                URLConnection connection = new URL("https://yivesmirror.com/grab/glowstone/Glowstone-latest.jar").openConnection();
                connection.setUseCaches(false);
                connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11");
                connection.connect();
                System.out.println("Downloading glowstone.jar...");
                Files.copy(connection.getInputStream(), path);
                System.out.println("Download was completed successfully");
                ((HttpURLConnection) connection).disconnect();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }
    // Init
    for (ServerInstallablePlugin plugin : cloudServerMeta.getPlugins()) FileCopy.copyFileToDirectory(new File("local/cache/web_plugins/" + plugin.getName() + ".jar"), new File(path + "/plugins"));
    for (ServerInstallablePlugin plugin : cloudServerMeta.getPlugins()) FileCopy.copyFileToDirectory(new File("local/cache/web_plugins/" + plugin.getName() + ".jar"), new File(path + "/plugins"));
    if (cloudServerMeta.getServerGroupType().equals(ServerGroupType.BUKKIT))
        if (!Files.exists(Paths.get(path + "/spigot.jar")))
            FileCopy.copyFileToDirectory(new File("local/spigot.jar"), new File(path));
    if (cloudServerMeta.getServerGroupType().equals(ServerGroupType.GLOWSTONE)) {
        if (!Files.exists(Paths.get(path + "/config")))
            Files.createDirectories(Paths.get(path + "/config"));
        if (!Files.exists(Paths.get(path + "/config/glowstone.yml")))
            FileCopy.insertData("files/glowstone.yml", path + "/config/glowstone.yml");
    }
    if (!Files.exists(Paths.get(path + "/server.properties")))
        FileCopy.insertData("files/server.properties", path + "/server.properties");
    if (!Files.exists(Paths.get(path + "/bukkit.yml")))
        FileCopy.insertData("files/bukkit.yml", path + "/bukkit.yml");
    if (!Files.exists(Paths.get(path + "/spigot.yml")))
        FileCopy.insertData("files/spigot.yml", path + "/spigot.yml");
    if (!Files.exists(Paths.get(path + "/plugins")))
        Files.createDirectory(Paths.get(path + "/plugins"));
    if (!Files.exists(Paths.get(path + "/CLOUD")))
        Files.createDirectory(Paths.get(path + "/CLOUD"));
    Files.deleteIfExists(Paths.get(path + "/plugins/CloudNetAPI.jar"));
    FileCopy.insertData("files/CloudNetAPI.jar", path + "/plugins/CloudNetAPI.jar");
    try {
        FileCopy.copyFilesInDirectory(new File("local/global_cloudserver"), new File(path));
    } catch (Exception ex) {
    }
    if (CloudNetWrapper.getInstance().getWrapperConfig().isViaVersion()) {
        if (!Files.exists(Paths.get("local/viaversion.jar"))) {
            try {
                System.out.println("Downloading ViaVersion...");
                URLConnection url = new URL("https://ci.viaversion.com/job/ViaVersion/177/artifact/jar/target/ViaVersion-1.2.0.jar").openConnection();
                url.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11");
                url.connect();
                Files.copy(url.getInputStream(), Paths.get("local/viaversion.jar"));
                ((HttpURLConnection) url).disconnect();
                System.out.println("Download was completed successfully!");
            } catch (Exception ex) {
            }
        }
        FileCopy.copyFileToDirectory(new File("local/viaversion.jar"), new File(path + "/plugins"));
    }
    /*===============================================================================*/
    String motd = "Default Motd";
    int maxPlayers = 0;
    if (!cloudServerMeta.getServerGroupType().equals(ServerGroupType.GLOWSTONE)) {
        Properties properties = new Properties();
        try (InputStreamReader inputStreamReader = new InputStreamReader(Files.newInputStream(Paths.get(path + "/server.properties")))) {
            properties.load(inputStreamReader);
        }
        Enumeration enumeration = this.cloudServerMeta.getServerProperties().keys();
        while (enumeration.hasMoreElements()) {
            String x = enumeration.nextElement().toString();
            properties.setProperty(x, this.cloudServerMeta.getServerProperties().getProperty(x));
        }
        properties.setProperty("server-ip", CloudNetWrapper.getInstance().getWrapperConfig().getInternalIP());
        properties.setProperty("server-port", cloudServerMeta.getPort() + NetworkUtils.EMPTY_STRING);
        properties.setProperty("online-mode", "false");
        // properties.setProperty("server-name", serverProcess.getMeta().getServiceId().getServerId());
        motd = properties.getProperty("motd");
        maxPlayers = Integer.parseInt(properties.getProperty("max-players"));
        try (OutputStream outputStream = Files.newOutputStream(Paths.get(path + "/server.properties"))) {
            properties.store(outputStream, "CloudNet-Wrapper EDIT");
        }
    } else {
        try (InputStreamReader inputStreamReader = new InputStreamReader(Files.newInputStream(Paths.get(path + "/config/glowstone.yml")), StandardCharsets.UTF_8)) {
            Configuration configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(inputStreamReader);
            Configuration section = configuration.getSection("server");
            section.set("ip", CloudNetWrapper.getInstance().getWrapperConfig().getInternalIP());
            section.set("port", cloudServerMeta.getPort());
            maxPlayers = section.getInt("max-players");
            motd = section.getString("motd");
            configuration.set("server", section);
            configuration.set("console.use-jline", false);
            try (OutputStreamWriter outputStreamWriter = new OutputStreamWriter(Files.newOutputStream(Paths.get(path + "/config/glowstone.yml")), StandardCharsets.UTF_8)) {
                ConfigurationProvider.getProvider(YamlConfiguration.class).save(configuration, outputStreamWriter);
            }
        }
    }
    /*===============================================================================*/
    this.serverInfo = new ServerInfo(cloudServerMeta.getServiceId(), CloudNetWrapper.getInstance().getWrapperConfig().getInternalIP(), this.cloudServerMeta.getPort(), false, new ArrayList<>(), cloudServerMeta.getMemory(), motd, 0, maxPlayers, ServerState.OFFLINE, this.cloudServerMeta.getServerConfig(), cloudServerMeta.getTemplate());
    new Document().append("serviceId", cloudServerMeta.getServiceId()).append("cloudProcess", cloudServerMeta).append("serverInfo", serverInfo).append("ssl", CloudNetWrapper.getInstance().getOptionSet().has("ssl")).append("memory", cloudServerMeta.getMemory()).saveAsConfig(Paths.get(path + "/CLOUD/config.json"));
    new Document().append("connection", new ConnectableAddress(CloudNetWrapper.getInstance().getWrapperConfig().getCloudnetHost(), CloudNetWrapper.getInstance().getWrapperConfig().getCloudnetPort())).saveAsConfig(Paths.get(path + "/CLOUD/connection.json"));
    Files.deleteIfExists(Paths.get(path + "/plugins/CloudNetAPI.jar"));
    FileCopy.insertData("files/CloudNetAPI.jar", path + "/plugins/CloudNetAPI.jar");
    StringBuilder commandBuilder = new StringBuilder();
    commandBuilder.append("java ");
    for (String command : cloudServerMeta.getProcessParameters()) {
        commandBuilder.append(command).append(NetworkUtils.SPACE_STRING);
    }
    commandBuilder.append("-XX:+UseG1GC -XX:MaxGCPauseMillis=50 -XX:MaxPermSize=256M -XX:-UseAdaptiveSizePolicy -Dio.netty.leakDetectionLevel=DISABLED -Dfile.encoding=UTF-8 -Dio.netty.maxDirectMemory=0 -Dcom.mojang.eula.agree=true -Dio.netty.recycler.maxCapacity=0 -Dio.netty.recycler.maxCapacity.default=0 -Djline.terminal=jline.UnsupportedTerminal -Xmx" + cloudServerMeta.getMemory() + "M -jar ");
    switch(cloudServerMeta.getServerGroupType()) {
        case CAULDRON:
            commandBuilder.append("cauldron.jar nogui");
            break;
        case GLOWSTONE:
            commandBuilder.append("glowstone.jar nogui");
            break;
        case CUSTOM:
            commandBuilder.append("minecraft_server.jar nogui");
            break;
        default:
            commandBuilder.append("spigot.jar nogui");
            break;
    }
    CloudNetWrapper.getInstance().getCloudservers().put(this.cloudServerMeta.getServiceId().getServerId(), this);
    CloudNetWrapper.getInstance().getNetworkConnection().sendPacket(new PacketOutAddCloudServer(this.serverInfo, cloudServerMeta));
    System.out.println("CloudServer " + toString() + " [" + (cloudServerMeta.isPriorityStop() ? "priority stop: true" : "priority stop: false") + "] start [" + (System.currentTimeMillis() - startupTime) + " milliseconds]");
    this.instance = Runtime.getRuntime().exec(commandBuilder.toString().split(NetworkUtils.SPACE_STRING), null, new File(path));
    return true;
}
Also used : Configuration(net.md_5.bungee.config.Configuration) YamlConfiguration(net.md_5.bungee.config.YamlConfiguration) ServerInfo(de.dytanic.cloudnet.lib.server.info.ServerInfo) ZipEntry(java.util.zip.ZipEntry) ArrayList(java.util.ArrayList) Properties(java.util.Properties) YamlConfiguration(net.md_5.bungee.config.YamlConfiguration) Document(de.dytanic.cloudnet.lib.utility.document.Document) URL(java.net.URL) HttpURLConnection(java.net.HttpURLConnection) Path(java.nio.file.Path) ServerInstallablePlugin(de.dytanic.cloudnet.lib.service.plugin.ServerInstallablePlugin) Enumeration(java.util.Enumeration) MasterTemplateLoader(de.dytanic.cloudnet.lib.server.template.MasterTemplateLoader) PacketOutAddCloudServer(de.dytanic.cloudnetwrapper.network.packet.out.PacketOutAddCloudServer) SimpledUser(de.dytanic.cloudnet.lib.user.SimpledUser) HttpURLConnection(java.net.HttpURLConnection) URLConnection(java.net.URLConnection) ConnectableAddress(de.dytanic.cloudnet.lib.ConnectableAddress) ZipFile(java.util.zip.ZipFile) ZipFile(java.util.zip.ZipFile)

Aggregations

YamlConfiguration (net.md_5.bungee.config.YamlConfiguration)32 Configuration (net.md_5.bungee.config.Configuration)30 File (java.io.File)16 IOException (java.io.IOException)12 TextComponent (net.md_5.bungee.api.chat.TextComponent)6 InputStream (java.io.InputStream)5 ArrayList (java.util.ArrayList)5 ProxiedPlayer (net.md_5.bungee.api.connection.ProxiedPlayer)5 Path (java.nio.file.Path)4 ConnectableAddress (de.dytanic.cloudnet.lib.ConnectableAddress)3 ServerInfo (de.dytanic.cloudnet.lib.server.info.ServerInfo)2 ServerInstallablePlugin (de.dytanic.cloudnet.lib.service.plugin.ServerInstallablePlugin)2 SimpledUser (de.dytanic.cloudnet.lib.user.SimpledUser)2 Document (de.dytanic.cloudnet.lib.utility.document.Document)2 FileOutputStream (java.io.FileOutputStream)2 OutputStream (java.io.OutputStream)2 OutputStreamWriter (java.io.OutputStreamWriter)2 URLConnection (java.net.URLConnection)2 Enumeration (java.util.Enumeration)2 Properties (java.util.Properties)2