Class DefaultConfig

java.lang.Object
io.github.projectunified.faststats.core.DefaultConfig
All Implemented Interfaces:
Config

public class DefaultConfig extends Object implements Config
Default implementation of Config that reads and writes configurations from a properties file.
  • Field Details

    • DEFAULT_COMMENT

      public static final String[] DEFAULT_COMMENT
  • Constructor Details

    • DefaultConfig

      public DefaultConfig(Path file, String[] comment, boolean externallyManaged, Properties properties, boolean firstRun, UUID serverId, boolean additionalMetrics, boolean debug, boolean enabled)
      Constructs a new DefaultConfig instance.
      Parameters:
      file - the config file path
      comment - the comment header
      externallyManaged - true if configuration is externally managed
      properties - the raw properties
      firstRun - whether it is the first time running stats
      serverId - the server ID
      additionalMetrics - whether to submit additional metrics
      debug - whether debug logging is enabled
      enabled - whether metrics collection is enabled
  • Method Details

    • read

      public static DefaultConfig read(Path file) throws RuntimeException
      Reads a config from the specified path with default settings.
      Parameters:
      file - the path to the config file
      Returns:
      the loaded DefaultConfig
      Throws:
      RuntimeException - if loading or saving fails
    • read

      public static DefaultConfig read(Path file, String[] comment, boolean externallyManaged, boolean externallyEnabled) throws RuntimeException
      Reads a config from the specified path with custom comments and external control flags.
      Parameters:
      file - the path to the config file
      comment - the comment header to write to the file if saved
      externallyManaged - true if the configuration is controlled externally
      externallyEnabled - true if externally enabled
      Returns:
      the loaded DefaultConfig
      Throws:
      RuntimeException - if loading or saving fails
    • getServerId

      public UUID getServerId()
      Description copied from interface: Config
      Retrieves the unique identifier of the server.
      Specified by:
      getServerId in interface Config
      Returns:
      the server identifier UUID
    • isEnabled

      public boolean isEnabled()
      Description copied from interface: Config
      Checks if metrics submission is enabled.
      Specified by:
      isEnabled in interface Config
      Returns:
      true if enabled, false otherwise
    • isSubmitAdditionalMetrics

      public boolean isSubmitAdditionalMetrics()
      Description copied from interface: Config
      Checks if additional/custom metrics are enabled for submission.
      Specified by:
      isSubmitAdditionalMetrics in interface Config
      Returns:
      true if enabled, false otherwise
    • isDebug

      public boolean isDebug()
      Description copied from interface: Config
      Checks if debug logging is enabled.
      Specified by:
      isDebug in interface Config
      Returns:
      true if enabled, false otherwise
    • isFirstRun

      public boolean isFirstRun()
      Description copied from interface: Config
      Checks if this is the first time the metrics are running.
      Specified by:
      isFirstRun in interface Config
      Returns:
      true if first run, false otherwise
    • setDefaultProperty

      public void setDefaultProperty(Map<String,String> properties)
      Description copied from interface: Config
      Sets default properties.
      Specified by:
      setDefaultProperty in interface Config
      Parameters:
      properties - the default properties map
    • getProperty

      public String getProperty(String key, String defaultValue)
      Description copied from interface: Config
      Gets a property value.
      Specified by:
      getProperty in interface Config
      Parameters:
      key - the key
      defaultValue - the default value to return if not present
      Returns:
      the property value or the default value