Getting EXP level to be displayed in a scoreboard

Discussion in 'Plugin Development' started by Wirexin, Jan 8, 2020.

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

    Wirexin

    Hello,
    I am currently trying to make a plugin that displays players' EXP level (minecraft level) right under their nametags (the names appearing on top of their heads) but I am a total beginner in plugin making and I know almost nothing about the syntax.
    I am currently trying to get the players' level data to be displayed in the scoreboard but I don't know how to.

    Here is the code I have so far:

    Code:
    @Override
        public void onEnable() {
            s = Bukkit.getScoreboardManager().getMainScoreboard();
            registerLevelBar();
            //registerNameTag();
            Bukkit.getPluginManager().registerEvents(this, (Plugin) this);
        }
       
        @SuppressWarnings("deprecation")
       
        //EventHandler
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent e) {
           
            e.getPlayer().sendMessage("HELLO THERE.");
           
            s.getTeam("blue").addPlayer(e.getPlayer());
        }
       
        public void registerLevelBar() {
           
            //Player p = e.getPlayer();
            //int plvl = p.getLevel();
           
            if (s.getObjective("plvl") != null) {
                s.getObjective("plvl").unregister();
            }
            Objective o = s.registerNewObjective("plvl", "plvl");
            o.setDisplayName(ChatColor.AQUA + " lv");
            o.setDisplaySlot(DisplaySlot.BELOW_NAME);
        }

    Any thoughts?
     
  2. Offline

    KarimAKL

    @Wirexin What are you having problems with?
     
  3. Offline

    Wirexin

    The point is, it doesn't work at all. Nothing shows up and I am not %100 sure what I did wrong I need some handholding level guidance here
     
  4. Offline

    KarimAKL

    @Wirexin I haven't worked with scoreboards a lot but, don't you need to set the scoreboard using Player#setScoreboard(Scoreboard)?
     
  5. Offline

    Wirexin

    How do I even implement this ? Also are you sure I got the level variable right ? I think the issue could be because it cannot reach the level variable from the player.
     
Thread Status:
Not open for further replies.

Share This Page