Scoreboard/Sidebar and teams problem

Discussion in 'Plugin Development' started by Kozomo, May 5, 2020.

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

    Kozomo

    So I made a scoreboard that displays Kills and Deaths and it worked fine till i had to make teams. Now the way i was doing it is by getting a new scoreboard each time, but that didn't seem to work for teams when i had to make like an owner rank or a default ranks and so on.. because if i added teams each player will only be able to see his own rank/team and not other players'. So what i did is instead of getting a new scoreboard, I'm getting the main scoreboard, now that worked fine for the teams but the sidebar itself started bugging for example it started showing other player's Kills and Deaths (Like in the pic below) and the numbers started to get on top of each other and not the way it was intended to be. The way i want the scoreboard to work is for each player to only see his own score and in the same time be able to see other player's ranks/teams. I searched google for a fix for my problem but couldn't find anything that would help me. I'd like to also note that I'm using spigot 1.8.8
    Codes (open)

    Code:
    public void onEnable()
        {
            getServer().getPluginManager().registerEvents(this, this);
            getServer().getPluginManager().registerEvents(new SBa(), this);
        }
     
        public void onDisable()
        {
            saveConfig();
        }
     
        @SuppressWarnings({ "deprecation", "unused" })
        @EventHandler
        public void join(PlayerJoinEvent e)
        {
            Player p = e.getPlayer();
            p.teleport(new Location(Bukkit.getWorld("World"), -320.5, 112, 225.5));
            sendSB(p);
         
            Scoreboard b = Bukkit.getScoreboardManager().getMainScoreboard();
         
            Team tm = b.getTeam("OP");
            tm.setPrefix("OP ");
            tm.setDisplayName("Test");
         
            if(tm == null)
            {
                tm = b.registerNewTeam("OP");
            }
         
            Team tm1 = b.getTeam("Def");
            tm1.setPrefix("Def ");
            tm1.setDisplayName("Test1");
         
            if(tm1 == null)
            {
                tm1 = b.registerNewTeam("Def");
             
            }
         
            if(p.isOp())
            {
                tm.addPlayer(p);
            } else {tm1.addPlayer(p);}
        }
     
        public static void sendSB(Player player)
        {
            int kills = getPlugin(SBtst.class).getConfig().getInt(player.getPlayer().getName().toLowerCase() + ".Kills");
            int deaths = getPlugin(SBtst.class).getConfig().getInt(player.getPlayer().getName().toLowerCase() + ".Deaths");
    
            ScoreboardManager m = Bukkit.getScoreboardManager();
         
    //        Scoreboard b = m.getNewScoreboard();
         
            Scoreboard b = m.getMainScoreboard();
         
            Objective o = b.getObjective(player.getName()) != null ? b.getObjective(player.getName()) : b.registerNewObjective(player.getName(), "dummy");
         
            o.setDisplayName("Test");
            o.setDisplaySlot(DisplaySlot.SIDEBAR);
    
            Score s2 = o.getScore("Kills: " + kills);
            s2.setScore(2);
         
            Score s1 = o.getScore("Deaths: " + deaths);
            s1.setScore(1);
    
            player.setScoreboard(b);
         
            player.sendMessage(b.getObjectives().toString());
        }
     
        public static void updateScoreboard(Player player)
        {
            if (player.getScoreboard() != null)
            { 
                int kills = getPlugin(SBtst.class).getConfig().getInt(player.getPlayer().getName().toLowerCase() + ".Kills");
                int deaths = getPlugin(SBtst.class).getConfig().getInt(player.getPlayer().getName().toLowerCase() + ".Deaths");
             
                ScoreboardManager m = Bukkit.getScoreboardManager();
             
    //            Scoreboard b = m.getNewScoreboard();
             
                Scoreboard b = m.getMainScoreboard();
             
                Objective o = b.getObjective(player.getName()) != null ? b.getObjective(player.getName()) : b.registerNewObjective(player.getName(), "dummy");
             
                o.setDisplayName("Test");
                o.setDisplaySlot(DisplaySlot.SIDEBAR);
             
                Score s2 = o.getScore("Kills: " + kills);
                s2.setScore(2);
                 
                Score s1 = o.getScore("Deaths: " + deaths);
                s1.setScore(1);
                
                   player.setScoreboard(b);
            }
        }
    test.png
    If someone can help me or give me any suggestions or a fix that would be awesome and thanks in advance

    Bump

    Bump
     
    Last edited by a moderator: May 5, 2020
  2. Offline

    Kozomo

    Bump
     
Thread Status:
Not open for further replies.

Share This Page