Help W/ PlayerExpChangeEvent?

Discussion in 'Spigot Plugin Development' started by eli.musgrove9, May 5, 2015.

  1. I am trying to add speed 1 to a player that reaches level 50. My code is below. I don't know why its working. Should I be using xp as a number, not a level number?

    Code (Text):
        @EventHandler
        public void levelUp(PlayerExpChangeEvent e) {
            String playerclass = plugin.getConfig().getString("Player_Data." + e.getPlayer().getName() + ".Class");
           
            // Assassin Speed
            if (playerclass.equalsIgnoreCase("Assassin")) {
               
                // Speed 1
                if (e.getPlayer().getLevel() >= 50) {
                    e.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 999999999, 2));
                }
            }
        }
     
  2. I need more help with exp. (I don't want to make another thread.)

    How can I send a message when a player reaches level 50?
    Code (Text):
    @EventHandler
        public void onPlayerXpChange(PlayerExpChangeEvent e) {
            Player player = e.getPlayer();
           
            if (player.getLevel() == 50) {
                player.sendMessage(ChatColor.DARK_RED + "You just leveled up to level 50! New abilities unlocked!");
            }
        }
     
  3. Anybody got any ideas?
     
  4. So it appears the PlayerExpChangeEvent isn't working. I have no idea why...
     
  5. Omnivion

    Patron

    Spigot/Bukkit version?
     
  6. It is the correct version! I am so confused!
     
  7. PlayerExpChangeEvent Javadoc says that this event is "called when a players experience changes naturally". I'm guessing whatever you're doing to set the players level doesn't count as "natural". Try playing around with some print statements and see when the event is fired.
     
  8. Omnivion

    Patron

    wat

    'correct version'