Class RootFileReader<R,T extends Serializer<R>>

java.lang.Object
me.deecaad.core.file.RootFileReader<R,T>
Type Parameters:
R - The serialized type
T - The serializer
All Implemented Interfaces:
org.bukkit.event.Listener

public class RootFileReader<R,T extends Serializer<R>> extends Object implements org.bukkit.event.Listener
Parses a pre-defined folder from config into a Configuration.

For example, WeaponMechanics has the "ammo" folder which is serialized by the Ammo serializer. So we may call new RootFileReader(plugin, Ammo.class, "ammos"). This serializer will recursively read through all YAML files in the "ammos" directory.

For "extension functionality," this class supports adding serializers and validators that are used in the file reading stage.

  • Constructor Details

    • RootFileReader

      public RootFileReader(@NotNull @NotNull me.deecaad.core.MechanicsPlugin plugin, @NotNull @NotNull Class<T> serializerClass, @NotNull @NotNull String relativeFolder)
      Uses the given MechanicsPlugin to set the data, as a shorthand.
      Parameters:
      plugin - The plugin to use
      serializerClass - The serializer class to use for deserialization
      relativeFolder - The relative folder to read from, relative to the plugin's data folder
    • RootFileReader

      public RootFileReader(@NotNull @NotNull File pluginDataFolder, @NotNull @NotNull me.deecaad.core.MechanicsLogger debugger, @NotNull @NotNull ClassLoader classLoader, @NotNull @NotNull Class<T> serializerClass, @NotNull @NotNull String relativeFolder)
  • Method Details

    • getSerializerClass

      @NotNull public @NotNull Class<T> getSerializerClass()
    • getRelativeFolder

      @NotNull public @NotNull String getRelativeFolder()
    • getRootFolder

      @NotNull public @NotNull File getRootFolder()
    • withSerializers

      @NotNull public @NotNull RootFileReader<R,T> withSerializers(@NotNull @NotNull Collection<Serializer<?>> serializers)
    • withValidators

      @NotNull public @NotNull RootFileReader<R,T> withValidators(@NotNull @NotNull Collection<IValidator> validators)
    • assertFiles

      @NotNull public @NotNull RootFileReader<R,T> assertFiles()
      If the root folder does not exist, copy the default files from the jar to the root folder. This method is great for forcing a required directory, or letting users delete the directory so you can refill it with default values.
    • read

      @NotNull public @NotNull me.deecaad.core.file.Configuration read()
      Walks the file directory and tries to parse everything.

      All YAML files will be read, and accumulated into 1 Configuration. Rarely, a duplicate value may be detected (YAML doesn't allow for duplicate values, but when combining many YAML files, duplicate values may occur). In this case, that file will skip the deserialization phase and an error will be logged to console.

      Returns:
      The filled config