CloudNet Development Wiki

Jul 28, 2017
CloudNet Development Wiki
  • Hey Guys using CloudNet,

    I'm not the author of this plugin. All Credits goes to @Dytanic

    i really like CN (CloudNet) and on the Support Discord are very very very much questions about how to use this or that so i decided to make a Wiki Page for those who need it :D

    When something is not correct please contact me i'll change that.


    1. Diffrent classes and their methods

    There a are a few ways to access the API or to "use" it.


    The CloudNetAPI.class

    Here you can do following:

    • writeCNPCommand(String command)
    • writeCNSCommand(CNSInfo cnsInfo, String command)
    • reloadPermissions()
    • reload()
    • reload(CNSInfo cnsInfo)
    • getOnlinePlayers()
    • getOnlinePlayersByUUID()
    • getOnlinePlayersByName()
    • getProxys()
    • getProxysByName()
    • getGroups()
    • getServers()
    • getPermissionPool()
    • getServers(String group)
    • getServerInfos()
    • getServerInfos(String group)
    • getCloudNetServer(String serverId)
    • getOnlineCloudNetServers()
    • getProxyInfo(String proxy)
    • getOnlineCountByGroup(String group)
    • createPermissionGroup(PermissionGroup permissionGroup)
    • deletePermissionGroup(PermissionGroup permissionGroup)
    • updatePermissionGroup(PermissionGroup permissionGroup)
    • addPermission(UUID user, String permission, boolean value)
    • removePermission(UUID user, String permission)
    • createServerGroup(CNSInfo cnsInfo, ServerGroup serverGroup)
    • deleteServerGroup(CNSInfo cnsInfo, ServerGroup serverGroup)
    • updateServerGroup(CNSInfo cnsInfo, ServerGroup serverGroup)
    • getPermissionsGroups()
    • updatePlayer(PlayerWhereAmI playerWhereAmI)
    • setRank(PlayerWhereAmI playerWhereAmI, PermissionGroup permissionGroup, long timeout)
    • setRank(PlayerWhereAmI playerWhereAmI, String permissionGroup, long timeout)
    • setRank(PlayerWhereAmI playerWhereAmI, PermissionGroup permissionGroup, int days)
    • setRank(PlayerWhereAmI playerWhereAmI, PermissionGroup permissionGroup)
    • setRank(PlayerWhereAmI playerWhereAmI, String permissionGroup)
    • setRank(String name, String permissionGroup, long timeout)
    • startServer(SimpleServerGroup group, Document properties, boolean priorityStop)
    • boolean priorityStop, int maxplayers, int memory, boolean hide)
    • startCustomServer(SimpleServerGroup group, String serverId, Document properties,
    • startServer(String group, Document properties, boolean priorityStop)
    • startHidedServer(SimpleServerGroup group, Document properties, boolean priorityStop)
    • setPlayerToGroup(String name, PermissionGroup permissionGroup, long timeout)
    • sendServerCommand(ServerInfo serverInfo, String command)
    • getOnlineCount()
    • stopServer(String serverId)
    • startStaticServer(SimpleServerGroup group, String serverId, Document properties,
    • boolean priorityStop, int memory)
    • restartServer(String serverId, Document properties, boolean priorityStop)
    • restartStaticServer(String serverId, Document properties, boolean priorityStop, int memory)
    • sendCustomMessage(ServerType serviceType, String message, Document document)
    • query(String qry, Document metaData, Callback<Document> resultHandler)
    • getOfflinePlayer(String name, Callback<PlayerWhereAmI> callback)
    • getUUID(String name, Callback<UUID> uuidCallback)
    • getServerGroup(String name, Callback<ServerGroup> result)
    • getOnlinePlayer(String name)
    • getGroupData(String groupName)
    • getPermissionGroup(String name)
    • getOnlinePlayer(UUID uuid)
    • getServerInfo(String serverId)
    • getCnpConnector()
    • getCloudNetwork()
    • getMetaData()
    • getScheduler()
    • getCloudId()
    • getServerId()
    • getScheduledThread()
    • getUniqueId()
    • setCloudNetwork(CloudNetwork cloudNetwork)
    • getInstance()

    Then there is the CloudServer.class

    If you write in your code:

    Code (Text):
    CloudServer cloudServer = CloudServer.getInstance();
    You get the "instance" of the server the API is currently running on!

    • getInstance()
    • getServerGroup()
    • update()
    • sendCustomProxyMessage(String message, Document dataCatcher)
    • changeToIngame(boolean newServer)
    • updateNameTags(Player player)
    • setProperties(Document properties)
    • setServerState(ServerState serverState)
    • setMotd(String motd)
    • setMaxPlayers(int maxPlayers)
    • setExtra(String extra)
    • getMemory()
    • getProperties()
    • getMaxPlayers()
    • getPlugin()
    • getStartUp()
    • getServerGroupMode()
    • getMap()
    • getServerState()
    • getExtra()
    • getGroup()
    • getMotd()
    • isBetaServer()
    • getProfile()
    • setMap(ServerMap map)
    • setProfile(ServerGroupProfile profile)
    • getOwner()
    • isAutoStartServerByFull()
    • setAutoStartServerByFull(boolean autoStartServerByFull)
    • isHide()

    Also there is the CloudProxy.class

    • sendCustomProxyMessage(String message, Document metaData)
    • kickPlayer(String name, String resaon)
    • kickPlayer(UUID uuid, String reason)
    • sendPlayer(UUID uuid, ServerInfo serverInfo)
    • broadcast(String message)
    • updateProxyLayout(ProxyLayout proxyLayout)
    • update()
    • getProxyLayout()
    • getHostName()
    • getPort()
    • getMemory()
    • getFallback()
    • getInstance()
    • setProxyLayout(ProxyLayout proxyLayout)

    2. A few examples

    For all examples no guarantee they work please contact me when not working i try to correct it!

    Start a hidden Server (PrivateServer):
    Code (Text):
    UUID uuid; //UUID of the player
    CloudNetAPI.getInstance().startHidedServer(CloudNetAPI.getInstance().getGroupData(serverGroup), (new Document()).append("createdServerUUID", uuid.toString()), true);
    Start a different types of server:
    Code (Text):
    //start normal server
    CloudNetAPI.getInstance().startServer(CloudNetAPI.getInstance().getGroupData("lobby"), (new Document()), false);
    //or
    CloudNetAPI.getInstance().startServer("lobby", (new Document()), false);
     
    //start static server
    CloudNetAPI.getInstance().startStaticServer(CloudNetAPI.getInstance().getGroupData("bedwars"), "bedwars-1", (new Document()), false, 512);
    /* Declaration:
    *
    * CloudNetAPI.getInstance().startStaticServer(group, serverId, properties, priorityStop, memory);
    * group = a specific servergroup [SimpleServerGroup]
    * serverId = name of the server like lobby-1, lobby-2 etc. [String]
    * properties = place to change aditional things [Document]
    * priorityStop = server shut's down when "owner" is no on the server !! Better way to do that is Hidded or Custom Server
    * memory = how much RAM gets the server (MB) {Integer]
    * */
    Get all INGAME stated servers of a group:
    Code (Text):
        /*
        * @param serverGroup name of a specific group or null for all ingame servers
        * @return gives you a list of the ingame servers of a group or all servers
        */
        public List<ServerInfo> getListOfIngameServer(String serverGroup) {
            List<ServerInfo> list = new ArrayList<>();
            for (String serverId : CloudNetAPI.getInstance().getServers().keySet()) {
                ServerInfo serverInfo = CloudNetAPI.getInstance().getServerInfo(serverId);
                if (serverInfo.isIngame()) {
                    if (serverGroup != null) {
                        if (serverInfo.getGroup().equalsIgnoreCase(serverGroup)) {
                            list.add(serverInfo);
                        }
                    } else {
                        list.add(serverInfo);
                    }
                }
            }
            return list;
        }
     

    Execute a command on any server in the CN:
    Here the first one sends a command to the BungeeCord server to execute
    The second executes a command on lobby-1
    Code (Text):
    CloudNetAPI.getInstance().writeCNSCommand(CloudNetAPI.getInstance().getCloudNetServer("CNS-1"), "command -p Proxy-1 alert Nice Server");
    CloudNetAPI.getInstance().writeCNSCommand(CloudNetAPI.getInstance().getCloudNetServer("CNS-1"), "command -s lobby-1 gamemode 1 zM4xi");

    Send a player to any server in the CN:
    Code (Text):
    UUID uuid; //UUID of a player
    String serverName; //name/id of a server
    CloudProxy.getInstance().sendPlayer(uuid, CloudNetAPI.getInstance().getServerInfo(serverName));




    For more or specific examples please contact me i'll add them!

    3. Setup the CN (Step by Step)


    1.Folder Setup
    1.1 Recommended Folder paths
    1.2 Server Requirements
    2. First Start-Up and Configuration
    2.1 Follow the instructions
    2.2 Configure the CNP
    2.3 Configure the CNS

    1. Folder Setup
    1.1 Recommended Folder paths

    I recommend making a new folder named something clearly pointing out that here is the network stored, something like "network" or cloudsystem".
    Im gonna use following for this example:
    /server/network/...

    1.2 Server Requirements

    You can use the CN with any server you want to, but however i recommend a server a minimum of 8 GB of RAM and an average to very good CPU.

    The RAM is the most important because of the multiroot support of CN you can easily relive the CPU of a server.

    For this example im using following:

    Server 1:
    AMD Opteron(tm) Processor 3365
    32 GB RAM

    Server 2:
    Intel(R) Xeon(R) CPU E5-1650 v2 @ 3.50GHz
    12 GB RAM

    CNP: running on Server 1
    CNS-1: running on Server 1 (only lobbys)
    CNS-2: running on Server 2 (gameserver etc.)

    For optimized workload i recommend spreading it as far as possible.

    2. First Start-Up and Configuration
    2.1 Follow the instructions

    Navigate in the folder /server/network/ (example).
    Download the latest version of CN on linux with following command:

    Unpack the .zip and you will get 3 new folder

    On the first startup the console will guide you through a few questions that are self explanatory.

    How To Start? Navigate to /server/network/CloudNet-Proxy (example) and there you find a .jar and to start files on linux run the CNP by using following command:

    on Windows just execute the .bat file
    On Linux make sure the file has permission to execute to be sure all works navigate in the folder above /server/ (example)
    Here enter following command:

    This will give the files in the folder the needed permissions.

    For the CNS? Navigate to /server/network/CloudNet-Server/ (example)
    and make the same liek before execute the "start" files.

    2.2 Configure the CNP

    After the first setup i would recommend stop both instances by typing "stop" and hitting ENTER and then go in the filebrowser to configure both.

    File: config.yml

    edit the motd, maintenance motd and the messages and some options

    File: signsLayouts.json

    edit your layouts how you want them

    File:permissions.yml

    Edit the permissions, prefix and more

    2.3 Configure the CNS

    File: config.properties

    edit the maxmemory of the complete CNS, the ports, the CNS Name (for multiple roots/CNS), and you can turn records/logs on.

    File: groups.json

    edit all servergroups, their diffrent settings like dynamic ram and mor, the proxy setttings
  • Loading...
  • Loading...