java.lang.Object
org.polyfrost.oneconfig.api.config.v1.Config

public abstract class Config extends Object
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    A category for the config used for sorting in the UI
    IDs start at 1 because 0 is reserved for the default category ("All")
    They are also subject to change at any time
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
     
    final String
     
    final String
     
    final String
     
    protected org.polyfrost.oneconfig.api.config.v1.Tree
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Config(@NotNull String id, @NotNull String title, @NotNull Config.Category category)
     
    Config(@NotNull String id, @Nullable String iconPath, @NotNull String title, @Nullable Config.Category category)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    final void
    addAliases(String... aliases)
     
    final void
    addAliases(String option, String... aliases)
     
    protected void
    addCallback(String option, Runnable callback)
    Add a callback to the specified option path which is dot-separated for sub-configs
    The name of the option should be the name of the field
    protected <T> void
    addCallback(String option, Predicate<T> callback)
    Add a callback to the specified option path which is dot-separated for sub-configs
    The name of the option should be the name of the field
    protected void
    addDependency(String option, String condition)
     
    protected void
    addDependency(String option, String condition, boolean hide)
    Add a dependency on the given option which will gray out or hide the option unless condition is true
    protected void
    addDependency(String option, String name, Supplier<org.polyfrost.oneconfig.api.config.v1.Property.Display> condition)
     
    protected void
    Add multiple migration entries to the config
    This should be in the format of pairs where the first element is the old name and the second element is the new name
    To be used in conjunction with loadFrom(String) or loadFrom(Path) to migrate old configs to new ones
    protected void
    addMigrationEntry(String oldName, String newName)
    Add a migration entry to the config
    This should be in the format of oldName -> newName
    To be used in conjunction with loadFrom(String) or loadFrom(Path) to migrate old configs to new ones
    protected void
     
    static void
    captureDefaults(org.polyfrost.oneconfig.api.config.v1.Tree tree)
    Recursively record the current value of every property in [tree] as transient "default" metadata
    Call before ConfigManager.register(Tree) so stored profile values do not overwrite the captured code defaults
    For complex (non-simple) types a deep copy is stored because Property.set0(T) mutates such values in place
    Storing the live reference would alias the working value and make a reset a no-op
    static Object
    copyDefault(Class<?> type, Object value)
     
    protected void
    disableAllUnless(String toggleOption)
    Gray out every other option in this config, including those in sub-configs, unless the given boolean option is true
    Safe to call from the constructor
    protected org.polyfrost.oneconfig.api.config.v1.Property<?>
     
    protected static org.polyfrost.oneconfig.api.config.v1.Property<?>
    getProperty(org.polyfrost.oneconfig.api.config.v1.Tree tree, String option)
     
    org.polyfrost.oneconfig.api.config.v1.Tree
     
    protected void
    hideIf(String option, String condition)
     
    protected void
    hideIf(String option, BooleanSupplier condition)
     
    protected void
    initialize(boolean byConfigManager)
    Use this method to add any initialization logic to your config for example hideIf(String, String)
    make sure to call super
    protected void
     
    protected void
     
    protected org.polyfrost.oneconfig.api.config.v1.Tree
     
    protected void
    onInitialized(org.polyfrost.oneconfig.api.config.v1.Tree tree)
    Called once each time this config's tree has been built and registered, including after a profile switch which rebuilds the tree
    Unlike an override of initialize(boolean) this is not called when initialization is skipped
    void
    If you intend for your Config to be its own self-contained class you may need to call this method in your mod constructor to ensure that this class is initialized by Java
    If you do not call this method your config might not appear in the UI
    It will still function correctly and it will appear once some code that loads it is called
    static void
    restoreCapturedDefaults(org.polyfrost.oneconfig.api.config.v1.Tree tree)
     
    static void
    restoreCapturedDefaults(org.polyfrost.oneconfig.api.config.v1.Tree tree, boolean silent)
     
    protected void
     
    protected void
     
    void
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • tree

      protected org.polyfrost.oneconfig.api.config.v1.Tree tree
    • id

      public final String id
    • title

      public final String title
    • iconPath

      public final String iconPath
    • category

      public final Config.Category category
  • Constructor Details

    • Config

      public Config(@NotNull @NotNull String id, @Nullable @Nullable String iconPath, @NotNull @NotNull String title, @Nullable @Nullable Config.Category category)
      Parameters:
      iconPath - the path to your mod icon file which must be located within your mod-specific assets folder to avoid conflicts
    • Config

      public Config(@NotNull @NotNull String id, @NotNull @NotNull String title, @NotNull @NotNull Config.Category category)
  • Method Details

    • addAliases

      public final void addAliases(String... aliases)
    • addAliases

      public final void addAliases(String option, String... aliases)
    • makeTree

      protected org.polyfrost.oneconfig.api.config.v1.Tree makeTree()
    • addToInitQueue

      @Internal protected void addToInitQueue()
    • initialize

      @MustBeInvokedByOverriders protected void initialize(boolean byConfigManager)
      Use this method to add any initialization logic to your config for example hideIf(String, String)
      make sure to call super
    • onInitialized

      protected void onInitialized(org.polyfrost.oneconfig.api.config.v1.Tree tree)
      Called once each time this config's tree has been built and registered, including after a profile switch which rebuilds the tree
      Unlike an override of initialize(boolean) this is not called when initialization is skipped
    • captureDefaults

      public static void captureDefaults(org.polyfrost.oneconfig.api.config.v1.Tree tree)
      Recursively record the current value of every property in [tree] as transient "default" metadata
      Call before ConfigManager.register(Tree) so stored profile values do not overwrite the captured code defaults
      For complex (non-simple) types a deep copy is stored because Property.set0(T) mutates such values in place
      Storing the live reference would alias the working value and make a reset a no-op
    • restoreCapturedDefaults

      public static void restoreCapturedDefaults(org.polyfrost.oneconfig.api.config.v1.Tree tree)
    • restoreCapturedDefaults

      public static void restoreCapturedDefaults(org.polyfrost.oneconfig.api.config.v1.Tree tree, boolean silent)
    • copyDefault

      @Internal public static Object copyDefault(Class<?> type, Object value)
    • addDependency

      protected void addDependency(String option, String name, Supplier<org.polyfrost.oneconfig.api.config.v1.Property.Display> condition)
    • restoreDefaults

      protected void restoreDefaults()
    • restoreProperty

      protected void restoreProperty(String option)
    • addDependency

      protected void addDependency(String option, String condition)
    • hideIf

      protected void hideIf(String option, BooleanSupplier condition)
    • hideIf

      protected void hideIf(String option, String condition)
    • addDependency

      protected void addDependency(String option, String condition, boolean hide)
      Add a dependency on the given option which will gray out or hide the option unless condition is true
      Parameters:
      option - the option to add the dependency to
      condition - the boolean option which provides the dependency
    • disableAllUnless

      protected void disableAllUnless(String toggleOption)
      Gray out every other option in this config, including those in sub-configs, unless the given boolean option is true
      Safe to call from the constructor
    • addCallback

      protected <T> void addCallback(String option, Predicate<T> callback)
      Add a callback to the specified option path which is dot-separated for sub-configs
      The name of the option should be the name of the field
    • addCallback

      protected void addCallback(String option, Runnable callback)
      Add a callback to the specified option path which is dot-separated for sub-configs
      The name of the option should be the name of the field
    • getTree

      public org.polyfrost.oneconfig.api.config.v1.Tree getTree()
    • addMigrationEntry

      protected void addMigrationEntry(String oldName, String newName)
      Add a migration entry to the config
      This should be in the format of oldName -> newName
      To be used in conjunction with loadFrom(String) or loadFrom(Path) to migrate old configs to new ones
    • addMigrationEntries

      protected void addMigrationEntries(String... entries)
      Add multiple migration entries to the config
      This should be in the format of pairs where the first element is the old name and the second element is the new name
      To be used in conjunction with loadFrom(String) or loadFrom(Path) to migrate old configs to new ones
    • loadFrom

      protected void loadFrom(String id)
    • loadFrom

      protected void loadFrom(Path p)
    • getProperty

      protected org.polyfrost.oneconfig.api.config.v1.Property<?> getProperty(String option)
    • getProperty

      protected static org.polyfrost.oneconfig.api.config.v1.Property<?> getProperty(org.polyfrost.oneconfig.api.config.v1.Tree tree, String option)
    • save

      public void save()
    • preload

      public void preload()
      If you intend for your Config to be its own self-contained class you may need to call this method in your mod constructor to ensure that this class is initialized by Java
      If you do not call this method your config might not appear in the UI
      It will still function correctly and it will appear once some code that loads it is called