Removed static getInstance usage

This commit is contained in:
tastybento 2023-06-04 08:44:55 -07:00
parent db5ef4d5da
commit e6a1cd17bb
10 changed files with 106 additions and 114 deletions

View File

@ -11,6 +11,7 @@ import world.bentobox.bentobox.api.configuration.Config;
import world.bentobox.bentobox.api.flags.Flag; import world.bentobox.bentobox.api.flags.Flag;
import world.bentobox.bentobox.api.flags.Flag.Mode; import world.bentobox.bentobox.api.flags.Flag.Mode;
import world.bentobox.bentobox.api.flags.Flag.Type; import world.bentobox.bentobox.api.flags.Flag.Type;
import world.bentobox.greenhouses.greenhouse.Walls;
import world.bentobox.greenhouses.managers.GreenhouseManager; import world.bentobox.greenhouses.managers.GreenhouseManager;
import world.bentobox.greenhouses.managers.RecipeManager; import world.bentobox.greenhouses.managers.RecipeManager;
import world.bentobox.greenhouses.ui.user.UserCommand; import world.bentobox.greenhouses.ui.user.UserCommand;
@ -28,19 +29,13 @@ public class Greenhouses extends Addon {
public static final Flag GREENHOUSES = new Flag.Builder("GREENHOUSE", Material.GREEN_STAINED_GLASS) public static final Flag GREENHOUSES = new Flag.Builder("GREENHOUSE", Material.GREEN_STAINED_GLASS)
.mode(Mode.BASIC) .mode(Mode.BASIC)
.type(Type.PROTECTION).build(); .type(Type.PROTECTION).build();
private static Greenhouses instance;
private final Config<Settings> config; private final Config<Settings> config;
public static Greenhouses getInstance() {
return instance;
}
/** /**
* Constructor * Constructor
*/ */
public Greenhouses() { public Greenhouses() {
super(); super();
instance = this;
config = new Config<>(this, Settings.class); config = new Config<>(this, Settings.class);
} }
@ -122,4 +117,15 @@ public class Greenhouses extends Addon {
return activeWorlds; return activeWorlds;
} }
/**
* Check if material is a wall material
* @param m - material
* @return true if wall material
*/
public boolean wallBlocks(Material m) {
return Walls.WALL_BLOCKS.contains(m)
|| (m.equals(Material.GLOWSTONE) && getSettings().isAllowGlowstone())
|| (m.name().endsWith("GLASS_PANE") && getSettings().isAllowPanes());
}
} }

View File

