Class ServerPropertiesFile

java.lang.Object
me.pauleff.common.handlers.files.ServerPropertiesFile

public final class ServerPropertiesFile extends Object
Represents a Minecraft server.properties file and supports order-preserving edits.

Prefer the static one-shot methods for single operations. Use of(Path) when performing multiple edits on the same file.

  • Method Details

    • of

      public static ServerPropertiesFile of(Path path)
      Returns a handle for the given properties file path.
      Parameters:
      path - the path to server.properties
      Returns:
      a properties file handle
      Throws:
      NullPointerException - if path is null
    • worldName

      public static String worldName(Path path)
      Reads the level-name value from the given properties file.
      Parameters:
      path - the path to server.properties
      Returns:
      the configured world name, or "world" as a fallback
    • writeProperty

      public static void writeProperty(Path path, String key, String value) throws IOException
      Updates a key-value entry in the given properties file, or appends it if absent.
      Parameters:
      path - the path to the properties file
      key - the property key to set
      value - the property value to write
      Throws:
      IOException - if reading or writing the file fails
    • path

      public Path path()
      Returns the path to this properties file.
      Returns:
      the properties file path
    • worldName

      public String worldName()
      Reads the level-name value from this properties file.

      Returns "world" if the property is missing or the file cannot be read.

      Returns:
      the configured world name, or "world" as a fallback
    • writeProperty

      public void writeProperty(String key, String value) throws IOException
      Updates a key-value entry in this properties file, or appends it if the key is not present.

      Matching lines are identified by a key= prefix. Line order and unrelated content are preserved. The file is rewritten in place.

      Parameters:
      key - the property key to set
      value - the property value to write
      Throws:
      NullPointerException - if key or value is null
      IOException - if reading or writing the file fails