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:
net.kyori.adventure.key.Keyed, 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 org.bukkit.NamespacedKeyThe NamespacedKey used to identify the first selection of this selection toolfinal @NotNull org.bukkit.NamespacedKeyThe NamespacedKey used to identify the second selection of this selection toolFields inherited from class 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.voidremoveSelectionFromPlayer(@NotNull org.bukkit.entity.Player player) Methods inherited from class AbstractCustomItem
buildDefaultItemStack, getCustomItemKey, getKey, getPlugin, giveToPlayer, giveToPlayer, giveToPlayer, isThis, onInteractEventMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.bukkit.Keyed
key
-
Field Details
-
firstSelectionKey
@NotNull public final @NotNull org.bukkit.NamespacedKey firstSelectionKeyThe NamespacedKey used to identify the first selection of this selection tool -
secondSelectionKey
@NotNull public final @NotNull org.bukkit.NamespacedKey secondSelectionKeyThe NamespacedKey used to identify the second selection of this selection tool
-
-
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
-
removeSelectionFromPlayer
public void removeSelectionFromPlayer(@NotNull @NotNull org.bukkit.entity.Player player) -
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
-