Package redempt.redlib.protection
Class ProtectionPolicy
java.lang.Object
redempt.redlib.protection.ProtectionPolicy
- All Implemented Interfaces:
org.bukkit.event.Listener
Represents a set of rules in the form of
ProtectionPolicy.ProtectionTypes protecting a set of blocks, which can have bypasses-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static Set<ProtectionPolicy>protected static RegionMap<ProtectionPolicy> -
Constructor Summary
ConstructorsModifierConstructorDescriptionProtectionPolicy(Predicate<org.bukkit.block.Block> protectionCheck, ProtectionPolicy.ProtectionType... protections) Create a ProtectionPolicy to protect blocks.protectedProtectionPolicy(org.bukkit.plugin.Plugin plugin, CuboidRegion bounds, Predicate<org.bukkit.block.Block> protectionCheck, ProtectionPolicy.ProtectionType... protections) ProtectionPolicy(CuboidRegion bounds, Predicate<org.bukkit.block.Block> protectionCheck, ProtectionPolicy.ProtectionType... protections) Create a ProtectionPolicy to protect blocks -
Method Summary
Modifier and TypeMethodDescriptionvoidaddBypassPolicy(BiPredicate<org.bukkit.entity.Player, ProtectionPolicy.ProtectionType> bypassPolicy) Adds a bypass policy, which allows certain players to bypass certain protection typesvoidaddBypassPolicy(BypassPolicy bypassPolicy) Adds a bypass policy, which allows certain players to bypass certain protection typesvoidaddProtectionTypes(ProtectionPolicy.ProtectionType... protections) Adds ProtectionTypes to this ProtectionPolicybooleanallow(org.bukkit.block.Block block, ProtectionPolicy.ProtectionType type, org.bukkit.entity.Player player) voidRemoves all bypass policiesvoidClear all deny messagesvoiddisable()Disables all protections for this ProtectionPolicyvoidenable()Enables all protections specified for this ProtectionPolicyvoidonCreatureSpawn(org.bukkit.event.entity.CreatureSpawnEvent e) static <T extends org.bukkit.event.Event & org.bukkit.event.Cancellable>
voidregisterProtection(Class<T> clazz, ProtectionPolicy.ProtectionType type, Function<T, org.bukkit.entity.Player> getPlayer, Function<T, org.bukkit.block.Block>... getBlocks) Registers a custom event to be protected using a specific ProtectionTypestatic <T extends org.bukkit.event.Event & org.bukkit.event.Cancellable>
voidregisterProtectionDirectional(Class<T> clazz, ProtectionPolicy.ProtectionType type, Function<T, org.bukkit.entity.Player> getPlayer, Function<T, org.bukkit.block.Block> getActingBlock, Function<T, List<org.bukkit.block.Block>> getSubjectBlocks) Registers a custom event to be protected using a specific ProtectionType, where there is a block acting and blocks being acted uponstatic <T extends org.bukkit.event.Event>
voidregisterProtectionMultiBlock(Class<T> clazz, ProtectionPolicy.ProtectionType type, Function<T, org.bukkit.entity.Player> getPlayer, BiConsumer<T, org.bukkit.block.Block> cancel, Function<T, List<org.bukkit.block.Block>> getBlocks) Registers a custom event that modifies multiple blocks to be protected using a specific ProtectionTypestatic <T extends org.bukkit.event.Event>
voidregisterProtectionNonCancellable(Class<T> clazz, ProtectionPolicy.ProtectionType type, Function<T, org.bukkit.entity.Player> getPlayer, Consumer<T> cancel, Function<T, org.bukkit.block.Block>... getBlocks) Registers a custom event that cannot be cancelled usingCancellable.setCancelled(boolean)using a specific ProtectionTypevoidremoveProtectionTypes(ProtectionPolicy.ProtectionType... protections) Removes ProtectionTypes from this ProtectionPolicyvoidsetDenyMessage(Predicate<ProtectionPolicy.ProtectionType> filter, String message) Sets the message to be shown to a player when they attempt to do an action which is protected againvoidsetDenyMessage(ProtectionPolicy.ProtectionType type, String message) Sets the message to be shown to a player when they attempt to do an action which is protected againvoidsetProtectionTypes(ProtectionPolicy.ProtectionType... protections) Sets the ProtectionTypes to be used
-
Field Details
-
globalPolicies
-
regionMap
-
-
Constructor Details
-
ProtectionPolicy
protected ProtectionPolicy(org.bukkit.plugin.Plugin plugin, CuboidRegion bounds, Predicate<org.bukkit.block.Block> protectionCheck, ProtectionPolicy.ProtectionType... protections) -
ProtectionPolicy
public ProtectionPolicy(CuboidRegion bounds, Predicate<org.bukkit.block.Block> protectionCheck, ProtectionPolicy.ProtectionType... protections) Create a ProtectionPolicy to protect blocks- Parameters:
bounds- A region that defines the bounds inside which this ProtectionPolicy protects blocksprotectionCheck- A predicate which will be used to check whether blocks are protected by this ProtectionPolicyprotections- The types of actions to protect against
-
ProtectionPolicy
public ProtectionPolicy(Predicate<org.bukkit.block.Block> protectionCheck, ProtectionPolicy.ProtectionType... protections) Create a ProtectionPolicy to protect blocks. PreferProtectionPolicy(CuboidRegion, Predicate, ProtectionType...), as it will improve performance- Parameters:
protectionCheck- A predicate which will be used to check whether blocks are protected by this ProtectionPolicyprotections- The types of actions to protect against
-
-
Method Details
-
registerProtection
public static <T extends org.bukkit.event.Event & org.bukkit.event.Cancellable> void registerProtection(Class<T> clazz, ProtectionPolicy.ProtectionType type, Function<T, org.bukkit.entity.Player> getPlayer, Function<T, org.bukkit.block.Block>... getBlocks) Registers a custom event to be protected using a specific ProtectionType- Type Parameters:
T- The event type- Parameters:
clazz- The event class of an event which implementsCancellabletype- The ProtectionType to protect against this eventgetPlayer- A function to get the player associated with the event - can return nullgetBlocks- A vararg of functions to get blocks associated with the event
-
registerProtectionNonCancellable
public static <T extends org.bukkit.event.Event> void registerProtectionNonCancellable(Class<T> clazz, ProtectionPolicy.ProtectionType type, Function<T, org.bukkit.entity.Player> getPlayer, Consumer<T> cancel, Function<T, org.bukkit.block.Block>... getBlocks) Registers a custom event that cannot be cancelled usingCancellable.setCancelled(boolean)using a specific ProtectionType- Type Parameters:
T- The event type- Parameters:
clazz- The event classtype- The ProtectionType to protect against this eventgetPlayer- A function to get the player associated with the event - can return nullcancel- A consumer to cancel the eventgetBlocks- A vararg of functions to get the blocks associated with this event
-
registerProtectionMultiBlock
public static <T extends org.bukkit.event.Event> void registerProtectionMultiBlock(Class<T> clazz, ProtectionPolicy.ProtectionType type, Function<T, org.bukkit.entity.Player> getPlayer, BiConsumer<T, org.bukkit.block.Block> cancel, Function<T, List<org.bukkit.block.Block>> getBlocks) Registers a custom event that modifies multiple blocks to be protected using a specific ProtectionType- Type Parameters:
T- The event type- Parameters:
clazz- The event classtype- The ProtectionType to protect against this eventgetPlayer- A function to get the player associated with the event - can return nullcancel- A function to cancel the modification of a specific block in the eventgetBlocks- A vararg of functions to get the blocks associated with the event
-
registerProtectionDirectional
public static <T extends org.bukkit.event.Event & org.bukkit.event.Cancellable> void registerProtectionDirectional(Class<T> clazz, ProtectionPolicy.ProtectionType type, Function<T, org.bukkit.entity.Player> getPlayer, Function<T, org.bukkit.block.Block> getActingBlock, Function<T, List<org.bukkit.block.Block>> getSubjectBlocks) Registers a custom event to be protected using a specific ProtectionType, where there is a block acting and blocks being acted upon- Type Parameters:
T- The event type- Parameters:
clazz- The event classtype- The ProtectionType to protect against this eventgetPlayer- A function to get the player associated with the event - can be nullgetActingBlock- A function to get the block acting upon the other blocks, i.e. a piston pushing blocks or a water source spawning new water blocksgetSubjectBlocks- A function to get the list of blocks being acted upon, i.e. the blocks being pushed by a piston or the water block being spawned
-
setProtectionTypes
Sets the ProtectionTypes to be used- Parameters:
protections- The ProtectionTypes
-
addProtectionTypes
Adds ProtectionTypes to this ProtectionPolicy- Parameters:
protections- The ProtectionTypes to add
-
removeProtectionTypes
Removes ProtectionTypes from this ProtectionPolicy- Parameters:
protections- The ProtectionTypes to remove
-
disable
public void disable()Disables all protections for this ProtectionPolicy -
enable
public void enable()Enables all protections specified for this ProtectionPolicy -
addBypassPolicy
public void addBypassPolicy(BiPredicate<org.bukkit.entity.Player, ProtectionPolicy.ProtectionType> bypassPolicy) Adds a bypass policy, which allows certain players to bypass certain protection types- Parameters:
bypassPolicy- TheBiPredicateto determine bypasses by player and protection type
-
addBypassPolicy
Adds a bypass policy, which allows certain players to bypass certain protection types- Parameters:
bypassPolicy- TheBypassPolicyto determine bypasses by player and protection type
-
clearBypassPolicies
public void clearBypassPolicies()Removes all bypass policies -
setDenyMessage
Sets the message to be shown to a player when they attempt to do an action which is protected again- Parameters:
type- The type of action the message corresponds tomessage- The message players should be shown when this type of action is denied
-
setDenyMessage
Sets the message to be shown to a player when they attempt to do an action which is protected again- Parameters:
filter- A filter for which types to set the message formessage- The message players should be shown when these types of actions are denied
-
clearDenyMessages
public void clearDenyMessages()Clear all deny messages -
getBounds
- Returns:
- The cuboid bounds of this ProtectionPolicy, or null if it is a global policy
-
allow
public boolean allow(org.bukkit.block.Block block, ProtectionPolicy.ProtectionType type, org.bukkit.entity.Player player) -
onCreatureSpawn
public void onCreatureSpawn(org.bukkit.event.entity.CreatureSpawnEvent e)
-