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 the AnnoyingFile instance
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 Classes
    Modifier and Type
    Class
    Description
    static class 
    A class to hold the options for a file

    Default options: AnnoyingFile.Options.canBeEmpty = true AnnoyingFile.Options.replace = false
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final @NotNull File
    The File for the file
    protected final @NotNull AnnoyingFile.Options<?>
    The AnnoyingFile.Options for the file
    final @NotNull AnnoyingPlugin
    The AnnoyingPlugin instance

    Fields inherited from class org.bukkit.configuration.file.YamlConfiguration

    BLANK_CONFIG, COMMENT_PREFIX

    Fields inherited from class org.bukkit.configuration.file.FileConfiguration

    SYSTEM_UTF, UTF_BIG, UTF8_OVERRIDE

    Fields inherited from class org.bukkit.configuration.MemoryConfiguration

    defaults, options

    Fields inherited from class org.bukkit.configuration.MemorySection

    map
  • Constructor Summary

    Constructors
    Constructor
    Description
    AnnoyingFile(@NotNull AnnoyingPlugin plugin, @NotNull File file)
    Constructs a new AnnoyingFile
    AnnoyingFile(@NotNull AnnoyingPlugin plugin, @NotNull File file, @Nullable AnnoyingFile.Options<?> fileOptions)
    Constructs a new AnnoyingFile
    AnnoyingFile(@NotNull AnnoyingPlugin plugin, @NotNull String path)
    Constructs a new AnnoyingFile
    AnnoyingFile(@NotNull AnnoyingPlugin plugin, @NotNull String path, @Nullable AnnoyingFile.Options<?> fileOptions)
    Constructs a new AnnoyingFile
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Creates the file
    boolean
    Deletes the file, won't fail silently
    boolean
    delete(boolean silentFail)
    Deletes the file
    <G> @NotNull Optional<G>
    1.9+ Gets an AttributeModifier from the path.
    <G> @NotNull Optional<G>
    getAttributeModifier(@NotNull String path, boolean log)
    1.9+ Gets an AttributeModifier from the path.
    @NotNull Optional<org.bukkit.configuration.ConfigurationSection>
    Get a ConfigurationSection from the path in an Optional
    <G> @NotNull Optional<G>
    getDef(@NotNull String path)
    Gets the default value from the path
    @Nullable org.bukkit.inventory.ItemStack
    getItemStack(@NotNull String path)
    Gets an ItemStack from the path.
    @Nullable org.bukkit.inventory.ItemStack
    getItemStack(@NotNull String path, @Nullable org.bukkit.inventory.ItemStack def)
    Gets an ItemStack from the path.
    @NotNull Optional<org.bukkit.inventory.ItemStack>
    Gets an ItemStack from the path.
    @NotNull Optional<org.bukkit.inventory.ItemStack>
    getItemStackOptional(@NotNull String path, boolean log)
    Gets an ItemStack from the path.
    getPlayableSound(@NotNull String path)
    Gets a PlayableSound from the path.
    @NotNull Optional<org.bukkit.potion.PotionEffect>
    getPotionEffect(@NotNull String path)
    Gets a PotionEffect from the path.
    @NotNull Optional<org.bukkit.potion.PotionEffect>
    getPotionEffect(@NotNull String path, boolean log)
    Gets a PotionEffect from the path.
    @NotNull Optional<org.bukkit.inventory.Recipe>
    getRecipe(@NotNull String path)
    Gets a Recipe from the YAML.
    @NotNull Optional<org.bukkit.inventory.Recipe>
    getRecipe(@NotNull String path, @Nullable UnaryOperator<org.bukkit.inventory.ItemStack> itemFunction)
    Gets a Recipe from the YAML.
    @NotNull Optional<org.bukkit.inventory.Recipe>
    getRecipe(@NotNull String path, @Nullable UnaryOperator<org.bukkit.inventory.ItemStack> itemFunction, @Nullable String name)
    Gets a Recipe from 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 a Recipe from the YAML.
    @NotNull Optional<org.bukkit.Sound>
    getSound(@NotNull String path)
    Gets a Sound from the path
    boolean
    Loads the YAML from the path.
    void
    log(@NotNull Level level, @Nullable String key, @NotNull String message)
    Sends a formatted log message to the console Sends a formatted warning message to the console
    boolean
    Saves the YAML to the file
    setChain(@NotNull String path, @Nullable Object value)
    Sets a value in the YAML and returns the AnnoyingFile instance
    boolean
    setSave(@NotNull String path, @Nullable Object value)
    Sets a value in the YAML and then saves the file
    @NotNull String
     

    Methods inherited from class org.bukkit.configuration.file.YamlConfiguration

    buildHeader, convertMapsToSections, loadConfiguration, loadConfiguration, loadConfiguration, loadFromString, options, parseHeader, saveToString

    Methods inherited from class org.bukkit.configuration.file.FileConfiguration

    load, load, load, load, save, save

    Methods inherited from class org.bukkit.configuration.MemoryConfiguration

    addDefault, addDefaults, addDefaults, getDefaults, getParent, setDefaults

    Methods 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, set

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods 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

  • Constructor Details

  • Method Details

    • toString

      @NotNull public @NotNull String toString()
      Overrides:
      toString in class org.bukkit.configuration.MemorySection
    • create

      public void create()
      Creates the file
    • load

      public boolean load()
      Loads the YAML from the path. If the file doesn't exist and can't be empty, an empty YamlConfiguration will be used
      Returns:
      whether the file was loaded successfully
    • delete

      public boolean delete(boolean silentFail)
      Deletes the file
      Parameters:
      silentFail - whether to fail silently
      Returns:
      whether the file was deleted successfully
      See Also:
    • delete

      public boolean delete()
      Deletes the file, won't fail silently
      Returns:
      whether the file was deleted successfully
      See Also:
    • setChain

      @NotNull public T setChain(@NotNull @NotNull String path, @Nullable @Nullable Object value)
      Sets a value in the YAML and returns the AnnoyingFile instance
      Parameters:
      path - the path to the node
      value - the value to set the node to
      Returns:
      the AnnoyingFile instance
    • setSave

      public boolean setSave(@NotNull @NotNull String path, @Nullable @Nullable Object value)
      Sets a value in the YAML and then saves the file
      Parameters:
      path - the path to the node
      value - the value to set the node to
      Returns:
      whether the file was saved successfully
    • save

      public boolean save()
      Saves the YAML to the file
      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 - the Level of the message
      key - the key of the node that the message is about (null if it's not about a node)
      message - the message to send
    • getDef

      @NotNull public <G> @NotNull Optional<G> getDef(@NotNull @NotNull String path)
      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 a ConfigurationSection from the path in an Optional
      Parameters:
      path - the path to the node
      Returns:
      the ConfigurationSection or empty if it doesn't exist
    • getSound

      @NotNull public @NotNull Optional<org.bukkit.Sound> getSound(@NotNull @NotNull String path)
      Gets a Sound from the path
      Parameters:
      path - the path to the node
      Returns:
      the Sound or empty if it's invalid
    • getPlayableSound

      @NotNull public @NotNull Optional<PlayableSound> getPlayableSound(@NotNull @NotNull String path)
      Gets a PlayableSound from the path. See the wiki for more information
      Parameters:
      path - the path to the node
      Returns:
      the PlayableSound or empty if it's invalid
    • getPotionEffect

      @NotNull public @NotNull Optional<org.bukkit.potion.PotionEffect> getPotionEffect(@NotNull @NotNull String path)
      Gets a PotionEffect from the path. See the wiki for more information
      Parameters:
      path - the path to the node
      Returns:
      the PotionEffect or empty if it's invalid
    • getPotionEffect

      @NotNull public @NotNull Optional<org.bukkit.potion.PotionEffect> getPotionEffect(@NotNull @NotNull String path, boolean log)
      Gets a PotionEffect from the path. See the wiki for more information
      Parameters:
      path - the path to the node
      log - whether to log warnings if the potion effect is invalid
      Returns:
      the PotionEffect or empty if it's invalid
    • getAttributeModifier

      @NotNull public <G> @NotNull Optional<G> getAttributeModifier(@NotNull @NotNull String path)
      1.9+ Gets an AttributeModifier from the path. See the wiki for more information
      Type Parameters:
      G - the AttributeModifier class
      Parameters:
      path - the path to the node
      Returns:
      the AttributeModifier or empty if it's invalid
    • getAttributeModifier

      @NotNull public <G> @NotNull Optional<G> getAttributeModifier(@NotNull @NotNull String path, boolean log)
      1.9+ Gets an AttributeModifier from the path. See the wiki for more information
      Type Parameters:
      G - the AttributeModifier class
      Parameters:
      path - the path to the node
      log - whether to log warnings if the attribute modifier is invalid
      Returns:
      the AttributeModifier or empty if it's invalid
    • getItemStack

      @Nullable public @Nullable org.bukkit.inventory.ItemStack getItemStack(@NotNull @NotNull String path)
      Gets an ItemStack from the path. See the wiki for more information
      If you want to disable warning/error logging, use getItemStackOptional(String, boolean)
      Specified by:
      getItemStack in interface org.bukkit.configuration.ConfigurationSection
      Overrides:
      getItemStack in class org.bukkit.configuration.MemorySection
      Parameters:
      path - the path to the node
      Returns:
      the ItemStack or null if it's invalid
    • getItemStack

      @Nullable public @Nullable org.bukkit.inventory.ItemStack getItemStack(@NotNull @NotNull String path, @Nullable @Nullable org.bukkit.inventory.ItemStack def)
      Gets an ItemStack from the path. See the wiki for more information
      If you want to disable warning/error logging, use getItemStackOptional(String, boolean)
      Specified by:
      getItemStack in interface org.bukkit.configuration.ConfigurationSection
      Overrides:
      getItemStack in class org.bukkit.configuration.MemorySection
      Parameters:
      path - the path to the node
      def - the default value
      Returns:
      the ItemStack or def if it's invalid
    • getItemStackOptional

      @NotNull public @NotNull Optional<org.bukkit.inventory.ItemStack> getItemStackOptional(@NotNull @NotNull String path)
      Gets an ItemStack from the path. See the wiki for more information
      Parameters:
      path - the path to the node
      Returns:
      the ItemStack or empty if it's invalid
    • getItemStackOptional

      @NotNull public @NotNull Optional<org.bukkit.inventory.ItemStack> getItemStackOptional(@NotNull @NotNull String path, boolean log)
      Gets an ItemStack from the path. See the wiki for more information
      Parameters:
      path - the path to the node
      log - whether to log warnings if the item stack is invalid
      Returns:
      the ItemStack or empty if it's invalid
    • getRecipe

      @NotNull public @NotNull Optional<org.bukkit.inventory.Recipe> getRecipe(@NotNull @NotNull String path)
      Gets a Recipe from the YAML. See the wiki for more information
      Parameters:
      path - the path to get the recipe from
      Returns:
      the Recipe or null if 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 a Recipe from the YAML. See the wiki for more information
      Parameters:
      path - the path to get the recipe from
      itemFunction - the function to apply to the ItemStack before returning it
      Returns:
      the Recipe or 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 a Recipe from the YAML. See the wiki for more information
      Parameters:
      path - the path to get the recipe from
      itemFunction - the function to apply to the ItemStack before returning it
      name - the name of the recipe (only used in 1.12+ for the NamespacedKey), or null to use the node name
      Returns:
      the Recipe or the def 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, boolean log)
      Gets a Recipe from the YAML. See the wiki for more information
      Parameters:
      path - the path to get the recipe from
      itemFunction - the function to apply to the ItemStack before returning it
      name - the name of the recipe (only used in 1.12+ for the NamespacedKey), or null to use the node name
      log - whether to log warnings if the recipe is invalid
      Returns:
      the Recipe or the def if it's invalid