Error?

Discussion in 'Spigot Plugin Development' started by LazerShadow, Jun 4, 2015.

  1. Why is there an error here?

    Code (Javascript):
        @EventHandler
        public void onEntityDamage(EntityDamageByEntityEvent e) {
                if (e.getDamager() instanceof Fireball) {
                        Fireball f = (Fireball) e.getDamager();
                        if (f.getShooter() instanceof Player) {
                                Player shooter = (Player) f.getShooter();
                                if (shooter.getItemInHand().getType() == Material.IRON_SPADE) {
                                        e.setDamage(10.0);
                                }
                        }
                }
        }
    [​IMG]
     
  2. Serializator

    Supporter

    Hover over the text with the red line underneath it and post the message that shows up here.
     
  3. I don't think Fireballs can have a shooter (directly).
     
  4. This shouldn't be erroring. I just copy pasted it to my IDE and auto imported needed classes and I see no errors at all. Check your imports. Maybe you have a class called Fireball in your project and are accidentally importing that one instead?

    What do you mean "directly?" A fireball is a projectile, and all projectiles have the .getShooter() method.
     
  5. [​IMG]

    I checked. I am using Spigot so could that have a difference?
    [​IMG]
     
  6. Yes. You should be building against the API, not the implementation. ;)

    Edit: If you require the implementation (for NMS or whatever) then make sure you also include the API in your build path and set it first so it gets used first to avoid these kinds of issues (see this for more information)
     
  7. Try updating spigot again.
     
  8. @BillyGalbreath Yes, but it doesn't have to be a player who shot the Fireball, it can be spawned with a direction where it will shoot.
     
  9. Depends on how you spawned it. Player#launchProjectile obviously sets the shooter, but World#spawn might not.
     
  10. The value may be null, but it would never cause an error in the IDE like this. The problem is a common one, and I've already posted the solution and a link of more details for the curious.
     
  11. Check your imports.