Package me.deecaad.core.file
Class RootFileReader<R,T extends Serializer<R>>
java.lang.Object
me.deecaad.core.file.RootFileReader<R,T>
- Type Parameters:
R- The serialized typeT- 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 Summary
ConstructorsConstructorDescriptionRootFileReader(@NotNull File pluginDataFolder, @NotNull me.deecaad.core.MechanicsLogger debugger, @NotNull ClassLoader classLoader, @NotNull Class<T> serializerClass, @NotNull String relativeFolder) RootFileReader(@NotNull me.deecaad.core.MechanicsPlugin plugin, @NotNull Class<T> serializerClass, @NotNull String relativeFolder) Uses the givenMechanicsPluginto set the data, as a shorthand. -
Method Summary
Modifier and TypeMethodDescription@NotNull RootFileReader<R, T> If the root folder does not exist, copy the default files from the jar to the root folder.@NotNull String@NotNull File@NotNull me.deecaad.core.file.Configurationread()Walks the file directory and tries to parse everything.@NotNull RootFileReader<R, T> withSerializers(@NotNull Collection<Serializer<?>> serializers) @NotNull RootFileReader<R, T> withValidators(@NotNull Collection<IValidator> validators)
-
Constructor Details
-
RootFileReader
public RootFileReader(@NotNull @NotNull me.deecaad.core.MechanicsPlugin plugin, @NotNull @NotNull Class<T> serializerClass, @NotNull @NotNull String relativeFolder) Uses the givenMechanicsPluginto set the data, as a shorthand.- Parameters:
plugin- The plugin to useserializerClass- The serializer class to use for deserializationrelativeFolder- 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
-
getRelativeFolder
-
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
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
-