Solved setTarget() error

Discussion in 'Plugin Development' started by Higgsboson728, Nov 2, 2015.

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

    Higgsboson728

    Hello, I get an error when in Eclipse IDE when I do this:

    Code:
    for (LivingEntity other: Bukkit.getOnlinePlayers()) {
                             if (other.getLocation().distance(e.getLocation()) <= 25 && ((HumanEntity) other).getItemInHand().getType() == Material.BLAZE_POWDER || ((HumanEntity) other).getItemInHand().getType() == Material.SUGAR) {
                                
                                 ((LivingEntity) e).setTarget(other);
                                 break;
                             }
                         }
    "The method setTarget(LivingEntity) is undefined for the type LivingEntity"

    What could be the problem? Thanks
     
  2. Offline

    teej107

    LivingEntity doesn't have the method "setTarget".
     
    Konato_K likes this.
  3. Offline

    Higgsboson728

    "e" is suppose to be a zombie pigman.
    @teej107
    Code:
    Player p = (Player) sender;
                    Location loc = p.getLocation();
                    LivingEntity e = (LivingEntity) p.getWorld().spawnEntity(loc, EntityType.PIG_ZOMBIE);
    And what can I do to fix this? Should I change the cast LivingEntity to something else?

    When I remove (LivingEntity) it gives me an error saying that I need to cast "e"


    EDIT: Fixed. I needed to change (LivingEntity) to (Creature) :D
     
    Last edited: Nov 2, 2015
Thread Status:
Not open for further replies.

Share This Page