Interface ConfigurableUnit


public interface ConfigurableUnit
Represents a configuration unit used for handling permissions, groups, and priorities in a configuration section.

A ConfigurableUnit provides methods to access the underlying ConfigurationSection, retrieve its name, permission, group, and priority settings, and perform permission and group checks on a CommandSender. It serves as a basic unit for representing configuration-based access control.

The interface also includes static factory methods to create new instances based on an existing ConfigurationSection or another ConfigurableUnit.

See Also:
  • ConfigurationSection
  • CommandSender
  • Method Summary

    Modifier and Type
    Method
    Description
    default @Nullable String
    Gets the group associated with this unit.
    default @NotNull String
    Gets the name of the configuration section.
    default @NotNull String
    Gets the permission associated with this unit.
    default int
    Gets the priority associated with this unit.
    @NotNull org.bukkit.configuration.ConfigurationSection
    Gets the configuration section associated with this unit.
    default boolean
    hasPerm(org.bukkit.command.CommandSender sender)
    Checks if the given command sender has the permission associated with this unit.
    boolean
    isInGroup(org.bukkit.command.CommandSender sender)
    Checks if the given command sender is in the group associated with this unit.
    default boolean
    isInGroupAsNull(org.bukkit.command.CommandSender sender)
    Checks if the group associated with this unit is blank or the given sender is in that group.
    default boolean
    isInGroupNonNull(org.bukkit.command.CommandSender sender)
    Checks if the group associated with this unit is not blank and the given sender is in that group.
    Creates a new ConfigurableUnit instance based on the provided ConfigurableUnit.
    of(org.bukkit.configuration.ConfigurationSection section)
    Creates a new ConfigurableUnit instance based on the provided configuration section.
  • Method Details

    • getSection

      @NotNull @NotNull org.bukkit.configuration.ConfigurationSection getSection() throws NullPointerException
      Gets the configuration section associated with this unit.
      Returns:
      the configuration section (never null).
      Throws:
      NullPointerException - if the configuration section is null.
    • getName

      @NotNull default @NotNull String getName()
      Gets the name of the configuration section.
      Returns:
      the name of the configuration section.
    • getPermission

      @NotNull default @NotNull String getPermission()
      Gets the permission associated with this unit.
      Returns:
      the permission string; if not specified, returns "DEFAULT".
    • hasPerm

      default boolean hasPerm(org.bukkit.command.CommandSender sender)
      Checks if the given command sender has the permission associated with this unit.
      Parameters:
      sender - the command sender.
      Returns:
      true if the sender has the permission, false otherwise.
    • getGroup

      @Nullable default @Nullable String getGroup()
      Gets the group associated with this unit.
      Returns:
      the group string, or null if not specified.
    • isInGroup

      boolean isInGroup(org.bukkit.command.CommandSender sender)
      Checks if the given command sender is in the group associated with this unit.
      Parameters:
      sender - the command sender.
      Returns:
      true if the sender is in the group, false otherwise.
    • isInGroupNonNull

      default boolean isInGroupNonNull(org.bukkit.command.CommandSender sender)
      Checks if the group associated with this unit is not blank and the given sender is in that group.
      Parameters:
      sender - the command sender.
      Returns:
      true if the group is not blank and the sender is in that group, false otherwise.
    • isInGroupAsNull

      default boolean isInGroupAsNull(org.bukkit.command.CommandSender sender)
      Checks if the group associated with this unit is blank or the given sender is in that group.
      Parameters:
      sender - the command sender.
      Returns:
      true if the group is blank or the sender is in that group, false otherwise.
    • getPriority

      default int getPriority()
      Gets the priority associated with this unit.

      The priority is determined by the "priority" value in the configuration section. If not specified, it returns 0 when the permission is "DEFAULT" (case-insensitive), and 1 otherwise.

      Returns:
      the priority value.
    • of

      static ConfigurableUnit of(org.bukkit.configuration.ConfigurationSection section)
      Creates a new ConfigurableUnit instance based on the provided configuration section.

      This factory method returns a simple implementation of ConfigurableUnit where the group check always returns true.

      Parameters:
      section - the configuration section.
      Returns:
      a new ConfigurableUnit instance.
      Throws:
      NullPointerException - if the configuration section is null.
    • of

      Creates a new ConfigurableUnit instance based on the provided ConfigurableUnit.
      Parameters:
      unit - the existing ConfigurableUnit instance.
      Returns:
      a new ConfigurableUnit instance based on the unit's configuration section.