Need help with Listeners

Discussion in 'Plugin Development' started by poxsgaming, May 26, 2014.

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


    First of all I'm terrible at coding, I'm helping a friend who taught me how to make the listeners, but I'm stuck on one that I can't get to work. And he's not on right now and I'm not sure when he will get back.

    Here's the code:

    1. package com.plugindev.rslevels.skills;
    3. import org.bukkit.entity.Zombie;
    4. import org.bukkit.event.EventHandler;
    5. import org.bukkit.event.EventPriority;
    6. import org.bukkit.event.Listener;
    7. import org.bukkit.event.entity.EntityDeathEvent;
    9. import com.plugindev.rslevels.RSLevels;
    10. import com.plugindev.rslevels.Skill;
    12. public class SlayerListener implements Listener {
    14. private RSLevels parent;
    16. public SlayerListener (RSLevels _parent) {
    17. parent = _parent;
    18. }
    19. @EventHandler(priority = EventPriority.MONITOR)
    20. public void onEntityDeath(EntityDeathEvent e) {
    21. boolean add = false;
    22. if(e.getEntity() instanceof Zombie) {
    23. parent.addExpToPlayer(e.getPlayer(), Skill.SLAYER, 120); //this part is having the error the e.getPlayer(), everything else is fine
    24. add = true;
    25. }
    27. }
    28. }
  2. Offline


    Well, that's pretty straight forward. EntityDeathEvent has no method called getPlayer(), therefore you can't use it. That simple :)
  3. Offline


    poxsgaming just look at what you are doing. You are testing to see if the entity is a zombie and then trying to add experience to a value that doesn't exist. There is no e.getPlayer() inside of the EntityDeathEvent.
  4. Offline


    poxsgaming "e.getPlayer()" doesn't exist. What should it look like:
    1. if(e.getEntity() instanceof Zombie) {
    2. if (e.getEntity().getKiller() instanceof Player) {
    3. parent.addExpToPlayer(e.getEntity().getKiller(), Skill.SLAYER, 120);
    4. //this part is having the error the e.getPlayer(), everything else is fine add = true;
    5. }
    6. }
  5. Offline


    I'm trying to gain xp when you kill a Zombie
  6. Offline


    Entity has a method getKiller() which returns the Player who killed it. Note however, that it will be null if the entity is still alive or was killed by a natural cause, not a player.
Thread Status:
Not open for further replies.

Share This Page