1.16.5 Run scheduled BukkitRunnable at beginning of tick

Discussion in 'Spigot Plugin Development' started by SebasSV, Sep 14, 2020.

  1. I'm making a plugin that creates a fake shield in front of the player, so I have to make calculations to check when a projectile hits it. I currently have those calculations in a BukkitRunnable.

    Problem is, if the arrow is going to hit the shield in the same tick it was shot, the BukkitRunnable won't catch it since it's ran after the arrow movement is processed. Is it possible to somehow run the Runnable before that, like at the beginning of the tick?

    If not, I'm gonna stick to triggering the calculations in ProjectileLaunchEvent, but I would prefer the former method.
    #1 SebasSV, Sep 14, 2020
    Last edited: Sep 14, 2020
  2. You could use ProjectileHitEvent instead, create the shield when this event is fired
  3. The shield is a fake barrier in front of the player, and is supposed to deflect projectiles without them necessarily hitting an entity. Like the shields in Overwatch. Because it's not a real entity, I implemented my own methods to detect te collision, and can't just use ProjectileHitEvent.
  4. try doing do task later and set it to one tick
  5. Wait, I read again your first post and... I don't understand when you say "if the arrow is going to hit the shield in the same tick it was shot", do you mean if an arrow is shot and hits an entity instantly?
  6. Where would I put the doTaskLater?
  7. If an arrow is shot, and it must hit the shield in the same tick, not an entity since the shield isn't an entity. I say "must hit", because I'm quite literally predicting it the arrow is gonna hit, by extrapolating it's trajectory. Those are the collision calculations I mentioned.
  8. I guess the best way of doing what you want is using the ProjectileLaunchEvent you mentioned in the beggining. That way you don't have to handle any type of runnable.