From 1086808cf080a5fe2000b7a8552fb98af2123e26 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 25 Feb 2023 14:29:26 +0100 Subject: [PATCH] Fix some NPE's Signed-off-by: yoyosource --- .../bausystem/features/simulator/TNTSimulator.java | 14 +++++++++++--- .../features/simulator/TNTSimulatorListener.java | 3 +++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java index 1f51b10b..fb6a91cd 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java @@ -88,12 +88,20 @@ public class TNTSimulator { } public void show(Player player) { - entityServer.addPlayer(player); - players.add(player); + if (!players.contains(player)) { + entityServer.addPlayer(player); + players.add(player); + } } public void hide(Player player) { - entityServer.removePlayer(player); + if (players.contains(player)) { + entityServer.removePlayer(player); + players.remove(player); + } + } + + void _hide(Player player) { players.remove(player); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorListener.java index e877fc90..48285d78 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorListener.java @@ -88,6 +88,9 @@ public class TNTSimulatorListener implements Listener { @EventHandler public void onPlayerQuit(PlayerQuitEvent event) { SimulatorCursor.hide(event.getPlayer(), null); + SimulatorStorage.getSimulatorNames().forEach(s -> { + SimulatorStorage.getSimulator(s)._hide(event.getPlayer()); + }); } @EventHandler