onJoinEvent

Discussion in 'Plugin Development' started by rob4001, Jul 30, 2011.

Thread Status:
Not open for further replies.
  1. Hey im truing to make a plugin which gives the player information when the log in

    ive registered the event
    Code:
    PluginManager pm = this.getServer().getPluginManager();
    
            pm.registerEvent(Event.Type.PLAYER_JOIN, new UMPlayerListener(this), Event.Priority.Monitor,
                    this);
    and ive got this in my listener

    Code:
    public class UMPlayerListener extends PlayerListener{
        private final UmTowny plugin;
        public UMPlayerListener(UmTowny thisa){
            this.plugin = thisa;
        }
        @Override
        public void onPlayerJoin(PlayerJoinEvent e){
    e.getPlayer().sendMessage("Herro");
    }
    }
    
    What do i have wrong?
     
  2. Offline

    stelar7

    try this:

    Code:
    PluginManager pm = getServer().getPluginManager();
    
    pm.registerEvent(Event.Type.PLAYER_JOIN, UMPlayerListener, Event.Priority.Monitor, this);
    listener

    Code:
    public class UMPlayerListener extends PlayerListener{
        private final UmTowny plugin;
        public UMPlayerListener(UmTowny thisa){
            this.plugin = thisa;
        }
    
     public void onPlayerJoin(PlayerJoinEvent e){
    e.getPlayer().sendMessage("Herro");
    }
    }
    
     
  3. What did you change?
     
  4. Offline

    stelar7

    Code:
    PluginManager pm = this.getServer().getPluginManager();
    pm.registerEvent(Event.Type.PLAYER_JOIN, new UMPlayerListener(this), Event.Priority.Monitor, this);
    
    to

    Code:
    PluginManager pm = getServer().getPluginManager();
    pm.registerEvent(Event.Type.PLAYER_JOIN, UMPlayerListener, Event.Priority.Monitor, this);
    
     
  5. Offline

    DrBowe

    Declare this in your main class:
    Code:java
    1.  
    2. private final UMPlayerListener playerListener = new UMPlayerListener(this);
    3.  


    Then, change your event registering to this:
    Code:java
    1.  
    2. pm.registerEvent(Event.Type.PLAYER_JOIN, playerListener, Event.Priority.Monitor, this);
    3.  


    I believe the issue is that your player listener isn't final, though I may be wrong.
     
  6. Offline

    Shamebot

    @DrBoweNur Why would it need to be final?
     
  7. Offline

    DrBowe

    @Shamebot

    Honestly, I just look at what I have in my source and pass it on. I don't even remember where the final came into play, probably a habit from my very first plugin that I carry around with me today.

    So really...it probably doesn't need to be final, but I can't find anything else that stands out as "THIS WONT WORK" in his source.
     
  8. Offline

    Jaker232

    @DrBoweNur The "Event.(blabla other shit)" is outdated. It would be like "Type.PLAYER_JOIN" and "Priority.(priority)". Just to clarify.
     
  9. Offline

    DrBowe

    @Jaker232

    Ummm, no. They both work just fine, neither is outdated. If you're looking to import an extra package just so you can avoid typing "Event.", then that's your choice. :confused:
     
  10. Offline

    Faelsel

    And don't use priority monitor! use highest instead...
     
  11. Offline

    Shamebot

    @Jaker232 But Type and Priority are enums within the Event class, why should you not be able to refer to them with Event.Type and Event.Priority?

    Edit:
    @Faelsel He doesn't cancel it, so Monitor is okay.
     
  12. Offline

    Jaker232

    @Shamebot That's actually a easier way than typing "Event.Priority.(priority)" and "Event.Type.(type)".
     
  13. Offline

    Shamebot

    But it probably isn't the cause of his problem.
    @ rob4001 Are you sure it doesn't work? Try and put some debug messages in.
     
  14. Offline

    DrBowe

    It may get rid of 6 characters that you need to type, but is that really worth having to import 'Type' and 'Priority' to you?
     
  15. Offline

    Jaker232

  16. Offline

    nisovin

    There sure is a lot of bad, incorrect advise in this thread. Of course, that's probably because there's nothing obviously wrong with his code, so people are just throwing out random suggestions. But still...
     
  17. Offline

    DrBowe

  18. Thanks guys it seems the final thing worked
     
  19. Offline

    DrBowe

    @rob4001
    Glad to help (Though I'm not sure if the final had anything to do with it, may have just been a strange issue with declaring the playerListener to begin with)
     
Thread Status:
Not open for further replies.

Share This Page