Package wtf.choco.arrows.api
Class AlchemicalArrow
java.lang.Object
wtf.choco.arrows.api.AlchemicalArrow
- Direct Known Subclasses:
ConfigurableAlchemicalArrow
public abstract class AlchemicalArrow extends Object
Represents the base of an alchemical arrow with special effects upon hitting a
block, entity or player
- Author:
- Parker Hawke - Choco
-
Constructor Summary
Constructors Constructor Description AlchemicalArrow()
-
Method Summary
Modifier and Type Method Description org.bukkit.inventory.ItemStack
createItemStack()
Create a newItemStack
that represents this AlchemicalArrow in an inventory.org.bukkit.inventory.ItemStack
createItemStack(int amount)
Create a newItemStack
that represents this AlchemicalArrow in an inventory.@NotNull AlchemicalArrowEntity
createNewArrow(@NotNull org.bukkit.entity.Arrow arrow)
Create a new instance of anAlchemicalArrowEntity
.boolean
equals(Object object)
abstract @NotNull String
getDisplayName()
Get the display name of this alchemical arrow.abstract @NotNull org.bukkit.inventory.ItemStack
getItem()
Get the item representation of this alchemical arrow.abstract @NotNull org.bukkit.NamespacedKey
getKey()
Get this arrow's unique key.@NotNull PropertyMap
getProperties()
Get a map containing all properties for this arrowint
hashCode()
void
hitEntityEventHandler(@NotNull AlchemicalArrowEntity arrow, @NotNull org.bukkit.event.entity.EntityDamageByEntityEvent event)
Called the instant beforeonHitPlayer(AlchemicalArrowEntity, Player)
oronHitEntity(AlchemicalArrowEntity, Entity)
is called.void
hitGroundEventHandler(@NotNull AlchemicalArrowEntity arrow, @NotNull org.bukkit.event.entity.ProjectileHitEvent event)
Called the instant beforeonHitBlock(AlchemicalArrowEntity, Block)
is called.boolean
matchesItem(org.bukkit.inventory.ItemStack item)
Check whether or not the providedItemStack
represents this AlchemicalArrow.void
onHitBlock(@NotNull AlchemicalArrowEntity arrow, @NotNull org.bukkit.block.Block block)
Called when the arrow hits a solid blockvoid
onHitEntity(@NotNull AlchemicalArrowEntity arrow, @NotNull org.bukkit.entity.Entity entity)
Called when the arrow hits an entity (this excludes Players.void
onHitPlayer(@NotNull AlchemicalArrowEntity arrow, @NotNull org.bukkit.entity.Player player)
Called when the arrow hits a playerboolean
onShootFromBlockSource(@NotNull AlchemicalArrowEntity arrow, @NotNull org.bukkit.projectiles.BlockProjectileSource source)
Called at a low priority when aBlockProjectileSource
(i.e.boolean
onShootFromPlayer(@NotNull AlchemicalArrowEntity arrow, @NotNull org.bukkit.entity.Player player)
Called at low priority when a player has successfully shot this alchemical arrow, but it has yet to be registered.boolean
onShootFromSkeleton(@NotNull AlchemicalArrowEntity arrow, @NotNull org.bukkit.entity.Skeleton skeleton)
Called at a low priority when aSkeleton
successfully shoots an arrow, but it has yet to be registered.void
shootEventHandler(@NotNull AlchemicalArrowEntity arrow, @NotNull org.bukkit.event.entity.ProjectileLaunchEvent event)
Called the instant beforeonShootFromPlayer(AlchemicalArrowEntity, Player)
,onShootFromSkeleton(AlchemicalArrowEntity, Skeleton)
oronShootFromBlockSource(AlchemicalArrowEntity, BlockProjectileSource)
is called.void
tick(@NotNull AlchemicalArrowEntity arrow, @NotNull org.bukkit.Location location)
Called 20 times every second.
-
Constructor Details
-
AlchemicalArrow
public AlchemicalArrow()
-
-
Method Details
-
getKey
@NotNull public abstract @NotNull org.bukkit.NamespacedKey getKey()Get this arrow's unique key.- Returns:
- the unique key
-
getDisplayName
Get the display name of this alchemical arrow. This includes colour codes and formatting. The returned String should be expected in messages sent to players- Returns:
- the arrow's display name
-
getItem
@NotNull public abstract @NotNull org.bukkit.inventory.ItemStack getItem()Get the item representation of this alchemical arrow. The type must be be tagged byTag.ITEMS_ARROWS
, otherwise an exception will be thrown at registration.NOTE: This item does NOT have applied the NamespacedKey for this arrow and cannot be shot unless
matchesItem(ItemStack)
is overridden by implementation. Callers should prefer instead to callcreateItemStack()
. This method is expected to be overridden by implementations, NOT to be called by API.- Returns:
- the arrow item
-
createItemStack
public org.bukkit.inventory.ItemStack createItemStack()Create a newItemStack
that represents this AlchemicalArrow in an inventory. This arrow can be shot by a player.- Returns:
- the item stack
-
createItemStack
public final org.bukkit.inventory.ItemStack createItemStack(int amount)Create a newItemStack
that represents this AlchemicalArrow in an inventory. This arrow can be shot by a player.- Parameters:
amount
- the item amount- Returns:
- the item stack
-
matchesItem
public boolean matchesItem(org.bukkit.inventory.ItemStack item)Check whether or not the providedItemStack
represents this AlchemicalArrow.- Parameters:
item
- the item to check- Returns:
- true if valid, false otherwise
-
getProperties
Get a map containing all properties for this arrow- Returns:
- the arrow properties
-
tick
public void tick(@NotNull @NotNull AlchemicalArrowEntity arrow, @NotNull @NotNull org.bukkit.Location location)Called 20 times every second. This method is intended for displaying particles around the arrow, performing tasks whilst the arrow is still in the world, etc.- Parameters:
arrow
- the alchemical arrow entity instancelocation
- the arrow's current location at this tick
-
onHitBlock
public void onHitBlock(@NotNull @NotNull AlchemicalArrowEntity arrow, @NotNull @NotNull org.bukkit.block.Block block)Called when the arrow hits a solid block- Parameters:
arrow
- the alchemical arrow entity instanceblock
- the block on which the arrow landed
-
onHitPlayer
public void onHitPlayer(@NotNull @NotNull AlchemicalArrowEntity arrow, @NotNull @NotNull org.bukkit.entity.Player player)Called when the arrow hits a player- Parameters:
arrow
- the alchemical arrow entity instanceplayer
- the player damaged by the arrow
-
onHitEntity
public void onHitEntity(@NotNull @NotNull AlchemicalArrowEntity arrow, @NotNull @NotNull org.bukkit.entity.Entity entity)Called when the arrow hits an entity (this excludes Players. For Players, seeonHitPlayer(AlchemicalArrowEntity, Player)
)- Parameters:
arrow
- the alchemical arrow entity instanceentity
- the entity damaged by the arrow
-
onShootFromPlayer
public boolean onShootFromPlayer(@NotNull @NotNull AlchemicalArrowEntity arrow, @NotNull @NotNull org.bukkit.entity.Player player)Called at low priority when a player has successfully shot this alchemical arrow, but it has yet to be registered. Such that this method returns true, the alchemical arrow will be launched- Parameters:
arrow
- the alchemical arrow entity instanceplayer
- the player that shot the arrow- Returns:
- whether the shot should be permitted or not
-
onShootFromSkeleton
public boolean onShootFromSkeleton(@NotNull @NotNull AlchemicalArrowEntity arrow, @NotNull @NotNull org.bukkit.entity.Skeleton skeleton)Called at a low priority when aSkeleton
successfully shoots an arrow, but it has yet to be registered. Such that this method returns true, the alchemical arrow will be launched. TheArrowProperty.SKELETONS_CAN_SHOOT
property must return true in order for this method to be invoked- Parameters:
arrow
- the alchemical arrow entity instanceskeleton
- the skeleton that shot the arrow- Returns:
- whether the shot should be permitted or not
-
onShootFromBlockSource
public boolean onShootFromBlockSource(@NotNull @NotNull AlchemicalArrowEntity arrow, @NotNull @NotNull org.bukkit.projectiles.BlockProjectileSource source)Called at a low priority when aBlockProjectileSource
(i.e. Dispenser) shoots an arrow, but it has yet to be registered. Such that this method returns true, the alchemical arrow will be launched- Parameters:
arrow
- the alchemical arrow entity instancesource
- the block source that shot the arrow- Returns:
- whether the shot should be permitted or not
-
hitEntityEventHandler
public void hitEntityEventHandler(@NotNull @NotNull AlchemicalArrowEntity arrow, @NotNull @NotNull org.bukkit.event.entity.EntityDamageByEntityEvent event)Called the instant beforeonHitPlayer(AlchemicalArrowEntity, Player)
oronHitEntity(AlchemicalArrowEntity, Entity)
is called. Used to cancel events if necessary- Parameters:
arrow
- the alchemical arrow entity instanceevent
- the EntityDamageByEntityEvent source
-
hitGroundEventHandler
public void hitGroundEventHandler(@NotNull @NotNull AlchemicalArrowEntity arrow, @NotNull @NotNull org.bukkit.event.entity.ProjectileHitEvent event)Called the instant beforeonHitBlock(AlchemicalArrowEntity, Block)
is called. Used to cancel events if necessary- Parameters:
arrow
- the alchemical arrow entity instanceevent
- the ProjectileHitEvent source
-
shootEventHandler
public void shootEventHandler(@NotNull @NotNull AlchemicalArrowEntity arrow, @NotNull @NotNull org.bukkit.event.entity.ProjectileLaunchEvent event)Called the instant beforeonShootFromPlayer(AlchemicalArrowEntity, Player)
,onShootFromSkeleton(AlchemicalArrowEntity, Skeleton)
oronShootFromBlockSource(AlchemicalArrowEntity, BlockProjectileSource)
is called. Used to cancel events if necessary- Parameters:
arrow
- the alchemical arrow entity instanceevent
- the ProjectileLaunchEvent source
-
createNewArrow
@NotNull public @NotNull AlchemicalArrowEntity createNewArrow(@NotNull @NotNull org.bukkit.entity.Arrow arrow)Create a new instance of anAlchemicalArrowEntity
. If a custom AlchemicalArrowEntity implementation is used, this method must be overridden to return a custom instance of it. Under no circumstance should additional, non-arrow entity-related code be executed in an overridden implementation of this method. For additional logic, see AlchemicalArrow's various methods and override them where required- Parameters:
arrow
- the BukkitArrow
instance from which to create an AlchemicalArrowEntity- Returns:
- the new AlchemicalArrowEntity instance of this implementation
-
hashCode
public int hashCode() -
equals
-