Interface IBrigadierConfigurator
public interface IBrigadierConfigurator
An interface your config should implement.
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptiondefault void
buildEditCommand
(com.mojang.brigadier.tree.LiteralCommandNode<net.minecraft.commands.CommandSourceStack> editNode, String permissionPrefix) Generates the command and attaches it to the provided child.default boolean
Whether to try getting comments from fields that are prefixed withgetCommentPrefix()
and have customSerializedName
values.default void
generateCommand
(com.mojang.brigadier.tree.LiteralCommandNode<net.minecraft.commands.CommandSourceStack> editNode) Deprecated.default void
generateConfigCommand
(String modId, com.mojang.brigadier.CommandDispatcher<net.minecraft.commands.CommandSourceStack> dispatcher) All-in-one solution for generating config command.default net.minecraft.network.chat.MutableComponent
generateFieldDescription
(Object parent, Field attribute) Gets the description for attribute field of parent object by checking relevantSerializedName
annotations.default int
generateFieldInfo
(com.mojang.brigadier.context.CommandContext<net.minecraft.commands.CommandSourceStack> context, Object parent, Field attribute) Generates text information for field and sends it to command executor.default void
generateReloadableConfigCommand
(String modId, com.mojang.brigadier.CommandDispatcher<net.minecraft.commands.CommandSourceStack> dispatcher, @Nullable Supplier<? extends IBrigadierConfigurator> newConfigLoader) All-in-one solution for generating config command.default String
Gets comment prefix of fields.default String
getDescription
(Field field) Gets description for the field.static <C extends IBrigadierConfigurator>
CloadConfigFile
(File file, Class<C> configClass, Supplier<C> defaultConfig) Loads config file.default void
recursiveEditCommand
(com.mojang.brigadier.tree.LiteralCommandNode<net.minecraft.commands.CommandSourceStack> root, ConfigFieldList configFields, List<String> permissionNodes) Recursively generates the command for config editing and attaches it to child.default void
recursiveReload
(Object config, Object newConfig) Loads changes from given config object into this object recursively.default void
reload
(IBrigadierConfigurator newConfig) Loads changes from given config object into this object.void
save()
Method called after a value is edited.default boolean
shouldExclude
(Field field) Indicates whether this field should be excluded from command.default void
writeToFile
(File file) Saves the config to the given file.
-
Field Details
-
COMMENT_PREFIX
Default comment field prefix.- See Also:
-
CONFIG_STR
- See Also:
-
EDIT_STR
- See Also:
-
RELOAD_STR
- See Also:
-
-
Method Details
-
save
void save()Method called after a value is edited. The config should be saved to prevent in-memory-only changes.You can call
writeToFile(File)
to save the config to a file. -
reload
Loads changes from given config object into this object. Useful as if we overwrite the config, we'd have to re-register command.- Parameters:
newConfig
- new config object which field values will be copied over to default one.
-
recursiveReload
Loads changes from given config object into this object recursively. Useful as if we overwrite the config, we'd have to re-register command. Usage: config.reloadValues(config, newConfig);- Parameters:
config
- config object that will have its values changed.newConfig
- new config object which field values will be copied over to default one.
-
getDescription
Gets description for the field.- Parameters:
field
- field to check.- Returns:
- description string of the field.
-
enableSerializedNameComments
default boolean enableSerializedNameComments()Whether to try getting comments from fields that are prefixed withgetCommentPrefix()
and have customSerializedName
values.- Returns:
- true by default.
- See Also:
-
shouldExclude
Indicates whether this field should be excluded from command. Field is excluded if it- is static
- starts with "_comment_"
-
has
BrigadierExcluded
annotation
- Parameters:
field
- field to check.- Returns:
- true if it should not be included in command, otherwise false.
-
loadConfigFile
static <C extends IBrigadierConfigurator> C loadConfigFile(File file, Class<C> configClass, Supplier<C> defaultConfig) Loads config file.- Parameters:
file
- file to load the language file from.configClass
- class of config object.defaultConfig
- default config supplier.- Returns:
- config object
-
buildEditCommand
default void buildEditCommand(com.mojang.brigadier.tree.LiteralCommandNode<net.minecraft.commands.CommandSourceStack> editNode, String permissionPrefix) Generates the command and attaches it to the provided child.- Parameters:
editNode
- child to attach fields to.
-
generateCommand
@Deprecated default void generateCommand(com.mojang.brigadier.tree.LiteralCommandNode<net.minecraft.commands.CommandSourceStack> editNode) Deprecated.usegenerateReloadableConfigCommand(String, CommandDispatcher, Supplier)
orgenerateConfigCommand(String, CommandDispatcher)
instead. If you still want to manually generate the command, usebuildEditCommand(LiteralCommandNode, String)
.Generates the command and attaches it to the provided child.- Parameters:
editNode
- the command node to attach fields to.
-
generateConfigCommand
default void generateConfigCommand(String modId, com.mojang.brigadier.CommandDispatcher<net.minecraft.commands.CommandSourceStack> dispatcher) All-in-one solution for generating config command. Doesn't include reloading.- Parameters:
modId
- your mod iddispatcher
- command dispatcher
-
generateReloadableConfigCommand
default void generateReloadableConfigCommand(String modId, com.mojang.brigadier.CommandDispatcher<net.minecraft.commands.CommandSourceStack> dispatcher, @Nullable @Nullable Supplier<? extends IBrigadierConfigurator> newConfigLoader) All-in-one solution for generating config command.- Parameters:
modId
- mod iddispatcher
- command dispatcher Generates command like: /modid config edit <config fields> And the reloading (if provided): /modid config reload
-
recursiveEditCommand
@Internal default void recursiveEditCommand(com.mojang.brigadier.tree.LiteralCommandNode<net.minecraft.commands.CommandSourceStack> root, ConfigFieldList configFields, List<String> permissionNodes) Recursively generates the command for config editing and attaches it to child.- Parameters:
root
- child to attach available fields to, e. g. `/modid editConfig`configFields
- a list of fields for this config.permissionNodes
- list of permission nodes. If empty, no permission check will be done.
-
getCommentPrefix
Gets comment prefix of fields.- Returns:
- field prefix that is used by comment fields.
-
writeToFile
Saves the config to the given file.- Parameters:
file
- file to save config to
-
generateFieldDescription
default net.minecraft.network.chat.MutableComponent generateFieldDescription(Object parent, Field attribute) Gets the description for attribute field of parent object by checking relevantSerializedName
annotations. Some examples: config.simpleToggle -> config = parent, simpleToggle field = attribute- Parameters:
parent
- parent config object.attribute
- field to generate description for.- Returns:
- text description of field.
-
generateFieldInfo
@Internal default int generateFieldInfo(com.mojang.brigadier.context.CommandContext<net.minecraft.commands.CommandSourceStack> context, Object parent, Field attribute) Generates text information for field and sends it to command executor.- Parameters:
context
- command executor.parent
- parent object that contains the attribute. Used to get current attribute value.attribute
- field to generate description for.- Returns:
- 1 as success for command execution.
-
generateReloadableConfigCommand(String, CommandDispatcher, Supplier)
orgenerateConfigCommand(String, CommandDispatcher)
instead.