Class ProjectileScript<T extends AProjectile>

java.lang.Object
me.deecaad.weaponmechanics.weapon.projectile.ProjectileScript<T>
Type Parameters:
T - The projectile type the script expects.

public abstract class ProjectileScript<T extends AProjectile> extends Object
A projectile script is a class that can be attached to a projectile. The script can listen for projectile related events (colliding with blocks, for example). The AProjectile class stores a list of scripts, and each script is updated for each event.

In order for you to attach a script to a projectile, you need to register your ProjectileScriptManager (which handles which projectiles to use) using ProjectileSpawner.addScriptManager(ProjectileScriptManager).

While you can use bukkit events and scripts interchangeably, scripts have the added advantage of better OOP and less overhead from the EventHandler. Scripts may also allow better control over when you want code to execute.

  • Field Details

    • projectile

      @NotNull protected final T extends AProjectile projectile
    • removeScript

      protected boolean removeScript
    • removeProjectile

      protected boolean removeProjectile
  • Constructor Details

    • ProjectileScript

      public ProjectileScript(@NotNull org.bukkit.plugin.Plugin owner, @NotNull T projectile)
  • Method Details

    • getOwner

      @NotNull public org.bukkit.plugin.Plugin getOwner()
    • getProjectile

      @NotNull public T getProjectile()
    • isRemoveScript

      public boolean isRemoveScript()
      Each time a projectile iterates through its list of scripts, it will check this method BEFORE calling any api methods [onStart(), onTickStart(), onTickEnd(), onEnd(), onCollide(RayTraceResult)]. This can be used to remove a script from a projectile without removing the projectile.
      Returns:
      true will remove the script from the projectile.
    • isRemoveProjectile

      public boolean isRemoveProjectile()
      Each time a projectile iterates through its list of scripts, it will check this method AFTER calling any api methods [onStart(), onTickStart(), onTickEnd(), onEnd(), onCollide(RayTraceResult)]. This can be used to completely remove a projectile.
      Returns:
      true will remove the projectile.
    • onStart

      public void onStart()
      Called while the projectile is spawning. It is guaranteed that this method will be called before all other methods in this class. This method is called after the projectile is shot, so getting the shooter (for WeaponProjectile) is a safe operation.
    • onTickStart

      public void onTickStart()
      Called towards the beginning of AProjectile.tick(). This method probably should be used instead of onTickEnd() when you are modifying projectile values (Changing speed/location, for example).
    • onTickEnd

      public void onTickEnd()
      Called towards the end of AProjectile.tick(). This method probably should be used instead of onTickStart() when you only want to read the result of a tick method (See how a projectile moved, for example).
    • onEnd

      public void onEnd()
      Called when the projectile is removed.
    • onCollide

      public void onCollide(@NotNull me.deecaad.core.utils.ray.RayTraceResult hit)
      Called when the projectile collides with a block or living entity.
      Parameters:
      hit - The non-null ray trace result of block or living entity.