Teams and Scoreboard Tags not working

Discussion in 'Plugin Development' started by TaintedIsles, Oct 17, 2019.

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

    TaintedIsles

    I am trying to change the colour of a player dependant on something they choose earlier in the game, but teams don't seem to be registering and they don't show the prefix or the suffix I have said. Also, setting the player's health under their name isn't updating and stays at 0.

    Code:
        public void createPlayerProfile(Player pl){
            ScoreboardManager m = Bukkit.getScoreboardManager();
            Scoreboard s = m.getNewScoreboard();
            Objective o = s.registerNewObjective("health", "showhealth");
            o.setDisplaySlot(DisplaySlot.BELOW_NAME);
            o.setDisplayName(ChatColor.RED + "❤");
            pl.setHealth(pl.getHealth());
            pl.setLevel(pl.getLevel());
            Team t = s.registerNewTeam(pl.getName());
            t.addEntry(pl.getName());
            t.setSuffix(ChatColor.GRAY + " | " + ChatColor.GOLD + BountyFunctions.getBountyAmount(pl.getName()) +
                    ChatColor.GOLD.toString() + " \u2694");
    
    
            setProfile(pl, s);
    
            if (BloodlineFunctions.hasBloodline(pl.getName())){
                updateDisplayName(pl);
            }
        }
    
        public void updatePlayerHealthBar(){
            Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(Main.instance, new Runnable(){
                    public void run(){
                        for (Player pl : Bukkit.getOnlinePlayers()){
                            if (hasProfile(pl)){
                                Scoreboard s = getProfile(pl);
                                Objective o = s.getObjective(DisplaySlot.BELOW_NAME);
                              
                                o.getScore(pl.getName()).setScore((int) pl.getHealth());
                                setProfile(pl, s);
                            }
                        }
                    }
            }, 1L, 1L);
        }
    
        public void updateDisplayName(Player pl){
            Scoreboard s = getProfile(pl);
            Team t = s.getTeam(pl.getName());
            t.setPrefix(BloodlineFunctions.getBloodlineColour(pl.getName()).toString());
    
            setProfile(pl, s);
        }
    
        public void setProfile(Player pl, Scoreboard sb){
            pl.setScoreboard(sb);
            PlayerMechanics.player_profile.put(pl, sb);
        }
    
        public boolean hasProfile(Player pl){
            if (PlayerMechanics.player_profile.containsKey(pl)){
                return true;
            }
    
            return false;
        }
    
        public Scoreboard getProfile(Player pl){
            return PlayerMechanics.player_profile.get(pl);
        }
     
  2. Set the scoreboard with Player#setScoreboard(Scoreboard)
     
  3. Offline

    TaintedIsles

    the setProfile function does that
     
  4. You're right.
    Everybody who gets a new profile gets his own scoreboard that means he'll just see his own suffix etc. Save the scoreboard and use it again

    Also, does createPlayerProfile gets called at some time?
     
  5. Offline

    TaintedIsles

    The createPlayerProfile is only called when they log in, when they log out it deletes their profile. If you look, when they create their profile I save their scoreboard and then use it again whenever I edit it - it should work, it just doesn't so I must have gone wrong somewhere.
     
  6. You save a scoreboard for each player tyats right but you want all the players to have the same scoreboard otherwise everyone just sees his own team
     
  7. Offline

    Remigio07_

    use
    Code:
    m.getMainScoreboard();
    when declaring the Scoreboard and try to use the /scoreboard teams list command in game to see if the teams are registered or not.
     
Thread Status:
Not open for further replies.

Share This Page