How to manipulate player inventory in the login event?

Discussion in 'Plugin Development' started by SaxSalute, Apr 23, 2014.

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

    SaxSalute

    Code:
        @SuppressWarnings("deprecation")
        @EventHandler
        public void onPlayerLogin(PlayerLoginEvent event)
        {
            Player p = event.getPlayer();
            event.getPlayer().getInventory().clear();
            event.getPlayer().getInventory().addItem(Inventories.COMPASS); //This is a custom meta compass I have defined.
            event.getPlayer().updateInventory();
        }
    This code throws an NPE, but it works perfectly fine when called in any other location in the code. Is there any way to make something like this work in the login event?
     
  2. Have you tried using the PlayerJoinEvent instead?
     
  3. Offline

    daytonpoop

    Their not even in the server yet.
     
  4. Offline

    TGRHavoc

    SaxSalute
    Try adding a delay to it or making it a "onPlayerJoinEvent" . And also, I don't think you have to call the "updateInventory" method, and you could just do "p.getInventory()" instead of "e.getPlayer()".
     
  5. Offline

    SaxSalute

    I actually copy pasted that code from elsewhere because I knew it was functional. I didn't retool it properly. Didn't realize there were 2 separate login type events. Thanks!
     
  6. Offline

    Nateb1121

    EDIT: Nevermind, seems to have been solved! :)

    Out of pure curiosity what line is the NPE on? I don't think it's your enum throwing that error... but knowing which line would help a lot.
     
Thread Status:
Not open for further replies.

Share This Page