Class AbstractSelectionTool

All Implemented Interfaces:
org.bukkit.Keyed

public abstract class AbstractSelectionTool extends AbstractTool
An abstract-class that can be used to create selection tools.

A selection tool that is made with this class will write the players selection into the players metadata.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final @NotNull String
    The metadata-key that is used to store the first selection.
    final @NotNull String
    The metadata-key that is used to store the second selection.
    static final @NotNull org.bukkit.NamespacedKey
    The NamespacedKey used to identify the cooldown group of selection tools

    Fields inherited from class net.mathias2246.buildmc.api.item.AbstractCustomItem

    CUSTOM_ITEM_PDC_KEY, customItemsRegistry
  • Constructor Summary

    Constructors
    Constructor
    Description
    AbstractSelectionTool(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull org.bukkit.NamespacedKey key)
    The default constructor for selection tools.
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract boolean
    allowFirstSelection(@NotNull org.bukkit.inventory.ItemStack item, @NotNull org.bukkit.Location at, @NotNull org.bukkit.event.player.PlayerInteractEvent event)
    Checks if the player should be able to set the first selection position.
    abstract boolean
    allowSecondSelection(@NotNull org.bukkit.inventory.ItemStack item, @NotNull org.bukkit.Location at, @NotNull org.bukkit.event.player.PlayerInteractEvent event)
    Checks if the player should be able to set the second selection position.
    abstract boolean
    canUse(@NotNull org.bukkit.inventory.ItemStack item, @NotNull org.bukkit.event.player.PlayerInteractEvent event)
    Checks is this custom item is usable.
    @Nullable org.bukkit.Location
    getFirstSelection(@NotNull org.bukkit.entity.Player player)
    Tries reading the first selection position from the player's metadata.
    @Nullable org.bukkit.Location
    getSecondSelection(@NotNull org.bukkit.entity.Player player)
    Tries reading the second selection position from the player's metadata.
    protected void
    onInteract(@NotNull org.bukkit.inventory.ItemStack item, @NotNull org.bukkit.event.player.PlayerInteractEvent event)
    Executed when a player left- or right-clicks with this custom-item type in his hand.
    protected void
    onLeftClick(@NotNull org.bukkit.inventory.ItemStack item, @NotNull org.bukkit.Location at, @NotNull org.bukkit.event.player.PlayerInteractEvent event)
    Executed when a player left-clicks with this custom-item type in his hand.
    protected void
    onRightClick(@NotNull org.bukkit.inventory.ItemStack item, @NotNull org.bukkit.Location at, @NotNull org.bukkit.event.player.PlayerInteractEvent event)
    Executed when a player right-clicks with this custom-item type in his hand.
    abstract void
    onSuccessfulFirstSelection(@NotNull org.bukkit.inventory.ItemStack item, @NotNull org.bukkit.Location at, @NotNull org.bukkit.event.player.PlayerInteractEvent event)
    Called when the first selection was successful.
    abstract void
    onSuccessfulSecondSelection(@NotNull org.bukkit.inventory.ItemStack item, @NotNull org.bukkit.Location at, @NotNull org.bukkit.event.player.PlayerInteractEvent event)
    Called when the second selection was successful.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • SELECTION_TOOL_COOLDOWN_GROUP

      @NotNull public static final @NotNull org.bukkit.NamespacedKey SELECTION_TOOL_COOLDOWN_GROUP
      The NamespacedKey used to identify the cooldown group of selection tools
    • firstSelectionKey

      @NotNull public final @NotNull String firstSelectionKey
      The metadata-key that is used to store the first selection.
    • secondSelectionKey

      @NotNull public final @NotNull String secondSelectionKey
      The metadata-key that is used to store the second selection.
  • Constructor Details

    • AbstractSelectionTool

      public AbstractSelectionTool(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull org.bukkit.NamespacedKey key)
      The default constructor for selection tools.
  • Method Details

    • canUse

      public abstract boolean canUse(@NotNull @NotNull org.bukkit.inventory.ItemStack item, @NotNull @NotNull org.bukkit.event.player.PlayerInteractEvent event)
      Checks is this custom item is usable.

      Should check for things like e.g. cooldown, or other conditions

      Specified by:
      canUse in class AbstractCustomItem
      Parameters:
      item - The selection tool item that was used
      event - The PlayerInteractEvent that was fired
      Returns:
      True if, the selection tool should be usable right now
    • onInteract

      protected void onInteract(@NotNull @NotNull org.bukkit.inventory.ItemStack item, @NotNull @NotNull org.bukkit.event.player.PlayerInteractEvent event)
      Description copied from class: AbstractCustomItem
      Executed when a player left- or right-clicks with this custom-item type in his hand.
      Specified by:
      onInteract in class AbstractCustomItem
    • onLeftClick

      protected void onLeftClick(@NotNull @NotNull org.bukkit.inventory.ItemStack item, @NotNull @NotNull org.bukkit.Location at, @NotNull @NotNull org.bukkit.event.player.PlayerInteractEvent event)
      Description copied from class: AbstractCustomItem
      Executed when a player left-clicks with this custom-item type in his hand.
      Specified by:
      onLeftClick in class AbstractCustomItem
    • getFirstSelection

      @Nullable public @Nullable org.bukkit.Location getFirstSelection(@NotNull @NotNull org.bukkit.entity.Player player)
      Tries reading the first selection position from the player's metadata.
      Parameters:
      player - The player that made the selection
      Returns:
      The Location of the first selection or null if not found or invalid
    • getSecondSelection

      @Nullable public @Nullable org.bukkit.Location getSecondSelection(@NotNull @NotNull org.bukkit.entity.Player player)
      Tries reading the second selection position from the player's metadata.
      Parameters:
      player - The player that made the selection
      Returns:
      The Location of the second selection or null if not found or invalid
    • onRightClick

      protected void onRightClick(@NotNull @NotNull org.bukkit.inventory.ItemStack item, @NotNull @NotNull org.bukkit.Location at, @NotNull @NotNull org.bukkit.event.player.PlayerInteractEvent event)
      Description copied from class: AbstractCustomItem
      Executed when a player right-clicks with this custom-item type in his hand.
      Specified by:
      onRightClick in class AbstractCustomItem
    • allowFirstSelection

      public abstract boolean allowFirstSelection(@NotNull @NotNull org.bukkit.inventory.ItemStack item, @NotNull @NotNull org.bukkit.Location at, @NotNull @NotNull org.bukkit.event.player.PlayerInteractEvent event)
      Checks if the player should be able to set the first selection position.

      If this returns false, onSuccessfulFirstSelection will not be called.

    • allowSecondSelection

      public abstract boolean allowSecondSelection(@NotNull @NotNull org.bukkit.inventory.ItemStack item, @NotNull @NotNull org.bukkit.Location at, @NotNull @NotNull org.bukkit.event.player.PlayerInteractEvent event)
      Checks if the player should be able to set the second selection position.

      If this returns false, onSuccessfulSecondSelection will not be called.

      Parameters:
      item - The selection tool item that was used
      at - The Location the player clicked at
      Returns:
      True if, the second selection should be made.
    • onSuccessfulFirstSelection

      public abstract void onSuccessfulFirstSelection(@NotNull @NotNull org.bukkit.inventory.ItemStack item, @NotNull @NotNull org.bukkit.Location at, @NotNull @NotNull org.bukkit.event.player.PlayerInteractEvent event)
      Called when the first selection was successful.
      Parameters:
      item - The selection tool item that was used
      at - The Location the player clicked at
    • onSuccessfulSecondSelection

      public abstract void onSuccessfulSecondSelection(@NotNull @NotNull org.bukkit.inventory.ItemStack item, @NotNull @NotNull org.bukkit.Location at, @NotNull @NotNull org.bukkit.event.player.PlayerInteractEvent event)
      Called when the second selection was successful.
      Parameters:
      item - The selection tool item that was used
      at - The Location the player clicked at