diff --git a/src/main/java/world/bentobox/greenhouses/Settings.java b/src/main/java/world/bentobox/greenhouses/Settings.java index 588331a..9d99ce3 100644 --- a/src/main/java/world/bentobox/greenhouses/Settings.java +++ b/src/main/java/world/bentobox/greenhouses/Settings.java @@ -23,10 +23,13 @@ public class Settings implements ConfigObject { @ConfigEntry(path = "greenhouses.game-modes") private List gameModes = new ArrayList<>(); + + @ConfigComment("") @ConfigComment("Show loaded recipe details during startup of server") @ConfigEntry(path = "greenhouses.startup-log") private boolean startupLog = false; + @ConfigComment("") @ConfigComment("Weather and ecosystem settings") @ConfigComment("How often it should snow in the g/h when the weather is raining, in seconds") @ConfigEntry(path = "greenhouses.snowspeed") @@ -40,6 +43,7 @@ public class Settings implements ConfigObject { @ConfigEntry(path = "greenhouses.snowdensity") private double snowDensity = 0.1; + @ConfigComment("") @ConfigComment("Biome activity") @ConfigComment("How often should greenhouse biomes be checked to make sure they are still valid") @ConfigEntry(path = "greenhouses.ecotick") @@ -56,6 +60,7 @@ public class Settings implements ConfigObject { private int mobTick = 5; + @ConfigComment("") @ConfigComment("Default settings for greenhouse actions") @ConfigComment("Allow lava or water to flow out of a greenhouse, e.g. through the door, floor") @ConfigEntry(path = "greenhouses.allowflowout") @@ -64,10 +69,15 @@ public class Settings implements ConfigObject { @ConfigEntry(path = "greenhouses.allowflowin") private boolean allowFlowIn; + @ConfigComment("") @ConfigComment("Allow glowstone to be used as well as glass in roof and walls") @ConfigEntry(path = "greenhouses.allowglowstone") private boolean allowGlowstone = true; + @ConfigComment("") + @ConfigComment("Allow glass panes to be used to build greenhouses") + @ConfigEntry(path = "greenhouses.allowpanes") + private boolean allowPanes = true; /** * @return the gameModes */ @@ -212,5 +222,17 @@ public class Settings implements ConfigObject { public void setAllowGlowstone(boolean allowGlowstone) { this.allowGlowstone = allowGlowstone; } + /** + * @return the allowPanes + */ + public boolean isAllowPanes() { + return allowPanes; + } + /** + * @param allowPanes the allowPanes to set + */ + public void setAllowPanes(boolean allowPanes) { + this.allowPanes = allowPanes; + } } \ No newline at end of file diff --git a/src/main/java/world/bentobox/greenhouses/greenhouse/Roof.java b/src/main/java/world/bentobox/greenhouses/greenhouse/Roof.java index 5587bb3..cf68d47 100644 --- a/src/main/java/world/bentobox/greenhouses/greenhouse/Roof.java +++ b/src/main/java/world/bentobox/greenhouses/greenhouse/Roof.java @@ -24,7 +24,7 @@ public class Roof extends MinMaxXZ { List r = Arrays.stream(Material.values()) .filter(Material::isBlock) // Blocks only, no items .filter(m -> m.name().contains("TRAPDOOR") // All trapdoors - || m.name().contains("GLASS") // All glass blocks + || (m.name().contains("GLASS") && !m.name().contains("GLASS_PANE")) // All glass blocks || m.equals(Material.HOPPER)) // Hoppers .collect(Collectors.toList()); ROOF_BLOCKS = Collections.unmodifiableList(r); @@ -172,7 +172,9 @@ public class Roof extends MinMaxXZ { * @return true if roof material */ public static boolean roofBlocks(Material m) { - return ROOF_BLOCKS.contains(m) || (m.equals(Material.GLOWSTONE) && Greenhouses.getInstance().getSettings().isAllowGlowstone()); + return ROOF_BLOCKS.contains(m) + || (m.equals(Material.GLOWSTONE) && Greenhouses.getInstance().getSettings().isAllowGlowstone()) + || (m.name().endsWith("GLASS_PANE") && Greenhouses.getInstance().getSettings().isAllowPanes()); } /** diff --git a/src/main/java/world/bentobox/greenhouses/greenhouse/Walls.java b/src/main/java/world/bentobox/greenhouses/greenhouse/Walls.java index bd7c271..616d26c 100644 --- a/src/main/java/world/bentobox/greenhouses/greenhouse/Walls.java +++ b/src/main/java/world/bentobox/greenhouses/greenhouse/Walls.java @@ -19,7 +19,7 @@ public class Walls extends MinMaxXZ { .filter(Material::isBlock) // Blocks only, no items .filter(m -> !m.name().contains("TRAPDOOR")) // No trap doors .filter(m -> m.name().contains("DOOR") // All doors - || m.name().contains("GLASS") // All glass blocks + || (m.name().contains("GLASS") && !m.name().contains("GLASS_PANE")) // All glass blocks || m.equals(Material.HOPPER)) // Hoppers .collect(Collectors.toList()); WALL_BLOCKS = Collections.unmodifiableList(w); @@ -175,7 +175,9 @@ public class Walls extends MinMaxXZ { * @return true if wall material */ public static boolean wallBlocks(Material m) { - return WALL_BLOCKS.contains(m) || (m.equals(Material.GLOWSTONE) && Greenhouses.getInstance().getSettings().isAllowGlowstone()); + return WALL_BLOCKS.contains(m) + || (m.equals(Material.GLOWSTONE) && Greenhouses.getInstance().getSettings().isAllowGlowstone()) + || (m.name().endsWith("GLASS_PANE") && Greenhouses.getInstance().getSettings().isAllowPanes()); } /** diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 32fac30..54d33e4 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,4 +1,4 @@ -# Greenhouses Configuration +# Greenhouses Configuration {$version} # greenhouses: # BentoBox GameModes that will use Greenhouses @@ -7,9 +7,10 @@ greenhouses: - AcidIsland - SkyGrid - AOneBlock - - CaveBlock + # # Show loaded recipe details during startup of server startup-log: false + # # Weather and ecosystem settings # How often it should snow in the g/h when the weather is raining, in seconds snowspeed: 30.0 @@ -18,6 +19,7 @@ greenhouses: snowchance: 1.0 # How many blocks should get snow 1 = all of them, 0 = none, 0.1 = 1 in 10 snowdensity: 0.1 + # # Biome activity # How often should greenhouse biomes be checked to make sure they are still valid ecotick: 5 @@ -28,10 +30,15 @@ greenhouses: blocktick: 2 # How often should mobs be potentially spawned in a greenhouse, in minutes mobtick: 5 + # # Default settings for greenhouse actions # Allow lava or water to flow out of a greenhouse, e.g. through the door, floor allowflowout: false # Allow lava or water to flow into a greenhouse, e.g., through the door allowflowin: false + # # Allow glowstone to be used as well as glass in roof and walls - allowglowstone: true \ No newline at end of file + allowglowstone: true + # + # Allow glass panes to be used to build greenhouses + allowpanes: true diff --git a/src/test/java/world/bentobox/greenhouses/SettingsTest.java b/src/test/java/world/bentobox/greenhouses/SettingsTest.java new file mode 100644 index 0000000..5c72374 --- /dev/null +++ b/src/test/java/world/bentobox/greenhouses/SettingsTest.java @@ -0,0 +1,175 @@ +package world.bentobox.greenhouses; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.Collections; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +public class SettingsTest { + + private Settings s; + + @Before + public void setUp() throws Exception { + s = new Settings(); + } + + @Test + public void testGetGameModes() { + assertTrue(s.getGameModes().isEmpty()); + } + + @Test + public void testGetSnowSpeed() { + assertEquals(30D, s.getSnowSpeed(), 0D); + } + + @Test + public void testGetSnowChanceGlobal() { + assertEquals(1D, s.getSnowChanceGlobal(), 0D); + } + + @Test + public void testGetSnowDensity() { + assertEquals(0.1D, s.getSnowDensity(), 0D); + } + + @Test + public void testGetEcoTick() { + assertEquals(5, s.getEcoTick()); + } + + @Test + public void testGetPlantTick() { + assertEquals(1, s.getPlantTick()); + } + + @Test + public void testGetBlockTick() { + assertEquals(2, s.getBlockTick()); + } + + @Test + public void testGetMobTick() { + assertEquals(5, s.getMobTick()); + } + + @Test + public void testIsStartupLog() { + assertFalse(s.isStartupLog()); + } + + @Test + public void testSetStartupLog() { + s.setStartupLog(true); + assertTrue(s.isStartupLog()); + } + + @Test + public void testIsAllowFlowOut() { + assertFalse(s.isAllowFlowOut()); + } + + @Test + public void testIsAllowFlowIn() { + assertFalse(s.isAllowFlowIn()); + } + + @Test + public void testSetGameModes() { + s.setGameModes(Collections.singletonList("BSkyBlock")); + assertEquals("BSkyBlock", s.getGameModes().get(0)); + } + + @Test + public void testSetSnowSpeed() { + s.setSnowSpeed(50); + assertEquals(50D, s.getSnowSpeed(), 0D); + } + + @Test + public void testSetSnowChanceGlobal() { + s.setSnowChanceGlobal(50); + assertEquals(50D, s.getSnowChanceGlobal(), 0D); + + } + + @Test + public void testSetSnowDensity() { + s.setSnowDensity(50); + assertEquals(50D, s.getSnowDensity(), 0D); + } + + @Test + public void testSetEcoTick() { + s.setEcoTick(50); + assertEquals(50, s.getEcoTick()); + } + + @Test + public void testSetPlantTick() { + s.setPlantTick(50); + assertEquals(50, s.getPlantTick()); + + } + + @Test + public void testSetBlockTick() { + s.setBlockTick(50); + assertEquals(50, s.getBlockTick()); + + } + + @Test + public void testSetMobTick() { + s.setMobTick(50); + assertEquals(50, s.getMobTick()); + + } + + @Test + public void testSetAllowFlowOut() { + assertFalse(s.isAllowFlowOut()); + s.setAllowFlowOut(true); + assertTrue(s.isAllowFlowOut()); + } + + @Test + public void testSetAllowFlowIn() { + assertFalse(s.isAllowFlowIn()); + s.setAllowFlowIn(true); + assertTrue(s.isAllowFlowIn()); + } + + @Test + public void testIsAllowGlowstone() { + assertTrue(s.isAllowGlowstone()); + } + + @Test + public void testSetAllowGlowstone() { + assertTrue(s.isAllowGlowstone()); + s.setAllowGlowstone(false); + assertFalse(s.isAllowGlowstone()); + } + + @Test + public void testIsAllowPanes() { + assertTrue(s.isAllowPanes()); + } + + @Test + public void testSetAllowPanes() { + assertTrue(s.isAllowPanes()); + s.setAllowPanes(false); + assertFalse(s.isAllowPanes()); + } + +} diff --git a/src/test/java/world/bentobox/greenhouses/greenhouse/RoofTest.java b/src/test/java/world/bentobox/greenhouses/greenhouse/RoofTest.java index 316386d..c9cf476 100644 --- a/src/test/java/world/bentobox/greenhouses/greenhouse/RoofTest.java +++ b/src/test/java/world/bentobox/greenhouses/greenhouse/RoofTest.java @@ -1,6 +1,7 @@ package world.bentobox.greenhouses.greenhouse; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; @@ -14,14 +15,21 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; +import org.mockito.Mockito; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; +import world.bentobox.greenhouses.Greenhouses; +import world.bentobox.greenhouses.Settings; + /** * @author tastybento * */ @RunWith(PowerMockRunner.class) +@PrepareForTest(Greenhouses.class) public class RoofTest { private Roof roof; @@ -31,12 +39,20 @@ public class RoofTest { private Location location; @Mock private World world; + @Mock + private Greenhouses addon; + private Settings s; /** * @throws java.lang.Exception */ @Before public void setUp() throws Exception { + PowerMockito.mockStatic(Greenhouses.class, Mockito.RETURNS_MOCKS); + when(Greenhouses.getInstance()).thenReturn(addon); + s = new Settings(); + when(addon.getSettings()).thenReturn(s); + when(world.getMaxHeight()).thenReturn(255); // Block when(block.getType()).thenReturn(Material.AIR, Material.AIR, Material.AIR, Material.AIR, @@ -156,4 +172,33 @@ public class RoofTest { assertTrue(roof.toString().endsWith("minX=-9, maxX=28, minZ=-9, maxZ=29, height=14, roofFound=true]")); } + /** + * Test method for {@link world.bentobox.greenhouses.greenhouse.Roof#roofBlocks(org.bukkit.Material)}. + */ + @Test + public void testWallBlocks() { + assertFalse(Roof.roofBlocks(Material.ACACIA_BOAT)); + assertTrue(Roof.roofBlocks(Material.GLASS)); + assertTrue(Roof.roofBlocks(Material.GLOWSTONE)); + assertFalse(Roof.roofBlocks(Material.ACACIA_DOOR)); + assertTrue(Roof.roofBlocks(Material.HOPPER)); + assertTrue(Roof.roofBlocks(Material.PURPLE_STAINED_GLASS_PANE)); + assertTrue(Roof.roofBlocks(Material.BIRCH_TRAPDOOR)); + } + + /** + * Test method for {@link world.bentobox.greenhouses.greenhouse.Roof#roofBlocks(org.bukkit.Material)}. + */ + @Test + public void testWallBlocksNoGlowStoneNoPanes() { + s.setAllowGlowstone(false); + s.setAllowPanes(false); + assertFalse(Roof.roofBlocks(Material.ACACIA_BOAT)); + assertTrue(Roof.roofBlocks(Material.GLASS)); + assertFalse(Roof.roofBlocks(Material.GLOWSTONE)); + assertFalse(Roof.roofBlocks(Material.ACACIA_DOOR)); + assertTrue(Roof.roofBlocks(Material.HOPPER)); + assertFalse(Roof.roofBlocks(Material.PURPLE_STAINED_GLASS_PANE)); + assertTrue(Roof.roofBlocks(Material.BIRCH_TRAPDOOR)); + } } diff --git a/src/test/java/world/bentobox/greenhouses/greenhouse/WallsTest.java b/src/test/java/world/bentobox/greenhouses/greenhouse/WallsTest.java index 67e5adf..10ae344 100644 --- a/src/test/java/world/bentobox/greenhouses/greenhouse/WallsTest.java +++ b/src/test/java/world/bentobox/greenhouses/greenhouse/WallsTest.java @@ -1,17 +1,7 @@ package world.bentobox.greenhouses.greenhouse; -import static org.junit.Assert.*; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.powermock.modules.junit4.PowerMockRunner; - -import world.bentobox.greenhouses.greenhouse.Walls.WallFinder; - import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; @@ -21,12 +11,25 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import world.bentobox.greenhouses.Greenhouses; +import world.bentobox.greenhouses.Settings; +import world.bentobox.greenhouses.greenhouse.Walls.WallFinder; /** * @author tastybento * */ @RunWith(PowerMockRunner.class) +@PrepareForTest(Greenhouses.class) public class WallsTest { @Mock @@ -41,6 +44,9 @@ public class WallsTest { * Class under test */ private Walls walls; + @Mock + private Greenhouses addon; + private Settings s; /** @@ -48,6 +54,12 @@ public class WallsTest { */ @Before public void setUp() throws Exception { + PowerMockito.mockStatic(Greenhouses.class, Mockito.RETURNS_MOCKS); + when(Greenhouses.getInstance()).thenReturn(addon); + s = new Settings(); + when(addon.getSettings()).thenReturn(s); + + walls = new Walls(); when(world.getMaxHeight()).thenReturn(255); when(world.getBlockAt(anyInt(), anyInt(), anyInt())).thenReturn(block); @@ -65,13 +77,6 @@ public class WallsTest { } - /** - * @throws java.lang.Exception - */ - @After - public void tearDown() throws Exception { - } - /** * Test method for {@link world.bentobox.greenhouses.greenhouse.Walls#findWalls(world.bentobox.greenhouses.greenhouse.Roof)}. */ @@ -190,12 +195,29 @@ public class WallsTest { public void testWallBlocks() { assertFalse(Walls.wallBlocks(Material.ACACIA_BOAT)); assertTrue(Walls.wallBlocks(Material.GLASS)); + assertTrue(Walls.wallBlocks(Material.GLOWSTONE)); assertTrue(Walls.wallBlocks(Material.ACACIA_DOOR)); assertTrue(Walls.wallBlocks(Material.HOPPER)); assertTrue(Walls.wallBlocks(Material.PURPLE_STAINED_GLASS_PANE)); assertFalse(Walls.wallBlocks(Material.BIRCH_TRAPDOOR)); } + /** + * Test method for {@link world.bentobox.greenhouses.greenhouse.Walls#wallBlocks(org.bukkit.Material)}. + */ + @Test + public void testWallBlocksNoGlowStoneNoPanes() { + s.setAllowGlowstone(false); + s.setAllowPanes(false); + assertFalse(Walls.wallBlocks(Material.ACACIA_BOAT)); + assertTrue(Walls.wallBlocks(Material.GLASS)); + assertFalse(Walls.wallBlocks(Material.GLOWSTONE)); + assertTrue(Walls.wallBlocks(Material.ACACIA_DOOR)); + assertTrue(Walls.wallBlocks(Material.HOPPER)); + assertFalse(Walls.wallBlocks(Material.PURPLE_STAINED_GLASS_PANE)); + assertFalse(Walls.wallBlocks(Material.BIRCH_TRAPDOOR)); + } + /** * Test method for {@link world.bentobox.greenhouses.greenhouse.Walls#getFloor()}. */