Class DefaultConfigRef<T>

java.lang.Object
tech.guilhermekaua.spigotboot.config.reload.DefaultConfigRef<T>
Type Parameters:
T - the config type
All Implemented Interfaces:
Supplier<T>, ConfigRef<T>

public class DefaultConfigRef<T> extends Object implements ConfigRef<T>
Default implementation of ConfigRef.
  • Constructor Details

    • DefaultConfigRef

      public DefaultConfigRef(@NotNull @NotNull Class<T> configClass, @Nullable T initialValue, @NotNull @NotNull Supplier<T> reloader)
      Creates a new ConfigRef.
      Parameters:
      configClass - the config class
      initialValue - the initial value
      reloader - the reloader supplier
  • Method Details

    • get

      @NotNull public T get()
      Description copied from interface: ConfigRef
      Gets the current config value.
      Specified by:
      get in interface ConfigRef<T>
      Specified by:
      get in interface Supplier<T>
      Returns:
      the current value
    • addListener

      public void addListener(@NotNull @NotNull Consumer<T> listener)
      Description copied from interface: ConfigRef
      Adds a listener for config changes.
      Specified by:
      addListener in interface ConfigRef<T>
      Parameters:
      listener - the listener to add
    • removeListener

      public void removeListener(@NotNull @NotNull Consumer<T> listener)
      Description copied from interface: ConfigRef
      Removes a previously added listener.
      Specified by:
      removeListener in interface ConfigRef<T>
      Parameters:
      listener - the listener to remove
    • isLoaded

      public boolean isLoaded()
      Description copied from interface: ConfigRef
      Checks if the config has been loaded at least once.
      Specified by:
      isLoaded in interface ConfigRef<T>
      Returns:
      true if loaded
    • reload

      public void reload()
      Description copied from interface: ConfigRef
      Forces a reload of this config.
      Specified by:
      reload in interface ConfigRef<T>
    • getConfigClass

      @NotNull public @NotNull Class<T> getConfigClass()
      Description copied from interface: ConfigRef
      Gets the config class this ref wraps.
      Specified by:
      getConfigClass in interface ConfigRef<T>
      Returns:
      the config class
    • update

      public void update(@NotNull T newValue)
      Updates the value without triggering reload.
      Parameters:
      newValue - the new value