Added defensive code to protect from null gamemode worlds

Related to https://github.com/BentoBoxWorld/addon-invSwitcher/issues/2
This commit is contained in:
tastybento 2019-03-12 23:22:04 -07:00
parent fd7e3e4154
commit 3f355f59d1

View File

@ -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);