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
    Modifier and Type
    Field
    Description
    protected boolean
     
     
    protected boolean
     
    protected final Settings
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    CustomProjectile(org.bukkit.entity.LivingEntity thrower, Settings settings)
    Constructs a new custom projectile and starts its timer task
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    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
    Marks the projectile as invalid when the associated task is cancelled
    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
    protected abstract org.bukkit.event.Event
    Handles expiring due to range or leaving loaded chunks
    protected abstract double
     
    abstract org.bukkit.Location
    Retrieves the location of the projectile
    List<org.bukkit.metadata.MetadataValue>
    Retrieves a metadata value from the projectile.
    org.bukkit.entity.LivingEntity
    Retrieves the entity that shot the projectile
    protected abstract org.bukkit.util.Vector
     
    boolean
    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 entity
    protected boolean
    Checks whether the projectile is still valid.
    boolean
    Checks whether the projectile is still active
    protected abstract org.bukkit.event.Event
    Handles landing on terrain
    protected abstract boolean
     
    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 enemies
    void
    Sets the callback handler for the projectile
    void
    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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface java.lang.Runnable

    run
  • Field Details

    • callback

      protected ProjectileCallback callback
    • settings

      protected final Settings settings
    • enemy

      protected boolean enemy
    • ally

      protected boolean ally
  • Constructor Details

    • CustomProjectile

      public CustomProjectile(org.bukkit.entity.LivingEntity thrower, Settings settings)
      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 spread
      angle - angle which to spread at
      amount - 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 on
      radius - radius of the circle
      height - height above the target to use
      amount - 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 interface Followable
      Returns:
      location of the projectile
    • isValid

      public boolean isValid()
      Checks whether the projectile is still active
      Specified by:
      isValid in interface Followable
      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 hit
      enemy - 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 class org.bukkit.scheduler.BukkitRunnable
    • setMetadata

      public void setMetadata(String key, org.bukkit.metadata.MetadataValue meta)

      Sets a bit of metadata onto the projectile.

      Specified by:
      setMetadata in interface org.bukkit.metadata.Metadatable
      Parameters:
      key - the key for the metadata
      meta - the metadata to set
    • getMetadata

      public List<org.bukkit.metadata.MetadataValue> getMetadata(String key)

      Retrieves a metadata value from the projectile.

      If no metadata was set with the key, this will instead return null

      Specified by:
      getMetadata in interface org.bukkit.metadata.Metadatable
      Parameters:
      key - the key for the metadata
      Returns:
      the metadata value
    • hasMetadata

      public boolean hasMetadata(String key)

      Checks whether this has a metadata set for the key.

      Specified by:
      hasMetadata in interface org.bukkit.metadata.Metadatable
      Parameters:
      key - the key for the metadata
      Returns:
      whether there is metadata set for the key
    • removeMetadata

      public void removeMetadata(String key, org.bukkit.plugin.Plugin plugin)

      Removes a metadata value from the object.

      If no metadata is set for the key, this will do nothing.

      Specified by:
      removeMetadata in interface org.bukkit.metadata.Metadatable
      Parameters:
      key - the key for the metadata
      plugin - plugin to remove the metadata for
    • setCallback

      public void setCallback(ProjectileCallback callback)
      Sets the callback handler for the projectile
      Parameters:
      callback - callback handler