Solved Scoreboard without flashing and new line.

Discussion in 'Plugin Development' started by Scrapnix, Dec 8, 2016.

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

    Scrapnix

    Hey, I have a new problem. I want to make a scoreboard, without flashing. I updated the objectives every second, but if a objective has a new value, it makes a new line. Here`s my code:
    Code:
    public org.bukkit.scoreboard.Scoreboard Scoreboard(Player player){
           
           
            int online = Bukkit.getOnlinePlayers().size();
            int coins = this.getConfig().getInt("Coins." + player.getName());
           
            ScoreboardManager sm = Bukkit.getScoreboardManager();
            Scoreboard board = sm.getNewScoreboard();
            Objective score = board.getObjective("aaa") != null ? board.getObjective("aaa") : board.registerNewObjective("aaa", "bbb");       
            score.setDisplayName("§e§l>> §6§lDrazonMC");
            score.setDisplaySlot(DisplaySlot.SIDEBAR);
           
           
            score.getScore(ChatColor.RESET.toString() + ChatColor.RESET.toString() + ChatColor.RESET.toString() + ChatColor.RESET.toString() + ChatColor.RESET.toString() + ChatColor.RESET.toString()).setScore(16);
            score.getScore("§f§lOnline Spieler: ").setScore(15);
            score.getScore("§b§l"+ online).setScore(14);
            score.getScore(ChatColor.RESET.toString() + ChatColor.RESET.toString() + ChatColor.RESET.toString() + ChatColor.RESET.toString() +ChatColor.RESET.toString()).setScore(13);
            score.getScore("§f§lDeine Coins:").setScore(12);
            score.getScore("§4§l" + coins).setScore(11);
            score.getScore(ChatColor.RESET.toString() + ChatColor.RESET.toString() + ChatColor.RESET.toString() + ChatColor.RESET.toString()).setScore(10);
            score.getScore("§f§lNächstes Event : ").setScore(9);
            score.getScore("§d§lEröffnungsparty!").setScore(8);
            score.getScore(ChatColor.RESET.toString() + ChatColor.RESET.toString() + ChatColor.RESET.toString()).setScore(7);
            score.getScore("§6§lMach doch mal:").setScore(6);
            score.getScore("§5§l/server!").setScore(5);
            score.getScore(ChatColor.RESET.toString() + ChatColor.RESET.toString()).setScore(4);
            score.getScore("§4F§fr§4o§fh§4e§fs §4F§fe§4s§ft §4!").setScore(2);
            score.getScore("§f*§c*§f*§c*§f*§c*§f*§c*§f*§c*§f*§c*§f*").setScore(1);
           
    
            return board;
    
        }
        public void updateScoreboard(Player player) {
            if (player.getScoreboard() != null) {
                int online = Bukkit.getOnlinePlayers().size();
                int coins = this.getConfig().getInt("Coins." + player.getName());
                    Objective score = player.getScoreboard().getObjective("aaa") != null ? player.getScoreboard().getObjective("aaa") : player.getScoreboard().registerNewObjective("aaa", "bbb");
                    score.getScore(ChatColor.RESET.toString() + ChatColor.RESET.toString() + ChatColor.RESET.toString() + ChatColor.RESET.toString() + ChatColor.RESET.toString() + ChatColor.RESET.toString()).setScore(16);
                    score.getScore("§f§lOnline Spieler: ").setScore(15);
                    score.getScore("§b§l"+ online).setScore(14);
                    score.getScore(ChatColor.RESET.toString() + ChatColor.RESET.toString() + ChatColor.RESET.toString() + ChatColor.RESET.toString() +ChatColor.RESET.toString()).setScore(13);
                    score.getScore("§f§lDeine Coins:").setScore(12);
                    score.getScore("§4§l" + coins).setScore(11);
                    score.getScore(ChatColor.RESET.toString() + ChatColor.RESET.toString() + ChatColor.RESET.toString() + ChatColor.RESET.toString()).setScore(10);
                    score.getScore("§f§lNächstes Event : ").setScore(9);
                    score.getScore("§d§lEröffnungsparty!").setScore(8);
                    score.getScore(ChatColor.RESET.toString() + ChatColor.RESET.toString() + ChatColor.RESET.toString()).setScore(7);
                    score.getScore("§6§lMach doch mal:").setScore(6);
                    score.getScore("§5§l/server!").setScore(5);
                    score.getScore(ChatColor.RESET.toString() + ChatColor.RESET.toString()).setScore(4);
                    score.getScore("§4F§fr§4o§fh§4e§fs §4F§fe§4s§ft §4!").setScore(2);
                    score.getScore("§f*§c*§f*§c*§f*§c*§f*§c*§f*§c*§f*§c*§f*").setScore(1);
            }
            }
    Sorry, I`m from Germany, the text is German.
     
  2. Offline

    timtower Administrator Administrator Moderator

    @Scrapnix Don't create a new scoreboard every time, reuse the old one.
     
  3. Offline

    Scrapnix

    And how do i do that?

    That`s the only way, I know to make this, sorry, I`m a Bukkit newbie :D
     
    Last edited: Dec 8, 2016
  4. Offline

    Zombie_Striker

    @Scrapnix
    Replace
    With
    Code:
     board = Player#getScoreboard
     
  5. Offline

    Scrapnix

    Sorry, but where do I have to replace the board? If I replace this into the Scoreboard method, it updates the Scoreboard, but still with new lines. The only thing which it does, is, that it catches the old Scoreboard and it shows up the old lines (Which have been updated) too. I hope for help :)
     
  6. Offline

    Zombie_Striker

    Are you making sure to clear the scoreboard before adding the new lines? Post the updated code.
     
  7. Offline

    Scrapnix

    Hey, I cleared all the new lines, with the old objective (Objective old = p.getObjctives()), and then old.unregister(). Thats `s okay. The old lines aren`t show up, but now my next problem is, if I make it with this code, all the objectives won`t get updated. Only if i reload the Server, the whole Scoreboard gets updated and it lags. Somewhere I read, that I have to make the whole thing with Teams.
    Here is my code:
    Code:
      public void updateScoreboard(Player player) {
            if (player.getScoreboard() != null) {
                int online = Bukkit.getOnlinePlayers().size();
                int coins = this.getConfig().getInt("Coins." + player.getName());
                Scoreboard board = player.getScoreboard();
                Objective old = board.getObjective("aaa");
                old.unregister();
                Objective score = player.getScoreboard().registerNewObjective("aaa", "bbb");
                score.setDisplayName("§e§l>> §6§lDrazonMC");
                score.setDisplaySlot(DisplaySlot.SIDEBAR);
                score.getScore(ChatColor.RESET.toString() + ChatColor.RESET.toString() + ChatColor.RESET.toString() + ChatColor.RESET.toString() + ChatColor.RESET.toString() + ChatColor.RESET.toString()).setScore(16);
                score.getScore("§f§lOnline Spieler: ").setScore(15);
                score.getScore("§b§l"+ online).setScore(14);
                score.getScore(ChatColor.RESET.toString() + ChatColor.RESET.toString() + ChatColor.RESET.toString() + ChatColor.RESET.toString() +ChatColor.RESET.toString()).setScore(13);
                score.getScore("§f§lDeine Coins:").setScore(12);
                score.getScore("§4§l" + coins).setScore(11);
                score.getScore(ChatColor.RESET.toString() + ChatColor.RESET.toString() + ChatColor.RESET.toString() + ChatColor.RESET.toString()).setScore(10);
                score.getScore("§f§lNächstes Event : ").setScore(9);
                score.getScore("§d§lEröffnungsparty!").setScore(8);
                score.getScore(ChatColor.RESET.toString() + ChatColor.RESET.toString() + ChatColor.RESET.toString()).setScore(7);
                score.getScore("§6§lMach doch mal:").setScore(6);
                score.getScore("§5§l/server!").setScore(5);
                score.getScore(ChatColor.RESET.toString() + ChatColor.RESET.toString()).setScore(4);
                score.getScore("§4F§fr§4o§fh§4e§fs §4F§fe§4s§ft §4!").setScore(2);
                score.getScore("§f*§c*§f*§c*§f*§c*§f*§c*§f*§c*§f*§c*§f*").setScore(1);
     
  8. Offline

    Scrapnix

    Last edited: Dec 12, 2016
Thread Status:
Not open for further replies.

Share This Page