Package dev.le_app.mcss_api_java
Class Server
java.lang.Object
dev.le_app.mcss_api_java.Server
Represents a server.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidexecuteServerAction(ServerAction action) Execute a power action on the server.voidexecuteServerCommand(String command) Executes a command on a servervoidexecuteServerCommands(String... commands) Executes multiple commands on the serverGet a list of backups for this serverString[]getConsole(int lines) Get last console linesString[]getConsole(int lines, boolean takeFromBeginning, boolean reversed) Get last console lines, with the ability to take the lines from the beginning of the console instead of the end and the ability to reverse the console linesString[]getConsoleFromBeginning(int lines, boolean takeFromBeginning) Get last console lines, with the ability to take the lines from the beginning of the console instead of the endString[]getConsoleReversed(int lines, boolean reversed) Get last console lines, with the ability reverse the lines of the consoleintGet the server CPU usage - this value is updated with every method runbooleangetGUID()booleanintintGet the server memory limit - this value is updated with every method rungetName()intGet the number of online players on the server - this value is updated with every method runintGet the player limit on the server - this value is updated with every method runintGet the server RAM usage - this value is updated with every method runGet the server icon - this value is updated with every method runGet the server start time - Uses default system timezone to calculate! - this value is updated with every method runbooleanisConsoleOutdated(String secondLastLine, String lastLine) Check if the console is outdatedvoidsetAutostart(boolean autostart) Set if the server autostarts with mcssvoidsetDescription(String description) Set the server descriptionvoidsetForceSaveOnStop(boolean forceSaveOnStop) Change if the server is forced to save when stoppingvoidsetJavaAllocatedMemory(int javaAllocatedMemory) Change the java allocated memory - This applies after a server restartvoidsetKeepOnline(KeepOnline keepOnline) Set the new KeepOnline behaviourvoidSet the server namevoidUpdate the server details
-
Constructor Details
-
Server
-
-
Method Details
-
getGUID
- Returns:
- GUID of the server
-
getStatus
public ServerStatus getStatus() throws APIUnauthorizedException, IOException, APINoServerAccessException, APINotFoundException- Returns:
- enum of the status of the server. - This value is updated every time you call this method.
- Throws:
APIUnauthorizedException- if the API token is invalid or expired.APINotFoundException- if the serverID is invalid.APINoServerAccessException- if you do not have access to this server.IOException- if an error occurs while connecting to the API.
-
getName
- Returns:
- the name of the server
-
getDescription
- Returns:
- the description of the server
-
getPathToFolder
- Returns:
- the path to the folder of the server
-
getFolderName
- Returns:
- the name of the folder of the server
-
getCreationDate
- Returns:
- the creation date of the server
-
getIsSetToAutostart
public boolean getIsSetToAutostart()- Returns:
- true if the server is set to autostart, false if not
-
getForceSaveOnStop
public boolean getForceSaveOnStop()- Returns:
- whether the server is forced to /save-all before shutdown
-
getKeepOnline
- Returns:
- the keep online time of the server
-
getJavaAllocatedMemory
public int getJavaAllocatedMemory()- Returns:
- the allocated memory of the server, in megabytes
-
getJavaStartupLine
- Returns:
- the startup line of the server
-
getScheduler
- Returns:
- a scheduler object for this server
-
getBackups
public ArrayList<Backup> getBackups() throws APIUnauthorizedException, APINoServerAccessException, APINotFoundException, IOExceptionGet a list of backups for this server- Returns:
- an arraylist of backups
- Throws:
APIUnauthorizedException- if the API token is invalid or expired.APINoServerAccessException- if you do not have access to this server.APINotFoundException- if the serverID is invalid.IOException- if an error occurs while connecting to the API.
-
getCpuUsage
public int getCpuUsage() throws APIUnauthorizedException, APINotFoundException, IOException, APINoServerAccessExceptionGet the server CPU usage - this value is updated with every method run- Returns:
- the server CPU usage percentage as int
- Throws:
APIUnauthorizedException- if the API token is invalidAPINotFoundException- if the server is not foundIOException- if there is an error while connecting to the APIAPINoServerAccessException- if you do not have access to this server
-
getRamUsage
public int getRamUsage() throws APIUnauthorizedException, APINotFoundException, IOException, APINoServerAccessExceptionGet the server RAM usage - this value is updated with every method run- Returns:
- the server RAM usage in megabytes as int
- Throws:
APIUnauthorizedException- if the API token is invalidAPINotFoundException- if the server is not foundIOException- if there is an error while connecting to the APIAPINoServerAccessException- if you do not have access to this server
-
getMemoryLimit
public int getMemoryLimit() throws APIUnauthorizedException, APINotFoundException, IOException, APINoServerAccessExceptionGet the server memory limit - this value is updated with every method run- Returns:
- the server memory limit in megabytes as int
- Throws:
APIUnauthorizedException- if the API token is invalidAPINotFoundException- if the server is not foundIOException- if there is an error while connecting to the APIAPINoServerAccessException- if you do not have access to this server
-
getOnlinePlayers
public int getOnlinePlayers() throws APIUnauthorizedException, APINotFoundException, IOException, APINoServerAccessExceptionGet the number of online players on the server - this value is updated with every method run- Returns:
- the online player number as an int
- Throws:
APIUnauthorizedException- if the API token is invalidAPINotFoundException- if the server is not foundIOException- if there is an error while connecting to the APIAPINoServerAccessException- if the API token does not have access to the server
-
getPlayerLimit
public int getPlayerLimit() throws APIUnauthorizedException, APINotFoundException, IOException, APINoServerAccessExceptionGet the player limit on the server - this value is updated with every method run- Returns:
- the player limit as an int
- Throws:
APIUnauthorizedException- if the API token is invalidAPINotFoundException- if the server is not foundIOException- if there is an error while connecting to theAPINoServerAccessException- if the API token does not have access to the server
-
getStartDate
public LocalDateTime getStartDate() throws APIUnauthorizedException, APINoServerAccessException, APINotFoundException, IOExceptionGet the server start time - Uses default system timezone to calculate! - this value is updated with every method run- Returns:
- The LocalDateTime of when the server was started
- Throws:
APIUnauthorizedException- if the API token is invalidAPINotFoundException- if the server is not foundIOException- if there is an error while connecting to the APIAPINoServerAccessException- if the API token does not have access to the server
-
getServerIcon
public BufferedImage getServerIcon() throws APIUnauthorizedException, APINotFoundException, IOException, APINoServerAccessExceptionGet the server icon - this value is updated with every method run- Returns:
- server icon as a BufferedImage
- Throws:
APIUnauthorizedException- if the API token is invalidAPINotFoundException- if the server is not foundIOException- if there is an error while connecting to the APIAPINoServerAccessException- if the API token does not have access to the server
-
executeServerAction
public void executeServerAction(ServerAction action) throws APIUnauthorizedException, IOException, APINotFoundException, APINoServerAccessException Execute a power action on the server.- Parameters:
action- 0 invalid, 1 stop, 2 start, 3 kill, 4 restart- Throws:
IOException- if there is an error with the connectionAPINotFoundException- if the server is not foundAPIUnauthorizedException- if the API key is invalid/expiredAPINoServerAccessException- if the API key does not have access to the server
-
executeServerCommand
public void executeServerCommand(String command) throws APIUnauthorizedException, IOException, APINotFoundException, APINoServerAccessException Executes a command on a server- Parameters:
command- String of the command to execute- Throws:
APIUnauthorizedException- if the API key is invalid/expiredIOException- if there is an error with the connectionAPINotFoundException- if the server is not foundAPINoServerAccessException- if the API token does not have access to the server
-
executeServerCommands
public void executeServerCommands(String... commands) throws APIUnauthorizedException, IOException, APINotFoundException, APINoServerAccessException Executes multiple commands on the server- Parameters:
commands- Array of strings of the commands to execute- Throws:
APIUnauthorizedException- if the API key is invalid/expiredIOException- if there is an error with the connectionAPINotFoundException- if the server is not foundAPINoServerAccessException- if the API token does not have access to the server
-
getConsole
public String[] getConsole(int lines) throws APIUnauthorizedException, IOException, APINotFoundException, APINoServerAccessException Get last console lines- Parameters:
lines- amount of lines to get- Returns:
- string array of the last console lines
- Throws:
APIUnauthorizedException- if the API key is invalid/expiredIOException- if there is an error with the connectionAPINotFoundException- if the server is not foundAPINoServerAccessException- if the API token does not have access to the server
-
getConsoleFromBeginning
public String[] getConsoleFromBeginning(int lines, boolean takeFromBeginning) throws APIUnauthorizedException, IOException, APINotFoundException, APINoServerAccessException Get last console lines, with the ability to take the lines from the beginning of the console instead of the end- Parameters:
lines- amount of lines to gettakeFromBeginning- true if you want to get the lines from the beginning of the console, false if you want to get the lines from the end of the console- Returns:
- string array of the last console lines
- Throws:
APIUnauthorizedException- if the API key is invalid/expiredIOException- if there is an error with the connectionAPINotFoundException- if the server is not foundAPINoServerAccessException- if the API token does not have access to the server
-
getConsoleReversed
public String[] getConsoleReversed(int lines, boolean reversed) throws APIUnauthorizedException, IOException, APINotFoundException, APINoServerAccessException Get last console lines, with the ability reverse the lines of the console- Parameters:
lines- amount of lines to getreversed- true if you want to reverse the lines of the console, false if you want to get the lines in the normal order- Returns:
- string array of the last console lines
- Throws:
APIUnauthorizedException- if the API key is invalid/expiredIOException- if there is an error with the connectionAPINotFoundException- if the server is not foundAPINoServerAccessException- if the API token does not have access to the server
-
getConsole
public String[] getConsole(int lines, boolean takeFromBeginning, boolean reversed) throws APIUnauthorizedException, IOException, APINotFoundException, APINoServerAccessException Get last console lines, with the ability to take the lines from the beginning of the console instead of the end and the ability to reverse the console lines- Parameters:
lines- amount of lines to gettakeFromBeginning- true if you want to get the lines from the beginning of the console, false if you want to get the lines from the end of the consolereversed- true if you want to reverse the lines of the console, false if you want to get the lines in the normal order- Returns:
- string array of the last console lines
- Throws:
APIUnauthorizedException- if the API key is invalid/expiredIOException- if there is an error with the connectionAPINotFoundException- if the server is not foundAPINoServerAccessException- if the API token does not have access to the server
-
isConsoleOutdated
public boolean isConsoleOutdated(String secondLastLine, String lastLine) throws APIUnauthorizedException, IOException, APINotFoundException, APINoServerAccessException Check if the console is outdated- Parameters:
secondLastLine- Second to last line for comparisonlastLine- Last line for comparison- Returns:
- true if the console is outdated, false if the console is not outdated
- Throws:
APIUnauthorizedException- if the API key is invalid/expiredIOException- if there is an error with the connectionAPINotFoundException- if the server is not foundAPINoServerAccessException- if the API key does not have access to the server
-
setName
public void setName(String name) throws APINotFoundException, APIUnauthorizedException, APINoServerAccessException, IOException Set the server name- Parameters:
name- new name of the server- Throws:
APINotFoundException- if the server is not foundAPIUnauthorizedException- if the API key is invalid/expiredAPINoServerAccessException- if the API key does not have access to the serverIOException- if there is an error with the connection
-
setDescription
public void setDescription(String description) throws APINotFoundException, APIUnauthorizedException, APINoServerAccessException, IOException Set the server description- Parameters:
description- new description of the server- Throws:
APINotFoundException- if the server is not foundAPIUnauthorizedException- if the API key is invalid/expiredAPINoServerAccessException- if the API key does not have access to the serverIOException- if there is an error with the connection
-
setAutostart
public void setAutostart(boolean autostart) throws APINotFoundException, APIUnauthorizedException, APINoServerAccessException, IOException Set if the server autostarts with mcss- Parameters:
autostart- the new autostart value- Throws:
APINotFoundException- if the server is not foundAPIUnauthorizedException- if the API key is invalid/expiredAPINoServerAccessException- if the API key does not have access to the serverIOException- if there is an error with the connection
-
setForceSaveOnStop
public void setForceSaveOnStop(boolean forceSaveOnStop) throws APINotFoundException, APIUnauthorizedException, APINoServerAccessException, IOException Change if the server is forced to save when stopping- Parameters:
forceSaveOnStop- the new value- Throws:
APINotFoundException- if the server is not foundAPIUnauthorizedException- if the API key is invalid/expiredAPINoServerAccessException- if the API key does not have access to the serverIOException- if there is an error with the connection
-
setJavaAllocatedMemory
public void setJavaAllocatedMemory(int javaAllocatedMemory) throws APINotFoundException, APIUnauthorizedException, APINoServerAccessException, IOException Change the java allocated memory - This applies after a server restart- Parameters:
javaAllocatedMemory- new memory size in MegaBytes- Throws:
APINotFoundException- if the server is not foundAPIUnauthorizedException- if the API key is invalid/expiredAPINoServerAccessException- if the API key does not have access to the serverIOException- if there is an error with the connection
-
setKeepOnline
public void setKeepOnline(KeepOnline keepOnline) throws APINotFoundException, APIUnauthorizedException, APINoServerAccessException, IOException Set the new KeepOnline behaviour- Parameters:
keepOnline- the new KeepOnline behaviour- Throws:
APINotFoundException- if the server is not foundAPIUnauthorizedException- if the API key is invalid/expiredAPINoServerAccessException- if the API key does not have access to the serverIOException- if there is an error with the connection
-
updateDetails
public void updateDetails() throws APINotFoundException, APIUnauthorizedException, IOException, APINoServerAccessExceptionUpdate the server details- Throws:
APIUnauthorizedException- if the API key is invalid/expiredIOException- if there is an error with the connectionAPINotFoundException- if the server is not foundAPINoServerAccessException- if the API key does not have access to the server
-