Solved Scoreboard Update Issue

Discussion in 'Spigot Plugin Development' started by Odogo, Jul 1, 2018.

Thread Status:
Not open for further replies.
  1. Hia there. I am not really new to coding, but I use the internet to my guide.

    Anyway, I have an issue of updating the entries of a scoreboard, and I just don't know how to do it.
    So I came here to ask the community who is mostly better then me (depends on what you're knowledge is on Spigot/BukkitAPI)

    Here is the scoreboard,
    (If image doesn't work, link: https://gyazo.com/8ade91705eef4be6c9127036d68e42f0)
    [​IMG]

    I would like to update the Balance and the Vote Party entries.

    Code for the Scoreboard:
    Code (Java):
    @EventHandler
        public void playerJoin(PlayerJoinEvent e) {
            Player player = e.getPlayer();
            ScoreboardManager scoreboardManager = plugin.getServer().getScoreboardManager();
            Scoreboard scoreboard = scoreboardManager.getNewScoreboard();
            Objective objective = scoreboard.registerNewObjective("Main", "Dummy");
            objective.setDisplaySlot(DisplaySlot.SIDEBAR);
            Team health = scoreboard.registerNewTeam("Main");
            health.addEntry(ChatColor.AQUA + "Balance " + ChatColor.GRAY + ">> " + ChatColor.GREEN + plugin.getEcon().getBalance(player));
            health.addEntry(ChatColor.AQUA + "Vote Party: " + ChatColor.GREEN + plugin.getConfig().getInt("voting-amount") + "/50");
            health.addEntry(" ");
            health.setSuffix("");
            health.setPrefix("");
            objective.getScore(ChatColor.AQUA + "Balance " + ChatColor.GRAY + ">> " + ChatColor.GREEN + plugin.getEcon().getBalance(player)).setScore(5);;
            objective.getScore(" ").setScore(4);
            objective.getScore(ChatColor.AQUA + "Vote Party: " + ChatColor.GREEN + plugin.getConfig().getInt("voting-amount") + "/50").setScore(3);

            new BukkitRunnable() {

                int titlenum = 0;

                @Override
                public void run() {
                    player.setScoreboard(scoreboard);
                    if(titlenum == 0) {
                        objective.setDisplayName("" + ChatColor.AQUA + ChatColor.BOLD + "Firestar");

                    } else if(titlenum == 1) {
                        objective.setDisplayName("" + ChatColor.GOLD + ChatColor.BOLD + "F" + ChatColor.AQUA + ChatColor.BOLD + "irestar");

                    } else if(titlenum == 2) {
                        objective.setDisplayName("" + ChatColor.AQUA + ChatColor.BOLD + "F" + ChatColor.GOLD + ChatColor.BOLD + "i" + ChatColor.AQUA + ChatColor.BOLD + "restar");

                    } else if(titlenum == 3) {
                        objective.setDisplayName("" + ChatColor.AQUA + ChatColor.BOLD + "Fi" + ChatColor.GOLD + ChatColor.BOLD + "r" + ChatColor.AQUA + ChatColor.BOLD + "estar");

                    } else if(titlenum == 4) {
                        objective.setDisplayName("" + ChatColor.AQUA + ChatColor.BOLD + "Fir" + ChatColor.GOLD + ChatColor.BOLD + "e" + ChatColor.AQUA + ChatColor.BOLD + "star");

                    } else if(titlenum == 5) {
                        objective.setDisplayName("" + ChatColor.AQUA + ChatColor.BOLD + "Fire" + ChatColor.GOLD + ChatColor.BOLD + "s" + ChatColor.AQUA + ChatColor.BOLD + "tar");

                    } else if(titlenum == 6) {
                        objective.setDisplayName("" + ChatColor.AQUA + ChatColor.BOLD + "Fires" + ChatColor.GOLD + ChatColor.BOLD + "t" + ChatColor.AQUA + ChatColor.BOLD + "ar");

                    } else if(titlenum == 7) {
                        objective.setDisplayName("" + ChatColor.AQUA + ChatColor.BOLD + "Firest" + ChatColor.GOLD + ChatColor.BOLD + "a" + ChatColor.AQUA + ChatColor.BOLD + "r");

                    } else if(titlenum == 8) {
                        objective.setDisplayName("" + ChatColor.AQUA + ChatColor.BOLD + "Firesta" + ChatColor.GOLD + ChatColor.BOLD + "r");

                    } else if(titlenum == 9) {
                        objective.setDisplayName("" + ChatColor.AQUA + ChatColor.BOLD + "Firestar");

                    } else if(titlenum == 10) {
                        objective.setDisplayName("" + ChatColor.AQUA + ChatColor.BOLD + "Firestar");

                    } else if(titlenum == 11) {
                        objective.setDisplayName("" + ChatColor.GOLD + ChatColor.BOLD + "Firestar");

                    } else if(titlenum == 12) {
                        objective.setDisplayName("" + ChatColor.AQUA + ChatColor.BOLD + "Firestar");

                    } else if(titlenum == 13) {
                        objective.setDisplayName("" + ChatColor.GOLD + ChatColor.BOLD + "Firestar");

                    } else if(titlenum == 14) {
                        objective.setDisplayName("" + ChatColor.AQUA + ChatColor.BOLD + "Firestar");

                    } else if(titlenum == 15) {
                        objective.setDisplayName("" + ChatColor.AQUA + ChatColor.BOLD + "Firestar");

                    } else if(titlenum == 16) {
                        objective.setDisplayName("" + ChatColor.AQUA + ChatColor.BOLD + "Firestar");
                        titlenum = 0;
                    }

                    titlenum++;
                    player.setScoreboard(null);
                }

            }.runTaskTimer(plugin, 0, 5);
        }
    If you find anything else with this code, please let me know.

    (Implemented nuVotifier and Vault)
     
  2. ciz

    ciz

    First of all, don't make a new runnable for each player, especially when you don't even cancel it. Secondly, have a look at this. It might help you a bit.
     
    • Useful Useful x 1
  3. In your case, you would have to remove the old entry and create a new one. This is because you use the name you have to change as the id of the entry.
     
  4. Thanks for the link to the Wiki page. That will fix this.
     
    #4 Odogo, Jul 1, 2018
    Last edited: Jul 1, 2018
    • Like Like x 1
Thread Status:
Not open for further replies.