Class JacksonConfig<T>

java.lang.Object
de.eldoria.eldoutilities.config.JacksonConfig<T>
Type Parameters:
T - type of main configuration
All Implemented Interfaces:
DebugDataProvider

public class JacksonConfig<T> extends Object implements DebugDataProvider
Class allowing to manage multiple configuration files.

Each file is associated with a ConfigKey, which provides a name, path and a default value.

  • Constructor Details

    • JacksonConfig

      public JacksonConfig(@NotNull @NotNull Plugin plugin, @NotNull @NotNull ConfigKey<T> mainKey)
      Creates a new Jackson Configuration
      Parameters:
      plugin - plugin owning the configuration
      mainKey - key for the main configuration file former config.yml
  • Method Details

    • plugin

      public Plugin plugin()
      Plugin associated with this configuration
      Returns:
      plugin instance
    • main

      public T main()
      Get the primary configuration.

      This will be the config.yml in most cases.

      If the config was not yet created, it will be created.

      Returns:
      configuration
    • secondary

      public <V> V secondary(ConfigKey<V> key)
      Get a configuration file.

      If this file was not yet created, it will be created.

      Type Parameters:
      V - type of configuration
      Parameters:
      key - configuration key
      Returns:
      configuration file
    • mainWrapped

      public Wrapper<T> mainWrapped()
      Get the primary configuration wrapper.

      This wrapper can be used to save the config using the closable. It is also safe to be stored since it does not store the file itself.

      This will be the config.yml in most cases.

      If the config was not yet created, it will be created.

      Returns:
      configuration
    • secondaryWrapped

      public <V> Wrapper<V> secondaryWrapped(ConfigKey<V> key)
      Get a configuration file.

      This wrapper can be used to save the config using the closable. It is also safe to be stored since it does not store the file itself.

      If this file was not yet created, it will be created.

      Type Parameters:
      V - type of configuration
      Parameters:
      key - configuration key
      Returns:
      configuration file
    • exists

      public <V> boolean exists(ConfigKey<V> key)
      Checks whether the config file was created already
      Type Parameters:
      V - type
      Parameters:
      key - key
      Returns:
      true when exists
    • loaded

      public <V> boolean loaded(ConfigKey<V> key)
      Checks whether the config file was already loaded
      Type Parameters:
      V - type
      Parameters:
      key - key
      Returns:
      true when loaded
    • replace

      public <V> void replace(ConfigKey<V> key, V newValue)
      Replace the configuration currently associated with this key with a new configuration.
      Type Parameters:
      V - type of key
      Parameters:
      key - configuration key
      newValue - new value of key
    • save

      public void save()
      Saves all files loaded via this instance.
    • save

      public void save(ConfigKey<?> key)
      Saves the file associated with the config key
      Parameters:
      key - configuration key
    • reload

      public void reload()
      Relaods all files loaded via this instance including the main configuration.
    • reload

      public void reload(ConfigKey<?> key)
      Reloads a single file associated with the config key
      Parameters:
      key - configuration key
    • reader

      public final ObjectMapper reader()
      Get the object mapper used to read files
      Returns:
      object mapper instance
    • writer

      public final ObjectMapper writer()
      Get the mapper used to write objects
      Returns:
      object mapper instance
    • mapper

      public final ObjectMapper mapper()
      Get the object mapper used to read and write objects
      Returns:
      object mapper instance
    • createReadMapper

      protected ObjectMapper createReadMapper()
      Create a mapper for reading files.
      Returns:
      mapper instance
    • createWriteMapper

      protected ObjectMapper createWriteMapper()
      Create a mapper for writing files.
      Returns:
      mapper instance
    • load

      protected final <V> V load(ConfigKey<V> key)
      Load a file defined in the configuration key.

      Will fail if the file is not present.

      Use createAndLoad(ConfigKey) if you want the file to be created.

      Type Parameters:
      V - type of file
      Parameters:
      key - configuration key
      Returns:
      instance of file
    • createAndLoad

      protected final <V> V createAndLoad(ConfigKey<V> key)
      Load a file defined in the configuration key.

      If this file was not yet created, it will be created.

      Type Parameters:
      V - type of file
      Parameters:
      key - configuration key
      Returns:
      instance of file
    • createMapper

      protected ObjectMapper createMapper()
      Create a general mapper for read and write.

      You can define different wrapper for read and write operations by overwriting createReadMapper() and createWriteMapper()

      Returns:
      mapper instance
    • configureDefault

      public ObjectMapper configureDefault(MapperBuilder<?,?> builder)
    • getPlatformModule

      public final Module getPlatformModule()
      Get the module for the current platform.
      Returns:
      module
    • additionalModules

      protected List<Module> additionalModules()
      Allows to register additional modules to the mapper.
      Returns:
      list of modules.
    • getPaperModule

      protected de.eldoria.jacksonbukkit.JacksonPaper getPaperModule()
      Create the module used for paper server.

      This should be a JacksonPaper module.

      Returns:
      paper module
    • getBukkitModule

      protected de.eldoria.jacksonbukkit.JacksonBukkit getBukkitModule()
      Create the module used for spigot/bukkit server.

      This should be a JacksonBukkit module.

      Returns:
      spigot/bukkit module
    • getDebugInformations

      @NotNull public @NotNull EntryData[] getDebugInformations()
      Description copied from interface: DebugDataProvider
      Get debug information for the current object instance.
      Specified by:
      getDebugInformations in interface DebugDataProvider
      Returns:
      array of entry data.