Interface IProtectionHookSpigot

All Known Implementing Classes:
GriefDefender2ProtectionHook, GriefPreventionProtectionHook, LandsProtectionHook, PlotSquared6ProtectionHook, PlotSquared7ProtectionHook, RedProtectProtectionHook, TownyProtectionHook, WorldGuard7ProtectionHook

public interface IProtectionHookSpigot
Represents a protection hook for a specific plugin.

The intended use of this interface is to allow for checking if a player is allowed to break blocks at a given location. This is used to prevent players from creating or operating structures in protected areas.

Additionally, this interface allows for running quick checks that can prevent more expensive checks from being run. These pre-checks can give one of three results:

  • HookPreCheckResult.ALLOW: All further checks will be run as normal. This is the default behavior.
  • HookPreCheckResult.DENY: The action will be denied. This means that no further checks are necessary, because only a single hook needs to deny the action for it to be denied.
  • HookPreCheckResult.BYPASS: The check is bypassed. This means that the main check of this hook is not run at all. This can be useful if the hook is not enabled in the world that the check is run in. This has no effect on other hooks.

The pre-checks have two methods: preCheck(Player, World) and preCheckAsync(Player, World). Both methods should be run to get the final result, as the async method should only check things that must be done asynchronously and the sync method should only check things that must be done on the main thread.

  • Method Details

    • preCheck

      default HookPreCheckResult preCheck(org.bukkit.entity.Player player, org.bukkit.World world)
      Method that runs before any other checks are done.

      The intention of this method is to allow for running quick checks that can prevent more expensive checks from being run.

      This method is run on the main thread. If you need to run this method asynchronously, use preCheckAsync(Player, World) instead.

      If the method returns HookPreCheckResult.ALLOW, all further checks will be run as normal. This is the default behavior.

      Parameters:
      player - The player to check.
      world - The world to check in.
      Returns:
      True if the player is allowed to break blocks in the given world.
    • preCheckAsync

      default CompletableFuture<HookPreCheckResult> preCheckAsync(org.bukkit.entity.Player player, org.bukkit.World world)
      Method that runs before any other checks are done.

      The intention of this method is to allow for running quick checks that can prevent more expensive checks from being run.

      This method is run asynchronously. If you need to run this method on the main thread, use preCheck(Player, World) instead.

      If the method returns HookPreCheckResult.ALLOW, all further checks will be run as normal. This is the default behavior.

      Parameters:
      player - The player to check.
      world - The world to check in.
      Returns:
      True if the player is allowed to break blocks in the given world.
    • canBreakBlock

      CompletableFuture<Boolean> canBreakBlock(org.bukkit.entity.Player player, org.bukkit.Location loc)
      Check if this compatibility hook allows a player to break blocks at a given location.
      Parameters:
      player - The (fake) player to check.
      loc - The location to check.
      Returns:
      True if the player is allowed to break blocks at the given location.
    • canBreakBlocksInCuboid

      CompletableFuture<Boolean> canBreakBlocksInCuboid(org.bukkit.entity.Player player, org.bukkit.World world, Cuboid cuboid)
      Check if this compatibility hook allows a player to break blocks in a given cuboid.
      Parameters:
      player - The (fake) player to check.
      world - The world to check in.
      cuboid - The cuboid to check.
      Returns:
      True if the player is allowed to break all the blocks in the given cuboid.
    • getName

      default String getName()
      Get the name of the JavaPlugin that is being hooked into.
      Returns:
      The name of the JavaPlugin that is being hooked into.
    • getContext

      ProtectionHookContext getContext()
      Get the ProtectionHookContext that is being used.
      Returns:
      The ProtectionHookContext that is being used.
    • hasPermission

      default boolean hasPermission(org.bukkit.entity.Player player, String node)
      Shortcut method to check if a player has a given permission node.

      See ProtectionHookContext.getPermissionsManager() and IPermissionsManager.hasPermission(IPlayer, String)

      Parameters:
      player - The player to check.
      node - The node to check.
      Returns:
      True if the given node is set for the given player.
    • hasPermissionOffline

      default CompletableFuture<Boolean> hasPermissionOffline(org.bukkit.World world, org.bukkit.OfflinePlayer player, String permission)
      Shortcut method to check if an offline player has a given permission node.

      See ProtectionHookContext.getPermissionsManager() and IPermissionsManagerSpigot.hasPermissionOffline(World, OfflinePlayer, String)

      Parameters:
      world - The world to check in.
      player - The player to check.
      permission - The permission node to check.
      Returns:
      A CompletableFuture that will be completed with true if the player has the permission node in the given world, false otherwise.
    • lazyFormatPlayerName

      default com.google.common.flogger.LazyArg<String> lazyFormatPlayerName(org.bukkit.entity.Player player)
      Formats a player's name to a string that can be used in a message.
      Parameters:
      player - The player to format.
      Returns:
      The formatted player name wrapped in a LazyArg.