Class Config<T>

java.lang.Object
com.hypixel.hytale.server.core.util.Config<T>
Type Parameters:
T - The type of the configuration structure that this contains

public class Config<T> extends Object
A helper to load/save configuration files
  • Constructor Summary

    Constructors
    Constructor
    Description
    Config(Path path, String name, BuilderCodec<T> codec)
    Creates a configuration file accessor that will attempt to load the configuration file from the given path and decode it with the given codec.
  • Method Summary

    Modifier and Type
    Method
    Description
    get()
    Returns the current instance of the config if loaded.
    Loads the config from the given location if it exists, otherwise the default config will be used instead
    static <T> Config<T>
    preloadedConfig(Path path, String name, BuilderCodec<T> codec, T config)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Exists for backwards compatibility with the old module config
    Saves the current state of the config to the config path.

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Config

      public Config(@Nonnull Path path, String name, BuilderCodec<T> codec)
      Creates a configuration file accessor that will attempt to load the configuration file from the given path and decode it with the given codec.
      Parameters:
      path - The location of the config file
      codec - The codec to use to decode the file
  • Method Details

    • preloadedConfig

      @Nonnull @Deprecated(forRemoval=true) public static <T> Config<T> preloadedConfig(@Nonnull Path path, String name, BuilderCodec<T> codec, T config)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Exists for backwards compatibility with the old module config
    • load

      @Nonnull public CompletableFuture<T> load()
      Loads the config from the given location if it exists, otherwise the default config will be used instead
      Returns:
      A future that will return the loaded config.
    • get

      public T get()
      Returns the current instance of the config if loaded.

      If the config has started loading then this will block until it completes.

      The value returned from this should not be stored as the value could be reloaded any time load() is called.

      Returns:
      The loaded config
      Throws:
      IllegalStateException - If this is called before load is called at least once
    • save

      @Nonnull public CompletableFuture<Void> save()
      Saves the current state of the config to the config path.

      If the config is still loading this does nothing.

      Returns:
      A future that will complete when the config is saved
      Throws:
      IllegalStateException - If this is called before load is called at least once