3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-26 16:12:46 +01:00

Various Scoreboard fixes (#1381)

* Various Scoreboard fixes

Fixes #1328 and a few other potential Scoreboard problems

* Consistent whitespacing

Co-authored-by: DoctorMacc <toy.fighter1@gmail.com>
Dieser Commit ist enthalten in:
Tim203 2020-10-09 01:30:05 +02:00 committet von GitHub
Ursprung 4514167835
Commit 45c5ef02cd
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
3 geänderte Dateien mit 15 neuen und 29 gelöschten Zeilen

Datei anzeigen

@ -76,7 +76,8 @@ public class Objective {
if (!scores.containsKey(id)) { if (!scores.containsKey(id)) {
Score score1 = new Score(this, id) Score score1 = new Score(this, id)
.setScore(score) .setScore(score)
.setTeam(scoreboard.getTeamFor(id)); .setTeam(scoreboard.getTeamFor(id))
.setUpdateType(UpdateType.ADD);
scores.put(id, score1); scores.put(id, score1);
} }
} }
@ -96,15 +97,6 @@ public class Objective {
return 0; return 0;
} }
public Score getScore(int line) {
for (Score score : scores.values()) {
if (score.getScore() == line) {
return score;
}
}
return null;
}
public void removeScore(String id) { public void removeScore(String id) {
if (scores.containsKey(id)) { if (scores.containsKey(id)) {
scores.get(id).setUpdateType(UpdateType.REMOVE); scores.get(id).setUpdateType(UpdateType.REMOVE);

Datei anzeigen

@ -49,7 +49,6 @@ public class Score {
this.id = objective.getScoreboard().getNextId().getAndIncrement(); this.id = objective.getScoreboard().getNextId().getAndIncrement();
this.objective = objective; this.objective = objective;
this.name = name; this.name = name;
update();
} }
public String getDisplayName() { public String getDisplayName() {

Datei anzeigen

@ -122,7 +122,7 @@ public class Scoreboard {
for (Objective objective : objectives.values()) { for (Objective objective : objectives.values()) {
if (!objective.isActive()) { if (!objective.isActive()) {
logger.debug("Ignoring non-active Scoreboard Objective '"+ objective.getObjectiveName() +'\''); logger.debug("Ignoring non-active Scoreboard Objective '" + objective.getObjectiveName() + '\'');
continue; continue;
} }
@ -152,10 +152,6 @@ public class Scoreboard {
boolean globalAdd = objective.getUpdateType() == ADD; boolean globalAdd = objective.getUpdateType() == ADD;
boolean globalRemove = objective.getUpdateType() == REMOVE; boolean globalRemove = objective.getUpdateType() == REMOVE;
// Track if any scores changed
// Used to delete and resend scoreboard objectives; otherwise they won't update on Bedrock
boolean scoreChanged = false;
for (Score score : objective.getScores().values()) { for (Score score : objective.getScores().values()) {
Team team = score.getTeam(); Team team = score.getTeam();
@ -171,16 +167,21 @@ public class Scoreboard {
teamChanged |= team.getUpdateType() == UPDATE; teamChanged |= team.getUpdateType() == UPDATE;
add |= team.getUpdateType() == ADD || team.getUpdateType() == UPDATE; add |= team.getUpdateType() == ADD || team.getUpdateType() == UPDATE;
remove |= team.getUpdateType() == REMOVE; remove |= team.getUpdateType() != NOTHING;
} }
add |= score.getUpdateType() == ADD || score.getUpdateType() == UPDATE; add |= score.getUpdateType() == ADD || score.getUpdateType() == UPDATE;
remove |= score.getUpdateType() == REMOVE; remove |= score.getUpdateType() == REMOVE || score.getUpdateType() == UPDATE;
if (score.getUpdateType() == REMOVE) {
if (score.getUpdateType() == REMOVE || globalRemove) {
add = false; add = false;
} }
if (score.getUpdateType() == UPDATE || teamChanged) { if (score.getUpdateType() == ADD) {
remove = false;
}
if (score.getUpdateType() == ADD || score.getUpdateType() == UPDATE || teamChanged) {
score.update(); score.update();
} }
@ -191,12 +192,6 @@ public class Scoreboard {
removeScores.add(score.getCachedInfo()); removeScores.add(score.getCachedInfo());
} }
if (add || remove) {
scoreChanged = true;
}
// score is pending to be updated, so we use the current score as the old score
score.setOldScore(score.getScore());
// score is pending to be removed, so we can remove it from the objective // score is pending to be removed, so we can remove it from the objective
if (score.getUpdateType() == REMOVE) { if (score.getUpdateType() == REMOVE) {
objective.removeScore0(score.getName()); objective.removeScore0(score.getName());
@ -205,17 +200,17 @@ public class Scoreboard {
score.setUpdateType(NOTHING); score.setUpdateType(NOTHING);
} }
if (globalRemove || globalUpdate || scoreChanged) { if (globalRemove || globalUpdate) {
RemoveObjectivePacket removeObjectivePacket = new RemoveObjectivePacket(); RemoveObjectivePacket removeObjectivePacket = new RemoveObjectivePacket();
removeObjectivePacket.setObjectiveId(objective.getObjectiveName()); removeObjectivePacket.setObjectiveId(objective.getObjectiveName());
session.sendUpstreamPacket(removeObjectivePacket); session.sendUpstreamPacket(removeObjectivePacket);
if (objective.getUpdateType() == REMOVE) { if (globalRemove) {
objectives.remove(objective.getObjectiveName()); // now we can deregister objectives.remove(objective.getObjectiveName()); // now we can deregister
objective.removed(); objective.removed();
} }
} }
if (globalAdd || globalUpdate || scoreChanged) { if ((globalAdd || globalUpdate) && !globalRemove) {
SetDisplayObjectivePacket displayObjectivePacket = new SetDisplayObjectivePacket(); SetDisplayObjectivePacket displayObjectivePacket = new SetDisplayObjectivePacket();
displayObjectivePacket.setObjectiveId(objective.getObjectiveName()); displayObjectivePacket.setObjectiveId(objective.getObjectiveName());
displayObjectivePacket.setDisplayName(objective.getDisplayName()); displayObjectivePacket.setDisplayName(objective.getDisplayName());