mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Add exception handling to the scoreboard updater
This commit is contained in:
parent
1316f6e1da
commit
c115afba85
1 changed files with 60 additions and 54 deletions
|
@ -62,82 +62,88 @@ public final class ScoreboardUpdater extends Thread {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
while (!connector.isShuttingDown()) {
|
while (!connector.isShuttingDown()) {
|
||||||
long timeTillAction = getTimeTillNextAction();
|
try {
|
||||||
if (timeTillAction > 0) {
|
long timeTillAction = getTimeTillNextAction();
|
||||||
sleepFor(timeTillAction);
|
if (timeTillAction > 0) {
|
||||||
continue;
|
sleepFor(timeTillAction);
|
||||||
}
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
long currentTime = System.currentTimeMillis();
|
long currentTime = System.currentTimeMillis();
|
||||||
|
|
||||||
// reset score-packets per second every second
|
// reset score-packets per second every second
|
||||||
if (currentTime - lastPacketsPerSecondUpdate >= 1000) {
|
if (currentTime - lastPacketsPerSecondUpdate >= 1000) {
|
||||||
lastPacketsPerSecondUpdate = currentTime;
|
lastPacketsPerSecondUpdate = currentTime;
|
||||||
for (GeyserSession session : connector.getPlayers()) {
|
for (GeyserSession session : connector.getPlayers()) {
|
||||||
ScoreboardSession scoreboardSession = session.getWorldCache().getScoreboardSession();
|
ScoreboardSession scoreboardSession = session.getWorldCache().getScoreboardSession();
|
||||||
|
|
||||||
int oldPps = scoreboardSession.getPacketsPerSecond();
|
int oldPps = scoreboardSession.getPacketsPerSecond();
|
||||||
int newPps = scoreboardSession.getPendingPacketsPerSecond().get();
|
int newPps = scoreboardSession.getPendingPacketsPerSecond().get();
|
||||||
|
|
||||||
scoreboardSession.packetsPerSecond = newPps;
|
scoreboardSession.packetsPerSecond = newPps;
|
||||||
scoreboardSession.pendingPacketsPerSecond.set(0);
|
scoreboardSession.pendingPacketsPerSecond.set(0);
|
||||||
|
|
||||||
// just making sure that all updates are pushed before giving up control
|
// just making sure that all updates are pushed before giving up control
|
||||||
if (oldPps >= FIRST_SCORE_PACKETS_PER_SECOND_THRESHOLD &&
|
if (oldPps >= FIRST_SCORE_PACKETS_PER_SECOND_THRESHOLD &&
|
||||||
newPps < FIRST_SCORE_PACKETS_PER_SECOND_THRESHOLD) {
|
newPps < FIRST_SCORE_PACKETS_PER_SECOND_THRESHOLD) {
|
||||||
session.getWorldCache().getScoreboard().onUpdate();
|
session.getWorldCache().getScoreboard().onUpdate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (currentTime - lastUpdate >= FIRST_MILLIS_BETWEEN_UPDATES) {
|
if (currentTime - lastUpdate >= FIRST_MILLIS_BETWEEN_UPDATES) {
|
||||||
lastUpdate = currentTime;
|
lastUpdate = currentTime;
|
||||||
|
|
||||||
for (GeyserSession session : connector.getPlayers()) {
|
for (GeyserSession session : connector.getPlayers()) {
|
||||||
WorldCache worldCache = session.getWorldCache();
|
WorldCache worldCache = session.getWorldCache();
|
||||||
ScoreboardSession scoreboardSession = worldCache.getScoreboardSession();
|
ScoreboardSession scoreboardSession = worldCache.getScoreboardSession();
|
||||||
|
|
||||||
int pps = scoreboardSession.getPacketsPerSecond();
|
int pps = scoreboardSession.getPacketsPerSecond();
|
||||||
if (pps >= FIRST_SCORE_PACKETS_PER_SECOND_THRESHOLD) {
|
if (pps >= FIRST_SCORE_PACKETS_PER_SECOND_THRESHOLD) {
|
||||||
boolean reachedSecondThreshold = pps >= SECOND_SCORE_PACKETS_PER_SECOND_THRESHOLD;
|
boolean reachedSecondThreshold = pps >= SECOND_SCORE_PACKETS_PER_SECOND_THRESHOLD;
|
||||||
|
|
||||||
int millisBetweenUpdates = reachedSecondThreshold ?
|
int millisBetweenUpdates = reachedSecondThreshold ?
|
||||||
SECOND_MILLIS_BETWEEN_UPDATES :
|
SECOND_MILLIS_BETWEEN_UPDATES :
|
||||||
FIRST_MILLIS_BETWEEN_UPDATES;
|
FIRST_MILLIS_BETWEEN_UPDATES;
|
||||||
|
|
||||||
if (currentTime - scoreboardSession.lastUpdate >= millisBetweenUpdates) {
|
if (currentTime - scoreboardSession.lastUpdate >= millisBetweenUpdates) {
|
||||||
worldCache.getScoreboard().onUpdate();
|
worldCache.getScoreboard().onUpdate();
|
||||||
scoreboardSession.lastUpdate = currentTime;
|
scoreboardSession.lastUpdate = currentTime;
|
||||||
|
|
||||||
if (DEBUG_ENABLED && (currentTime - scoreboardSession.lastLog >= 60000)) { // one minute
|
if (DEBUG_ENABLED && (currentTime - scoreboardSession.lastLog >= 60000)) { // one minute
|
||||||
int threshold = reachedSecondThreshold ?
|
int threshold = reachedSecondThreshold ?
|
||||||
SECOND_SCORE_PACKETS_PER_SECOND_THRESHOLD :
|
SECOND_SCORE_PACKETS_PER_SECOND_THRESHOLD :
|
||||||
FIRST_SCORE_PACKETS_PER_SECOND_THRESHOLD;
|
FIRST_SCORE_PACKETS_PER_SECOND_THRESHOLD;
|
||||||
|
|
||||||
connector.getLogger().info(
|
connector.getLogger().info(
|
||||||
LanguageUtils.getLocaleStringLog("geyser.scoreboard.updater.threshold_reached.log", session.getName(), threshold, pps) +
|
LanguageUtils.getLocaleStringLog("geyser.scoreboard.updater.threshold_reached.log", session.getName(), threshold, pps) +
|
||||||
LanguageUtils.getLocaleStringLog("geyser.scoreboard.updater.threshold_reached", (millisBetweenUpdates / 1000.0))
|
LanguageUtils.getLocaleStringLog("geyser.scoreboard.updater.threshold_reached", (millisBetweenUpdates / 1000.0))
|
||||||
);
|
);
|
||||||
|
|
||||||
scoreboardSession.lastLog = currentTime;
|
scoreboardSession.lastLog = currentTime;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (DEBUG_ENABLED) {
|
if (DEBUG_ENABLED) {
|
||||||
long timeSpent = System.currentTimeMillis() - currentTime;
|
long timeSpent = System.currentTimeMillis() - currentTime;
|
||||||
if (timeSpent > 0) {
|
if (timeSpent > 0) {
|
||||||
connector.getLogger().info(String.format(
|
connector.getLogger().info(String.format(
|
||||||
"Scoreboard updater: took %s ms. Updated %s players",
|
"Scoreboard updater: took %s ms. Updated %s players",
|
||||||
timeSpent, connector.getPlayers().size()
|
timeSpent, connector.getPlayers().size()
|
||||||
));
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
long timeTillNextAction = getTimeTillNextAction();
|
long timeTillNextAction = getTimeTillNextAction();
|
||||||
sleepFor(timeTillNextAction);
|
sleepFor(timeTillNextAction);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
connector.getLogger().error("Error while translating scoreboard information!", e);
|
||||||
|
// Wait so we don't try to run the scoreboard immediately after this
|
||||||
|
sleepFor(FIRST_MILLIS_BETWEEN_UPDATES);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue