Class BlockLockCheckEvent

java.lang.Object
org.bukkit.event.Event
org.bukkit.event.block.BlockEvent
io.papermc.paper.event.block.BlockLockCheckEvent

public class BlockLockCheckEvent extends BlockEvent
Called when the server tries to check the lock on a lockable block entity.
See setResult(Result) to change behavior
  • Constructor Details

  • Method Details

    • getBlockState

      @NotNull public @NotNull LockableTileState getBlockState()
      Gets the snapshot LockableTileState of the block entity whose lock is being checked.
      Returns:
      the snapshot block state.
    • getPlayer

      @NotNull public @NotNull Player getPlayer()
      Get the player involved this lock check.
      Returns:
      the player
    • getKeyItem

      @NotNull public @NotNull ItemStack getKeyItem()
      Gets the itemstack that will be used as the key itemstack. Initially this will be the item in the player's main hand but an override can be set with setKeyItem(ItemStack). Use isUsingCustomKeyItemStack() to check if a custom key stack has been set.
      Returns:
      the item being used as the key item
      See Also:
    • setKeyItem

      public void setKeyItem(@NotNull @NotNull ItemStack stack)
      Sets the itemstack that will be used as the key item.
      Parameters:
      stack - the stack to use as a key
      See Also:
    • resetKeyItem

      public void resetKeyItem()
      Reset the key stack to the default (the player's main hand).
    • isUsingCustomKeyItemStack

      public boolean isUsingCustomKeyItemStack()
      Checks if a custom key stack has been set.
      Returns:
      true if a custom key itemstack has been set
    • getResult

      @NotNull public @NotNull Event.Result getResult()
      Gets the result of this event.
      Returns:
      the result
      See Also:
    • setResult

      public void setResult(@NotNull @NotNull Event.Result result)
      Gets the result of this event. Event.Result.DEFAULT is the default allowing the vanilla logic to check the lock of this block. Set to Event.Result.ALLOW or Event.Result.DENY to override that behavior.

      Setting this to Event.Result.ALLOW bypasses the spectator check.

      Parameters:
      result - the result of this event
    • denyWithMessageAndSound

      public void denyWithMessageAndSound(@Nullable @Nullable net.kyori.adventure.text.Component lockedMessage, @Nullable @Nullable net.kyori.adventure.sound.Sound lockedSound)
      Shorthand method to set the getResult() to Event.Result.DENY, the locked message and locked sound.
      Parameters:
      lockedMessage - the message to show if locked (or null for none)
      lockedSound - the sound to play if locked (or null for none)
    • getLockedMessage

      @Nullable public @Nullable net.kyori.adventure.text.Component getLockedMessage()
      Gets the locked message that will be sent if the player cannot open the block.
      Returns:
      the locked message (or null if none)
    • setLockedMessage

      public void setLockedMessage(@Nullable @Nullable net.kyori.adventure.text.Component lockedMessage)
      Sets the locked message that will be sent if the player cannot open the block.
      Parameters:
      lockedMessage - the locked message (or null for none)
    • getLockedSound

      @Nullable public @Nullable net.kyori.adventure.sound.Sound getLockedSound()
      Gets the locked sound that will play if the player cannot open the block.
      Returns:
      the locked sound (or null if none)
    • setLockedSound

      public void setLockedSound(@Nullable @Nullable net.kyori.adventure.sound.Sound lockedSound)
      Sets the locked sound that will play if the player cannot open the block.
      Parameters:
      lockedSound - the locked sound (or null for none)
    • getHandlers

      @NotNull public @NotNull HandlerList getHandlers()
      Specified by:
      getHandlers in class Event
    • getHandlerList

      @NotNull public static @NotNull HandlerList getHandlerList()