From 771ad5575d275b421858b7b4b6b451883140fb54 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 30 Apr 2020 15:08:51 +0200 Subject: [PATCH] Fixing NPE Signed-off-by: Lixfel --- .../bungeecore/listeners/TablistManager.java | 63 ++++++++++--------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/src/de/steamwar/bungeecore/listeners/TablistManager.java b/src/de/steamwar/bungeecore/listeners/TablistManager.java index b7058a8..bea60d7 100644 --- a/src/de/steamwar/bungeecore/listeners/TablistManager.java +++ b/src/de/steamwar/bungeecore/listeners/TablistManager.java @@ -9,6 +9,7 @@ import de.steamwar.bungeecore.Subserver; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.md_5.bungee.api.connection.Server; import net.md_5.bungee.api.event.PlayerDisconnectEvent; import net.md_5.bungee.api.event.PostLoginEvent; import net.md_5.bungee.event.EventHandler; @@ -79,41 +80,41 @@ public class TablistManager extends BasicListener { } private synchronized void updateCustomTablist(){ - try{ - calcHeader(); + calcHeader(); - //Calculate server-player-map - playerMap.clear(); - for(ProxiedPlayer player : ProxyServer.getInstance().getPlayers()){ - ServerInfo server = player.getServer().getInfo(); - String serverName = server.getName(); - if(serverName.equals("Developer")) - continue; + //Calculate server-player-map + playerMap.clear(); + for(ProxiedPlayer player : ProxyServer.getInstance().getPlayers()){ + Server pserver = player.getServer(); + if(pserver == null) //Happens temporarily + continue; - Subserver subserver = Subserver.getSubserver(server); - List players; - if(subserver != null && subserver.getType() == Servertype.BAUSERVER){ - players = playerMap.getOrDefault("Bau", new ArrayList<>()); - players.add(player); - playerMap.putIfAbsent("Bau", players); - }else{ - players = playerMap.getOrDefault(serverName, new ArrayList<>()); - players.add(player); - playerMap.putIfAbsent(serverName, players); - } + ServerInfo server = pserver.getInfo(); + String serverName = server.getName(); + if(serverName.equals("Developer")) + continue; + + Subserver subserver = Subserver.getSubserver(server); + List players; + if(subserver != null && subserver.getType() == Servertype.BAUSERVER){ + players = playerMap.getOrDefault("Bau", new ArrayList<>()); + players.add(player); + playerMap.putIfAbsent("Bau", players); + }else{ + players = playerMap.getOrDefault(serverName, new ArrayList<>()); + players.add(player); + playerMap.putIfAbsent(serverName, players); } - playerMap.forEach((server, players) -> players.sort((proxiedPlayer, t1) -> proxiedPlayer.getName().compareToIgnoreCase(t1.getName()))); - - //Set size - calculateSize(); - - for(Tablist tablist : tablists.values()) - tablist.refresh(); - - seconds++; - }catch(NullPointerException e){ - ProxyServer.getInstance().getLogger().log(Level.SEVERE, "NPE", e); } + playerMap.forEach((server, players) -> players.sort((proxiedPlayer, t1) -> proxiedPlayer.getName().compareToIgnoreCase(t1.getName()))); + + //Set size + calculateSize(); + + for(Tablist tablist : tablists.values()) + tablist.refresh(); + + seconds++; } @EventHandler