Setting a Player Level to 0

Discussion in 'Spigot Plugin Development' started by natesbait, Jun 13, 2019 at 2:16 AM.

  1. So yeah, I want to set a players level to 0 when they join if they have previously played, but I am having some problems with getting it working.

    Code:

    Code (Text):
    package com.nathan.clearxp;

    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;

    public class ClearXP implements Listener {
       
        public void onjoin(PlayerJoinEvent event) {
            Player player = event.getPlayer();
            boolean hasjoined = player.hasPlayedBefore();
           
            if (hasjoined) {
                player.setLevel(player.getLevel() - 0);
            }
        }

    }
     
     
  2. Choco

    Junior Mod

    Ehm... well... anything minus 0 is just itself. What's wrong with player.setLevel(0)?
     
  3. Just set the level to 0....
    What makes you think anything minus 0 changes anything?
     
  4. This still doesn't work:

    Code (Text):
    package com.nathan.clearxp;

    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.java.JavaPlugin;

    public class ClearXP extends JavaPlugin implements Listener {
       
        public void onjoin(PlayerJoinEvent event) {
            Player player = event.getPlayer();
            boolean hasjoined = player.hasPlayedBefore();
           
            if (hasjoined) {
                player.setLevel(0);
            }
        }

    }
     
     
  5. You arent using @EventHandler and probably not registering it
     
    • Agree Agree x 1
  6. EWS

    EWS

    The event is probably not triggering.
    You did not mark you method as @EventHandler, and probably didn't register it in the main class.

    Code (Text):

    @EventHandler
    public void onJoin(PlayerJoinEvent e) {
        // code here
    }
     
    In your main class:
    Code (Text):

    this.getServer().getPluginManager().registerEvents(new ClearXP(), this)
     
     
    • Agree Agree x 1

Share This Page