Making Scoreboard with Teams (No flicker)

Sep 27, 2017
Making Scoreboard with Teams (No flicker)
  • Hello there :),

    In this Wiki you will read on how to create a Scoreboard with Teams which has no flicker.

    Please read below and don't copy and paste :D


    Setting scoreboard
    Here we set the scoreboard for the player if player has no scoreboard yet!
    Code (Java):

            public void setScoreBoard(Player player){
            Scoreboard board = Bukkit.getScoreboardManager().getNewScoreboard();
            Objective obj = board.registerNewObjective("ThisCanBeYourServerName", "dummy");
            obj.setDisplaySlot(DisplaySlot.SIDEBAR);
            obj.setDisplayName("Test Server ");
     
    Now we make a Score that is just there and wont update.
    Like » Online and below that one we show the onlineplayers (Using teams)
    Code (Java):

            Score onlineName = obj.getScore(ChatColor.GRAY + "» Online");
            onlineName.setScore(15);
     
    /*
    * Scoreboard looks now like:
    *
    * == Title ==
    * » Online
    */

    Now we going to make the onlineCounter using teams (Wont be visible by /scoreboard teams list etc.
    Register a new team called "onlineCounter".
    We will need to use the "onlineCounter" later to update it! They are case Sensitive.
    Code (Java):

            Team onlineCounter = board.registerNewTeam("onlineCounter");
     
    Now we add just a blank entry instead of a player.
    Note that entry's for teams much be identical! You can't have 2 different teams with same entry!
    Code (Java):

            onlineCounter.addEntry(ChatColor.BLACK + "" + ChatColor.WHITE + "");
     
    Here we set the prefix of the team.
    This will look like:
    onlineplayers/maxplayers
    Example: 4/200
    You can change it yourself!
    Code (Java):

            if(Bukkit.getOnlinePlayers().size() == 0){
                onlineCounter.setPrefix(ChatColor.DARK_RED + "" + "0" + ChatColor.RED + "/" + "" + ChatColor.DARK_RED + Bukkit.getServer().getMaxPlayers());
            }else{
                onlineCounter.setPrefix(String.valueOf(ChatColor.DARK_RED + "" + Bukkit.getOnlinePlayers().size() + "" + ChatColor.RED + "/" + "" + ChatColor.DARK_RED + "" + Bukkit.getServer().getMaxPlayers()));
            }
     
    Now we add the team into the scoreboard so it will display it!
    Note that the getScore(""); must be the same as your team entry!
    This one is the same as the onlineCounter entry!
    Code (Java):

            obj.getScore(ChatColor.BLACK + "" + ChatColor.WHITE + "").setScore(14);
     
    /*
    * Scoreboard will now look like:
    *
    * == Title ==
    * » Online
    * 4/200 (From example)
    */


    Going to make a moneyCounter that will display your vault balance!
    Code (Java):

            Score money = obj.getScore(ChatColor.GRAY + "» Money");
            money.setScore(13);

            Team moneyCounter = board.registerNewTeam("moneyCounter");
            moneyCounter.addEntry(ChatColor.RED + "" + ChatColor.WHITE + "");
            moneyCounter.setPrefix(ChatColor.GREEN + "$" + economy.getBalance(player));
            obj.getScore(ChatColor.RED + "" + ChatColor.WHITE + "").setScore("12");
     
    * Scoreboard looks now like:
    *
    * == Title ==
    * » Online
    * 4/200
    * » Money
    * ${player's balance}



    Now we just set the scoreboard with:
    Code (Java):

            player.setScoreboard(board);
     
    Scoreboard been set! Time to update the scoreboard.

    Updating scoreboard
    So now we are going to update the scoreboard for a player.

    First we need to get the player's scoreboard

    Code (Java):

        public void updateScoreBoard(Player player){

            Scoreboard board = player.getScoreboard();
     
    Now we have that we can access the scoreboard stuff.
    Now lets update the onlineCounter and the moneyCounter

    Code (Java):

            if(Bukkit.getOnlinePlayers().size() == 0){
                board.getTeam("onlineCounter").setPrefix(ChatColor.DARK_RED + "" + "0" + ChatColor.RED + "/" + "" + ChatColor.DARK_RED + Bukkit.getServer().getMaxPlayers());
            }else{
                board.getTeam("onlineCounter").setPrefix(String.valueOf(ChatColor.DARK_RED + "" + Bukkit.getOnlinePlayers().size() + "" + ChatColor.RED + "/" + "" + ChatColor.DARK_RED + "" + Bukkit.getServer().getMaxPlayers()));
            }
     
    Here we get the team called "onlineCounter" and we update it by setting the new prefix
    Now lets update the moneyCounter
    Code (Java):

            board.getTeam("moneyCounter").setPrefix(ChatColor.GREEN + "$" + economy.getBalance(player));
     
    And now you have updated the scoreboard!


    Thanks for reading and have a nice day :D
  • Loading...
  • Loading...