mirror of
https://github.com/BentoBoxWorld/Greenhouses.git
synced 2025-01-20 23:21:45 +01:00
Trapdoors in roof were not counted as doors.
Fixes https://github.com/BentoBoxWorld/Greenhouses/issues/73
This commit is contained in:
parent
39a88a4f84
commit
88b655ee00
@ -11,6 +11,7 @@ import java.util.stream.Collectors;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Tag;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
@ -29,7 +30,7 @@ public class Roof extends MinMaxXZ {
|
||||
static {
|
||||
List<Material> r = Arrays.stream(Material.values())
|
||||
.filter(Material::isBlock) // Blocks only, no items
|
||||
.filter(m -> m.name().contains("TRAPDOOR") // All trapdoors
|
||||
.filter(m -> Tag.TRAPDOORS.isTagged(m) // All trapdoors
|
||||
|| (m.name().contains("GLASS") && !m.name().contains("GLASS_PANE")) // All glass blocks
|
||||
|| m.equals(Material.HOPPER)) // Hoppers
|
||||
.collect(Collectors.toList());
|
||||
|
@ -201,8 +201,8 @@ public class GreenhouseFinder {
|
||||
*/
|
||||
boolean checkDoorsHoppers(CounterCheck cc, Material m, Vector v) {
|
||||
// Count doors
|
||||
if (Tag.DOORS.isTagged(m)) {
|
||||
cc.doorCount++;
|
||||
if (Tag.TRAPDOORS.isTagged(m) || Tag.DOORS.isTagged(m)) {
|
||||
cc.doorCount = Tag.TRAPDOORS.isTagged(m) ? cc.doorCount + 2 : cc.doorCount + 1;
|
||||
|
||||
// If we already have 8 doors add these blocks to the red list
|
||||
if (cc.doorCount > 8) {
|
||||
|
@ -7,8 +7,10 @@ import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Tag;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.junit.Before;
|
||||
@ -30,7 +32,7 @@ import world.bentobox.greenhouses.world.AsyncWorldCache;
|
||||
*
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest(Greenhouses.class)
|
||||
@PrepareForTest({Greenhouses.class, Bukkit.class})
|
||||
public class RoofTest {
|
||||
|
||||
private Roof roof;
|
||||
@ -49,6 +51,8 @@ public class RoofTest {
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
|
||||
when(Tag.TRAPDOORS.isTagged(Material.BIRCH_TRAPDOOR)).thenReturn(true);
|
||||
PowerMockito.mockStatic(Greenhouses.class, Mockito.RETURNS_MOCKS);
|
||||
when(Greenhouses.getInstance()).thenReturn(addon);
|
||||
s = new Settings();
|
||||
|
@ -5,6 +5,7 @@ import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@ -12,6 +13,7 @@ import java.util.concurrent.CompletableFuture;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Tag;
|
||||
import org.bukkit.World;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@ -36,7 +38,6 @@ import world.bentobox.greenhouses.world.AsyncWorldCache;
|
||||
@PrepareForTest({Bukkit.class, Greenhouses.class})
|
||||
public class WallsTest {
|
||||
|
||||
@Mock
|
||||
private Roof roof;
|
||||
@Mock
|
||||
private Location location;
|
||||
@ -63,6 +64,9 @@ public class WallsTest {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
|
||||
when(Tag.TRAPDOORS.isTagged(Material.BIRCH_TRAPDOOR)).thenReturn(true);
|
||||
// Declare mock after mocking Bukkit
|
||||
roof = mock(Roof.class);
|
||||
PowerMockito.mockStatic(Greenhouses.class, Mockito.RETURNS_MOCKS);
|
||||
when(Greenhouses.getInstance()).thenReturn(addon);
|
||||
s = new Settings();
|
||||
|
@ -6,6 +6,7 @@ import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Collection;
|
||||
@ -54,7 +55,7 @@ public class GreenhouseFinderTest {
|
||||
// Class under test
|
||||
private GreenhouseFinder gf;
|
||||
private CounterCheck cc;
|
||||
@Mock
|
||||
|
||||
private Roof roof;
|
||||
@Mock
|
||||
private Walls walls;
|
||||
@ -68,6 +69,9 @@ public class GreenhouseFinderTest {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
|
||||
when(Tag.TRAPDOORS.isTagged(Material.BIRCH_TRAPDOOR)).thenReturn(true);
|
||||
// Declare mock after mocking Bukkit
|
||||
roof = mock(Roof.class);
|
||||
// Location
|
||||
when(location.getBlockX()).thenReturn(5);
|
||||
when(location.getBlockY()).thenReturn(14);
|
||||
@ -198,14 +202,28 @@ public class GreenhouseFinderTest {
|
||||
*/
|
||||
@Test
|
||||
public void testCheckDoorsHoppers() {
|
||||
// Doors are 2 blocks
|
||||
when(Tag.DOORS.isTagged(any(Material.class))).thenReturn(true);
|
||||
for (int i = 0; i < 8; i++) {
|
||||
assertTrue("Door number " + i, gf.checkDoorsHoppers(cc, Material.ACACIA_DOOR, new Vector(0,0,0)));
|
||||
}
|
||||
// 9th door will fail
|
||||
// 5th door will fail
|
||||
assertFalse(gf.checkDoorsHoppers(cc, Material.ACACIA_DOOR, new Vector(0,0,0)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.greenhouses.managers.GreenhouseFinder#checkDoorsHoppers(CounterCheck, Material, Vector)}
|
||||
*/
|
||||
@Test
|
||||
public void testCheckDoorsHoppersTrapdoors() {
|
||||
// Trapdoors are one block
|
||||
for (int i = 0; i < 4; i++) {
|
||||
assertTrue("Door number " + i, gf.checkDoorsHoppers(cc, Material.BIRCH_TRAPDOOR, new Vector(0,0,0)));
|
||||
}
|
||||
// 5th door will fail
|
||||
assertFalse(gf.checkDoorsHoppers(cc, Material.BIRCH_TRAPDOOR, new Vector(0,0,0)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.greenhouses.managers.GreenhouseFinder#checkDoorsHoppers(world.bentobox.greenhouses.managers.GreenhouseFinder.CounterCheck, org.bukkit.block.Block)}.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user