Search in sources :

Example 1 with Configuration

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

the class CloudConfig method defaultInit.

private void defaultInit(ConsoleReader consoleReader) throws Exception {
    if (Files.exists(configPath))
        return;
    String hostName = NetworkUtils.getHostName();
    if (hostName.equals("127.0.0.1") || hostName.equals("127.0.1.1") || hostName.split("\\.").length != 4) {
        String input;
        System.out.println("Your IP address where located is 127.0.0.1 please write your service ip");
        while ((input = consoleReader.readLine()) != null) {
            if ((input.equals("127.0.0.1") || input.equals("127.0.1.1")) || input.split("\\.").length != 4) {
                System.out.println("Please write your real ip address :)");
                continue;
            }
            hostName = input;
            break;
        }
    }
    Configuration configuration = new Configuration();
    configuration.set("general.auto-update", false);
    configuration.set("general.dynamicservices", false);
    configuration.set("general.server-name-splitter", "-");
    configuration.set("general.notify-service", true);
    configuration.set("general.disabled-modules", new ArrayList<>());
    configuration.set("general.cloudGameServer-wrapperList", Arrays.asList("Wrapper-1"));
    configuration.set("server.hostaddress", hostName);
    configuration.set("server.ports", Arrays.asList(1410));
    configuration.set("server.webservice.hostaddress", hostName);
    configuration.set("server.webservice.port", 1420);
    configuration.set("cloudnet-statistics.enabled", true);
    configuration.set("cloudnet-statistics.uuid", UUID.randomUUID().toString());
    configuration.set("networkproperties.test", true);
    try (OutputStreamWriter outputStreamWriter = new OutputStreamWriter(Files.newOutputStream(configPath), StandardCharsets.UTF_8)) {
        CONFIGURATION_PROVIDER.save(configuration, outputStreamWriter);
    }
}
Also used : Configuration(net.md_5.bungee.config.Configuration) YamlConfiguration(net.md_5.bungee.config.YamlConfiguration) OutputStreamWriter(java.io.OutputStreamWriter)

Example 2 with Configuration

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

the class CloudConfig method load.

public CloudConfig load() throws Exception {
    try (InputStream inputStream = Files.newInputStream(configPath);
        InputStreamReader inputStreamReader = new InputStreamReader(inputStream, StandardCharsets.UTF_8)) {
        Configuration configuration = CONFIGURATION_PROVIDER.load(inputStreamReader);
        this.config = configuration;
        String host = configuration.getString("server.hostaddress");
        Collection<ConnectableAddress> addresses = new ArrayList<>();
        for (int value : configuration.getIntList("server.ports")) {
            addresses.add(new ConnectableAddress(host, value));
        }
        this.addresses = addresses;
        this.wrapperKey = NetworkUtils.readWrapperKey();
        this.autoUpdate = configuration.getBoolean("general.auto-update");
        this.notifyService = configuration.getBoolean("general.notify-service");
        this.cloudDevServices = configuration.getBoolean("general.devservices");
        this.cloudDynamicServices = configuration.getBoolean("general.dynamicservices");
        this.webServerConfig = new WebServerConfig(true, configuration.getString("server.webservice.hostaddress"), configuration.getInt("server.webservice.port"));
        this.formatSplitter = configuration.getString("general.server-name-splitter");
        this.networkProperties = configuration.getSection("networkproperties").self;
        // configuration.set("general.disabled-modules", new ArrayList<>());
        if (!configuration.getSection("general").self.containsKey("disabled-modules")) {
            configuration.set("general.disabled-modules", new ArrayList<>());
            try (OutputStreamWriter outputStreamWriter = new OutputStreamWriter(Files.newOutputStream(configPath), StandardCharsets.UTF_8)) {
                CONFIGURATION_PROVIDER.save(configuration, outputStreamWriter);
            }
        }
        if (!configuration.getSection("general").self.containsKey("cloudGameServer-wrapperList")) {
            configuration.set("general.cloudGameServer-wrapperList", Arrays.asList("Wrapper-1"));
            try (OutputStreamWriter outputStreamWriter = new OutputStreamWriter(Files.newOutputStream(configPath), StandardCharsets.UTF_8)) {
                CONFIGURATION_PROVIDER.save(configuration, outputStreamWriter);
            }
        }
        this.disabledModules = configuration.getStringList("general.disabled-modules");
        this.cloudServerWrapperList = configuration.getStringList("general.cloudGameServer-wrapperList");
    }
    this.serviceDocument = Document.loadDocument(servicePath);
    this.wrappers = this.serviceDocument.getObject("wrapper", new TypeToken<List<WrapperMeta>>() {
    }.getType());
    this.userDocument = Document.loadDocument(usersPath);
    /* ============================================================== */
    return this;
}
Also used : InputStreamReader(java.io.InputStreamReader) Configuration(net.md_5.bungee.config.Configuration) YamlConfiguration(net.md_5.bungee.config.YamlConfiguration) InputStream(java.io.InputStream) ConnectableAddress(de.dytanic.cloudnet.lib.ConnectableAddress) WebServerConfig(de.dytanic.cloudnet.web.server.util.WebServerConfig) OutputStreamWriter(java.io.OutputStreamWriter)

