From 014c5d574f7a87ef0b6cfe9332cc0c4aeefb418c Mon Sep 17 00:00:00 2001 From: tastybento Date: Fri, 5 Jul 2019 20:07:19 -0700 Subject: [PATCH] Fixes clean super flat tests. --- .../worldsettings/CleanSuperFlatListener.java | 5 ++++ .../CleanSuperFlatListenerTest.java | 27 +++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/CleanSuperFlatListener.java b/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/CleanSuperFlatListener.java index 6b49502ca..f2d702a88 100644 --- a/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/CleanSuperFlatListener.java +++ b/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/CleanSuperFlatListener.java @@ -81,6 +81,11 @@ public class CleanSuperFlatListener extends FlagListener { } MyBiomeGrid grid = new MyBiomeGrid(world.getEnvironment()); ChunkGenerator cg = plugin.getAddonsManager().getDefaultWorldGenerator(world.getName(), ""); + if (cg == null) { + Flags.CLEAN_SUPER_FLAT.setSetting(world, false); + getPlugin().logWarning("Clean super flat is not available for " + world.getName()); + return; + } // Add to queue chunkQueue.add(new Pair<>(e.getChunk().getX(), e.getChunk().getZ())); if (task == null || task.isCancelled()) { diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/CleanSuperFlatListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/CleanSuperFlatListenerTest.java index deb5af1bd..2f868efab 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/CleanSuperFlatListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/CleanSuperFlatListenerTest.java @@ -2,19 +2,27 @@ package world.bentobox.bentobox.listeners.flags.worldsettings; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import static org.mockito.Mockito.anyString; +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.anyInt; import java.util.HashMap; import java.util.Map; +import java.util.Random; import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; import org.bukkit.event.world.ChunkLoadEvent; +import org.bukkit.generator.ChunkGenerator; +import org.bukkit.generator.ChunkGenerator.ChunkData; import org.bukkit.inventory.ItemFactory; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.scheduler.BukkitScheduler; +import org.eclipse.jdt.annotation.Nullable; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -28,7 +36,9 @@ import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.api.configuration.WorldSettings; import world.bentobox.bentobox.api.events.BentoBoxReadyEvent; import world.bentobox.bentobox.lists.Flags; +import world.bentobox.bentobox.managers.AddonsManager; import world.bentobox.bentobox.managers.IslandWorldManager; +import world.bentobox.bentobox.util.MyBiomeGrid; import world.bentobox.bentobox.util.Util; /** @@ -77,6 +87,7 @@ public class CleanSuperFlatListenerTest { when(iwm.isEndGenerate(Mockito.any())).thenReturn(true); when(iwm.isNetherIslands(Mockito.any())).thenReturn(true); when(iwm.isEndIslands(Mockito.any())).thenReturn(true); + when(iwm.isUseOwnGenerator(any())).thenReturn(false); PowerMockito.mockStatic(Bukkit.class); @@ -84,9 +95,9 @@ public class CleanSuperFlatListenerTest { ItemMeta im = mock(ItemMeta.class); when(itemF.getItemMeta(Mockito.any())).thenReturn(im); when(Bukkit.getItemFactory()).thenReturn(itemF); - + // Default is that flag is active Flags.CLEAN_SUPER_FLAT.setSetting(world, true); - + // Default is that chunk has bedrock chunk = mock(Chunk.class); when(chunk.getWorld()).thenReturn(world); block = mock(Block.class); @@ -100,6 +111,18 @@ public class CleanSuperFlatListenerTest { // Scheduler scheduler = mock(BukkitScheduler.class); when(Bukkit.getScheduler()).thenReturn(scheduler); + + // Addons Manager + AddonsManager am = mock(AddonsManager.class); + @Nullable + ChunkGenerator cg = mock(ChunkGenerator.class); + ChunkData cd = mock(ChunkData.class); + when(cg.generateChunkData(any(World.class), any(Random.class), anyInt(), anyInt(), any(MyBiomeGrid.class))).thenReturn(cd); + BlockData bd = mock(BlockData.class); + when(cd.getBlockData(anyInt(), anyInt(), anyInt())).thenReturn(bd); + + when(plugin.getAddonsManager()).thenReturn(am); + when(am.getDefaultWorldGenerator(anyString(), anyString())).thenReturn(cg); } /**