@ -209,7 +209,7 @@ public class BiomeRecipe implements Comparable<BiomeRecipe> {
* @return set of results from the check * @return set of results from the check
*/ */
private Set<GreenhouseResult> checkRecipeAsync(CompletableFuture<Set<GreenhouseResult>> r, Greenhouse gh) { private Set<GreenhouseResult> checkRecipeAsync(CompletableFuture<Set<GreenhouseResult>> r, Greenhouse gh) {
AsyncWorldCache cache = new AsyncWorldCache(gh.getWorld()); AsyncWorldCache cache = new AsyncWorldCache(addon, gh.getWorld());
Set<GreenhouseResult> result = new HashSet<>(); Set<GreenhouseResult> result = new HashSet<>();
long area = gh.getArea(); long area = gh.getArea();
Map<Material, Integer> blockCount = new EnumMap<>(Material.class); Map<Material, Integer> blockCount = new EnumMap<>(Material.class);

View File

@ -23,33 +23,17 @@ import world.bentobox.greenhouses.world.AsyncWorldCache;
* @author tastybento * @author tastybento
* *
*/ */
@SuppressWarnings("deprecation")
public class Roof extends MinMaxXZ { public class Roof extends MinMaxXZ {
private static final List<Material> ROOF_BLOCKS; private static final List<Material> ROOF_BLOCKS = Arrays.stream(Material.values())
static { .filter(Material::isBlock) // Blocks only, no items
// Roof blocks .filter(m -> Tag.TRAPDOORS.isTagged(m) // All trapdoors
ROOF_BLOCKS = Arrays.stream(Material.values()) || (m.name().contains("GLASS") && !m.name().contains("GLASS_PANE")) // All glass blocks
.filter(m -> !m.isLegacy()) || m.equals(Material.HOPPER)).toList();
.filter(Material::isBlock) // Blocks only, no items
.filter(m -> Tag.TRAPDOORS.isTagged(m) // All trapdoors
|| (m.name().contains("GLASS") && !m.name().contains("GLASS_PANE")) // All glass blocks
|| m.equals(Material.HOPPER)).toList();
}
/**
* Check if material is a roof material
* @param m - material
* @return true if roof material
*/
public static boolean roofBlocks(@NonNull Material m) {
return ROOF_BLOCKS.contains(Objects.requireNonNull(m))
|| (m.equals(Material.GLOWSTONE) && Greenhouses.getInstance().getSettings().isAllowGlowstone())
|| (m.name().endsWith("GLASS_PANE") && Greenhouses.getInstance().getSettings().isAllowPanes());
}
private final AsyncWorldCache cache; private final AsyncWorldCache cache;
private int height; private int height;
private final Location location; private final Location location;
private boolean roofFound; private boolean roofFound;
private final Greenhouses addon;
private final World world; private final World world;
@ -58,13 +42,23 @@ public class Roof extends MinMaxXZ {
* @param cache async world cache * @param cache async world cache
* @param loc - starting location * @param loc - starting location
*/ */
public Roof(AsyncWorldCache cache, Location loc) { public Roof(AsyncWorldCache cache, Location loc, Greenhouses addon) {
this.cache = cache; this.cache = cache;
this.location = loc; this.location = loc;
this.addon = addon;
this.world = loc.getWorld(); this.world = loc.getWorld();
} }
/**
* Check if material is a roof material
* @param m - material
* @return true if roof material
*/
public boolean roofBlocks(@NonNull Material m) {
return ROOF_BLOCKS.contains(Objects.requireNonNull(m))
|| (m.equals(Material.GLOWSTONE) && addon.getSettings().isAllowGlowstone())
|| (m.name().endsWith("GLASS_PANE") && addon.getSettings().isAllowPanes());
}
/** /**
* This takes any location and tries to go as far as possible in NWSE directions finding contiguous roof blocks * This takes any location and tries to go as far as possible in NWSE directions finding contiguous roof blocks
@ -211,7 +205,7 @@ public class Roof extends MinMaxXZ {
* @param z - z coord of current search * @param z - z coord of current search
*/ */
private Optional<Vector> checkVertically(final int x, final int startY, final int z) { private Optional<Vector> checkVertically(final int x, final int startY, final int z) {
if (!Walls.wallBlocks(cache.getBlockType(x, startY, z))) { if (!addon.wallBlocks(cache.getBlockType(x, startY, z))) {
// Look up // Look up
for (int y = startY; y < world.getMaxHeight() && !roofFound; y++) { for (int y = startY; y < world.getMaxHeight() && !roofFound; y++) {
if (roofBlocks(cache.getBlockType(x,y,z))) { if (roofBlocks(cache.getBlockType(x,y,z))) {

View File

@ -9,25 +9,17 @@ import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.BentoBox;
import world.bentobox.greenhouses.Greenhouses;
import world.bentobox.greenhouses.world.AsyncWorldCache; import world.bentobox.greenhouses.world.AsyncWorldCache;
@SuppressWarnings("deprecation")
public class Walls extends MinMaxXZ { public class Walls extends MinMaxXZ {
private static final List<Material> WALL_BLOCKS; public static final List<Material> WALL_BLOCKS = Arrays.stream(Material.values())
static { .filter(Material::isBlock) // Blocks only, no items
// Hoppers .filter(m -> !m.name().contains("TRAPDOOR")) // No trap doors
WALL_BLOCKS = Arrays.stream(Material.values()) .filter(m -> m.name().contains("DOOR") // All doors
.filter(Material::isBlock) // Blocks only, no items || (m.name().contains("GLASS") && !m.name().contains("GLASS_PANE")) // All glass blocks
.filter(m -> !m.isLegacy()) || m.equals(Material.HOPPER)).toList();
.filter(m -> !m.name().contains("TRAPDOOR")) // No trap doors
.filter(m -> m.name().contains("DOOR") // All doors
|| (m.name().contains("GLASS") && !m.name().contains("GLASS_PANE")) // All glass blocks
|| m.equals(Material.HOPPER)).toList();
}
private int floor; private int floor;
private final AsyncWorldCache cache; private final AsyncWorldCache cache;
static class WallFinder { static class WallFinder {
@ -177,17 +169,6 @@ public class Walls extends MinMaxXZ {
} }
/**
* Check if material is a wall material
* @param m - material
* @return true if wall material
*/
public static boolean wallBlocks(Material m) {
return WALL_BLOCKS.contains(m)
|| (m.equals(Material.GLOWSTONE) && Greenhouses.getInstance().getSettings().isAllowGlowstone())
|| (m.name().endsWith("GLASS_PANE") && Greenhouses.getInstance().getSettings().isAllowPanes());
}
/** /**
* @return the floor * @return the floor
*/ */

View File

@ -12,6 +12,7 @@ import org.bukkit.Tag;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.BentoBox;
import world.bentobox.greenhouses.Greenhouses;
import world.bentobox.greenhouses.data.Greenhouse; import world.bentobox.greenhouses.data.Greenhouse;
import world.bentobox.greenhouses.greenhouse.Roof; import world.bentobox.greenhouses.greenhouse.Roof;
import world.bentobox.greenhouses.greenhouse.Walls; import world.bentobox.greenhouses.greenhouse.Walls;
@ -28,10 +29,12 @@ public class GreenhouseFinder {
// If this is the bottom layer, the player has most likely uneven walls // If this is the bottom layer, the player has most likely uneven walls
private int otherBlockLayer = -1; private int otherBlockLayer = -1;
private int wallBlockCount; private int wallBlockCount;
private final Greenhouses addon;
/** /**
* This is the count of the various items * This is the count of the various items
*/ */
private CounterCheck cc = new CounterCheck(); private CounterCheck cc = new CounterCheck();
private Roof roof;
static class CounterCheck { static class CounterCheck {
int doorCount; int doorCount;
@ -40,6 +43,13 @@ public class GreenhouseFinder {
boolean otherBlock; boolean otherBlock;
} }
/**
* @param addon
*/
public GreenhouseFinder(Greenhouses addon) {
this.addon = addon;
}
/** /**
* Find out if there is a greenhouse here * Find out if there is a greenhouse here
* @param location - start location * @param location - start location
@ -51,9 +61,9 @@ public class GreenhouseFinder {
redGlass.clear(); redGlass.clear();
// Get a world cache // Get a world cache
AsyncWorldCache cache = new AsyncWorldCache(location.getWorld()); AsyncWorldCache cache = new AsyncWorldCache(addon, location.getWorld());
// Find the roof // Find the roof
Roof roof = new Roof(cache, location); roof = new Roof(cache, location, addon);
roof.findRoof().thenAccept(found -> { roof.findRoof().thenAccept(found -> {
if (Boolean.FALSE.equals(found)) { if (Boolean.FALSE.equals(found)) {
result.add(GreenhouseResult.FAIL_NO_ROOF); result.add(GreenhouseResult.FAIL_NO_ROOF);
@ -166,7 +176,8 @@ public class GreenhouseFinder {
// Check wall blocks only // Check wall blocks only
if (y == roof.getHeight() || x == walls.getMinX() || x == walls.getMaxX() || z == walls.getMinZ() || z== walls.getMaxZ()) { if (y == roof.getHeight() || x == walls.getMinX() || x == walls.getMaxX() || z == walls.getMinZ() || z== walls.getMaxZ()) {
// Check for non-wall blocks or non-roof blocks at the top of walls // Check for non-wall blocks or non-roof blocks at the top of walls
if ((y != roof.getHeight() && !Walls.wallBlocks(m)) || (y == roof.getHeight() && !Roof.roofBlocks(m))) { if ((y != roof.getHeight() && !addon.wallBlocks(m))
|| (y == roof.getHeight() && !roof.roofBlocks(m))) {
if (m.equals(Material.AIR)) { if (m.equals(Material.AIR)) {
// Air hole found // Air hole found
cc.airHole = true; cc.airHole = true;

View File

@ -96,19 +96,19 @@ public class GreenhouseManager implements Listener {
handler.loadObjects().forEach(g -> { handler.loadObjects().forEach(g -> {
GreenhouseResult result = map.addGreenhouse(g); GreenhouseResult result = map.addGreenhouse(g);
switch (result) { switch (result) {
case FAIL_NO_ISLAND -> case FAIL_NO_ISLAND ->
// Delete the failed greenhouse // Delete the failed greenhouse
toBeRemoved.add(g); toBeRemoved.add(g);
case FAIL_OVERLAPPING -> addon.logError("Greenhouse overlaps with another greenhouse. Skipping..."); case FAIL_OVERLAPPING -> addon.logError("Greenhouse overlaps with another greenhouse. Skipping...");
case NULL -> addon.logError("Null location of greenhouse. Cannot load. Skipping..."); case NULL -> addon.logError("Null location of greenhouse. Cannot load. Skipping...");
case SUCCESS -> activateGreenhouse(g); case SUCCESS -> activateGreenhouse(g);
case FAIL_NO_WORLD -> addon.logError("Database contains greenhouse for a non-loaded world. Skipping..."); case FAIL_NO_WORLD -> addon.logError("Database contains greenhouse for a non-loaded world. Skipping...");
case FAIL_UNKNOWN_RECIPE -> { case FAIL_UNKNOWN_RECIPE -> {
addon.logError("Greenhouse uses a recipe that does not exist in the biomes.yml. Skipping..."); addon.logError("Greenhouse uses a recipe that does not exist in the biomes.yml. Skipping...");
addon.logError("Greenhouse Id " + g.getUniqueId()); addon.logError("Greenhouse Id " + g.getUniqueId());
} }
default -> { default -> {
} }
} }
}); });
addon.log("Loaded " + map.getSize() + " greenhouses."); addon.log("Loaded " + map.getSize() + " greenhouses.");
@ -153,7 +153,7 @@ public class GreenhouseManager implements Listener {
*/ */
public CompletableFuture<GhResult> tryToMakeGreenhouse(Location location, BiomeRecipe greenhouseRecipe) { public CompletableFuture<GhResult> tryToMakeGreenhouse(Location location, BiomeRecipe greenhouseRecipe) {
CompletableFuture<GhResult> r = new CompletableFuture<>(); CompletableFuture<GhResult> r = new CompletableFuture<>();
GreenhouseFinder finder = new GreenhouseFinder(); GreenhouseFinder finder = new GreenhouseFinder(addon);
finder.find(location).thenAccept(resultSet -> { finder.find(location).thenAccept(resultSet -> {
if (!resultSet.isEmpty()) { if (!resultSet.isEmpty()) {
// Failure! // Failure!

View File

@ -27,14 +27,16 @@ public class AsyncWorldCache {
private final World world; private final World world;
private final Map<Pair<Integer, Integer>, ChunkSnapshot> cache; private final Map<Pair<Integer, Integer>, ChunkSnapshot> cache;
private final Greenhouses addon;
/** /**
* Chunk cache. This class is designed to be run async and blocks futures * Chunk cache. This class is designed to be run async and blocks futures
* @param world - world to cache * @param world - world to cache
*/ */
public AsyncWorldCache(World world) { public AsyncWorldCache(Greenhouses addon, World world) {
this.world = world; this.world = world;
cache = new HashMap<>(); cache = new HashMap<>();
this.addon = addon;
} }
/** /**
@ -59,7 +61,7 @@ public class AsyncWorldCache {
*/ */
private CompletableFuture<ChunkSnapshot> getAChunk(int x, int z) { private CompletableFuture<ChunkSnapshot> getAChunk(int x, int z) {
CompletableFuture<ChunkSnapshot> r = new CompletableFuture<>(); CompletableFuture<ChunkSnapshot> r = new CompletableFuture<>();
Bukkit.getScheduler().runTask(Greenhouses.getInstance().getPlugin(), () -> Bukkit.getScheduler().runTask(addon.getPlugin(), () ->
Util.getChunkAtAsync(world, x, z).thenAccept(chunk -> r.complete(chunk.getChunkSnapshot()))); Util.getChunkAtAsync(world, x, z).thenAccept(chunk -> r.complete(chunk.getChunkSnapshot())));
return r; return r;
} }
@ -104,7 +106,7 @@ public class AsyncWorldCache {
try { try {
return Objects.requireNonNull(getSnap(x, z)).getBlockType(xx, y, zz); return Objects.requireNonNull(getSnap(x, z)).getBlockType(xx, y, zz);
} catch (InterruptedException | ExecutionException e) { } catch (InterruptedException | ExecutionException e) {
Greenhouses.getInstance().logError("Chunk could not be obtained async! " + e); addon.logError("Chunk could not be obtained async! " + e);
// Restore interrupted state... // Restore interrupted state...
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
return Material.AIR; return Material.AIR;

View File

@ -50,8 +50,6 @@ public class RoofTest {
public void setUp() { public void setUp() {
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS); PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
when(Tag.TRAPDOORS.isTagged(Material.BIRCH_TRAPDOOR)).thenReturn(true); when(Tag.TRAPDOORS.isTagged(Material.BIRCH_TRAPDOOR)).thenReturn(true);
PowerMockito.mockStatic(Greenhouses.class, Mockito.RETURNS_MOCKS);
when(Greenhouses.getInstance()).thenReturn(addon);
s = new Settings(); s = new Settings();
when(addon.getSettings()).thenReturn(s); when(addon.getSettings()).thenReturn(s);
@ -89,14 +87,14 @@ public class RoofTest {
when(location.clone()).thenReturn(location); when(location.clone()).thenReturn(location);
// Test // Test
roof = new Roof(cache, location); roof = new Roof(cache, location, addon);
assertTrue(roof.findRoof(new Vector(10,10,10))); assertTrue(roof.findRoof(new Vector(10,10,10)));
} }
@Test @Test
public void testNoGlass() { public void testNoGlass() {
when(cache.getBlockType(anyInt(), anyInt(), anyInt())).thenReturn(Material.AIR); when(cache.getBlockType(anyInt(), anyInt(), anyInt())).thenReturn(Material.AIR);
roof = new Roof(cache, location); roof = new Roof(cache, location, addon);
assertFalse(roof.findRoof(new Vector(10,10,10))); assertFalse(roof.findRoof(new Vector(10,10,10)));
} }
@ -169,13 +167,13 @@ public class RoofTest {
*/ */
@Test @Test
public void testWallBlocks() { public void testWallBlocks() {
assertFalse(Roof.roofBlocks(Material.ACACIA_BOAT)); assertFalse(roof.roofBlocks(Material.ACACIA_BOAT));
assertTrue(Roof.roofBlocks(Material.GLASS)); assertTrue(roof.roofBlocks(Material.GLASS));
assertTrue(Roof.roofBlocks(Material.GLOWSTONE)); assertTrue(roof.roofBlocks(Material.GLOWSTONE));
assertFalse(Roof.roofBlocks(Material.ACACIA_DOOR)); assertFalse(roof.roofBlocks(Material.ACACIA_DOOR));
assertTrue(Roof.roofBlocks(Material.HOPPER)); assertTrue(roof.roofBlocks(Material.HOPPER));
assertTrue(Roof.roofBlocks(Material.PURPLE_STAINED_GLASS_PANE)); assertTrue(roof.roofBlocks(Material.PURPLE_STAINED_GLASS_PANE));
assertTrue(Roof.roofBlocks(Material.BIRCH_TRAPDOOR)); assertTrue(roof.roofBlocks(Material.BIRCH_TRAPDOOR));
} }
/** /**
@ -185,12 +183,12 @@ public class RoofTest {
public void testWallBlocksNoGlowStoneNoPanes() { public void testWallBlocksNoGlowStoneNoPanes() {
s.setAllowGlowstone(false); s.setAllowGlowstone(false);
s.setAllowPanes(false); s.setAllowPanes(false);
assertFalse(Roof.roofBlocks(Material.ACACIA_BOAT)); assertFalse(roof.roofBlocks(Material.ACACIA_BOAT));
assertTrue(Roof.roofBlocks(Material.GLASS)); assertTrue(roof.roofBlocks(Material.GLASS));
assertFalse(Roof.roofBlocks(Material.GLOWSTONE)); assertFalse(roof.roofBlocks(Material.GLOWSTONE));
assertFalse(Roof.roofBlocks(Material.ACACIA_DOOR)); assertFalse(roof.roofBlocks(Material.ACACIA_DOOR));
assertTrue(Roof.roofBlocks(Material.HOPPER)); assertTrue(roof.roofBlocks(Material.HOPPER));
assertFalse(Roof.roofBlocks(Material.PURPLE_STAINED_GLASS_PANE)); assertFalse(roof.roofBlocks(Material.PURPLE_STAINED_GLASS_PANE));
assertTrue(Roof.roofBlocks(Material.BIRCH_TRAPDOOR)); assertTrue(roof.roofBlocks(Material.BIRCH_TRAPDOOR));
} }
} }

View File

@ -64,12 +64,10 @@ public class WallsTest {
when(Tag.TRAPDOORS.isTagged(Material.BIRCH_TRAPDOOR)).thenReturn(true); when(Tag.TRAPDOORS.isTagged(Material.BIRCH_TRAPDOOR)).thenReturn(true);
// Declare mock after mocking Bukkit // Declare mock after mocking Bukkit
roof = mock(Roof.class); roof = mock(Roof.class);
PowerMockito.mockStatic(Greenhouses.class, Mockito.RETURNS_MOCKS);
when(Greenhouses.getInstance()).thenReturn(addon);
s = new Settings(); s = new Settings();
when(addon.getSettings()).thenReturn(s); when(addon.getSettings()).thenReturn(s);
when(addon.getPlugin()).thenReturn(plugin); when(addon.getPlugin()).thenReturn(plugin);
when(addon.wallBlocks(any())).thenCallRealMethod();
walls = new Walls(cache); walls = new Walls(cache);
when(world.getMaxHeight()).thenReturn(255); when(world.getMaxHeight()).thenReturn(255);
when(location.getWorld()).thenReturn(world); when(location.getWorld()).thenReturn(world);
@ -201,13 +199,13 @@ public class WallsTest {
*/ */
@Test @Test
public void testWallBlocks() { public void testWallBlocks() {
assertFalse(Walls.wallBlocks(Material.ACACIA_BOAT)); assertFalse(addon.wallBlocks(Material.ACACIA_BOAT));
assertTrue(Walls.wallBlocks(Material.GLASS)); assertTrue(addon.wallBlocks(Material.GLASS));
assertTrue(Walls.wallBlocks(Material.GLOWSTONE)); assertTrue(addon.wallBlocks(Material.GLOWSTONE));
assertTrue(Walls.wallBlocks(Material.ACACIA_DOOR)); assertTrue(addon.wallBlocks(Material.ACACIA_DOOR));
assertTrue(Walls.wallBlocks(Material.HOPPER)); assertTrue(addon.wallBlocks(Material.HOPPER));
assertTrue(Walls.wallBlocks(Material.PURPLE_STAINED_GLASS_PANE)); assertTrue(addon.wallBlocks(Material.PURPLE_STAINED_GLASS_PANE));
assertFalse(Walls.wallBlocks(Material.BIRCH_TRAPDOOR)); assertFalse(addon.wallBlocks(Material.BIRCH_TRAPDOOR));
} }
/** /**
@ -217,13 +215,13 @@ public class WallsTest {
public void testWallBlocksNoGlowStoneNoPanes() { public void testWallBlocksNoGlowStoneNoPanes() {
s.setAllowGlowstone(false); s.setAllowGlowstone(false);
s.setAllowPanes(false); s.setAllowPanes(false);
assertFalse(Walls.wallBlocks(Material.ACACIA_BOAT)); assertFalse(addon.wallBlocks(Material.ACACIA_BOAT));
assertTrue(Walls.wallBlocks(Material.GLASS)); assertTrue(addon.wallBlocks(Material.GLASS));
assertFalse(Walls.wallBlocks(Material.GLOWSTONE)); assertFalse(addon.wallBlocks(Material.GLOWSTONE));
assertTrue(Walls.wallBlocks(Material.ACACIA_DOOR)); assertTrue(addon.wallBlocks(Material.ACACIA_DOOR));
assertTrue(Walls.wallBlocks(Material.HOPPER)); assertTrue(addon.wallBlocks(Material.HOPPER));
assertFalse(Walls.wallBlocks(Material.PURPLE_STAINED_GLASS_PANE)); assertFalse(addon.wallBlocks(Material.PURPLE_STAINED_GLASS_PANE));
assertFalse(Walls.wallBlocks(Material.BIRCH_TRAPDOOR)); assertFalse(addon.wallBlocks(Material.BIRCH_TRAPDOOR));
} }
/** /**

View File

@ -71,12 +71,14 @@ public class GreenhouseFinderTest {
when(Tag.TRAPDOORS.isTagged(Material.BIRCH_TRAPDOOR)).thenReturn(true); when(Tag.TRAPDOORS.isTagged(Material.BIRCH_TRAPDOOR)).thenReturn(true);
// Declare mock after mocking Bukkit // Declare mock after mocking Bukkit
roof = mock(Roof.class); roof = mock(Roof.class);
when(roof.roofBlocks(any())).thenCallRealMethod();
// Location // Location
when(location.getBlockX()).thenReturn(5); when(location.getBlockX()).thenReturn(5);
when(location.getBlockY()).thenReturn(14); when(location.getBlockY()).thenReturn(14);
when(location.getBlockZ()).thenReturn(25); when(location.getBlockZ()).thenReturn(25);
when(location.getWorld()).thenReturn(world); when(location.getWorld()).thenReturn(world);
// Addon
when(addon.wallBlocks(any())).thenCallRealMethod();
// Block // Block
when(cache.getBlockType(any())).thenReturn(Material.GLASS); when(cache.getBlockType(any())).thenReturn(Material.GLASS);
when(cache.getBlockType(anyInt(), anyInt(), anyInt())).thenReturn(Material.GLASS); when(cache.getBlockType(anyInt(), anyInt(), anyInt())).thenReturn(Material.GLASS);
@ -94,7 +96,7 @@ public class GreenhouseFinderTest {
when(cache.getMaxHeight()).thenReturn(30); when(cache.getMaxHeight()).thenReturn(30);
gf = new GreenhouseFinder(); gf = new GreenhouseFinder(addon);
cc = new CounterCheck(); cc = new CounterCheck();
} }