Class ServerUtil

java.lang.Object
com.ranull.graves.util.ServerUtil

public final class ServerUtil extends Object
Utility class for gathering server information and generating server dumps. This class includes methods for retrieving various system and server-related information.
  • Constructor Details

    • ServerUtil

      public ServerUtil()
  • Method Details

    • getServerDumpInfo

      public static String getServerDumpInfo(Graves plugin)
      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

      private static String formatFrequency(double frequency)
    • readFileToString

      private static String readFileToString(File file) throws IOException
      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

      private static String formatDuration(long seconds)
    • getNmsVersion

      private static String getNmsVersion(Object server) throws Exception
      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

      private static String formatBytes(long bytes)
      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

      private static String getSystemProperty(String key)
      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

      private static String getOsName()
      Gets the detailed OS name from the system properties or files.
      Returns:
      A string with the OS name.
    • getLinuxOsName

      private static String getLinuxOsName()
      Reads the OS name from the /etc/os-release file on Unix-like systems.
      Returns:
      A string with the OS name.
    • 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

      private static boolean isPasswordField(String path)
      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

      private static String joinLines(List<String> lines)
      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

      private static String repeat(char ch, int times)
      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

      private static String getPlayerList()
      Gets a list of online players' names.
      Returns:
      A comma-separated string of online player names.
    • getPluginList

      private static String getPluginList()
      Gets a list of plugins with their names and versions.
      Returns:
      A comma-separated string of plugin names and versions.