Non flickering scoreboard

Discussion in 'Spigot Plugin Development' started by wantsome909, Jun 5, 2017.

  1. Code (Text):
        public void setScoreboard(){
            int minplayers = arena.getManager().getMinPlayers();
            int maxplayers = arena.getManager().getMaxPlayers();
            int onlineplayers = arena.getManager().getRunner().size();

            final Scoreboard board = Bukkit.getScoreboardManager().getNewScoreboard();
            final Objective obj = board.registerNewObjective("lobby", "dummy");

            obj.setDisplaySlot(DisplaySlot.SIDEBAR);
            obj.setDisplayName("§e§lFreezeTag");

            Team min = board.registerNewTeam("min");

            min.addEntry(ChatColor.YELLOW.toString());
            min.setPrefix("Min players: ");
            min.setSuffix("§a" + minplayers);
            obj.getScore(ChatColor.YELLOW.toString()).setScore(5);

            Team space = board.registerNewTeam("space");

            space.addEntry(ChatColor.DARK_PURPLE.toString());
            space.setPrefix(" ");
            obj.getScore(ChatColor.DARK_PURPLE.toString()).setScore(4);

            Team max = board.registerNewTeam("max");

            max.addEntry(ChatColor.GREEN.toString());
            max.setPrefix("Max players: ");
            max.setSuffix("§a" + maxplayers);
            obj.getScore(ChatColor.GREEN.toString()).setScore(3);

            Team space2 = board.registerNewTeam("space2");

            space2.addEntry(ChatColor.DARK_AQUA.toString());
            space2.setPrefix("  ");
            obj.getScore(ChatColor.DARK_AQUA.toString()).setScore(2);


            Team online = board.registerNewTeam("online");

            online.addEntry(ChatColor.BLUE.toString());
            online.setPrefix("Players: ");
            online.setSuffix("§a" + onlineplayers + "§a/§a" + maxplayers);
            obj.getScore(ChatColor.BLUE.toString()).setScore(1);

            Team space3 = board.registerNewTeam("space3");

            space3.addEntry(ChatColor.GOLD.toString());
            space3.setPrefix("   ");
            obj.getScore(ChatColor.GOLD.toString()).setScore(6);

            Team fake = board.registerNewTeam("faketimer");
            Team timer = board.registerNewTeam("realtimer");
            if(arena.getManager().counterTimer == false){

                fake.addEntry(ChatColor.RED.toString());
                fake.setPrefix("Waiting...");
                obj.getScore(ChatColor.RED.toString()).setScore(7);
            }else{
                timer.addEntry(ChatColor.GRAY.toString());
                timer.setPrefix("Timer: ");
                timer.setSuffix("0");
                obj.getScore(ChatColor.GRAY.toString()).setScore(7);
            }

            Team space1 = board.registerNewTeam("space1");

            space1.addEntry(ChatColor.BLACK.toString());
            space1.setPrefix(" ");
            obj.getScore(ChatColor.BLACK.toString()).setScore(8);

            if(onlineplayers == arena.getManager().getMinPlayers()){
                arena.getManager().counterTimer = true;
                new BukkitRunnable(){
                    int counter = 16;
                    @Override
                    public void run() {
                        counter--;
                        board.getTeam("faketimer").setSuffix("§a" + counter); //and for the fake timer
                        board.getTeam("realtimer").setSuffix("§a" + counter); //where i modified timer

                        if(counter == 0){
                            lobby.getManager().startGame();
                            cancel();
                        }
                    }
                }.runTaskTimer(main.getManager(), 0L, 20L);
            }

            for(Player people: Bukkit.getOnlinePlayers()){
                people.setScoreboard(board);
            }
        }
    my problem is. When a third person joins, the timer will get set to TIMER: 0 and i set it to get modified but it wont display the suffix.

    can anyone help me get this to work. i dont want flickering boards
     
  2. Well, I can't help you create a non-flickering scoreboard because it is pretty hard and confusing.

    But, my plugin 'Scoreboard' allows for custom placeholders to be injected via PlaceholderAPI.

    If you really wan't to do it yourself: create a team, set its prefix and suffix and instead of updating the scoreboard you change the prefix and the suffix.
     
  3. Or you go with the all-mighty FeatherBoard API. Or just dig into NMS packets, it isn't that hard todo as you might think. Then you can do everything you like without using a library.
     
  4. Please take a look at my signature ;) it will help you.
     
    • Useful Useful x 1
  5. very usefull thnx
     
  6. yep, thanks TheBlackTeddy :D
     
  7. Kyllian winner with best signature :v
     
    • Funny Funny x 1