getLevel() always returning 0 error

Discussion in 'Plugin Development' started by gabbo200, Feb 6, 2016.

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

    gabbo200

    Hey, I'm trying to create a condition on player join event, but the result of player.getLevel() is always 0 so I can0t make the condition.

    Code:
    public void onPlayerLogin(PlayerLoginEvent event) {
    Player player = event.getPlayer();
    
    int plevel = player.getLevel();
    
    if (plevel > 1) {
    
    player.sendMessage("Level:" + plevel); /*This returns 0*/
    player.sendMessage("You are now Level 2");
    
    
    
    }
     
  2. Offline

    q8minecraft

    @gabbo200 Have you tried PlayerJoinEvent ? I think PlayerLoginEvent gets the player when they still haven't joined, then I assume their level is still set to a default value, which is 0.
     
    Last edited: Feb 6, 2016
    Assist likes this.
  3. Offline

    JoaoBM

    @q8minecraft Did you register your events on onEnable? Did you add @EventHandler above your event? If you have both of these I mentioned, then add a delay before getting the XP level, according with what @q8minecraft said.
     
Thread Status:
Not open for further replies.

Share This Page