Class AbstractSelectionTool
java.lang.Object
net.mathias2246.buildmc.api.item.AbstractCustomItem
net.mathias2246.buildmc.api.item.abstractTypes.AbstractTool
net.mathias2246.buildmc.api.item.abstractTypes.AbstractSelectionTool
- All Implemented Interfaces:
org.bukkit.Keyed
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
FieldsModifier and TypeFieldDescriptionfinal @NotNull StringThe metadata-key that is used to store the first selection.final @NotNull StringThe metadata-key that is used to store the second selection.static final @NotNull org.bukkit.NamespacedKeyThe NamespacedKey used to identify the cooldown group of selection toolsFields inherited from class net.mathias2246.buildmc.api.item.AbstractCustomItem
CUSTOM_ITEM_PDC_KEY, customItemsRegistry -
Constructor Summary
ConstructorsConstructorDescriptionAbstractSelectionTool(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull org.bukkit.NamespacedKey key) The default constructor for selection tools. -
Method Summary
Modifier and TypeMethodDescriptionabstract booleanallowFirstSelection(@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 booleanallowSecondSelection(@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 booleancanUse(@NotNull org.bukkit.inventory.ItemStack item, @NotNull org.bukkit.event.player.PlayerInteractEvent event) Checks is this custom item is usable.@Nullable org.bukkit.LocationgetFirstSelection(@NotNull org.bukkit.entity.Player player) Tries reading the first selection position from the player's metadata.@Nullable org.bukkit.LocationgetSecondSelection(@NotNull org.bukkit.entity.Player player) Tries reading the second selection position from the player's metadata.protected voidonInteract(@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 voidonLeftClick(@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 voidonRightClick(@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 voidonSuccessfulFirstSelection(@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 voidonSuccessfulSecondSelection(@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 net.mathias2246.buildmc.api.item.AbstractCustomItem
buildDefaultItemStack, getCustomItemKey, getKey, getPlugin, giveToPlayer, giveToPlayer, giveToPlayer, isThis, onInteractEvent
-
Field Details
-
SELECTION_TOOL_COOLDOWN_GROUP
@NotNull public static final @NotNull org.bukkit.NamespacedKey SELECTION_TOOL_COOLDOWN_GROUPThe NamespacedKey used to identify the cooldown group of selection tools -
firstSelectionKey
The metadata-key that is used to store the first selection. -
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:
canUsein classAbstractCustomItem- Parameters:
item- The selection tool item that was usedevent- ThePlayerInteractEventthat 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:AbstractCustomItemExecuted when a player left- or right-clicks with this custom-item type in his hand.- Specified by:
onInteractin classAbstractCustomItem
-
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:AbstractCustomItemExecuted when a player left-clicks with this custom-item type in his hand.- Specified by:
onLeftClickin classAbstractCustomItem
-
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:AbstractCustomItemExecuted when a player right-clicks with this custom-item type in his hand.- Specified by:
onRightClickin classAbstractCustomItem
-
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 usedat- TheLocationthe 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 usedat- TheLocationthe 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 usedat- TheLocationthe player clicked at
-