Example 3 with Configuration

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

the class GameServer method bootstrap.

@Override
public boolean bootstrap() throws Exception {
    serverProcess.setServerStage(ServerStage.DOWNLOAD);
    long startupTime = System.currentTimeMillis();
    for (ServerInstallablePlugin url : serverProcess.getMeta().getDownloadablePlugins()) {
        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;
        }
    }
    for (ServerInstallablePlugin url : serverProcess.getMeta().getTemplate().getInstallablePlugins()) {
        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;
        }
    }
    if (serverGroup.getTemplates().size() == 0 && serverProcess.getMeta().getUrl() == null)
        return false;
    if (serverGroup.getGroupMode().equals(ServerGroupMode.STATIC)) {
        if (!Files.exists(dir))
            if (!a())
                return false;
    } else if (!a())
        return false;
    for (ServerInstallablePlugin plugin : serverProcess.getMeta().getDownloadablePlugins()) FileCopy.copyFileToDirectory(new File("local/cache/web_plugins/" + plugin.getName() + ".jar"), new File(path + "/plugins"));
    for (ServerInstallablePlugin plugin : serverProcess.getMeta().getTemplate().getInstallablePlugins()) FileCopy.copyFileToDirectory(new File("local/cache/web_plugins/" + plugin.getName() + ".jar"), new File(path + "/plugins"));
    serverProcess.setServerStage(ServerStage.COPY);
    if (serverGroup.getServerType().equals(ServerGroupType.BUKKIT))
        if (!Files.exists(Paths.get(path + "/spigot.jar")))
            FileCopy.copyFileToDirectory(new File("local/spigot.jar"), new File(path));
    if (serverGroup.getServerType().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 (!serverProcess.getMeta().isOnlineMode())
        if (!Files.exists(Paths.get(path + "/spigot.yml")))
            FileCopy.insertData("files/spigot.yml", path + "/spigot.yml");
    Files.deleteIfExists(Paths.get(path + "/plugins/CloudNetAPI.jar"));
    FileCopy.insertData("files/CloudNetAPI.jar", path + "/plugins/CloudNetAPI.jar");
    FileCopy.copyFilesInDirectory(new File("local/global"), new File(path));
    String motd = "Default Motd";
    int maxPlayers = 0;
    if (!serverGroup.getServerType().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.serverProcess.getMeta().getServerProperties().keys();
        while (enumeration.hasMoreElements()) {
            String x = enumeration.nextElement().toString();
            properties.setProperty(x, this.serverProcess.getMeta().getServerProperties().getProperty(x));
        }
        properties.setProperty("server-ip", CloudNetWrapper.getInstance().getWrapperConfig().getInternalIP());
        properties.setProperty("server-port", serverProcess.getMeta().getPort() + NetworkUtils.EMPTY_STRING);
        properties.setProperty("online-mode", serverProcess.getMeta().isOnlineMode() + NetworkUtils.EMPTY_STRING);
        // 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", serverProcess.getMeta().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(serverProcess.getMeta().getServiceId(), CloudNetWrapper.getInstance().getWrapperConfig().getInternalIP(), this.getServerProcess().getMeta().getPort(), false, new ArrayList<>(), serverProcess.getMeta().getMemory(), motd, 0, maxPlayers, ServerState.OFFLINE, this.serverProcess.getMeta().getServerConfig(), serverProcess.getMeta().getTemplate());
    if (!Files.exists(Paths.get(path + "/CLOUD"))) {
        Files.createDirectory(Paths.get(path + "/CLOUD"));
    }
    new Document().append("serviceId", serverProcess.getMeta().getServiceId()).append("serverProcess", serverProcess.getMeta()).append("serverInfo", serverInfo).append("ssl", CloudNetWrapper.getInstance().getOptionSet().has("ssl")).append("memory", serverProcess.getMeta().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"));
    CloudNetWrapper.getInstance().getNetworkConnection().sendPacket(new PacketOutAddServer(this.serverInfo, this.serverProcess.getMeta()));
    System.out.println("Server " + toString() + " started in [" + (System.currentTimeMillis() - startupTime) + " milliseconds]");
    this.startupTimeStamp = System.currentTimeMillis();
    startProcess();
    serverProcess.setServerStage(ServerStage.PROCESS);
    CloudNetWrapper.getInstance().getServers().put(this.serverProcess.getMeta().getServiceId().getServerId(), this);
    serverProcess.setServerStage(ServerStage.NET_INIT);
    return true;
}
Also used : ServerInstallablePlugin(de.dytanic.cloudnet.lib.service.plugin.ServerInstallablePlugin) PacketOutAddServer(de.dytanic.cloudnetwrapper.network.packet.out.PacketOutAddServer) Enumeration(java.util.Enumeration) Configuration(net.md_5.bungee.config.Configuration) YamlConfiguration(net.md_5.bungee.config.YamlConfiguration) ServerInfo(de.dytanic.cloudnet.lib.server.info.ServerInfo) ArrayList(java.util.ArrayList) Properties(java.util.Properties) YamlConfiguration(net.md_5.bungee.config.YamlConfiguration) Document(de.dytanic.cloudnet.lib.utility.document.Document) SimpledUser(de.dytanic.cloudnet.lib.user.SimpledUser) URLConnection(java.net.URLConnection) ConnectableAddress(de.dytanic.cloudnet.lib.ConnectableAddress)

Example 4 with Configuration

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

the class ConfigPermissions method write.

public void write(PermissionGroup permissionGroup, Configuration configuration) {
    Configuration section = configuration.getSection("groups");
    Configuration group = new Configuration();
    group.set("prefix", permissionGroup.getPrefix());
    group.set("suffix", permissionGroup.getSuffix());
    group.set("display", permissionGroup.getDisplay());
    group.set("tagId", permissionGroup.getTagId());
    group.set("joinPower", permissionGroup.getJoinPower());
    group.set("defaultGroup", permissionGroup.isDefaultGroup());
    Collection<String> perms = new CopyOnWriteArrayList<>();
    for (Map.Entry<String, Boolean> entry : permissionGroup.getPermissions().entrySet()) {
        perms.add((!entry.getValue() ? "-" : "") + entry.getKey());
    }
    group.set("permissions", perms);
    Configuration permsCfg = new Configuration();
    for (Map.Entry<String, List<String>> keys : permissionGroup.getServerGroupPermissions().entrySet()) {
        permsCfg.set(keys.getKey(), keys.getValue());
    }
    group.set("serverGroupPermissions", permsCfg);
    if (permissionGroup.getOptions().size() == 0)
        permissionGroup.getOptions().put("test_option", true);
    group.set("options", permissionGroup.getOptions());
    group.set("implements", permissionGroup.getImplementGroups());
    section.set(permissionGroup.getName(), null);
    section.set(permissionGroup.getName(), group);
}
Also used : YamlConfiguration(net.md_5.bungee.config.YamlConfiguration) Configuration(net.md_5.bungee.config.Configuration) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 5 with Configuration

use of net.md_5.bungee.config.Configuration in project FireAPI by FireBlade-Serv.

the class FireWL method exists.

public boolean exists(String name) throws IOException {
    File file = new File(plugin.getDataFolder(), "whitelist.yml");
    Configuration config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(file);
    return config.contains("players." + name);
}
Also used : YamlConfiguration(net.md_5.bungee.config.YamlConfiguration) Configuration(net.md_5.bungee.config.Configuration) YamlConfiguration(net.md_5.bungee.config.YamlConfiguration) File(java.io.File)

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