Listener not registering events?

Discussion in 'Plugin Development' started by rujush.org, Jul 11, 2012.

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

    rujush.org

    [​IMG]

    There's no output for anything, except for the onEnable() and onDisable() functions.
     
  2. You have to register the listener in your onEnable method, like this:

    Code:
    public void onEnable() {
        PluginManager pm = this.getServer().getPluginManager();
        pm.registerEvents(this, this);
    }
    In your case it should be like this. I just wrote this in notepad so i don't know if there are any syntax errors...
    greetz blackwolf12333
     
  3. Offline

    gjossep

  4. Offline

    rujush.org

    Thank you the quick answer(s). :)
     
  5. No problem:)
     
  6. Offline

    rujush.org

    Untitled.png

    I have another problem, I want to figure out the name of the player that gets attacked in this scenario.
     
  7. if i'm not wrong you can do it like this:

    if (event.getDamager().getType() == EntityType.PLAYER) {
    event.GetDisplayName().
    }
     
  8. Offline

    rujush.org

    No such thing, I'm afraid.

    Anyone? This is supposedly the only thing keeping my plugin from being finished. [redflower]

    Edit: event.getEntity().toString() returns "CraftPlayer{name=Putte}", but has no .getName() function.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
  9. You could try this:
    1. Check if event.getEntity() is an instanceof Player
    2. Cast Player to Entity? (i.e. Player p = (Player)event.getEntity();)
    3. p.getName();
     
  10. Offline

    rujush.org

    Thanks a lot, MeneXia, that worked perfectly!
     
Thread Status:
Not open for further replies.

Share This Page