Package com.ranull.graves.util
Class ServerUtil
java.lang.Object
com.ranull.graves.util.ServerUtil
Utility class for gathering server information and generating server dumps.
This class includes methods for retrieving various system and server-related information.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static StringformatBytes(long bytes) Formats a byte count into a human-readable string with appropriate units.private static StringformatDuration(long seconds) private static StringformatFrequency(double frequency) private static Stringprivate static StringgetNmsVersion(Object server) Retrieves the NMS version using reflection to ensure compatibility.private static Stringprivate static StringGets a list of online players' names.private static StringGets a list of plugins with their names and versions.static StringgetServerDumpInfo(Graves plugin) Gathers server information and generates a dump in string format.private static StringgetSystemProperty(String key) Gets the value of a system property or returns "Unknown" if the property is not set.static booleanhasKeepInventory(org.bukkit.World world) private static booleanisPasswordField(String path) Determines if the given configuration path corresponds to a password field.private static booleanChecks if the server is running in a rootless Docker container.private static booleanChecks if the server is running with root-level access.private static booleanChecks if the server is running in a Docker container.private static booleanChecks if the server is running with a panel (e.g., hosting panel).private static StringJoins a list of strings into a single string, separated by new lines.private static StringmaskPasswords(String configString, org.bukkit.configuration.file.FileConfiguration config) Masks passwords in the configuration string with asterisks while retaining the character count.private static StringreadFileToString(File file) Reads a file into a string.private static Stringrepeat(char ch, int times) Repeats a character a specified number of times.
-
Constructor Details
-
ServerUtil
private ServerUtil()
-
-
Method Details
-
getServerDumpInfo
Gathers server information and generates a dump in string format.- Parameters:
plugin- The Graves plugin instance.- Returns:
- A string containing the server dump information.
-
formatFrequency
-
readFileToString
Reads a file into a string.- Parameters:
file- The file to read.- Returns:
- The content of the file as a string.
- Throws:
IOException- If an I/O error occurs.
-
formatDuration
-
getNmsVersion
Retrieves the NMS version using reflection to ensure compatibility.- Parameters:
server- The Bukkit server instance.- Returns:
- The NMS version string.
- Throws:
Exception- if the method to retrieve NMS version is not found.
-
formatBytes
Formats a byte count into a human-readable string with appropriate units.- Parameters:
bytes- The number of bytes.- Returns:
- A string with the byte count formatted in B, KB, MB, GB, TB, or PB.
-
hasKeepInventory
public static boolean hasKeepInventory(org.bukkit.World world) -
getSystemProperty
Gets the value of a system property or returns "Unknown" if the property is not set.- Parameters:
key- The name of the system property.- Returns:
- The value of the system property or "Unknown" if not set.
-
getOsName
-
getLinuxOsName
-
isRunningInDocker
private static boolean isRunningInDocker()Checks if the server is running in a Docker container.- Returns:
- True if running in Docker, otherwise false.
-
isRootlessDocker
private static boolean isRootlessDocker()Checks if the server is running in a rootless Docker container.- Returns:
- True if running in a rootless Docker container, otherwise false.
-
isRunningWithPanel
private static boolean isRunningWithPanel()Checks if the server is running with a panel (e.g., hosting panel).- Returns:
- True if running with a panel, otherwise false.
-
isRunningAsRoot
private static boolean isRunningAsRoot()Checks if the server is running with root-level access.- Returns:
- True if running as root, otherwise false.
-
maskPasswords
private static String maskPasswords(String configString, org.bukkit.configuration.file.FileConfiguration config) Masks passwords in the configuration string with asterisks while retaining the character count.- Parameters:
configString- The configuration string.config- The FileConfiguration object.- Returns:
- The modified configuration string with passwords masked.
-
isPasswordField
Determines if the given configuration path corresponds to a password field.- Parameters:
path- The configuration path.- Returns:
- True if the path is a password field, otherwise false.
-
joinLines
Joins a list of strings into a single string, separated by new lines.- Parameters:
lines- The list of lines to join.- Returns:
- A single string with lines joined by new lines.
-
repeat
Repeats a character a specified number of times.- Parameters:
ch- The character to repeat.times- The number of times to repeat the character.- Returns:
- A string with the character repeated.
-
getPlayerList
Gets a list of online players' names.- Returns:
- A comma-separated string of online player names.
-
getPluginList
Gets a list of plugins with their names and versions.- Returns:
- A comma-separated string of plugin names and versions.
-