Class KamiConfig
java.lang.Object
com.kamikazejam.kamicommon.configuration.standalone.AbstractConfig<YamlConfiguration>
com.kamikazejam.kamicommon.configuration.spigot.KamiConfig
- All Implemented Interfaces:
ObservableConfig
,ConfigurationMethods<ConfigurationSection>
,ConfigurationSection
- Direct Known Subclasses:
KamiConfigExt
public class KamiConfig
extends AbstractConfig<YamlConfiguration>
implements ConfigurationSection, ObservableConfig
A class that represents a configuration file (Meant for implementations WITH a JavaPlugin object available)
If you DO NOT have a JavaPlugin object, it is recommended to use
This is an extension of a YamlConfiguration, so all get, set, and put methods are available.
When extending this class, provide the File to the config in the super, and then add all desired comments
Then you can use this object just like a YamlConfiguration, it has all the same methods plus a few others like
If you DO NOT have a JavaPlugin object, it is recommended to use
StandaloneConfig
instead This is an extension of a YamlConfiguration, so all get, set, and put methods are available.
When extending this class, provide the File to the config in the super, and then add all desired comments
Then you can use this object just like a YamlConfiguration, it has all the same methods plus a few others like
reload()
-
Constructor Summary
ConstructorsConstructorDescriptionKamiConfig
(@NotNull AbstractSubsystem<?, ?> subsystem, File file) Creates a new config instance with the given subsystem and destination file.
This constructor enables defaults using the following resource file method:
- Fetches the resource file using the provided file name, fromAbstractSubsystem.getSupplementalConfigResource(String)
KamiConfig
(@NotNull AbstractSubsystem<?, ?> subsystem, File file, @Nullable Supplier<InputStream> defaultsStream) Creates a new config instance with the given subsystem and destination file.
This constructor uses defaults if and only if the provided supplier is NOT null:
- Providing a non-null supplier will enable defaults using the provided InputStream - Providing a null supplier will disable defaultsKamiConfig
(@NotNull JavaPlugin plugin, File file) Creates a new config instance with the given plugin and destination file.
This constructor enables defaults using the following resource file method:
- Assumes a resource file with the same name as the provided file, exists in the current jar.KamiConfig
(@NotNull JavaPlugin plugin, File file, @Nullable Supplier<InputStream> defaultsStream) Creates a new config instance with the given plugin and destination file.
This constructor uses defaults if and only if the provided supplier is NOT null:
- Providing a non-null supplier will enable defaults using the provided InputStream - Providing a null supplier will disable defaults -
Method Summary
Modifier and TypeMethodDescriptionvoid
addDefault
(String key, Object o) boolean
getBigDecimal
(String key) getBigDecimal
(String key, BigDecimal def) boolean
getBoolean
(String key) boolean
getBoolean
(String key, boolean def) byte
byte
getByteList
(String key) getByteList
(String key, List<Byte> def) @NotNull MemorySection
@NotNull ConfigurationSequenceSpigot
double
double
protected File
getFile()
float
float
int
int
getIntegerList
(String key) getIntegerList
(String key, List<Integer> def) getItemStack
(String key) getItemStack
(String key, ItemStack def) getKeys
(boolean deep) Returns the keys of the config If Deep is enabled, it will dig and find all valid keys that resolve to a valueList
<?> List
<?> long
long
short
short
getStringList
(String key) getStringList
(String key, List<String> def) protected YamlConfiguration
boolean
boolean
boolean
boolean
boolean
isEmpty()
boolean
boolean
boolean
isItemStack
(String key) boolean
boolean
boolean
boolean
boolean
boolean
@NotNull ItemBuilder
parseItemBuilder
(@NotNull String key) Parses the subsection at the given key into anItemBuilder
.void
void
putBoolean
(String key, boolean value) void
void
void
void
void
putInteger
(String key, int value) void
void
void
boolean
registerConfigObserver
(@NotNull ConfigObserver observer) Registers an observer to this config (if not already registered)
Refer to theConfigObserver
docs for information on its lifecycle.void
reload()
Reloads the config from the filevoid
Reload the backing config for this observable, notifying all registered observers of the change.
Equivalent to callingreload()
void
void
setBoolean
(String key, boolean value) void
void
void
void
void
setInteger
(String key, int value) void
setItemStack
(String key, ItemStack item) void
void
void
void
unregisterConfigObserver
(@NotNull ConfigObserver observer) Unregisters an observer from this configvoid
Unregisters ALL observers from this config.
Intended for shutdown logic, but can be used at any time.Methods inherited from class com.kamikazejam.kamicommon.configuration.standalone.AbstractConfig
isChanged, save, save, setChanged
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.kamikazejam.kamicommon.yaml.base.ConfigurationMethods
isChanged, setChanged
-
Constructor Details
-
KamiConfig
Creates a new config instance with the given plugin and destination file.
This constructor enables defaults using the following resource file method:
- Assumes a resource file with the same name as the provided file, exists in the current jar. -
KamiConfig
public KamiConfig(@NotNull @NotNull JavaPlugin plugin, File file, @Nullable @Nullable Supplier<InputStream> defaultsStream) Creates a new config instance with the given plugin and destination file.
This constructor uses defaults if and only if the provided supplier is NOT null:
- Providing a non-null supplier will enable defaults using the provided InputStream - Providing a null supplier will disable defaults- Parameters:
defaultsStream
- The optional supplier to load defaults from.
-
KamiConfig
Creates a new config instance with the given subsystem and destination file.
This constructor enables defaults using the following resource file method:
- Fetches the resource file using the provided file name, fromAbstractSubsystem.getSupplementalConfigResource(String)
-
KamiConfig
public KamiConfig(@NotNull @NotNull AbstractSubsystem<?, ?> subsystem, File file, @Nullable @Nullable Supplier<InputStream> defaultsStream) Creates a new config instance with the given subsystem and destination file.
This constructor uses defaults if and only if the provided supplier is NOT null:
- Providing a non-null supplier will enable defaults using the provided InputStream - Providing a null supplier will disable defaults
-
-
Method Details
-
reload
public void reload()Description copied from class:AbstractConfig
Reloads the config from the file- Specified by:
reload
in classAbstractConfig<YamlConfiguration>
-
getFile
- Specified by:
getFile
in classAbstractConfig<YamlConfiguration>
- Returns:
- The file associated with this config
-
getYamlConfiguration
- Specified by:
getYamlConfiguration
in classAbstractConfig<YamlConfiguration>
- Returns:
- The YamlConfiguration associated with this config
-
registerConfigObserver
Description copied from interface:ObservableConfig
Registers an observer to this config (if not already registered)
Refer to theConfigObserver
docs for information on its lifecycle.- Specified by:
registerConfigObserver
in interfaceObservableConfig
- Returns:
- If the observer was successfully registered from this call (false if already registered)
-
unregisterConfigObserver
Description copied from interface:ObservableConfig
Unregisters an observer from this config- Specified by:
unregisterConfigObserver
in interfaceObservableConfig
-
unregisterConfigObservers
public void unregisterConfigObservers()Description copied from interface:ObservableConfig
Unregisters ALL observers from this config.
Intended for shutdown logic, but can be used at any time.- Specified by:
unregisterConfigObservers
in interfaceObservableConfig
-
reloadObservableConfig
public void reloadObservableConfig()Reload the backing config for this observable, notifying all registered observers of the change.
Equivalent to callingreload()
- Specified by:
reloadObservableConfig
in interfaceObservableConfig
-
set
- Specified by:
set
in interfaceConfigurationMethods<ConfigurationSection>
-
put
- Specified by:
put
in interfaceConfigurationMethods<ConfigurationSection>
-
putString
- Specified by:
putString
in interfaceConfigurationMethods<ConfigurationSection>
-
putBoolean
- Specified by:
putBoolean
in interfaceConfigurationMethods<ConfigurationSection>
-
putByte
- Specified by:
putByte
in interfaceConfigurationMethods<ConfigurationSection>
-
putShort
- Specified by:
putShort
in interfaceConfigurationMethods<ConfigurationSection>
-
putInteger
- Specified by:
putInteger
in interfaceConfigurationMethods<ConfigurationSection>
-
putInt
- Specified by:
putInt
in interfaceConfigurationMethods<ConfigurationSection>
-
putLong
- Specified by:
putLong
in interfaceConfigurationMethods<ConfigurationSection>
-
putDouble
- Specified by:
putDouble
in interfaceConfigurationMethods<ConfigurationSection>
-
putFloat
- Specified by:
putFloat
in interfaceConfigurationMethods<ConfigurationSection>
-
setString
- Specified by:
setString
in interfaceConfigurationMethods<ConfigurationSection>
-
setBoolean
- Specified by:
setBoolean
in interfaceConfigurationMethods<ConfigurationSection>
-
setByte
- Specified by:
setByte
in interfaceConfigurationMethods<ConfigurationSection>
-
setShort
- Specified by:
setShort
in interfaceConfigurationMethods<ConfigurationSection>
-
setInteger
- Specified by:
setInteger
in interfaceConfigurationMethods<ConfigurationSection>
-
setInt
- Specified by:
setInt
in interfaceConfigurationMethods<ConfigurationSection>
-
setLong
- Specified by:
setLong
in interfaceConfigurationMethods<ConfigurationSection>
-
setDouble
- Specified by:
setDouble
in interfaceConfigurationMethods<ConfigurationSection>
-
setFloat
- Specified by:
setFloat
in interfaceConfigurationMethods<ConfigurationSection>
-
get
- Specified by:
get
in interfaceConfigurationMethods<ConfigurationSection>
-
get
- Specified by:
get
in interfaceConfigurationMethods<ConfigurationSection>
-
getConfigurationSection
- Specified by:
getConfigurationSection
in interfaceConfigurationMethods<ConfigurationSection>
-
getConfigurationSequence
- Specified by:
getConfigurationSequence
in interfaceConfigurationMethods<ConfigurationSection>
-
getString
- Specified by:
getString
in interfaceConfigurationMethods<ConfigurationSection>
-
getString
- Specified by:
getString
in interfaceConfigurationMethods<ConfigurationSection>
-
isString
- Specified by:
isString
in interfaceConfigurationMethods<ConfigurationSection>
-
getInt
- Specified by:
getInt
in interfaceConfigurationMethods<ConfigurationSection>
-
getInt
- Specified by:
getInt
in interfaceConfigurationMethods<ConfigurationSection>
-
isInt
- Specified by:
isInt
in interfaceConfigurationMethods<ConfigurationSection>
-
getLong
- Specified by:
getLong
in interfaceConfigurationMethods<ConfigurationSection>
-
getLong
- Specified by:
getLong
in interfaceConfigurationMethods<ConfigurationSection>
-
isLong
- Specified by:
isLong
in interfaceConfigurationMethods<ConfigurationSection>
-
getList
- Specified by:
getList
in interfaceConfigurationMethods<ConfigurationSection>
-
getList
- Specified by:
getList
in interfaceConfigurationMethods<ConfigurationSection>
-
isList
- Specified by:
isList
in interfaceConfigurationMethods<ConfigurationSection>
-
getBoolean
- Specified by:
getBoolean
in interfaceConfigurationMethods<ConfigurationSection>
-
getBoolean
- Specified by:
getBoolean
in interfaceConfigurationMethods<ConfigurationSection>
-
isBoolean
- Specified by:
isBoolean
in interfaceConfigurationMethods<ConfigurationSection>
-
getStringList
- Specified by:
getStringList
in interfaceConfigurationMethods<ConfigurationSection>
-
getStringList
- Specified by:
getStringList
in interfaceConfigurationMethods<ConfigurationSection>
-
getIntegerList
- Specified by:
getIntegerList
in interfaceConfigurationMethods<ConfigurationSection>
-
getIntegerList
- Specified by:
getIntegerList
in interfaceConfigurationMethods<ConfigurationSection>
-
getByteList
- Specified by:
getByteList
in interfaceConfigurationMethods<ConfigurationSection>
-
getByteList
- Specified by:
getByteList
in interfaceConfigurationMethods<ConfigurationSection>
-
getDouble
- Specified by:
getDouble
in interfaceConfigurationMethods<ConfigurationSection>
-
getDouble
- Specified by:
getDouble
in interfaceConfigurationMethods<ConfigurationSection>
-
isDouble
- Specified by:
isDouble
in interfaceConfigurationMethods<ConfigurationSection>
-
getByte
- Specified by:
getByte
in interfaceConfigurationMethods<ConfigurationSection>
-
getByte
- Specified by:
getByte
in interfaceConfigurationMethods<ConfigurationSection>
-
isByte
- Specified by:
isByte
in interfaceConfigurationMethods<ConfigurationSection>
-
getShort
- Specified by:
getShort
in interfaceConfigurationMethods<ConfigurationSection>
-
getShort
- Specified by:
getShort
in interfaceConfigurationMethods<ConfigurationSection>
-
isShort
- Specified by:
isShort
in interfaceConfigurationMethods<ConfigurationSection>
-
getFloat
- Specified by:
getFloat
in interfaceConfigurationMethods<ConfigurationSection>
-
getFloat
- Specified by:
getFloat
in interfaceConfigurationMethods<ConfigurationSection>
-
isFloat
- Specified by:
isFloat
in interfaceConfigurationMethods<ConfigurationSection>
-
getBigDecimal
- Specified by:
getBigDecimal
in interfaceConfigurationMethods<ConfigurationSection>
-
getBigDecimal
- Specified by:
getBigDecimal
in interfaceConfigurationMethods<ConfigurationSection>
-
isNumber
- Specified by:
isNumber
in interfaceConfigurationMethods<ConfigurationSection>
-
getKeys
Returns the keys of the config If Deep is enabled, it will dig and find all valid keys that resolve to a value- Specified by:
getKeys
in interfaceConfigurationMethods<ConfigurationSection>
- Parameters:
deep
- Whether to search for all sub-keys- Returns:
- The list of keys found
-
isConfigurationSection
- Specified by:
isConfigurationSection
in interfaceConfigurationMethods<ConfigurationSection>
-
contains
- Specified by:
contains
in interfaceConfigurationMethods<ConfigurationSection>
-
isSet
- Specified by:
isSet
in interfaceConfigurationMethods<ConfigurationSection>
-
addDefault
- Specified by:
addDefault
in interfaceConfigurationMethods<ConfigurationSection>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmpty
in interfaceConfigurationMethods<ConfigurationSection>
-
getItemStack
- Specified by:
getItemStack
in interfaceConfigurationSection
-
getItemStack
- Specified by:
getItemStack
in interfaceConfigurationSection
-
setItemStack
- Specified by:
setItemStack
in interfaceConfigurationSection
-
isItemStack
- Specified by:
isItemStack
in interfaceConfigurationSection
-
parseItemBuilder
Description copied from interface:ConfigurationSection
Parses the subsection at the given key into anItemBuilder
. This is equivalent to using:
-ItemBuilderLoader.load(ConfigurationSection)
with the subsection at the given key as the argument.- Specified by:
parseItemBuilder
in interfaceConfigurationSection
- Parameters:
key
- The key of the subsection to parse.- Returns:
- The parsed
ItemBuilder
.
-
getCurrentPath
- Specified by:
getCurrentPath
in interfaceConfigurationMethods<ConfigurationSection>
- Specified by:
getCurrentPath
in interfaceConfigurationSection
-