Solved OnPlayerJoin() not triggering.

Discussion in 'Plugin Development' started by tuskiomi, May 26, 2013.

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

    tuskiomi

    okay in a plugin currently in dev i plan to take a players inventor if it scheduled
    Code:
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent EVNT) {
            if(List.contains(EVNT.getplayer())){
            EVNT.getplayer().getinventory().clear();
            }
    
    however, this code won't work. the event never gets called. In my main class I register the class as event. The class currently holding this event is holding one other event aswell. Anyone Have anyidea why this method isn't called? Thanks in advance.
     
  2. Offline

    Skyshayde

    Can we see the rest of the code?
     
  3. Offline

    chasechocolate

    Does the "List" variable contain the player? It's generally better to use List<String> for saving players because saving the player instance can cause memory leaks.
    Code:java
    1. if(List.contains(EVNT.getPlayer().getName())){
    2. //Do stuff
    3. }
     
  4. Offline

    tuskiomi

    i put an info output at the end outside the if/then so it would print to the console if anything happened. nothing did.
     
  5. Offline

    BajanAmerican

    tuskiomi are you firing the event on your onEnable()?
     
  6. Offline

    zachoooo

    You shouldn't store players in a list
     
  7. Offline

    ZachBora

    List is usually a type, if you got a variable named List, what type is it :confused:
    Like zachoooo said make a List<String> and store the Player.getName().
     
  8. Offline

    FuZioN720

    Did you register the event in onEnable()
     
  9. Offline

    tuskiomi

  10. Offline

    Jamesthatguy

    If your main class is also your listener, example
    Code:
    public class pluginname extends JavaPlugin implements Listener
    then put this in your onEnabled
    Code:
    getServer().getPluginManager().registerEvents(this, this);
    This is what everyone means by registering events.
     
  11. Offline

    tuskiomi

    i did do that, do i need to do that for every event?
     
  12. Offline

    Skyshayde

    Is the event in your main class?
     
  13. Offline

    FuZioN720


    If all your events are in different classes you have to register that class. If the events are not in your main class
    this would not work.
    Code:java
    1. getServer().getPluginManager().registerEvents(this, this);


    You need to do this
    Code:java
    1. getServer().getPluginManager().registerEvents(new Your Listener's Class Name, this);

    Your Listener's Class Name is the class your event is in.
     
  14. Offline

    tuskiomi

    all events are in the same class
     
  15. Offline

    Skyshayde

    tuskiomi Could we see the entire class?
     
  16. Offline

    tuskiomi

    fixed.
    Main problem: Tpyo in my parameters.
     
Thread Status:
Not open for further replies.

Share This Page