Solved How do I make a fireball not explosive?

Discussion in 'Plugin Development' started by AoH_Ruthless, Jun 1, 2014.

Thread Status:
Not open for further replies.
  1. Offline


    I am trying to listen for the ProjectileHitEvent in order to cancel the explosiveness of a Fireball, and to eliminate the fire effects everywhere around the fireball. This is what I have tried:

    1. @EventHandler (priority = EventPriority.HIGH)
    2. public void onProjectileHit(ProjectileHitEvent e) {
    3. Projectile p = e.getEntity();
    4. if (p instanceof Fireball) {
    5. Fireball f = (Fireball) p;
    6. for (Player player : f.getWorld().getPlayers()) {
    7. if (!f.hasMetadata(player.getName()))
    8. continue;
    10. f.setIsIncendiary(false);
    11. f.setFireTicks(0);
    12. f.setYield(0F);
    13. for (Entity entity : f.getNearbyEntities(3.2, 3.2, 3.2)) {
    14. if (entity instanceof LivingEntity) {
    15. LivingEntity le = (LivingEntity) entity;
    17. double distance = f.getLocation().distance(
    18. le.getLocation());
    19. le.damage(distance < 0.371 ? 0.325 * le.getMaxHealth()
    20. : Math.min(6.4 / distance + 0.75,
    21. 0.224 * le.getMaxHealth()));
    22. }
    23. }
    24. break;
    25. }
    26. }
    27. }

    Pay no attention to the second for loop, that's just an algorithm to try and damage players in a certain radius of the fireball (which works fine). In the game, the fireball blows up the landscape and sets fire to the land. So how can I fix it?

    Also, pay no attention to the metadata, that's just a check to make sure it's the right fireball we want to work with (and it gets the player who fired the fireball)

    I have thought about it, and while I could launch a different projectile than a fireball, I would prefer to be able to launch a fireball.
  2. Offline


    AoH_Ruthless Are you spawning this yourself? If so, then call
    When you launch it.
  3. Offline


    Yes it is spawned in a PlayerInteractEvent when a player right clicks a fireball. I did those two things you said, let me try doing it outside the for loop. I'll get back to you on this.

    Never mind, I didn't see the last part about "When you launch it"

    Yes, it worked. Thank you!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 30, 2016
Thread Status:
Not open for further replies.

Share This Page