Interface IBrigadierConfigurator


public interface IBrigadierConfigurator
An interface your config should implement.
  • Field Details

  • 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

      default void reload(IBrigadierConfigurator newConfig)
      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

      @Internal default void recursiveReload(Object config, Object newConfig)
      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

      default String getDescription(Field field)
      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 with getCommentPrefix() and have custom SerializedName values.
      Returns:
      true by default.
      See Also:
    • shouldExclude

      default boolean shouldExclude(Field field)
      Indicates whether this field should be excluded from command. Field is excluded if it
      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)
      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 id
      dispatcher - 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 id
      dispatcher - 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

      default String getCommentPrefix()
      Gets comment prefix of fields.
      Returns:
      field prefix that is used by comment fields.
    • writeToFile

      default void writeToFile(File file)
      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 relevant SerializedName 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.