From 6cbbf8a8dd1c6c300884ff6a16170d9755a0917e Mon Sep 17 00:00:00 2001 From: Tim203 Date: Wed, 20 Oct 2021 21:08:25 +0200 Subject: [PATCH] A DisplayScoreboard packet should also cause the scoreboard to update --- .../JavaDisplayScoreboardTranslator.java | 16 ++++++++++++++-- .../JavaScoreboardObjectiveTranslator.java | 2 +- .../java/scoreboard/JavaTeamTranslator.java | 2 +- .../scoreboard/JavaUpdateScoreTranslator.java | 2 +- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaDisplayScoreboardTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaDisplayScoreboardTranslator.java index 577e206b9..a56e59fe7 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaDisplayScoreboardTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaDisplayScoreboardTranslator.java @@ -27,15 +27,27 @@ package org.geysermc.connector.network.translators.java.scoreboard; import com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard.ServerDisplayScoreboardPacket; import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.session.cache.WorldCache; import org.geysermc.connector.network.translators.PacketTranslator; import org.geysermc.connector.network.translators.Translator; +import org.geysermc.connector.scoreboard.Scoreboard; +import org.geysermc.connector.scoreboard.ScoreboardUpdater; @Translator(packet = ServerDisplayScoreboardPacket.class) public class JavaDisplayScoreboardTranslator extends PacketTranslator { @Override public void translate(GeyserSession session, ServerDisplayScoreboardPacket packet) { - session.getWorldCache().getScoreboard() - .displayObjective(packet.getName(), packet.getPosition()); + WorldCache worldCache = session.getWorldCache(); + Scoreboard scoreboard = worldCache.getScoreboard(); + int pps = worldCache.increaseAndGetScoreboardPacketsPerSecond(); + + scoreboard.displayObjective(packet.getName(), packet.getPosition()); + + // ScoreboardUpdater will handle it for us if the packets per second + // (for score and team packets) is higher than the first threshold + if (pps < ScoreboardUpdater.FIRST_SCORE_PACKETS_PER_SECOND_THRESHOLD) { + scoreboard.onUpdate(); + } } } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaScoreboardObjectiveTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaScoreboardObjectiveTranslator.java index 30ef6568d..09e5df391 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaScoreboardObjectiveTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaScoreboardObjectiveTranslator.java @@ -84,7 +84,7 @@ public class JavaScoreboardObjectiveTranslator extends PacketTranslator { } // ScoreboardUpdater will handle it for us if the packets per second - // (for score and team packets) is higher then the first threshold + // (for score and team packets) is higher than the first threshold if (pps < ScoreboardUpdater.FIRST_SCORE_PACKETS_PER_SECOND_THRESHOLD) { scoreboard.onUpdate(); } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaUpdateScoreTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaUpdateScoreTranslator.java index 870f89a43..79d625fc7 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaUpdateScoreTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaUpdateScoreTranslator.java @@ -99,7 +99,7 @@ public class JavaUpdateScoreTranslator extends PacketTranslator