Can't hide nametags and show sidebar at same

Discussion in 'Plugin Development' started by lecreep, Jul 14, 2023.

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

    lecreep

    Im creating 2 teams and moving people from one to another to hide/show his nametag while they are into a mini-game

    Code:
            score = Bukkit.getScoreboardManager().getMainScoreboard();
            hideTeam = score.getTeam("nhide");
            showTeam = score.getTeam("nshow");
            hideTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER);
            showTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.ALWAYS);
            
    That works great and the name tag dissapears, but when i try to show a sidebar, the nametag come back

    Code:
    ScoreboardManager manager = Bukkit.getScoreboardManager();
    Scoreboard board = manager.getNewScoreboard();
    Objective objective = board.registerNewObjective("test", "dummy");
    objective.setDisplaySlot(DisplaySlot.SIDEBAR);
    objective.setDisplayName("Display Name");
    Score score;
    score = objective.getScore("Side text");
    score.setScore(0);
    player.setScoreboard(board); 
    Anny
    suggestions?
     
  2. Offline

    EvilWitchdoctor

    The problem is that Teams (like Objectives) are part of a scoreboard, so when you switch a player to a different scoreboard, their client won't know about the teams anymore.

    The two workaround would be 1) register your objective on the main scoreboard (the same one you have the Teams on) or 2) make identical copies of the Teams, with the same member lists, on the new scoreboard you are creating.

    I assume #1 will be the better solution for your case.
     
    lecreep likes this.
  3. Offline

    lecreep

    THAT IS GOLD


    I didn't fully understand how scoreboards worked.
    Thank you

    And yes, the solution 1 was the better


    Code:
    Scoreboard board = Bukkit.getScoreboardManager().getMainScoreboard();
    Objective objective = board.getObjective("test");
    objective.setDisplaySlot(DisplaySlot.SIDEBAR);
    objective.setDisplayName("Display Name");
    Score score = objective.getScore("Side text");
    score.setScore(0);
    player.setScoreboard(board);
    
    Edited---
    I rectify, solution 1 is the fastest. But now that I understand how this works and since there are several simultaneous arenas, solution 2 is the one I must reach
     
    Last edited: Jul 14, 2023
    EvilWitchdoctor likes this.
Thread Status:
Not open for further replies.

Share This Page