From 3f355f59d18daa18c67e400a0f0c93dbdb27daf0 Mon Sep 17 00:00:00 2001 From: tastybento Date: Tue, 12 Mar 2019 23:22:04 -0700 Subject: [PATCH] Added defensive code to protect from null gamemode worlds Related to https://github.com/BentoBoxWorld/addon-invSwitcher/issues/2 --- .../bentobox/bentobox/managers/IslandWorldManager.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/world/bentobox/bentobox/managers/IslandWorldManager.java b/src/main/java/world/bentobox/bentobox/managers/IslandWorldManager.java index ef896a041..2930667e6 100644 --- a/src/main/java/world/bentobox/bentobox/managers/IslandWorldManager.java +++ b/src/main/java/world/bentobox/bentobox/managers/IslandWorldManager.java @@ -139,11 +139,15 @@ public class IslandWorldManager { /** * Adds a GameMode to island world manager - * @param gameMode + * @param gameMode - game mode to add + * @throws NullPointerException - exception if the game mode overworld is null */ - public void addGameMode(@NonNull GameModeAddon gameMode) { + public void addGameMode(@NonNull GameModeAddon gameMode) throws NullPointerException { WorldSettings settings = gameMode.getWorldSettings(); World world = gameMode.getOverWorld(); + if (world == null) { + throw new NullPointerException("Gamemode overworld object is null for " + gameMode.getDescription().getName()); + } String friendlyName = settings.getFriendlyName().isEmpty() ? world.getName() : settings.getFriendlyName(); // Add worlds to map gameModes.put(world, gameMode);