Class Config
This class wraps YamlFile and exposes convenience getters/setters for common Bukkit and
utility types, while also providing a lightweight validation mechanism to ensure that
required keys exist in the configuration.
File lifecycle
Config(JavaPlugin, String): creates/loads a config located in the plugin's data folder. If missing, the resource is copied from the plugin JAR viaJavaPlugin.saveResource(String, boolean).Config(File),Config(Path),Config(String): load an existing file by location; if the file does not exist, anIllegalArgumentExceptionis thrown.
Supported value types
In addition to primitive and boxed types that Bukkit/YAML supports by default, this wrapper includes helpers for:
Vector2andVector3stored as nested keys (e.g.myVector.x,myVector.y,myVector.z).Materialstored by itsEnum.name()value.ItemStackstored using Bukkit's built-in serialization.- Lists (string/int/double and generic lists) using Bukkit's configuration API.
Validation
Validation entries can be registered via addValidationEntry(String, Object) (including
vector overloads). When validate() runs, missing keys are added with their default values
and the configuration is saved. reload() reloads the file content from disk.
Notes
- Most setters update the in-memory configuration only; call
saveConfig()to persist. hasKey(String)and section accessors log errors and may returnnullwhen invoked with anullor empty key.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRepresents a key-value entry for configuration validation. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddValidationEntry(String key, Object value) Adds a validation entry.voidaddValidationEntry(String key, Object value, String comment) Adds a validation entry with a single comment line.voidaddValidationEntry(String key, Object value, String comment, boolean inline) Adds a validation entry with a single comment line and an inline flag.voidaddValidationEntry(String key, Object value, List<String> comments) Adds a validation entry with comments.voidaddValidationEntry(String key, Object value, List<String> comments, boolean inline) Adds a validation entry with comments and an inline flag.<T extends Number>
voidaddValidationEntry(String key, Vector2<T> value) Adds validation entries for aVector2underkey.<T extends Number>
voidaddValidationEntry(String key, Vector3<T> value) Adds validation entries for aVector3underkey.voidAddValidationEntry(String key, Object value) Deprecated.voidAddValidationEntry(String key, Object value, String comment) Deprecated.voidAddValidationEntry(String key, Object value, List<String> comments) Deprecated.<T extends Number>
voidAddValidationEntry(String key, Vector2<T> value) Deprecated.<T extends Number>
voidAddValidationEntry(String key, Vector3<T> value) Deprecated.Gets a raw value from the underlying Bukkit configuration.Deprecated.Useget(String).Gets a boolean value.Deprecated.UsegetBool(String).getComments(String key) Gets comments associated with a key.GetComments(String key) Deprecated.UsegetComments(String).org.bukkit.configuration.ConfigurationSectionGets aConfigurationSectionat the given key.org.bukkit.configuration.ConfigurationSectionDeprecated.Gets a double value.Deprecated.UsegetDouble(String).getDoubleList(String key) Gets a list of doubles.GetDoubleList(String key) Deprecated.getFile()Returns the underlying YAML file wrapper.GetFile()Deprecated.UsegetFile().Deprecated.This method is outdated and will be removed in future versions.Deprecated.UsegetFloat(String).getInlineComment(String key) Gets inline comments associated with a key.Gets an integer value.Deprecated.UsegetInt(String).getIntList(String key) Gets a list of integers.GetIntList(String key) Deprecated.UsegetIntList(String).org.bukkit.inventory.ItemStackgetItemStack(String key) Gets anItemStack.org.bukkit.inventory.ItemStackGetItemStack(String key) Deprecated.UsegetItemStack(String).List<?> Gets a raw list.List<?> Deprecated.UsegetList(String).org.bukkit.MaterialgetMaterial(String key) Gets aMaterialby name.org.bukkit.MaterialGetMaterial(String key) Deprecated.UsegetMaterial(String).org.bukkit.OfflinePlayergetOfflinePlayer(String key) Gets an OfflinePlayer value.org.bukkit.plugin.java.JavaPluginReturns the plugin instance associated with this config.org.bukkit.plugin.java.JavaPluginDeprecated.UsegetPlugin().org.bukkit.configuration.ConfigurationSectiongetSection(String key) Gets a section at the given key.org.bukkit.configuration.ConfigurationSectionGetSection(String key) Deprecated.UsegetSection(String).<T extends org.bukkit.configuration.serialization.ConfigurationSerializable>
TgetSerializable(String key, Class<T> type) Gets a ConfigurationSerializable value.Gets a string value.Deprecated.UsegetString(String).getStringList(String key) Gets a list of strings.GetStringList(String key) Deprecated.getVector2(String key) Gets a 2D vector.GetVector2(String key) Deprecated.UsegetVector2(String).getVector3(String key) Gets a 3D vector.GetVector3(String key) Deprecated.UsegetVector3(String).Checks whether a key exists.Deprecated.UsehasKey(String).voidreload()Reloads the configuration from disk.voidReload()Deprecated.Usereload().voidSaves the configuration to disk.voidDeprecated.UsesaveConfig().voidSets a raw value in the underlying Bukkit configuration (in-memory).voidDeprecated.Useset(String, Object).voidSets a boolean value in-memory.voidDeprecated.voidsetComments(String key, List<String> comments) Sets comments for a key.voidSetComments(String key, List<String> comments) Deprecated.voidSets a double value in-memory.voidDeprecated.voidsetDoubleList(String key, List<Double> value) Sets a list of doubles in-memory.voidSetDoubleList(String key, List<Double> value) Deprecated.voidsetInlineComment(String key, List<String> comments) Sets inline comments for a key.voidSets an integer value in-memory.voidDeprecated.voidsetIntList(String key, List<Integer> value) Sets a list of integers in-memory.voidSetIntList(String key, List<Integer> value) Deprecated.voidsetItemStack(String key, org.bukkit.inventory.ItemStack item) Stores anItemStack(in-memory).voidSetItemStack(String key, org.bukkit.inventory.ItemStack item) Deprecated.voidSets a raw list in-memory.voidDeprecated.voidsetMaterial(String key, org.bukkit.Material material) Stores aMaterialas its enum name.voidSetMaterial(String key, org.bukkit.Material material) Deprecated.voidsetOfflinePlayer(String key, org.bukkit.OfflinePlayer value) Sets an OfflinePlayer value in-memory.voidsetSerializable(String key, org.bukkit.configuration.serialization.ConfigurationSerializable value) Sets a ConfigurationSerializable value in-memory.voidSets a string value in-memory.voidDeprecated.voidsetStringList(String key, List<String> value) Sets a list of strings in-memory.voidSetStringList(String key, List<String> value) Deprecated.<T extends Number>
voidsetVector2(String key, Vector2<T> value) Sets a 2D vector in-memory.<T extends Number>
voidSetVector2(String key, Vector2<T> value) Deprecated.<T extends Number>
voidsetVector3(String key, Vector3<T> value) Sets a 3D vector in-memory.<T extends Number>
voidSetVector3(String key, Vector3<T> value) Deprecated.voidvalidate()Ensures all registered validation keys exist.voidValidate()Deprecated.Usevalidate().
-
Constructor Details
-
Config
Constructs a new Config object.If the file does not exist, it will be copied from the plugin's resources.
- Parameters:
plugin- The JavaPlugin instance.file- The name of the configuration file.
-
Config
Constructs a new Config object.If the file does not exist, an error is thrown.
- Parameters:
file- The File of the configuration file.
-
Config
Constructs a new Config object.If the file does not exist, an error is thrown.
- Parameters:
path- The Path of the configuration file.
-
Config
Constructs a new Config object.If the file does not exist, an error is thrown.
- Parameters:
path- The path of the configuration file.
-
-
Method Details
-
getPlugin
public org.bukkit.plugin.java.JavaPlugin getPlugin()Returns the plugin instance associated with this config.When this
Configinstance was created without an explicit plugin (e.g. via theConfig(File),Config(Path)orConfig(String)constructors), the implementation currently logs an error and may returnnull.- Returns:
- the attached
JavaPlugin, ornullwhen no plugin is attached.
-
GetPlugin
Deprecated.UsegetPlugin(). -
getString
Gets a string value.- Parameters:
key- config path- Returns:
- string value or
nullif not present
-
GetString
Deprecated.UsegetString(String). -
setString
Sets a string value in-memory.- Parameters:
key- config pathvalue- value to set- See Also:
-
SetString
Deprecated. -
getBool
Gets a boolean value.- Parameters:
key- config path- Returns:
- boolean value (defaults to
falseif missing)
-
GetBool
Deprecated.UsegetBool(String). -
setBool
Sets a boolean value in-memory.- Parameters:
key- config pathvalue- value to set- See Also:
-
SetBool
Deprecated. -
getInt
Gets an integer value.- Parameters:
key- config path- Returns:
- integer value (defaults to
0if missing)
-
GetInt
Deprecated.UsegetInt(String). -
setInt
Sets an integer value in-memory.- Parameters:
key- config pathvalue- value to set- See Also:
-
SetInt
Deprecated. -
getFloat
Deprecated.This method is outdated and will be removed in future versions. UsegetDouble(String).Retrieves a float (double) value from the config.- Parameters:
key- config path- Returns:
- double value stored at
key
-
GetFloat
Deprecated.UsegetFloat(String).Retrieves a float (double) value from the config.- Parameters:
key- config path- Returns:
- double value stored at
key
-
getDouble
Gets a double value.- Parameters:
key- config path- Returns:
- double value (defaults to
0.0if missing)
-
GetDouble
Deprecated.UsegetDouble(String). -
setDouble
Sets a double value in-memory.- Parameters:
key- config pathvalue- value to set- See Also:
-
SetDouble
Deprecated. -
getOfflinePlayer
Gets an OfflinePlayer value.- Parameters:
key- config path- Returns:
- OfflinePlayer value or
nullif not present
-
setOfflinePlayer
Sets an OfflinePlayer value in-memory.- Parameters:
key- config pathvalue- value to set- See Also:
-
setSerializable
public void setSerializable(String key, org.bukkit.configuration.serialization.ConfigurationSerializable value) Sets a ConfigurationSerializable value in-memory.- Parameters:
key- config pathvalue- value to set- See Also:
-
getSerializable
public <T extends org.bukkit.configuration.serialization.ConfigurationSerializable> T getSerializable(String key, Class<T> type) Gets a ConfigurationSerializable value.- Parameters:
key- config pathtype- class of the value to get- Returns:
- deserialized value, or
nullif not present
-
getVector2
Gets a 2D vector.Values are read from nested keys:
key + ".x"andkey + ".y".- Parameters:
key- base config path- Returns:
- vector composed from the stored x/y values (may contain
nulls if keys are missing)
-
GetVector2
Deprecated.UsegetVector2(String). -
setVector2
Sets a 2D vector in-memory.Values are written to nested keys:
key + ".x"andkey + ".y".- Parameters:
key- base config pathvalue- vector to store- See Also:
-
SetVector2
@Deprecated @MarkedForRemoval public <T extends Number> void SetVector2(String key, Vector2<T> value) Deprecated. -
getVector3
Gets a 3D vector.Values are read from nested keys:
key + ".x",key + ".y",key + ".z".- Parameters:
key- base config path- Returns:
- vector composed from the stored x/y/z values (may contain
nulls if keys are missing)
-
GetVector3
Deprecated.UsegetVector3(String). -
setVector3
Sets a 3D vector in-memory.Values are written to nested keys:
key + ".x",key + ".y",key + ".z".- Parameters:
key- base config pathvalue- vector to store- See Also:
-
SetVector3
@Deprecated @MarkedForRemoval public <T extends Number> void SetVector3(String key, Vector3<T> value) Deprecated. -
getMaterial
Gets aMaterialby name.- Parameters:
key- config path containing the material name- Returns:
- resolved material, or
nullif the name is missing/invalid
-
GetMaterial
Deprecated.UsegetMaterial(String). -
setMaterial
Stores aMaterialas its enum name.- Parameters:
key- config pathmaterial- material to store- See Also:
-
SetMaterial
Deprecated. -
get
Gets a raw value from the underlying Bukkit configuration.- Parameters:
key- config path- Returns:
- stored value, or
nullif missing
-
Get
Deprecated.Useget(String). -
set
Sets a raw value in the underlying Bukkit configuration (in-memory).- Parameters:
key- config pathvalue- value to set- See Also:
-
Set
Deprecated.Useset(String, Object). -
getStringList
Gets a list of strings.- Parameters:
key- config path- Returns:
- list (never
null; may be empty)
-
GetStringList
Deprecated. -
setStringList
Sets a list of strings in-memory.- Parameters:
key- config pathvalue- list to store- See Also:
-
SetStringList
Deprecated. -
getIntList
Gets a list of integers.- Parameters:
key- config path- Returns:
- list (never
null; may be empty)
-
GetIntList
Deprecated.UsegetIntList(String). -
setIntList
Sets a list of integers in-memory.- Parameters:
key- config pathvalue- list to store- See Also:
-
SetIntList
Deprecated. -
getDoubleList
Gets a list of doubles.- Parameters:
key- config path- Returns:
- list (never
null; may be empty)
-
GetDoubleList
Deprecated. -
setDoubleList
Sets a list of doubles in-memory.- Parameters:
key- config pathvalue- list to store- See Also:
-
SetDoubleList
Deprecated. -
getList
Gets a raw list.- Parameters:
key- config path- Returns:
- list, or
nullif missing
-
GetList
Deprecated.UsegetList(String). -
setList
Sets a raw list in-memory.- Parameters:
key- config pathvalue- list to store- See Also:
-
SetList
Deprecated. -
getItemStack
Gets anItemStack.- Parameters:
key- config path- Returns:
- deserialized item, or
nullif missing
-
GetItemStack
Deprecated.UsegetItemStack(String). -
setItemStack
Stores anItemStack(in-memory).- Parameters:
key- config pathitem- item to store- See Also:
-
SetItemStack
@Deprecated @MarkedForRemoval public void SetItemStack(String key, org.bukkit.inventory.ItemStack item) Deprecated. -
hasKey
Checks whether a key exists.- Parameters:
key- config path- Returns:
trueif present;falseif not present; ornullwhenkeyisnull/empty (also logs an error)
-
HasKey
Deprecated.UsehasKey(String). -
getConfigurationSection
Gets aConfigurationSectionat the given key.This first attempts
MemorySection.getConfigurationSection(String). If that returnsnull, it falls back togetSection(String)for compatibility with different underlying YAML implementations.- Parameters:
key- config path- Returns:
- the configuration section for
key, ornullifkeyisnull/empty (logs an error) or the section does not exist
-
GetConfigurationSection
@Deprecated @MarkedForRemoval public org.bukkit.configuration.ConfigurationSection GetConfigurationSection(String key) Deprecated. -
getSection
Gets a section at the given key.- Parameters:
key- config path- Returns:
- the section, or
nullif missing/invalid key
-
GetSection
@Deprecated @MarkedForRemoval public org.bukkit.configuration.ConfigurationSection GetSection(String key) Deprecated.UsegetSection(String). -
getComments
Gets comments associated with a key.- Parameters:
key- config path- Returns:
- comment lines, or
nullifkeyisnull/empty
-
GetComments
Deprecated.UsegetComments(String). -
setComments
Sets comments for a key.- Parameters:
key- config pathcomments- comment lines to store
-
SetComments
Deprecated. -
getInlineComment
Gets inline comments associated with a key.- Parameters:
key- config path- Returns:
- inline comment lines, or
nullifkeyisnull/empty
-
setInlineComment
Sets inline comments for a key.- Parameters:
key- config pathcomments- inline comment lines to store
-
getFile
Returns the underlying YAML file wrapper.- Returns:
- backing
YamlFile
-
GetFile
Deprecated.UsegetFile(). -
reload
public void reload()Reloads the configuration from disk. -
Reload
Deprecated.Usereload(). -
saveConfig
public void saveConfig()Saves the configuration to disk. -
SaveConfig
Deprecated.UsesaveConfig(). -
addValidationEntry
Adds a validation entry.During
validate(), missing keys will be created withvalue.- Parameters:
key- config pathvalue- default value to write when missing
-
AddValidationEntry
Deprecated. -
addValidationEntry
Adds a validation entry with comments.- Parameters:
key- config pathvalue- default value to write when missingcomments- comment lines to associate with the key
-
AddValidationEntry
@Deprecated @MarkedForRemoval public void AddValidationEntry(String key, Object value, List<String> comments) Deprecated. -
addValidationEntry
Adds a validation entry with a single comment line.- Parameters:
key- config pathvalue- default value to write when missingcomment- comment line to associate with the key
-
AddValidationEntry
@Deprecated @MarkedForRemoval public void AddValidationEntry(String key, Object value, String comment) Deprecated. -
addValidationEntry
Adds a validation entry with comments and an inline flag.- Parameters:
key- config pathvalue- default value to write when missingcomments- comment lines to associate with the keyinline- whether the comments should be inline (true) or block (false)
-
addValidationEntry
Adds a validation entry with a single comment line and an inline flag.- Parameters:
key- config pathvalue- default value to write when missingcomment- comment line to associate with the keyinline- whether the comment should be inline (true) or block (false)
-
addValidationEntry
- Parameters:
key- base config pathvalue- vector providing default x/y values
-
AddValidationEntry
@Deprecated @MarkedForRemoval public <T extends Number> void AddValidationEntry(String key, Vector2<T> value) Deprecated. -
addValidationEntry
Adds validation entries for aVector3underkey.This registers
key + ".x",key + ".y"andkey + ".z".- Parameters:
key- base config pathvalue- vector providing default x/y/z values
-
AddValidationEntry
@Deprecated @MarkedForRemoval public <T extends Number> void AddValidationEntry(String key, Vector3<T> value) Deprecated. -
validate
public void validate()Ensures all registered validation keys exist.If any keys are missing, they are added with their defaults and the file is saved.
-
Validate
Deprecated.Usevalidate().
-
addValidationEntry(String, Object).