Scoreboard score reset

Discussion in 'Plugin Development' started by Niv-Mizzet, Apr 24, 2020.

  1. Offline

    Niv-Mizzet

    Hi everyone,
    I'm trying to update a scoreboard, but it is not working
    What happens is that every time I try to update it to something different, a new line is generated
    Code is below.

    Scoreboard creation method(all of this is inside of a method, parameters a Player object, the method is passed within a playerJoinEvent, and I grab the player from the event):
    Code:
    player.sendMessage("?????????");
            ScoreboardManager manager=Bukkit.getScoreboardManager();
            board=manager.getNewScoreboard();
            Team red=board.registerNewTeam("Red");
            Team green=board.registerNewTeam("Green");
            Team yellow=board.registerNewTeam("Yellow");
            Team blue=board.registerNewTeam("Blue");
            red.setColor(ChatColor.RED);
            blue.setColor(ChatColor.BLUE);
            yellow.setColor(ChatColor.YELLOW);
            green.setColor(ChatColor.GREEN);
            Team[] teamss={red, green, yellow, blue};
            for(int i =0; i<=3; i++){
                Bukkit.broadcastMessage(teamss[i].getName());
                teamss[i].setCanSeeFriendlyInvisibles(true);
                teamss[i].setAllowFriendlyFire(false);
                teamss[i].setPrefix(teamss[i].getColor()+teamss[i].getName());
                teamscores.put(teamss[i], 0);
              
            }
            Objective objective=board.registerNewObjective("Points", "", "dummy");
            objective.setDisplayName(ChatColor.GREEN+(ChatColor.BOLD+"Beacon Wars"));
            objective.setDisplaySlot(DisplaySlot.SIDEBAR);
            String stuff;
            String stufftoo;
            if (player.getScoreboard().getEntryTeam(player.getName())==null){
                stuff="";
            }else{
                stuff=player.getScoreboard().getEntryTeam(player.getName()).getName();
            }
          
            scoreteam=objective.getScore(ChatColor.WHITE+"Team: "+teamcolors.get(player.getScoreboard().getEntryTeam(player.getName()))+stuff);
            scoreteam.setScore(1);
            points=objective.getScore(ChatColor.WHITE+"Points: "+teamscores.get(player.getScoreboard().getEntryTeam(player.getName())));
            points.setScore(0);
            player.setScoreboard(board);}
    Scoreboard update method(parameters a Player and Scoreboard object(boardy)):
    Code:
    Objective objective=boardy.getObjective("Points");
            objective.setDisplayName(ChatColor.GREEN+(ChatColor.BOLD+"Beacon Wars"));
            objective.setDisplaySlot(DisplaySlot.SIDEBAR);
            objective.getScoreboard().resetScores(player.getName());
            String stuff;
            String stufftoo;
            if (player.getScoreboard().getEntryTeam(player.getName())==null){
                stuff="";
            }else{
                stuff=player.getScoreboard().getEntryTeam(player.getName()).getName();
            }
          
            scoreteam=objective.getScore(ChatColor.WHITE+"Team: "+teamcolors.get(player.getScoreboard().getEntryTeam(player.getName()))+stuff);
            scoreteam.setScore(1);
            points=objective.getScore(ChatColor.WHITE+"Points: "+teamscores.get(player.getScoreboard().getEntryTeam(player.getName())));
            points.setScore(0);
            player.setScoreboard(boardy);
    Where I call the Scoreboard update method:
    Code:
    playerlist.get(l).getScoreboard().clearSlot(DisplaySlot.SIDEBAR);
                    Scoreboardstuff(playerlist.get(l), playerlist.get(l).getScoreboard());
    Playerlist is a list of all the players on the server, l is the index inside of a loop this code is in, looping through all the players.

    Thanks in advance!

    eDIT

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited: Apr 25, 2020
  2. Offline

    Niv-Mizzet

  3. Offline

    Niv-Mizzet

  4. Offline

    Niv-Mizzet

  5. Offline

    Niv-Mizzet

  6. Offline

    Niv-Mizzet

  7. Offline

    Niv-Mizzet

  8. Offline

    seklyza

    Try Scoreboard#resetScores(String).
     
  9. He already is.

    Sure.
     
  10. Offline

    Niv-Mizzet

  11. Offline

    Niv-Mizzet

  12. Offline

    Niv-Mizzet

  13. These two lines are returning null. That means you need to fix teamscore.get and teamcolors.get to work how you want them to.
     
  14. Offline

    Niv-Mizzet

    @TheEnderCrafter9 I fixed that but the scoreboard still doesn't reset.
    Thanks for your help.
     

Share This Page