From 9b618eccc246524048b5c6b5a079702edea26040 Mon Sep 17 00:00:00 2001 From: trivernis Date: Tue, 11 Aug 2020 09:57:47 +0200 Subject: [PATCH] Fix dynmap version being null when dynmap doesn't support the minecraft versio - Fixes #69 --- .../net/trivernis/chunkmaster/Chunkmaster.kt | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/net/trivernis/chunkmaster/Chunkmaster.kt b/src/main/kotlin/net/trivernis/chunkmaster/Chunkmaster.kt index 448b873..442e549 100644 --- a/src/main/kotlin/net/trivernis/chunkmaster/Chunkmaster.kt +++ b/src/main/kotlin/net/trivernis/chunkmaster/Chunkmaster.kt @@ -9,6 +9,8 @@ import org.bstats.bukkit.Metrics import org.bukkit.plugin.java.JavaPlugin import org.bukkit.scheduler.BukkitTask import org.dynmap.DynmapAPI +import java.lang.IllegalStateException +import java.lang.NullPointerException class Chunkmaster : JavaPlugin() { lateinit var sqliteManager: SqliteManager @@ -103,11 +105,15 @@ class Chunkmaster : JavaPlugin() { } private fun getDynmap(): DynmapAPI? { - val dynmap = server.pluginManager.getPlugin("dynmap") - return if (dynmap != null && dynmap is DynmapAPI) { - logger.info(langManager.getLocalized("PLUGIN_DETECTED", "dynmap", dynmap.dynmapVersion)) - dynmap - } else { + return try { + val dynmap = server.pluginManager.getPlugin("dynmap") + if (dynmap != null && dynmap is DynmapAPI) { + logger.info(langManager.getLocalized("PLUGIN_DETECTED", "dynmap", dynmap.dynmapVersion)) + dynmap + } else { + null + } + } catch (e: IllegalStateException) { null } }