From cd24f5703146a41eb8f4005a507e6a77cc90ae60 Mon Sep 17 00:00:00 2001 From: "Blue (Lukas Rieger)" Date: Sun, 30 Aug 2020 20:52:30 +0200 Subject: [PATCH] Fix possible NPE and the forge-server instance never being initialized --- .../bluecolored/bluemap/common/live/LiveAPIRequestHandler.java | 2 ++ .../main/java/de/bluecolored/bluemap/fabric/FabricPlayer.java | 1 + .../main/java/de/bluecolored/bluemap/fabric/FabricPlayer.java | 1 + .../main/java/de/bluecolored/bluemap/fabric/FabricPlayer.java | 1 + .../main/java/de/bluecolored/bluemap/forge/ForgePlayer.java | 1 + .../main/java/de/bluecolored/bluemap/forge/ForgePlayer.java | 1 + .../src/main/java/de/bluecolored/bluemap/forge/ForgeMod.java | 3 ++- .../main/java/de/bluecolored/bluemap/forge/ForgePlayer.java | 1 + .../main/java/de/bluecolored/bluemap/bukkit/BukkitPlayer.java | 1 + .../main/java/de/bluecolored/bluemap/sponge/SpongePlayer.java | 1 + 10 files changed, 12 insertions(+), 1 deletion(-) diff --git a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/live/LiveAPIRequestHandler.java b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/live/LiveAPIRequestHandler.java index 4c4f2f76..93289881 100644 --- a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/live/LiveAPIRequestHandler.java +++ b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/live/LiveAPIRequestHandler.java @@ -100,6 +100,7 @@ public HttpResponse handlePlayersRequest(HttpRequest request) { json.beginObject(); json.name("players").beginArray(); for (Player player : server.getOnlinePlayers()) { + if (!player.isOnline()) continue; if (config.isHideInvisible() && player.isInvisible()) continue; if (config.isHideSneaking() && player.isSneaking()) continue; @@ -116,6 +117,7 @@ public HttpResponse handlePlayersRequest(HttpRequest request) { json.endObject(); json.endObject(); } + json.endArray(); json.endObject(); diff --git a/implementations/fabric-1.15.2/src/main/java/de/bluecolored/bluemap/fabric/FabricPlayer.java b/implementations/fabric-1.15.2/src/main/java/de/bluecolored/bluemap/fabric/FabricPlayer.java index f9c8279b..f0561ed2 100644 --- a/implementations/fabric-1.15.2/src/main/java/de/bluecolored/bluemap/fabric/FabricPlayer.java +++ b/implementations/fabric-1.15.2/src/main/java/de/bluecolored/bluemap/fabric/FabricPlayer.java @@ -129,6 +129,7 @@ public void update() { } this.gamemode = GAMEMODE_MAP.get(player.interactionManager.getGameMode()); + if (this.gamemode == null) this.gamemode = Gamemode.SURVIVAL; StatusEffectInstance invis = player.getStatusEffect(StatusEffects.INVISIBILITY); this.invisible = invis != null && invis.getDuration() > 0; diff --git a/implementations/fabric-1.16.1/src/main/java/de/bluecolored/bluemap/fabric/FabricPlayer.java b/implementations/fabric-1.16.1/src/main/java/de/bluecolored/bluemap/fabric/FabricPlayer.java index f9c8279b..f0561ed2 100644 --- a/implementations/fabric-1.16.1/src/main/java/de/bluecolored/bluemap/fabric/FabricPlayer.java +++ b/implementations/fabric-1.16.1/src/main/java/de/bluecolored/bluemap/fabric/FabricPlayer.java @@ -129,6 +129,7 @@ public void update() { } this.gamemode = GAMEMODE_MAP.get(player.interactionManager.getGameMode()); + if (this.gamemode == null) this.gamemode = Gamemode.SURVIVAL; StatusEffectInstance invis = player.getStatusEffect(StatusEffects.INVISIBILITY); this.invisible = invis != null && invis.getDuration() > 0; diff --git a/implementations/fabric-1.16.2/src/main/java/de/bluecolored/bluemap/fabric/FabricPlayer.java b/implementations/fabric-1.16.2/src/main/java/de/bluecolored/bluemap/fabric/FabricPlayer.java index f9c8279b..f0561ed2 100644 --- a/implementations/fabric-1.16.2/src/main/java/de/bluecolored/bluemap/fabric/FabricPlayer.java +++ b/implementations/fabric-1.16.2/src/main/java/de/bluecolored/bluemap/fabric/FabricPlayer.java @@ -129,6 +129,7 @@ public void update() { } this.gamemode = GAMEMODE_MAP.get(player.interactionManager.getGameMode()); + if (this.gamemode == null) this.gamemode = Gamemode.SURVIVAL; StatusEffectInstance invis = player.getStatusEffect(StatusEffects.INVISIBILITY); this.invisible = invis != null && invis.getDuration() > 0; diff --git a/implementations/forge-1.14.4/src/main/java/de/bluecolored/bluemap/forge/ForgePlayer.java b/implementations/forge-1.14.4/src/main/java/de/bluecolored/bluemap/forge/ForgePlayer.java index f55516f4..78875b2f 100644 --- a/implementations/forge-1.14.4/src/main/java/de/bluecolored/bluemap/forge/ForgePlayer.java +++ b/implementations/forge-1.14.4/src/main/java/de/bluecolored/bluemap/forge/ForgePlayer.java @@ -129,6 +129,7 @@ public void update() { } this.gamemode = GAMEMODE_MAP.get(player.interactionManager.getGameType()); + if (this.gamemode == null) this.gamemode = Gamemode.SURVIVAL; EffectInstance invis = player.getActivePotionEffect(Effects.INVISIBILITY); this.invisible = invis != null && invis.getDuration() > 0; diff --git a/implementations/forge-1.15.2/src/main/java/de/bluecolored/bluemap/forge/ForgePlayer.java b/implementations/forge-1.15.2/src/main/java/de/bluecolored/bluemap/forge/ForgePlayer.java index c4226074..9a60b7f1 100644 --- a/implementations/forge-1.15.2/src/main/java/de/bluecolored/bluemap/forge/ForgePlayer.java +++ b/implementations/forge-1.15.2/src/main/java/de/bluecolored/bluemap/forge/ForgePlayer.java @@ -129,6 +129,7 @@ public void update() { } this.gamemode = GAMEMODE_MAP.get(player.interactionManager.getGameType()); + if (this.gamemode == null) this.gamemode = Gamemode.SURVIVAL; EffectInstance invis = player.getActivePotionEffect(Effects.INVISIBILITY); this.invisible = invis != null && invis.getDuration() > 0; diff --git a/implementations/forge-1.16.2/src/main/java/de/bluecolored/bluemap/forge/ForgeMod.java b/implementations/forge-1.16.2/src/main/java/de/bluecolored/bluemap/forge/ForgeMod.java index 9d3d4f6c..438148bf 100644 --- a/implementations/forge-1.16.2/src/main/java/de/bluecolored/bluemap/forge/ForgeMod.java +++ b/implementations/forge-1.16.2/src/main/java/de/bluecolored/bluemap/forge/ForgeMod.java @@ -98,12 +98,13 @@ public ForgeMod() { @SubscribeEvent public void onServerStarting(FMLServerStartingEvent event) { this.worldUUIDs.clear(); + this.serverInstance = event.getServer(); //register commands new Commands<>(pluginInstance, event.getServer().getCommandManager().getDispatcher(), forgeSource -> new ForgeCommandSource(this, pluginInstance, forgeSource)); //save worlds to generate level.dat files - event.getServer().save(false, true, true); + serverInstance.save(false, true, true); new Thread(() -> { Logger.global.logInfo("Loading..."); diff --git a/implementations/forge-1.16.2/src/main/java/de/bluecolored/bluemap/forge/ForgePlayer.java b/implementations/forge-1.16.2/src/main/java/de/bluecolored/bluemap/forge/ForgePlayer.java index 9b0f32db..7287a5cb 100644 --- a/implementations/forge-1.16.2/src/main/java/de/bluecolored/bluemap/forge/ForgePlayer.java +++ b/implementations/forge-1.16.2/src/main/java/de/bluecolored/bluemap/forge/ForgePlayer.java @@ -128,6 +128,7 @@ public void update() { } this.gamemode = GAMEMODE_MAP.get(player.interactionManager.getGameType()); + if (this.gamemode == null) this.gamemode = Gamemode.SURVIVAL; EffectInstance invis = player.getActivePotionEffect(Effects.INVISIBILITY); this.invisible = invis != null && invis.getDuration() > 0; diff --git a/implementations/spigot/src/main/java/de/bluecolored/bluemap/bukkit/BukkitPlayer.java b/implementations/spigot/src/main/java/de/bluecolored/bluemap/bukkit/BukkitPlayer.java index 3dad1db0..0c03903c 100644 --- a/implementations/spigot/src/main/java/de/bluecolored/bluemap/bukkit/BukkitPlayer.java +++ b/implementations/spigot/src/main/java/de/bluecolored/bluemap/bukkit/BukkitPlayer.java @@ -114,6 +114,7 @@ public void update() { } this.gamemode = GAMEMODE_MAP.get(player.getGameMode()); + if (this.gamemode == null) this.gamemode = Gamemode.SURVIVAL; this.invisible = player.hasPotionEffect(PotionEffectType.INVISIBILITY); diff --git a/implementations/sponge-7.2.0/src/main/java/de/bluecolored/bluemap/sponge/SpongePlayer.java b/implementations/sponge-7.2.0/src/main/java/de/bluecolored/bluemap/sponge/SpongePlayer.java index cd5b1390..4ac33aa3 100644 --- a/implementations/sponge-7.2.0/src/main/java/de/bluecolored/bluemap/sponge/SpongePlayer.java +++ b/implementations/sponge-7.2.0/src/main/java/de/bluecolored/bluemap/sponge/SpongePlayer.java @@ -119,6 +119,7 @@ public void update() { } this.gamemode = GAMEMODE_MAP.get(player.get(Keys.GAME_MODE).orElse(GameModes.NOT_SET)); + if (this.gamemode == null) this.gamemode = Gamemode.SURVIVAL; boolean invis = player.get(Keys.VANISH).orElse(false); if (!invis && player.get(Keys.INVISIBLE).orElse(false)) invis = true;