Scoreboards

Discussion in 'Plugin Development' started by Praxounet, Dec 30, 2018.

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

    Praxounet

    So basically I'm trying to create a scoreboard, but even after further verification my scoreboard code cannot apply on my localhost.

    The code is :

    Code:
    @SuppressWarnings("deprecation")
        @EventHandler
        public void onJoin(PlayerJoinEvent event) {
            Player player = event.getPlayer();
           
            ScoreboardManager sm = Bukkit.getScoreboardManager();
            Scoreboard b = sm.getNewScoreboard();
           
           
            Objective obj = b.registerNewObjective("salut", "");
            obj.setDisplaySlot(DisplaySlot.SIDEBAR);
            obj.setDisplayName("§eScores");
           
            Score joueurs = obj.getScore("Joueurs :§e" + Bukkit.getOnlinePlayers());
            joueurs.setScore(5);
           
            player.setScoreboard(b);
        }
    I already looked if I saved my plugin in the right doc.
    Any help ?
     
  2. Offline

    Zombie_Striker

    @Praxounet
    1. Since the amount of players online does not change individually for each player seeing it, you should not create a new scoreboard every time a player joins. Instead, use a single scoreboard created in the onEnable, and only set the scoreboard in the onJoin.
    2. You should not use the paragraph symbols within the plugin/jar. Since it is not an ASCII character, the jar would need to be encoded using UTF8, which increases the file size. Instead, just use the ChatColor enum value when coloring text.
    3. Bukkit.getOnlinePlayers returns a list of players, which both contains text you don't need and may be too long for the scoreboard (there cannot be more than 16 characters per score). Instead, loop through all the players online, and add the name to the scoreboard individually. This is most likely why it is not working on your server.
     
Thread Status:
Not open for further replies.

Share This Page