Class Protection

java.lang.Object
net.mathias2246.buildmc.api.claims.Protection
All Implemented Interfaces:
Displayable, org.bukkit.event.Listener, org.bukkit.Keyed

public abstract class Protection extends Object implements org.bukkit.Keyed, Displayable, org.bukkit.event.Listener
Represents a type of Protection that can be applied to claims.

Protections define specific behaviors, rules, or restrictions within a claim (e.g., blocking explosions, preventing PVP, etc.). Each protection is uniquely identified by a NamespacedKey and can be enabled/disabled by default when a claim is created.

This class is abstract; concrete implementations should define the translation key for the UI via getTranslationBaseKey().

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final @NotNull Collection<String>
    A collection of all default protection keys that should be automatically applied when creating a new claim.
    protected boolean
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Protection(@NotNull org.bukkit.NamespacedKey key)
    Creates a new Protection with default values.
    Protection(@NotNull org.bukkit.NamespacedKey key, boolean defaultEnabled)
    Creates a new Protection.
    Protection(@NotNull org.bukkit.NamespacedKey key, boolean defaultEnabled, boolean isHidden)
    Creates a new Protection.
  • Method Summary

    Modifier and Type
    Method
    Description
    @NotNull org.bukkit.NamespacedKey
    Returns the unique NamespacedKey for this protection.
    abstract String
    Gets the translation base key used for localization.
    boolean
    Returns whether this protection should be enabled by default when creating a new claim.
    boolean
    Returns whether this protection is hidden from players.
    static boolean
    isHiddenProtection(@NotNull DeferredRegistry<Protection> registry, @Nullable org.bukkit.NamespacedKey key)
    Checks if a protection is considered a "hidden" protection in the given registry.
    void
    setDefaultEnabled(boolean defaultEnabled)
    Sets whether this protection should be enabled by default in new claims.
    void
    setHidden(boolean hidden)
    Sets whether this protection is hidden from players.

    Methods inherited from class java.lang.Object

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

    Methods inherited from interface net.mathias2246.buildmc.api.ui.Displayable

    getDisplay
  • Field Details

    • defaultProtections

      @Internal @NotNull public static final @NotNull Collection<String> defaultProtections
      A collection of all default protection keys that should be automatically applied when creating a new claim.

      This field is internal and should not be modified directly outside of registration logic.

    • isDefaultEnabled

      protected boolean isDefaultEnabled
  • Constructor Details

    • Protection

      public Protection(@NotNull @NotNull org.bukkit.NamespacedKey key, boolean defaultEnabled)
      Creates a new Protection.
      Parameters:
      key - the unique NamespacedKey identifier of this protection
      defaultEnabled - whether this protection should be enabled by default for new claims
    • Protection

      public Protection(@NotNull @NotNull org.bukkit.NamespacedKey key, boolean defaultEnabled, boolean isHidden)
      Creates a new Protection.
      Parameters:
      key - the unique NamespacedKey identifier of this protection
      defaultEnabled - whether this protection should be enabled by default for new claims
      isHidden - whether this protection should be hidden from players
    • Protection

      public Protection(@NotNull @NotNull org.bukkit.NamespacedKey key)
      Creates a new Protection with default values.

      Protections created this way default to isDefaultEnabled = true and isHidden = false.

      Parameters:
      key - the unique NamespacedKey identifier of this protection
  • Method Details

    • isHiddenProtection

      public static boolean isHiddenProtection(@NotNull @NotNull DeferredRegistry<Protection> registry, @Nullable @Nullable org.bukkit.NamespacedKey key)
      Checks if a protection is considered a "hidden" protection in the given registry. Hidden protections are usually not shown to players directly but may still be enforced internally.
      Parameters:
      registry - the registry of protections
      key - the NamespacedKey of the protection to check, may be null
      Returns:
      true if the protection exists in the registry and is marked hidden, otherwise false
    • getTranslationBaseKey

      public abstract String getTranslationBaseKey()
      Gets the translation base key used for localization.

      This value should be used as the root for retrieving translatable messages for the UI.

      Returns:
      the translation key base, never null
    • isHidden

      public boolean isHidden()
      Returns whether this protection is hidden from players.

      Hidden protections are still enforced but not visible in UIs or menus.

      Returns:
      true if this protection is hidden, otherwise false
    • setHidden

      public void setHidden(boolean hidden)
      Sets whether this protection is hidden from players.
      Parameters:
      hidden - true to hide this protection, false to make it visible
    • isDefaultEnabled

      public boolean isDefaultEnabled()
      Returns whether this protection should be enabled by default when creating a new claim.
      Returns:
      true if enabled by default, otherwise false
    • setDefaultEnabled

      public void setDefaultEnabled(boolean defaultEnabled)
      Sets whether this protection should be enabled by default in new claims.
      Parameters:
      defaultEnabled - true to enable by default, otherwise false
    • getKey

      @NotNull public @NotNull org.bukkit.NamespacedKey getKey()
      Returns the unique NamespacedKey for this protection.
      Specified by:
      getKey in interface org.bukkit.Keyed
      Returns:
      the key, never null