Get xp level

Discussion in 'Plugin Development' started by ArthurHoeke, Sep 2, 2014.

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

    ArthurHoeke

    Hey

    How to get how many xp a player has? I need to check it with a if, But it doesn't work!
    It just doesn't listen to the check code!
    Code:

    Code:
    @EventHandler
          public void onFly(PlayerToggleFlightEvent event)
          {
            Player player = event.getPlayer();
            flyusers.add(player.getName());
            if (player.getTotalExperience() == 1.0F) {
            if ((player.getGameMode() != GameMode.CREATIVE) &&
              (!Main.flyusers.contains(event.getPlayer().getName()))) {
              event.setCancelled(true);
              player.setAllowFlight(false);
              player.setFlying(false);
              player.setVelocity(player.getLocation().getDirection()
                .multiply(0.35D).setY(0.75D));
              player.playEffect(player.getLocation(), Effect.SMOKE, 0);
              player.playSound(player.getLocation(), Sound.ENDERDRAGON_WINGS, 10.0F,
                1.0F);
            }
            }
          }
     
  2. I think it is that when you use getTotalExperience you get it including the levels, but if you just use getExp it should work.
     
  3. Offline

    nlthijs48

    ArthurHoeke If you want to detect if the player has 1 level (meaning between 1.0 and 2.0) you can better use the getLevel() method instead of the getTotalExperience() method. The getLevel() returns in integer and can just be checked with ==1.
     
Thread Status:
Not open for further replies.

Share This Page