Class Config
java.lang.Object
org.polyfrost.oneconfig.api.config.v1.Config
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classA 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 -
Constructor Summary
ConstructorsConstructorDescriptionConfig(@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 TypeMethodDescriptionfinal voidaddAliases(String... aliases) final voidaddAliases(String option, String... aliases) protected voidaddCallback(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 fieldprotected <T> voidaddCallback(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 fieldprotected voidaddDependency(String option, String condition) protected voidaddDependency(String option, String condition, boolean hide) Add a dependency on the given option which will gray out or hide the option unless condition is trueprotected voidaddDependency(String option, String name, Supplier<org.polyfrost.oneconfig.api.config.v1.Property.Display> condition) protected voidaddMigrationEntries(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 withloadFrom(String)orloadFrom(Path)to migrate old configs to new onesprotected voidaddMigrationEntry(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 withloadFrom(String)orloadFrom(Path)to migrate old configs to new onesprotected voidstatic voidcaptureDefaults(org.polyfrost.oneconfig.api.config.v1.Tree tree) Recursively record the current value of every property in [tree] as transient"default"metadata
Call beforeConfigManager.register(Tree)so stored profile values do not overwrite the captured code defaults
For complex (non-simple) types a deep copy is stored becauseProperty.set0(T)mutates such values in place
Storing the live reference would alias the working value and make a reset a no-opstatic ObjectcopyDefault(Class<?> type, Object value) protected voiddisableAllUnless(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 constructorprotected org.polyfrost.oneconfig.api.config.v1.Property<?> getProperty(String option) 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.TreegetTree()protected voidprotected voidhideIf(String option, BooleanSupplier condition) protected voidinitialize(boolean byConfigManager) Use this method to add any initialization logic to your config for examplehideIf(String, String)
make sure to call superprotected voidprotected voidprotected org.polyfrost.oneconfig.api.config.v1.TreemakeTree()protected voidonInitialized(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 ofinitialize(boolean)this is not called when initialization is skippedvoidpreload()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 calledstatic voidrestoreCapturedDefaults(org.polyfrost.oneconfig.api.config.v1.Tree tree) static voidrestoreCapturedDefaults(org.polyfrost.oneconfig.api.config.v1.Tree tree, boolean silent) protected voidprotected voidrestoreProperty(String option) voidsave()
-
Field Details
-
tree
protected org.polyfrost.oneconfig.api.config.v1.Tree tree -
id
-
title
-
iconPath
-
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
-
addAliases
-
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 examplehideIf(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 ofinitialize(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 beforeConfigManager.register(Tree)so stored profile values do not overwrite the captured code defaults
For complex (non-simple) types a deep copy is stored becauseProperty.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
-
addDependency
-
restoreDefaults
protected void restoreDefaults() -
restoreProperty
-
addDependency
-
hideIf
-
hideIf
-
addDependency
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 tocondition- the boolean option which provides the dependency
-
disableAllUnless
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
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
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
Add a migration entry to the config
This should be in the format of oldName -> newName
To be used in conjunction withloadFrom(String)orloadFrom(Path)to migrate old configs to new ones -
addMigrationEntries
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 withloadFrom(String)orloadFrom(Path)to migrate old configs to new ones -
loadFrom
-
loadFrom
-
getProperty
-
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
-