Class CustomProjectile
java.lang.Object
org.bukkit.scheduler.BukkitRunnable
studio.magemonkey.fabled.api.projectile.CustomProjectile
- All Implemented Interfaces:
Runnable
,org.bukkit.metadata.Metadatable
,Followable
- Direct Known Subclasses:
ItemProjectile
,ParticleProjectile
public abstract class CustomProjectile
extends org.bukkit.scheduler.BukkitRunnable
implements org.bukkit.metadata.Metadatable, Followable
Base class for custom projectiles
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCustomProjectile
(org.bukkit.entity.LivingEntity thrower, Settings settings) Constructs a new custom projectile and starts its timer task -
Method Summary
Modifier and TypeMethodDescriptionvoid
static List
<org.bukkit.Location> calcRain
(org.bukkit.Location loc, double radius, double height, int amount) Calculates the locations to spawn projectiles to rain them down over a given location.static List
<org.bukkit.util.Vector> calcSpread
(org.bukkit.util.Vector dir, double angle, int amount) Calculates the directions for projectiles spread from the centered direction using the given angle and number of projectiles to be fired.void
cancel()
Marks the projectile as invalid when the associated task is cancelledprotected boolean
checkCollision
(boolean pierce) Checks if the projectile collides with a given list of entities Returns true if another check should happen, false otherwiseprotected abstract org.bukkit.event.Event
expire()
Handles expiring due to range or leaving loaded chunksprotected abstract double
abstract org.bukkit.Location
Retrieves the location of the projectileList
<org.bukkit.metadata.MetadataValue> getMetadata
(String key) Retrieves a metadata value from the projectile.org.bukkit.entity.LivingEntity
Retrieves the entity that shot the projectileprotected abstract org.bukkit.util.Vector
boolean
hasMetadata
(String key) Checks whether this has a metadata set for the key.protected abstract org.bukkit.event.Event
hit
(org.bukkit.entity.LivingEntity entity) Handles hitting an entityprotected boolean
Checks whether the projectile is still valid.boolean
isValid()
Checks whether the projectile is still activeprotected abstract org.bukkit.event.Event
land()
Handles landing on terrainprotected abstract boolean
landed()
void
removeMetadata
(String key, org.bukkit.plugin.Plugin plugin) Removes a metadata value from the object.void
setAllyEnemy
(boolean ally, boolean enemy) Sets whether the projectile can hit allies or enemiesvoid
setCallback
(ProjectileCallback callback) Sets the callback handler for the projectilevoid
setMetadata
(String key, org.bukkit.metadata.MetadataValue meta) Sets a bit of metadata onto the projectile.protected abstract void
setVelocity
(org.bukkit.util.Vector vel) Methods inherited from class org.bukkit.scheduler.BukkitRunnable
getTaskId, isCancelled, runTask, runTaskAsynchronously, runTaskLater, runTaskLaterAsynchronously, runTaskTimer, runTaskTimerAsynchronously
-
Field Details
-
callback
-
settings
-
enemy
protected boolean enemy -
ally
protected boolean ally
-
-
Constructor Details
-
CustomProjectile
Constructs a new custom projectile and starts its timer task- Parameters:
thrower
- entity firing the projectile
-
-
Method Details
-
calcSpread
public static List<org.bukkit.util.Vector> calcSpread(org.bukkit.util.Vector dir, double angle, int amount) Calculates the directions for projectiles spread from the centered direction using the given angle and number of projectiles to be fired.- Parameters:
dir
- center direction of the spreadangle
- angle which to spread atamount
- amount of directions to calculate- Returns:
- the list of calculated directions
-
calcRain
public static List<org.bukkit.Location> calcRain(org.bukkit.Location loc, double radius, double height, int amount) Calculates the locations to spawn projectiles to rain them down over a given location.- Parameters:
loc
- the center location to rain onradius
- radius of the circleheight
- height above the target to useamount
- amount of locations to calculate- Returns:
- list of locations to spawn projectiles
-
getLocation
public abstract org.bukkit.Location getLocation()Retrieves the location of the projectile- Specified by:
getLocation
in interfaceFollowable
- Returns:
- location of the projectile
-
isValid
public boolean isValid()Checks whether the projectile is still active- Specified by:
isValid
in interfaceFollowable
- Returns:
- true if active, false otherwise
-
expire
protected abstract org.bukkit.event.Event expire()Handles expiring due to range or leaving loaded chunks -
land
protected abstract org.bukkit.event.Event land()Handles landing on terrain -
hit
protected abstract org.bukkit.event.Event hit(org.bukkit.entity.LivingEntity entity) Handles hitting an entity- Parameters:
entity
- entity the projectile hit
-
landed
protected abstract boolean landed()- Returns:
- true if the projectile has landed on terrain, false otherwise
-
getCollisionRadius
protected abstract double getCollisionRadius()- Returns:
- squared radius for colliding
-
getVelocity
protected abstract org.bukkit.util.Vector getVelocity() -
setVelocity
protected abstract void setVelocity(org.bukkit.util.Vector vel) -
isTraveling
protected boolean isTraveling()Checks whether the projectile is still valid. Invalid would mean landing on the ground or leaving the loaded chunks. -
applyLanded
public void applyLanded() -
checkCollision
protected boolean checkCollision(boolean pierce) Checks if the projectile collides with a given list of entities Returns true if another check should happen, false otherwise -
setAllyEnemy
public void setAllyEnemy(boolean ally, boolean enemy) Sets whether the projectile can hit allies or enemies- Parameters:
ally
- whether allies can be hitenemy
- whether enemies can be hit
-
getShooter
public org.bukkit.entity.LivingEntity getShooter()Retrieves the entity that shot the projectile- Returns:
- the entity that shot the projectile
-
cancel
public void cancel()Marks the projectile as invalid when the associated task is cancelled- Overrides:
cancel
in classorg.bukkit.scheduler.BukkitRunnable
-
setMetadata
Sets a bit of metadata onto the projectile.
- Specified by:
setMetadata
in interfaceorg.bukkit.metadata.Metadatable
- Parameters:
key
- the key for the metadatameta
- the metadata to set
-
getMetadata
Retrieves a metadata value from the projectile.
If no metadata was set with the key, this will instead return null
- Specified by:
getMetadata
in interfaceorg.bukkit.metadata.Metadatable
- Parameters:
key
- the key for the metadata- Returns:
- the metadata value
-
hasMetadata
Checks whether this has a metadata set for the key.
- Specified by:
hasMetadata
in interfaceorg.bukkit.metadata.Metadatable
- Parameters:
key
- the key for the metadata- Returns:
- whether there is metadata set for the key
-
removeMetadata
Removes a metadata value from the object.
If no metadata is set for the key, this will do nothing.
- Specified by:
removeMetadata
in interfaceorg.bukkit.metadata.Metadatable
- Parameters:
key
- the key for the metadataplugin
- plugin to remove the metadata for
-
setCallback
Sets the callback handler for the projectile- Parameters:
callback
- callback handler
-