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
FieldsModifier and TypeFieldDescriptionstatic 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
ConstructorsConstructorDescriptionProtection(@NotNull org.bukkit.NamespacedKey key) Creates a newProtectionwith default values.Protection(@NotNull org.bukkit.NamespacedKey key, boolean defaultEnabled) Creates a newProtection.Protection(@NotNull org.bukkit.NamespacedKey key, boolean defaultEnabled, boolean isHidden) Creates a newProtection. -
Method Summary
Modifier and TypeMethodDescription@NotNull org.bukkit.NamespacedKeygetKey()Returns the uniqueNamespacedKeyfor this protection.abstract StringGets the translation base key used for localization.booleanReturns whether this protection should be enabled by default when creating a new claim.booleanisHidden()Returns whether this protection is hidden from players.static booleanisHiddenProtection(@NotNull DeferredRegistry<Protection> registry, @Nullable org.bukkit.NamespacedKey key) Checks if a protection is considered a "hidden" protection in the given registry.voidsetDefaultEnabled(boolean defaultEnabled) Sets whether this protection should be enabled by default in new claims.voidsetHidden(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, waitMethods inherited from interface net.mathias2246.buildmc.api.ui.Displayable
getDisplay
-
Field Details
-
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 newProtection.- Parameters:
key- the uniqueNamespacedKeyidentifier of this protectiondefaultEnabled- 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 newProtection.- Parameters:
key- the uniqueNamespacedKeyidentifier of this protectiondefaultEnabled- whether this protection should be enabled by default for new claimsisHidden- whether this protection should be hidden from players
-
Protection
public Protection(@NotNull @NotNull org.bukkit.NamespacedKey key) Creates a newProtectionwith default values.Protections created this way default to
isDefaultEnabled = trueandisHidden = false.- Parameters:
key- the uniqueNamespacedKeyidentifier 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 protectionskey- theNamespacedKeyof the protection to check, may benull- Returns:
trueif the protection exists in the registry and is marked hidden, otherwisefalse
-
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:
trueif this protection is hidden, otherwisefalse
-
setHidden
public void setHidden(boolean hidden) Sets whether this protection is hidden from players.- Parameters:
hidden-trueto hide this protection,falseto make it visible
-
isDefaultEnabled
public boolean isDefaultEnabled()Returns whether this protection should be enabled by default when creating a new claim.- Returns:
trueif enabled by default, otherwisefalse
-
setDefaultEnabled
public void setDefaultEnabled(boolean defaultEnabled) Sets whether this protection should be enabled by default in new claims.- Parameters:
defaultEnabled-trueto enable by default, otherwisefalse
-
getKey
@NotNull public @NotNull org.bukkit.NamespacedKey getKey()Returns the uniqueNamespacedKeyfor this protection.- Specified by:
getKeyin interfaceorg.bukkit.Keyed- Returns:
- the key, never
null
-