Package xyz.srnyx.annoyingapi.file
Class AnnoyingFile<T extends AnnoyingFile<T>>
java.lang.Object
org.bukkit.configuration.MemorySection
org.bukkit.configuration.MemoryConfiguration
org.bukkit.configuration.file.FileConfiguration
org.bukkit.configuration.file.YamlConfiguration
xyz.srnyx.annoyingapi.file.AnnoyingFile<T>
- Type Parameters:
T- the type of theAnnoyingFileinstance
- All Implemented Interfaces:
org.bukkit.configuration.Configuration,org.bukkit.configuration.ConfigurationSection
- Direct Known Subclasses:
AnnoyingData,AnnoyingResource
public class AnnoyingFile<T extends AnnoyingFile<T>>
extends org.bukkit.configuration.file.YamlConfiguration
Represents a file in the plugin's folder
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAnnoyingFile.Options<G extends AnnoyingFile.Options<G>>A class to hold the options for a file
Default options:AnnoyingFile.Options.canBeEmpty=trueAnnoyingFile.Options.replace=false -
Field Summary
FieldsModifier and TypeFieldDescriptionfinal @NotNull FileTheFilefor the fileprotected final @NotNull AnnoyingFile.Options<?> TheAnnoyingFile.Optionsfor the filefinal @NotNull AnnoyingPluginTheAnnoyingPlugininstanceFields inherited from class org.bukkit.configuration.file.YamlConfiguration
BLANK_CONFIG, COMMENT_PREFIXFields inherited from class org.bukkit.configuration.file.FileConfiguration
SYSTEM_UTF, UTF_BIG, UTF8_OVERRIDEFields inherited from class org.bukkit.configuration.MemoryConfiguration
defaults, optionsFields inherited from class org.bukkit.configuration.MemorySection
map -
Constructor Summary
ConstructorsConstructorDescriptionAnnoyingFile(@NotNull AnnoyingPlugin plugin, @NotNull File file) Constructs a newAnnoyingFileAnnoyingFile(@NotNull AnnoyingPlugin plugin, @NotNull File file, @Nullable AnnoyingFile.Options<?> fileOptions) Constructs a newAnnoyingFileAnnoyingFile(@NotNull AnnoyingPlugin plugin, @NotNull String path) Constructs a newAnnoyingFileAnnoyingFile(@NotNull AnnoyingPlugin plugin, @NotNull String path, @Nullable AnnoyingFile.Options<?> fileOptions) Constructs a newAnnoyingFile -
Method Summary
Modifier and TypeMethodDescriptionvoidcreate()Creates thefilebooleandelete()Deletes thefile, won't fail silentlybooleandelete(boolean silentFail) Deletes thefile<G> @NotNull Optional<G> getAttributeModifier(@NotNull String path) 1.9+Gets anAttributeModifierfrom the path.<G> @NotNull Optional<G> getAttributeModifier(@NotNull String path, boolean log) 1.9+Gets anAttributeModifierfrom the path.@NotNull Optional<org.bukkit.configuration.ConfigurationSection> getConfigurationSectionOptional(@NotNull String path) Get aConfigurationSectionfrom the path in anOptional<G> @NotNull Optional<G> Gets the default value from the path@Nullable org.bukkit.inventory.ItemStackgetItemStack(@NotNull String path) Gets anItemStackfrom the path.@Nullable org.bukkit.inventory.ItemStackgetItemStack(@NotNull String path, @Nullable org.bukkit.inventory.ItemStack def) Gets anItemStackfrom the path.@NotNull Optional<org.bukkit.inventory.ItemStack> getItemStackOptional(@NotNull String path) Gets anItemStackfrom the path.@NotNull Optional<org.bukkit.inventory.ItemStack> getItemStackOptional(@NotNull String path, boolean log) Gets anItemStackfrom the path.@NotNull Optional<PlayableSound> getPlayableSound(@NotNull String path) Gets aPlayableSoundfrom the path.@NotNull Optional<org.bukkit.potion.PotionEffect> getPotionEffect(@NotNull String path) Gets aPotionEffectfrom the path.@NotNull Optional<org.bukkit.potion.PotionEffect> getPotionEffect(@NotNull String path, boolean log) Gets aPotionEffectfrom the path.@NotNull Optional<org.bukkit.inventory.Recipe> Gets aRecipefrom the YAML.@NotNull Optional<org.bukkit.inventory.Recipe> getRecipe(@NotNull String path, @Nullable UnaryOperator<org.bukkit.inventory.ItemStack> itemFunction) Gets aRecipefrom the YAML.@NotNull Optional<org.bukkit.inventory.Recipe> getRecipe(@NotNull String path, @Nullable UnaryOperator<org.bukkit.inventory.ItemStack> itemFunction, @Nullable String name) Gets aRecipefrom the YAML.@NotNull Optional<org.bukkit.inventory.Recipe> getRecipe(@NotNull String path, @Nullable UnaryOperator<org.bukkit.inventory.ItemStack> itemFunction, @Nullable String name, boolean log) Gets aRecipefrom the YAML.@NotNull Optional<org.bukkit.Sound> Gets aSoundfrom the pathbooleanload()Loads the YAML from the path.voidSends a formatted log message to the console Sends a formatted warning message to the consolebooleansave()Saves the YAML to thefileSets a value in the YAML and returns theAnnoyingFileinstancebooleanSets a value in the YAML and thensavesthe file@NotNull StringtoString()Methods inherited from class org.bukkit.configuration.file.YamlConfiguration
buildHeader, convertMapsToSections, loadConfiguration, loadConfiguration, loadConfiguration, loadFromString, options, parseHeader, saveToStringMethods inherited from class org.bukkit.configuration.file.FileConfiguration
load, load, load, load, save, saveMethods inherited from class org.bukkit.configuration.MemoryConfiguration
addDefault, addDefaults, addDefaults, getDefaults, getParent, setDefaultsMethods inherited from class org.bukkit.configuration.MemorySection
contains, createPath, createPath, createSection, createSection, get, get, getBoolean, getBoolean, getBooleanList, getByteList, getCharacterList, getColor, getColor, getConfigurationSection, getCurrentPath, getDefault, getDefaultSection, getDouble, getDouble, getDoubleList, getFloatList, getInt, getInt, getIntegerList, getKeys, getList, getList, getLong, getLong, getLongList, getMapList, getName, getOfflinePlayer, getOfflinePlayer, getRoot, getShortList, getString, getString, getStringList, getValues, getVector, getVector, isBoolean, isColor, isConfigurationSection, isDouble, isInt, isItemStack, isList, isLong, isOfflinePlayer, isPrimitiveWrapper, isSet, isString, isVector, mapChildrenKeys, mapChildrenValues, setMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.bukkit.configuration.ConfigurationSection
contains, createSection, createSection, get, get, getBoolean, getBoolean, getBooleanList, getByteList, getCharacterList, getColor, getColor, getConfigurationSection, getCurrentPath, getDefaultSection, getDouble, getDouble, getDoubleList, getFloatList, getInt, getInt, getIntegerList, getKeys, getList, getList, getLong, getLong, getLongList, getMapList, getName, getOfflinePlayer, getOfflinePlayer, getRoot, getShortList, getString, getString, getStringList, getValues, getVector, getVector, isBoolean, isColor, isConfigurationSection, isDouble, isInt, isItemStack, isList, isLong, isOfflinePlayer, isSet, isString, isVector, set
-
Field Details
-
plugin
TheAnnoyingPlugininstance -
file
TheFilefor the file -
fileOptions
TheAnnoyingFile.Optionsfor the file
-
-
Constructor Details
-
AnnoyingFile
public AnnoyingFile(@NotNull @NotNull AnnoyingPlugin plugin, @NotNull @NotNull File file, @Nullable @Nullable AnnoyingFile.Options<?> fileOptions) Constructs a newAnnoyingFile- Parameters:
plugin-pluginfile-filefileOptions-fileOptions
-
AnnoyingFile
Constructs a newAnnoyingFile -
AnnoyingFile
public AnnoyingFile(@NotNull @NotNull AnnoyingPlugin plugin, @NotNull @NotNull String path, @Nullable @Nullable AnnoyingFile.Options<?> fileOptions) Constructs a newAnnoyingFile- Parameters:
plugin-pluginpath- the path to the file (relative to the plugin's folder). This usesPath, so just using/is okayfileOptions-fileOptions
-
AnnoyingFile
Constructs a newAnnoyingFile- Parameters:
plugin-pluginpath- the path to the file (relative to the plugin's folder)
-
-
Method Details
-
toString
- Overrides:
toStringin classorg.bukkit.configuration.MemorySection
-
create
public void create()Creates thefile -
load
public boolean load()Loads the YAML from the path. If the file doesn't exist andcan't be empty, an emptyYamlConfigurationwill be used- Returns:
- whether the file was loaded successfully
-
delete
public boolean delete(boolean silentFail) Deletes thefile- Parameters:
silentFail- whether to fail silently- Returns:
- whether the file was deleted successfully
- See Also:
-
delete
public boolean delete()Deletes thefile, won't fail silently- Returns:
- whether the file was deleted successfully
- See Also:
-
setChain
Sets a value in the YAML and returns theAnnoyingFileinstance- Parameters:
path- the path to the nodevalue- the value to set the node to- Returns:
- the
AnnoyingFileinstance
-
setSave
Sets a value in the YAML and thensavesthe file- Parameters:
path- the path to the nodevalue- the value to set the node to- Returns:
- whether the file was saved successfully
-
save
public boolean save()Saves the YAML to thefile- Returns:
- whether the file was saved successfully
-
log
public void log(@NotNull @NotNull Level level, @Nullable @Nullable String key, @NotNull @NotNull String message) Sends a formatted log message to the console Sends a formatted warning message to the console- Parameters:
level- theLevelof the messagekey- the key of the node that the message is about (nullif it's not about a node)message- the message to send
-
getDef
Gets the default value from the path- Type Parameters:
G- the type of the default value- Parameters:
path- the path to the node- Returns:
- the default value or empty if it doesn't exist
-
getConfigurationSectionOptional
@NotNull public @NotNull Optional<org.bukkit.configuration.ConfigurationSection> getConfigurationSectionOptional(@NotNull @NotNull String path) Get aConfigurationSectionfrom the path in anOptional- Parameters:
path- the path to the node- Returns:
- the
ConfigurationSectionor empty if it doesn't exist
-
getSound
Gets aSoundfrom the path- Parameters:
path- the path to the node- Returns:
- the
Soundor empty if it's invalid
-
getPlayableSound
Gets aPlayableSoundfrom the path. See the wiki for more information- Parameters:
path- the path to the node- Returns:
- the
PlayableSoundor empty if it's invalid
-
getPotionEffect
@NotNull public @NotNull Optional<org.bukkit.potion.PotionEffect> getPotionEffect(@NotNull @NotNull String path) Gets aPotionEffectfrom the path. See the wiki for more information- Parameters:
path- the path to the node- Returns:
- the
PotionEffector empty if it's invalid
-
getPotionEffect
@NotNull public @NotNull Optional<org.bukkit.potion.PotionEffect> getPotionEffect(@NotNull @NotNull String path, boolean log) Gets aPotionEffectfrom the path. See the wiki for more information- Parameters:
path- the path to the nodelog- whether to log warnings if the potion effect is invalid- Returns:
- the
PotionEffector empty if it's invalid
-
getAttributeModifier
- Type Parameters:
G- theAttributeModifierclass- Parameters:
path- the path to the node- Returns:
- the
AttributeModifieror empty if it's invalid
-
getAttributeModifier
@NotNull public <G> @NotNull Optional<G> getAttributeModifier(@NotNull @NotNull String path, boolean log) - Type Parameters:
G- theAttributeModifierclass- Parameters:
path- the path to the nodelog- whether to log warnings if the attribute modifier is invalid- Returns:
- the
AttributeModifieror empty if it's invalid
-
getItemStack
@Nullable public @Nullable org.bukkit.inventory.ItemStack getItemStack(@NotNull @NotNull String path) Gets anItemStackfrom the path. See the wiki for more information
If you want to disable warning/error logging, usegetItemStackOptional(String, boolean)- Specified by:
getItemStackin interfaceorg.bukkit.configuration.ConfigurationSection- Overrides:
getItemStackin classorg.bukkit.configuration.MemorySection- Parameters:
path- the path to the node- Returns:
- the
ItemStackornullif it's invalid
-
getItemStack
@Nullable public @Nullable org.bukkit.inventory.ItemStack getItemStack(@NotNull @NotNull String path, @Nullable @Nullable org.bukkit.inventory.ItemStack def) Gets anItemStackfrom the path. See the wiki for more information
If you want to disable warning/error logging, usegetItemStackOptional(String, boolean)- Specified by:
getItemStackin interfaceorg.bukkit.configuration.ConfigurationSection- Overrides:
getItemStackin classorg.bukkit.configuration.MemorySection- Parameters:
path- the path to the nodedef- the default value- Returns:
- the
ItemStackordefif it's invalid
-
getItemStackOptional
@NotNull public @NotNull Optional<org.bukkit.inventory.ItemStack> getItemStackOptional(@NotNull @NotNull String path) Gets anItemStackfrom the path. See the wiki for more information- Parameters:
path- the path to the node- Returns:
- the
ItemStackor empty if it's invalid
-
getItemStackOptional
@NotNull public @NotNull Optional<org.bukkit.inventory.ItemStack> getItemStackOptional(@NotNull @NotNull String path, boolean log) Gets anItemStackfrom the path. See the wiki for more information- Parameters:
path- the path to the nodelog- whether to log warnings if the item stack is invalid- Returns:
- the
ItemStackor empty if it's invalid
-
getRecipe
@NotNull public @NotNull Optional<org.bukkit.inventory.Recipe> getRecipe(@NotNull @NotNull String path) Gets aRecipefrom the YAML. See the wiki for more information- Parameters:
path- the path to get the recipe from- Returns:
- the
Recipeornullif it doesn't exist / is invalid / something went wrong
-
getRecipe
@NotNull public @NotNull Optional<org.bukkit.inventory.Recipe> getRecipe(@NotNull @NotNull String path, @Nullable @Nullable UnaryOperator<org.bukkit.inventory.ItemStack> itemFunction) Gets aRecipefrom the YAML. See the wiki for more information- Parameters:
path- the path to get the recipe fromitemFunction- the function to apply to theItemStackbefore returning it- Returns:
- the
Recipeor empty if it's invalid
-
getRecipe
@NotNull public @NotNull Optional<org.bukkit.inventory.Recipe> getRecipe(@NotNull @NotNull String path, @Nullable @Nullable UnaryOperator<org.bukkit.inventory.ItemStack> itemFunction, @Nullable @Nullable String name) Gets aRecipefrom the YAML. See the wiki for more information- Parameters:
path- the path to get the recipe fromitemFunction- the function to apply to theItemStackbefore returning itname- the name of the recipe (only used in 1.12+ for theNamespacedKey), ornullto use the node name- Returns:
- the
Recipeor thedefif it's invalid
-
getRecipe
@NotNull public @NotNull Optional<org.bukkit.inventory.Recipe> getRecipe(@NotNull @NotNull String path, @Nullable @Nullable UnaryOperator<org.bukkit.inventory.ItemStack> itemFunction, @Nullable @Nullable String name, boolean log) Gets aRecipefrom the YAML. See the wiki for more information- Parameters:
path- the path to get the recipe fromitemFunction- the function to apply to theItemStackbefore returning itname- the name of the recipe (only used in 1.12+ for theNamespacedKey), ornullto use the node namelog- whether to log warnings if the recipe is invalid- Returns:
- the
Recipeor thedefif it's invalid
-