Scoreboard Updating

Discussion in 'Plugin Development' started by ItsComits, Oct 31, 2017.

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

    ItsComits

    Hello, I am having trouble on updating my scoreboard.
    Here is the method below to get the scoreboard. I want to add an update feature in there so I don't have to call 'update' all the time. I know that you have to get the entry and replace the entry. But I'm unsure on how to do this. Any help is greatly appreciated.
    Code:
    Code:
            public Scoreboard getScoreboard(Player p, Arena a) {
                objective.setDisplaySlot(DisplaySlot.SIDEBAR);
                objective.setDisplayName(this.toString());
                List<String> lines = Messages.getStringList("Lines", p, a);
                lines = Variables.replaceVariablesList(lines, a, p);
                AtomicInteger i = new AtomicInteger(lines.size());
                lines.forEach(line -> {
                    //update
                    scoreboard.getEntries().forEach(entry -> {
                        Score score = (Score) scoreboard.getScores(entry);
                        if (score.getObjective().equals(this.toString())) {
                            //stuck here
                        }
                      
                    });
                  
                    // create one
                    Score score;
                    score = objective.getScore(line);
                    score.setScore(i.getAndDecrement());
                });
                return scoreboard;
            }
     
  2. Offline

    ChucknorisSR

    You want to clear the player's scoreboard before updating with:

    Code:
    p.setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard());
     
  3. Offline

    ItsComits

    @ChucknorisSR I have tried this but this seems to make the scoreboard flash as its adding and removing a scoreboard. I do know that you need to replace an entry but I do not know how to.
     
  4. Offline

    Zombie_Striker

    @ItsComits
    You can try for looping through all the entries. Once you find the entry you want to replace, remove it and create a new entry, using the same score.
     
  5. Offline

    ItsComits

    @Zombie_Striker Thanks for your reply. I have this to check for the entry equals to the line string but for some odd reason, I cannot get access to the line string which is within the lines loop
    Code:
                lines.forEach(line -> {
                    //update
                    scoreboard.getEntries().forEach(entry -> {
                        Score score = (Score) scoreboard.getScores(entry);
                        if (score.getObjective().equals(this.toString())) {
                            if (score.getEntry().equalsIgnoreCase(line)) {
                             
                            }
                        }
                    });
                    // create one
                    Score score;
                    score = objective.getScore(line);
                    score.setScore(i.getAndDecrement());
                });
     
  6. Offline

    ItsComits

    @Zombie_Striker @ChucknorisSR Hello. The problem that I am having is that every time the scoreboard is updated the score is removed from the scoreboard. Any ideas on how I can replace the entry? Here is the code the error is currently with:
    Code:
                AtomicInteger i = new AtomicInteger(lines.size());
                lines.forEach(line -> {
                    String s = line;
                    scoreboard.getEntries().forEach(entry -> {
                        if (!(entry.equalsIgnoreCase(s))) {
                            scoreboard.resetScores(entry);
                            Score score = (Score) scoreboard.getScores(s);
                            score.setScore(i.getAndDecrement());
                            p.setScoreboard(scoreboard);
                        }
                    });
                });
     
  7. Offline

    ItsComits

    Bump. Still can't get the problem solved.
     
Thread Status:
Not open for further replies.

Share This Page