Class ProtectionPolicy

java.lang.Object
redempt.redlib.protection.ProtectionPolicy
All Implemented Interfaces:
org.bukkit.event.Listener

public class ProtectionPolicy extends Object implements org.bukkit.event.Listener
Represents a set of rules in the form of ProtectionPolicy.ProtectionTypes protecting a set of blocks, which can have bypasses
  • Field Details

  • 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 blocks
      protectionCheck - A predicate which will be used to check whether blocks are protected by this ProtectionPolicy
      protections - 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. Prefer ProtectionPolicy(CuboidRegion, Predicate, ProtectionType...), as it will improve performance
      Parameters:
      protectionCheck - A predicate which will be used to check whether blocks are protected by this ProtectionPolicy
      protections - 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 implements Cancellable
      type - The ProtectionType to protect against this event
      getPlayer - A function to get the player associated with the event - can return null
      getBlocks - 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 using Cancellable.setCancelled(boolean) using a specific ProtectionType
      Type Parameters:
      T - The event type
      Parameters:
      clazz - The event class
      type - The ProtectionType to protect against this event
      getPlayer - A function to get the player associated with the event - can return null
      cancel - A consumer to cancel the event
      getBlocks - 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 class
      type - The ProtectionType to protect against this event
      getPlayer - A function to get the player associated with the event - can return null
      cancel - A function to cancel the modification of a specific block in the event
      getBlocks - 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 class
      type - The ProtectionType to protect against this event
      getPlayer - A function to get the player associated with the event - can be null
      getActingBlock - A function to get the block acting upon the other blocks, i.e. a piston pushing blocks or a water source spawning new water blocks
      getSubjectBlocks - 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

      public void setProtectionTypes(ProtectionPolicy.ProtectionType... protections)
      Sets the ProtectionTypes to be used
      Parameters:
      protections - The ProtectionTypes
    • addProtectionTypes

      public void addProtectionTypes(ProtectionPolicy.ProtectionType... protections)
      Adds ProtectionTypes to this ProtectionPolicy
      Parameters:
      protections - The ProtectionTypes to add
    • removeProtectionTypes

      public void removeProtectionTypes(ProtectionPolicy.ProtectionType... protections)
      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 - The BiPredicate to determine bypasses by player and protection type
    • addBypassPolicy

      public void addBypassPolicy(BypassPolicy bypassPolicy)
      Adds a bypass policy, which allows certain players to bypass certain protection types
      Parameters:
      bypassPolicy - The BypassPolicy to determine bypasses by player and protection type
    • clearBypassPolicies

      public void clearBypassPolicies()
      Removes all bypass policies
    • setDenyMessage

      public void setDenyMessage(ProtectionPolicy.ProtectionType type, String message)
      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 to
      message - The message players should be shown when this type of action is denied
    • setDenyMessage

      public void setDenyMessage(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 again
      Parameters:
      filter - A filter for which types to set the message for
      message - The message players should be shown when these types of actions are denied
    • clearDenyMessages

      public void clearDenyMessages()
      Clear all deny messages
    • getBounds

      public CuboidRegion 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)