Class SectionWrapper

java.lang.Object
dev.crafty.core.config.SectionWrapper

public class SectionWrapper extends Object
Wrapper class for ConfigurationSection that provides Optional-based access to configuration values. This class wraps all ConfigurationSection methods to return Optional values instead of null, providing safer access to configuration data.
  • Constructor Details

    • SectionWrapper

      public SectionWrapper(org.bukkit.configuration.ConfigurationSection section)
      Create a new SectionWrapper.
      Parameters:
      section - The ConfigurationSection to wrap, can be null
  • Method Details

    • exists

      public boolean exists()
      Check if the wrapped section exists and is not null.
      Returns:
      true if the section exists, false otherwise
    • getSection

      public Optional<org.bukkit.configuration.ConfigurationSection> getSection()
      Get the underlying ConfigurationSection.
      Returns:
      Optional containing the section, or empty if null
    • getSection

      public SectionWrapper getSection(String path)
      Get a nested configuration section.
      Parameters:
      path - The path to the section
      Returns:
      SectionWrapper for the nested section
    • getKeys

      public Optional<Set<String>> getKeys(boolean deep)
      Get all keys in this section.
      Parameters:
      deep - Whether to get keys from nested sections
      Returns:
      Optional containing the set of keys
    • getValues

      public Optional<Map<String,Object>> getValues(boolean deep)
      Get all values in this section.
      Parameters:
      deep - Whether to get values from nested sections
      Returns:
      Optional containing the map of values
    • contains

      public boolean contains(String path)
      Check if a path exists in this section.
      Parameters:
      path - The path to check
      Returns:
      true if the path exists, false otherwise
    • isSet

      public boolean isSet(String path, Class<?> clazz)
      Check if a path exists and is of the specified type.
      Parameters:
      path - The path to check
      clazz - The expected type
      Returns:
      true if the path exists and is of the specified type
    • getCurrentPath

      public Optional<String> getCurrentPath()
      Get the current path of this section.
      Returns:
      Optional containing the current path
    • getName

      public Optional<String> getName()
      Get the name of this section.
      Returns:
      Optional containing the section name
    • get

      public Optional<Object> get(String path)
      Get an object value.
      Parameters:
      path - The path to the value
      Returns:
      Optional containing the object value
    • get

      public Object get(String path, Object defaultValue)
      Get an object value with a default.
      Parameters:
      path - The path to the value
      defaultValue - The default value if not found
      Returns:
      The value or default
    • getString

      public Optional<String> getString(String path)
      Get a string value.
      Parameters:
      path - The path to the value
      Returns:
      Optional containing the string value
    • getString

      public String getString(String path, String defaultValue)
      Get a string value with a default.
      Parameters:
      path - The path to the value
      defaultValue - The default value if not found
      Returns:
      The value or default
    • getBoolean

      public Optional<Boolean> getBoolean(String path)
      Get a boolean value.
      Parameters:
      path - The path to the value
      Returns:
      Optional containing the boolean value
    • getBoolean

      public boolean getBoolean(String path, boolean defaultValue)
      Get a boolean value with a default.
      Parameters:
      path - The path to the value
      defaultValue - The default value if not found
      Returns:
      The value or default
    • getInt

      public Optional<Integer> getInt(String path)
      Get an integer value.
      Parameters:
      path - The path to the value
      Returns:
      Optional containing the integer value
    • getInt

      public int getInt(String path, int defaultValue)
      Get an integer value with a default.
      Parameters:
      path - The path to the value
      defaultValue - The default value if not found
      Returns:
      The value or default
    • getLong

      public Optional<Long> getLong(String path)
      Get a long value.
      Parameters:
      path - The path to the value
      Returns:
      Optional containing the long value
    • getLong

      public long getLong(String path, long defaultValue)
      Get a long value with a default.
      Parameters:
      path - The path to the value
      defaultValue - The default value if not found
      Returns:
      The value or default
    • getDouble

      public Optional<Double> getDouble(String path)
      Get a double value.
      Parameters:
      path - The path to the value
      Returns:
      Optional containing the double value
    • getDouble

      public double getDouble(String path, double defaultValue)
      Get a double value with a default.
      Parameters:
      path - The path to the value
      defaultValue - The default value if not found
      Returns:
      The value or default
    • getList

      public Optional<List<?>> getList(String path)
      Get a list value.
      Parameters:
      path - The path to the value
      Returns:
      Optional containing the list value
    • getList

      public List<?> getList(String path, List<?> defaultValue)
      Get a list value with a default.
      Parameters:
      path - The path to the value
      defaultValue - The default value if not found
      Returns:
      The value or default
    • getStringList

      public Optional<List<String>> getStringList(String path)
      Get a string list value.
      Parameters:
      path - The path to the value
      Returns:
      Optional containing the string list value
    • getIntegerList

      public Optional<List<Integer>> getIntegerList(String path)
      Get an integer list value.
      Parameters:
      path - The path to the value
      Returns:
      Optional containing the integer list value
    • getBooleanList

      public Optional<List<Boolean>> getBooleanList(String path)
      Get a boolean list value.
      Parameters:
      path - The path to the value
      Returns:
      Optional containing the boolean list value
    • getDoubleList

      public Optional<List<Double>> getDoubleList(String path)
      Get a double list value.
      Parameters:
      path - The path to the value
      Returns:
      Optional containing the double list value
    • getFloatList

      public Optional<List<Float>> getFloatList(String path)
      Get a float list value.
      Parameters:
      path - The path to the value
      Returns:
      Optional containing the float list value
    • getLongList

      public Optional<List<Long>> getLongList(String path)
      Get a long list value.
      Parameters:
      path - The path to the value
      Returns:
      Optional containing the long list value
    • getByteList

      public Optional<List<Byte>> getByteList(String path)
      Get a byte list value.
      Parameters:
      path - The path to the value
      Returns:
      Optional containing the byte list value
    • getCharacterList

      public Optional<List<Character>> getCharacterList(String path)
      Get a character list value.
      Parameters:
      path - The path to the value
      Returns:
      Optional containing the character list value
    • getShortList

      public Optional<List<Short>> getShortList(String path)
      Get a short list value.
      Parameters:
      path - The path to the value
      Returns:
      Optional containing the short list value
    • getMapList

      public Optional<List<Map<?,?>>> getMapList(String path)
      Get a map list value.
      Parameters:
      path - The path to the value
      Returns:
      Optional containing the map list value
    • getVector

      public Optional<org.bukkit.util.Vector> getVector(String path)
      Get a vector value.
      Parameters:
      path - The path to the value
      Returns:
      Optional containing the vector value
    • getVector

      public org.bukkit.util.Vector getVector(String path, org.bukkit.util.Vector defaultValue)
      Get a vector value with a default.
      Parameters:
      path - The path to the value
      defaultValue - The default value if not found
      Returns:
      The value or default
    • getOfflinePlayer

      public Optional<org.bukkit.OfflinePlayer> getOfflinePlayer(String path)
      Get an offline player value.
      Parameters:
      path - The path to the value
      Returns:
      Optional containing the offline player value
    • getOfflinePlayer

      public org.bukkit.OfflinePlayer getOfflinePlayer(String path, org.bukkit.OfflinePlayer defaultValue)
      Get an offline player value with a default.
      Parameters:
      path - The path to the value
      defaultValue - The default value if not found
      Returns:
      The value or default
    • getItemStack

      public Optional<org.bukkit.inventory.ItemStack> getItemStack(String path)
      Get an item stack value.
      Parameters:
      path - The path to the value
      Returns:
      Optional containing the item stack value
    • getItemStack

      public org.bukkit.inventory.ItemStack getItemStack(String path, org.bukkit.inventory.ItemStack defaultValue)
      Get an item stack value with a default.
      Parameters:
      path - The path to the value
      defaultValue - The default value if not found
      Returns:
      The value or default
    • getColor

      public Optional<org.bukkit.Color> getColor(String path)
      Get a color value.
      Parameters:
      path - The path to the value
      Returns:
      Optional containing the color value
    • getColor

      public org.bukkit.Color getColor(String path, org.bukkit.Color defaultValue)
      Get a color value with a default.
      Parameters:
      path - The path to the value
      defaultValue - The default value if not found
      Returns:
      The value or default
    • getLocation

      public Optional<org.bukkit.Location> getLocation(String path)
      Get a location value.
      Parameters:
      path - The path to the value
      Returns:
      Optional containing the location value
    • getLocation

      public org.bukkit.Location getLocation(String path, org.bukkit.Location defaultValue)
      Get a location value with a default.
      Parameters:
      path - The path to the value
      defaultValue - The default value if not found
      Returns:
      The value or default