From 5d2881383f8455f13c38b3665953e58cc45b4207 Mon Sep 17 00:00:00 2001 From: Andreas Troelsen Date: Mon, 23 Apr 2018 11:53:24 +0200 Subject: [PATCH] Guard against exceptions when setting scoreboards for disconnecting players. Turns out that a player who disconnects while in the arena is actually still online if you ask the Player object. The setScoreboard() javadoc specifically says it throws an IllegalStateException in that case, so we can just catch and swallow it. It's unclear what the state of the player's scoreboard is when they rejoin the server, but a borken scoreboard is better than a rogue exception. --- .../java/com/garbagemule/MobArena/ScoreboardManager.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/garbagemule/MobArena/ScoreboardManager.java b/src/main/java/com/garbagemule/MobArena/ScoreboardManager.java index 1950cc4..73e1125 100644 --- a/src/main/java/com/garbagemule/MobArena/ScoreboardManager.java +++ b/src/main/java/com/garbagemule/MobArena/ScoreboardManager.java @@ -44,7 +44,11 @@ public class ScoreboardManager { * @param player a player */ void removePlayer(Player player) { - player.setScoreboard(Bukkit.getScoreboardManager().getMainScoreboard()); + try { + player.setScoreboard(Bukkit.getScoreboardManager().getMainScoreboard()); + } catch (IllegalStateException e) { + // Happens if the player is logging out, just swallow it + } } /**