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 TypeMethodDescriptionvoidstatic 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.voidcancel()Marks the projectile as invalid when the associated task is cancelledprotected booleancheckCollision(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.Eventexpire()Handles expiring due to range or leaving loaded chunksprotected abstract doubleabstract org.bukkit.LocationRetrieves the location of the projectileList<org.bukkit.metadata.MetadataValue> getMetadata(String key) Retrieves a metadata value from the projectile.org.bukkit.entity.LivingEntityRetrieves the entity that shot the projectileprotected abstract org.bukkit.util.VectorbooleanhasMetadata(String key) Checks whether this has a metadata set for the key.protected abstract org.bukkit.event.Eventhit(org.bukkit.entity.LivingEntity entity) Handles hitting an entityprotected booleanChecks whether the projectile is still valid.booleanisValid()Checks whether the projectile is still activeprotected abstract org.bukkit.event.Eventland()Handles landing on terrainprotected abstract booleanlanded()voidremoveMetadata(String key, org.bukkit.plugin.Plugin plugin) Removes a metadata value from the object.voidsetAllyEnemy(boolean ally, boolean enemy) Sets whether the projectile can hit allies or enemiesvoidsetCallback(ProjectileCallback callback) Sets the callback handler for the projectilevoidsetMetadata(String key, org.bukkit.metadata.MetadataValue meta) Sets a bit of metadata onto the projectile.protected abstract voidsetVelocity(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:
getLocationin interfaceFollowable- Returns:
- location of the projectile
-
isValid
public boolean isValid()Checks whether the projectile is still active- Specified by:
isValidin 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:
cancelin classorg.bukkit.scheduler.BukkitRunnable
-
setMetadata
Sets a bit of metadata onto the projectile.
- Specified by:
setMetadatain 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:
getMetadatain 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:
hasMetadatain 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:
removeMetadatain 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
-