Multiple Scoreboard

Discussion in 'Plugin Development' started by jebbo, May 2, 2015.

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

    jebbo

    How can I make a scoreboard that shows the player's individual stats in the sidebar, and shows a custom Tag in above the name? When I've tried it, it always messed up the Sidebar scoreboard to somebody else's stats.

    My goal is to show each players Clan in the name & have the players score in the scoreboard.

    I can do each one individual, but I couldn't get them both together to work.

    This is what I'm using:

    (I just put this together to make it work, not to function lagfree / saving memory.)

    Code:
    public static void StatusBoard(Player player) {
            ScoreboardManager sbm = Bukkit.getScoreboardManager();
            Scoreboard board = sbm.getMainScoreboard();
            Objective aaa = board.registerNewObjective(player.getName(), "dummy");
            PlayerData pd = new PlayerData(player);
            aaa.setDisplaySlot(DisplaySlot.SIDEBAR);
            aaa.setDisplayName("§e§l< §b§lStats §e§l>");
            Score online1 = aaa.getScore("§6§lOnline");
            online1.setScore(Bukkit.getOnlinePlayers().length);
            Score coins1 = aaa.getScore("§6§lKills");
            coins1.setScore(pd.getKills());
            Score leer4 = aaa.getScore("§6§lTode");
            leer4.setScore(pd.getDeaths());
            Score ks1 = aaa.getScore("§6§lKillstreak");
            ks1.setScore(pd.getKS());
            Score money1 = aaa.getScore("§6§lCoins");
            money1.setScore((int)Main.econ.getBalance(player));
           
            String prefix;
           
            if(pd.claned()){
                prefix = pd.getClanData().getClanColor()+""+pd.getClanData().getClanTag()+"§6*§f";
                prefix = ChatColor.translateAlternateColorCodes('&', prefix);
            }else{
                prefix = "";
            }
           
            Team team = board.getTeam(player.getName());
            if (team == null) {
                team = board.registerNewTeam(player.getName());
            }
            team.setPrefix(prefix);
            team.addPlayer(player);
            for (Player all : Bukkit.getOnlinePlayers()) {
                    all.setScoreboard(board);  // so everybody see's their clantag
            }
    
        }
     
  2. First of all, the scoreboard you are using is bukkit's main scoreboard, use ScoreboardManager#getNewScoreboard() instead, second of all, you are setting the scoreboard of that player for each player online, you should just do the stats for the player, and call this method for each player online instead.
     
  3. Offline

    jebbo

    @megamichiel

    I changed some stuff around and ended up with this:

    Code:
    public static void refresh() {
            Bukkit.getScheduler().runTaskLater(Main.getInstance(), new Runnable() {
    
                @Override
                public void run() {
                    for (Player p : Bukkit.getOnlinePlayers()) {
                        Scoreboard board = Bukkit.getScoreboardManager()
                                .getNewScoreboard();
                        Objective obj = board.getObjective("sidebar");
                        if (obj == null) {
                            obj = board.registerNewObjective("sidebar", "dummy");
                        }
                        obj.setDisplaySlot(DisplaySlot.SIDEBAR);
                        obj.setDisplayName("§e§l< §b§lRaxStats §e§l>");
                        PlayerData pd = new PlayerData(p);
                        obj.getScore("§6Online").setScore(
                                Bukkit.getOnlinePlayers().length);
                        obj.getScore("§6Kills").setScore(pd.getKills());
                        obj.getScore("§6Tode").setScore(pd.getDeaths());
    
                        Team users = board.registerNewTeam("users");
                        users.setPrefix(pd.claned() ? pd.getClanData().getClanColor().replace("&", "§")+ pd.getClanData().getClanTag() + "§6*§f" : "§f");
                        users.addPlayer(p);
    
                        p.setScoreboard(board);
                    }
                }
    
            }, 1L);
    
        }
    Every player now sees their own scoreboard with their stats, but only the player itself can see his clan tag in the tab, and cannot see somebody elses. How can I change this so everybody sees their own stats, but see the others clan tags.

    Thanks!
     
  4. Offline

    Gater12

    @jebbo
    Upon join, create a scoreboard for the player. Load all their stats. Create and register Teams for all clans who have players currenlty online and set the Teams' prefixes. Add all the players to the teams according to their clan and set the scoreboard for the joining player.
    You will now have you update everyone else's scoreboard by simply adding the joining player to a Team or registering new team to everyone else's scoreboard.
     
  5. Offline

    jebbo

    @Gater12 Thanks for the help, I redid my class and I endet up with this:
    Show Spoiler

    Code:
    
    


    As you can see the setTag method is there to set the tag for the player.
    But I'm stuck at the part where the other players see each others tag..
    Everybody sees their own stats and their own clan tag, but not from the others.
    I guess I'm thinking too far with this and can't find the result..

    Thanks.
     
    Last edited: May 4, 2015
  6. @jebbo
    What you could do is iterate over all player online, and then set their clan in the player's scoreboard
     
  7. Offline

    jebbo

    @megamichiel I just came up with this and it works! I made a method that returns a Scoreboard wich has all players added and every prefix set, wich I then edit in the stats of each player. Thanks everybody for the help!
     
Thread Status:
Not open for further replies.

Share This Page