Source:
<code>public static boolean unloadWorld(final WorldServer worldServer, final boolean checkConfig, final boolean isShuttingDown) { checkNotNull(worldServer); final MinecraftServer server = SpongeImpl.getServer(); if (!worldByDimensionId.containsValue(worldServer)) { return false; } if (!isShuttingDown) { if (!worldServer.playerEntities.isEmpty()) { return false; } if (checkConfig) { if (((WorldProperties) worldServer.getWorldInfo()).doesKeepSpawnLoaded()) { return false; } } } final SpongeConfig<GlobalConfig> globalConfigAdapter = SpongeImpl.getGlobalConfigAdapter(); try (final PhaseContext<?> ignored = GeneralPhase.State.WORLD_UNLOAD.createPhaseContext().source(worldServer)) { ignored.buildAndSwitch(); final UnloadWorldEvent event = SpongeEventFactory.createUnloadWorldEvent(Sponge.getCauseStackManager().getCurrentCause(), (org.spongepowered.api.world.World) worldServer); final boolean isCancelled = SpongeImpl.postEvent(event); if (!isShuttingDown && isCancelled) { return false; } final WorldServerBridge mixinWorldServer = (WorldServerBridge) worldServer; final int dimensionId = mixinWorldServer.bridge$getDimensionId(); SpongeImpl.getLogger().info("Unloading world ({}/{})", worldServer.getWorldInfo().getWorldName(), <START> ((org.spongepowered.api.world.World) worldServer).getDimension().getType().getId(), dimensionId); <END> if (globalConfigAdapter.getConfig().getModules().useOptimizations() && globalConfigAdapter.getConfig().getOptimizations().useAsyncLighting()) { ((WorldServerBridge_AsyncLighting) worldServer).asyncLightingBridge$getLightingExecutor().shutdownNow(); } if (!isShuttingDown) { try { saveWorld(worldServer, true); } catch (MinecraftException e) { e.printStackTrace(); } } ((WorldInfoBridge) worldServer.getWorldInfo()).bridge$getConfigAdapter().save(); worldByDimensionId.remove(dimensionId); weakWorldByWorld.remove(worldServer); ((MinecraftServerBridge) server).bridge$removeWorldTickTimes(dimensionId); reorderWorldsVanillaFirst(); } return true; }</code><technical_language>Exception is fine</technical_language>

Target:
public static boolean unloadWorld(final WorldServer worldServer, final boolean checkConfig, final boolean isShuttingDown) { checkNotNull(worldServer); final MinecraftServer server = SpongeImpl.getServer(); if (!worldByDimensionId.containsValue(worldServer)) { return false; } if (!isShuttingDown) { if (!worldServer.playerEntities.isEmpty()) { return false; } if (checkConfig) { if (((WorldProperties) worldServer.getWorldInfo()).doesKeepSpawnLoaded()) { return false; } } } final SpongeConfig<GlobalConfig> globalConfigAdapter = SpongeImpl.getGlobalConfigAdapter(); try (final PhaseContext<?> ignored = GeneralPhase.State.WORLD_UNLOAD.createPhaseContext().source(worldServer)) { ignored.buildAndSwitch(); final UnloadWorldEvent event = SpongeEventFactory.createUnloadWorldEvent(Sponge.getCauseStackManager().getCurrentCause(), (org.spongepowered.api.world.World) worldServer); final boolean isCancelled = SpongeImpl.postEvent(event); if (!isShuttingDown && isCancelled) { return false; } final WorldServerBridge mixinWorldServer = (WorldServerBridge) worldServer; final int dimensionId = mixinWorldServer.bridge$getDimensionId(); SpongeImpl.getLogger().info("Unloading world ({}/{})", worldServer.getWorldInfo().getWorldName(), ((org.spongepowered.api.world.World) worldServer).getDimension().getType().getId(), dimensionId); try { try { if (globalConfigAdapter.getConfig().getModules().useOptimizations() && globalConfigAdapter.getConfig().getOptimizations().useAsyncLighting()) { ((WorldServerBridge_AsyncLighting) worldServer).asyncLightingBridge$getLightingExecutor().shutdownNow(); } } catch (Exception e) { e.printStackTrace(); } if (!isShuttingDown) { saveWorld(worldServer, true); } ((WorldInfoBridge) worldServer.getWorldInfo()).bridge$getConfigAdapter().save(); } catch (Exception e) { e.printStackTrace(); } finally { worldByDimensionId.remove(dimensionId); weakWorldByWorld.remove(worldServer); ((MinecraftServerBridge) server).bridge$removeWorldTickTimes(dimensionId); reorderWorldsVanillaFirst(); } } return true; }