From cf276bbb24737c077ac96e09d273c6c95f82805f Mon Sep 17 00:00:00 2001 From: tastybento Date: Sun, 1 Jan 2023 22:31:46 -0800 Subject: [PATCH 01/31] Version 1.7.3 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c8542f6..f9a955b 100644 --- a/pom.xml +++ b/pom.xml @@ -51,7 +51,7 @@ ${build.version}-SNAPSHOT - 1.7.2 + 1.7.3 -LOCAL BentoBoxWorld_Greenhouses bentobox-world From ce0eeae546c62f1db62a7ee8ba7a9c6cc258696c Mon Sep 17 00:00:00 2001 From: tastybento Date: Thu, 9 Feb 2023 15:18:43 -0800 Subject: [PATCH 02/31] Add ${argLine} to get jacoco coverage --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index c8542f6..35923bf 100644 --- a/pom.xml +++ b/pom.xml @@ -200,6 +200,7 @@ 3.0.0-M5 + ${argLine} --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.util.concurrent=ALL-UNNAMED From d6df904fbce4d9e474b93e096b9ae8cf39ae3f2c Mon Sep 17 00:00:00 2001 From: tastybento Date: Thu, 9 Feb 2023 17:09:21 -0800 Subject: [PATCH 03/31] Updated Jacoco POM entry --- pom.xml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index c2e8df7..5efa26c 100644 --- a/pom.xml +++ b/pom.xml @@ -258,7 +258,7 @@ org.jacoco jacoco-maven-plugin - 0.8.3 + 0.8.7 true @@ -269,16 +269,21 @@ - pre-unit-test + prepare-agent prepare-agent - post-unit-test + report report + + + XML + + From 9e407e659e8b55aaf97ee5358a7120e2b70bd83c Mon Sep 17 00:00:00 2001 From: tastybento Date: Thu, 9 Feb 2023 17:27:57 -0800 Subject: [PATCH 04/31] Address bugs reported by SonarCloud --- src/main/java/world/bentobox/greenhouses/data/Greenhouse.java | 2 +- .../java/world/bentobox/greenhouses/ui/panel/PanelClick.java | 4 ---- .../java/world/bentobox/greenhouses/ui/user/MakeCommand.java | 4 ---- .../world/bentobox/greenhouses/ui/user/RemoveCommand.java | 4 ---- 4 files changed, 1 insertion(+), 13 deletions(-) diff --git a/src/main/java/world/bentobox/greenhouses/data/Greenhouse.java b/src/main/java/world/bentobox/greenhouses/data/Greenhouse.java index 3d052b3..0383c9b 100644 --- a/src/main/java/world/bentobox/greenhouses/data/Greenhouse.java +++ b/src/main/java/world/bentobox/greenhouses/data/Greenhouse.java @@ -220,7 +220,7 @@ public World getWorld() { * @return true if inside the greenhouse */ public boolean contains(Location location2) { - return getLocation().getWorld() != null + return getLocation() != null && getLocation().getWorld() != null && getLocation().getWorld().equals(location2.getWorld()) && getBoundingBox().contains(location2.toVector()); } diff --git a/src/main/java/world/bentobox/greenhouses/ui/panel/PanelClick.java b/src/main/java/world/bentobox/greenhouses/ui/panel/PanelClick.java index 31479d9..2935861 100644 --- a/src/main/java/world/bentobox/greenhouses/ui/panel/PanelClick.java +++ b/src/main/java/world/bentobox/greenhouses/ui/panel/PanelClick.java @@ -43,10 +43,6 @@ public boolean onClick(Panel panel, User user, ClickType clickType, int slot) { } private boolean makeGreenhouse(User user, BiomeRecipe br) { - if (user.getLocation() == null) { - addon.logError("User has no location : " + user.getName()); - return false; - } // Check flag if (!addon.getIslands().getIslandAt(user.getLocation()).map(i -> i.isAllowed(user, Greenhouses.GREENHOUSES)).orElse(false)) { user.sendMessage("greenhouses.errors.no-rank"); diff --git a/src/main/java/world/bentobox/greenhouses/ui/user/MakeCommand.java b/src/main/java/world/bentobox/greenhouses/ui/user/MakeCommand.java index 0111e2e..6b7a893 100644 --- a/src/main/java/world/bentobox/greenhouses/ui/user/MakeCommand.java +++ b/src/main/java/world/bentobox/greenhouses/ui/user/MakeCommand.java @@ -92,10 +92,6 @@ private Map getRecipes(User user) { * @return true if successful */ private boolean makeGreenhouse(User user, BiomeRecipe br) { - if (user.getLocation() == null) { - getAddon().logError("User had no location"); - return false; - } // Check flag if (!getIslands().getIslandAt(user.getLocation()).map(i -> i.isAllowed(user, Greenhouses.GREENHOUSES)).orElse(false)) { user.sendMessage("greenhouses.errors.no-rank"); diff --git a/src/main/java/world/bentobox/greenhouses/ui/user/RemoveCommand.java b/src/main/java/world/bentobox/greenhouses/ui/user/RemoveCommand.java index 8ae6a8f..49ca538 100644 --- a/src/main/java/world/bentobox/greenhouses/ui/user/RemoveCommand.java +++ b/src/main/java/world/bentobox/greenhouses/ui/user/RemoveCommand.java @@ -35,10 +35,6 @@ public void setup() { */ @Override public boolean execute(User user, String label, List args) { - if (user.getLocation() == null) { - getAddon().logError("User had no location"); - return false; - } // Check flag if (!getIslands().getIslandAt(user.getLocation()).map(i -> i.isAllowed(user, Greenhouses.GREENHOUSES)).orElse(false)) { user.sendMessage("greenhouses.errors.no-rank"); From 4351247de2667900864769e37704120a70eca414 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 25 Feb 2023 08:22:44 -0800 Subject: [PATCH 05/31] Updated ReadMe --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 36d0fca..3dd4bd7 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,9 @@ # Greenhouses - an add-on for BentoBox -## Note for 1.15.x + servers - -Biomes have changed so that they take up a 4x4 area and so greenhouse biomes now can bleed outside of the greenhouse. Unfortunately, this cannot be mitigated (as far as I know). If you have a good imagination, you can say that the biome of the greenhouse influences the surroundings a bit and it is natural! So it's a feature, not a bug! +[![Build Status](https://ci.codemc.org/buildStatus/icon?job=BentoBoxWorld/Greenhouses)](https://ci.codemc.org/job/BentoBoxWorld/job/Greenhouses/)[ +![Bugs](https://sonarcloud.io/api/project_badges/measure?project=BentoBoxWorld_Greenhouses&metric=bugs)](https://sonarcloud.io/dashboard?id=BentoBoxWorld_Greenhouses) +[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=BentoBoxWorld_Greenhouses&metric=reliability_rating)](https://sonarcloud.io/dashboard?id=BentoBoxWorld_Greenhouses) +[![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=BentoBoxWorld_Greenhouses&metric=ncloc)](https://sonarcloud.io/dashboard?id=BentoBoxWorld_Greenhouses) ## About From 66270cf3e7feb61a2b5423313394f8e2fe067880 Mon Sep 17 00:00:00 2001 From: tastybento Date: Wed, 1 Mar 2023 08:26:34 -0800 Subject: [PATCH 06/31] Add max mobs option #99 --- .../greenhouses/greenhouse/BiomeRecipe.java | 17 ++++++- .../managers/EcoSystemManager.java | 3 ++ .../greenhouses/managers/RecipeManager.java | 1 + src/main/resources/biomes.yml | 48 ++++++++++++++++++- 4 files changed, 66 insertions(+), 3 deletions(-) diff --git a/src/main/java/world/bentobox/greenhouses/greenhouse/BiomeRecipe.java b/src/main/java/world/bentobox/greenhouses/greenhouse/BiomeRecipe.java index 7cd7266..92ad899 100644 --- a/src/main/java/world/bentobox/greenhouses/greenhouse/BiomeRecipe.java +++ b/src/main/java/world/bentobox/greenhouses/greenhouse/BiomeRecipe.java @@ -32,7 +32,6 @@ import org.bukkit.entity.EntityType; import org.bukkit.entity.Hoglin; import org.bukkit.entity.Piglin; -import org.bukkit.material.CocoaPlant; import org.bukkit.util.Vector; import com.google.common.base.Enums; @@ -102,6 +101,7 @@ public class BiomeRecipe implements Comparable { private String permission = ""; private final Random random = new Random(); + private int maxMob; /** @@ -715,5 +715,20 @@ public Set getMobTypes() { return mobTree.values().stream().map(GreenhouseMob::mobType).collect(Collectors.toSet()); } + /** + * Set the maximum number of mobs in a greenhouse + * @param maxMob maximum + */ + public void setMaxMob(int maxMob) { + this.maxMob = maxMob; + } + + /** + * @return the maxMob + */ + public int getMaxMob() { + return maxMob; + } + } diff --git a/src/main/java/world/bentobox/greenhouses/managers/EcoSystemManager.java b/src/main/java/world/bentobox/greenhouses/managers/EcoSystemManager.java index b4032b8..9684e31 100644 --- a/src/main/java/world/bentobox/greenhouses/managers/EcoSystemManager.java +++ b/src/main/java/world/bentobox/greenhouses/managers/EcoSystemManager.java @@ -161,6 +161,9 @@ private void addMobs(Greenhouse gh) { Collections.shuffle(list, new Random(System.currentTimeMillis())); Iterator it = list.iterator(); // Check if the greenhouse is full + if (sum >= gh.getBiomeRecipe().getMaxMob()) { + return; + } while (it.hasNext() && (sum == 0 || gh.getArea() / sum >= gh.getBiomeRecipe().getMobLimit())) { // Spawn something if chance says so if (gh.getBiomeRecipe().spawnMob(it.next().block())) { diff --git a/src/main/java/world/bentobox/greenhouses/managers/RecipeManager.java b/src/main/java/world/bentobox/greenhouses/managers/RecipeManager.java index 248ba15..7e0f559 100644 --- a/src/main/java/world/bentobox/greenhouses/managers/RecipeManager.java +++ b/src/main/java/world/bentobox/greenhouses/managers/RecipeManager.java @@ -155,6 +155,7 @@ private BiomeRecipe getBiomeRecipe(ConfigurationSection biomeRecipeConfig, Strin b.setLavacoverage(biomeRecipeConfig.getInt("lavacoverage",-1)); b.setIcecoverage(biomeRecipeConfig.getInt("icecoverage",-1)); b.setMobLimit(biomeRecipeConfig.getInt("moblimit", 9)); + b.setMaxMob(biomeRecipeConfig.getInt("maxmob", -1)); return b; } diff --git a/src/main/resources/biomes.yml b/src/main/resources/biomes.yml index 1a2807c..d196791 100644 --- a/src/main/resources/biomes.yml +++ b/src/main/resources/biomes.yml @@ -38,8 +38,12 @@ biomes: # The minimum number of blocks each mob requires. # Mobs will not spawn if there is more than 1 per this number of # blocks in the greenhouse. e.g., in this case only 2 mobs will spawn if the - # greenhouse area is 18 blocks + # greenhouse area is 18 blocks. This enables bigger greenhouses to spawn more. moblimit: 9 + # Maxmobs - this is the maximum number of greenhouse-spawed mobs allowed in + # the greenhouse at once. Spawning will stop when this limit is reached. + # If this value is not given, there is no maximum. + maxmobs: 5 Snowy_beach: friendlyname: "Snowy beach" biome: SNOWY_BEACH @@ -65,6 +69,10 @@ biomes: mobs: WOLF: 10:SNOW moblimit: 9 + # Maxmobs - this is the maximum number of greenhouse-spawed mobs allowed in + # the greenhouse at once. Spawning will stop when this limit is reached. + # If this value is not given, there is no maximum. + maxmobs: 5 Cold_Rabbit: friendlyname: "Cold Taiga Forest" biome: OLD_GROWTH_SPRUCE_TAIGA @@ -80,6 +88,10 @@ biomes: mobs: RABBIT: 10:SNOW moblimit: 9 + # Maxmobs - this is the maximum number of greenhouse-spawed mobs allowed in + # the greenhouse at once. Spawning will stop when this limit is reached. + # If this value is not given, there is no maximum. + maxmobs: 20 DESERT: friendlyname: "Desert" biome: DESERT @@ -134,6 +146,10 @@ biomes: STRIDER: 10:LAVA ENDERMAN: 5:NETHERRACK moblimit: 9 + # Maxmobs - this is the maximum number of greenhouse-spawed mobs allowed in + # the greenhouse at once. Spawning will stop when this limit is reached. + # If this value is not given, there is no maximum. + maxmobs: 50 permission: greenhouses.biome.nether SOUL_SAND_VALLEY: friendlyname: "&cSoul Sand Valley" @@ -149,6 +165,10 @@ biomes: mobs: SKELETON: 10:SOUL_SAND moblimit: 9 + # Maxmobs - this is the maximum number of greenhouse-spawed mobs allowed in + # the greenhouse at once. Spawning will stop when this limit is reached. + # If this value is not given, there is no maximum. + maxmobs: 50 permission: greenhouses.biome.nether # Conversion list - in this case, an adjacent block is required to convert # Format is: @@ -173,6 +193,10 @@ biomes: PIGLIN: 10:CRIMSON_NYLIUM HOGLIN: 10:CRIMSON_NYLIUM moblimit: 9 + # Maxmobs - this is the maximum number of greenhouse-spawed mobs allowed in + # the greenhouse at once. Spawning will stop when this limit is reached. + # If this value is not given, there is no maximum. + maxmobs: 50 permission: greenhouses.biome.nether WARPED_FOREST: friendlyname: "&cWarped Forest" @@ -190,6 +214,10 @@ biomes: STRIDER: 10:LAVA ENDERMAN: 20:WARPED_NYLIUM moblimit: 9 + # Maxmobs - this is the maximum number of greenhouse-spawed mobs allowed in + # the greenhouse at once. Spawning will stop when this limit is reached. + # If this value is not given, there is no maximum. + maxmobs: 50 permission: greenhouses.biome.nether JUNGLE: biome: JUNGLE @@ -221,6 +249,10 @@ biomes: mobs: MUSHROOM_COW: 10:MYCELIUM moblimit: 9 + # Maxmobs - this is the maximum number of greenhouse-spawed mobs allowed in + # the greenhouse at once. Spawning will stop when this limit is reached. + # If this value is not given, there is no maximum. + maxmobs: 20 OCEAN: biome: OCEAN icon: WATER_BUCKET @@ -242,6 +274,10 @@ biomes: mobs: HORSE: 10:GRASS_BLOCK moblimit: 1 + # Maxmobs - this is the maximum number of greenhouse-spawed mobs allowed in + # the greenhouse at once. Spawning will stop when this limit is reached. + # If this value is not given, there is no maximum. + maxmobs: 10 RIVER: friendlyname: "Clay river" biome: RIVER @@ -286,6 +322,10 @@ biomes: mobs: SLIME: 5:WATER moblimit: 3 + # Maxmobs - this is the maximum number of greenhouse-spawed mobs allowed in + # the greenhouse at once. Spawning will stop when this limit is reached. + # If this value is not given, there is no maximum. + maxmobs: 10 dripstone_caves: friendlyname: "&6Drippy Drops" biome: dripstone_caves @@ -304,4 +344,8 @@ biomes: mobs: skeleton: 5:STONE glow_squid: 5:WATER - moblimit: 5 \ No newline at end of file + moblimit: 5 + # Maxmobs - this is the maximum number of greenhouse-spawed mobs allowed in + # the greenhouse at once. Spawning will stop when this limit is reached. + # If this value is not given, there is no maximum. + maxmobs: 25 \ No newline at end of file From a4fc49689b414cf526f33431503947f36290e649 Mon Sep 17 00:00:00 2001 From: tastybento Date: Wed, 1 Mar 2023 17:59:10 -0800 Subject: [PATCH 07/31] Use updated Bucket event --- .../greenhouses/listeners/GreenhouseEventsTest.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/test/java/world/bentobox/greenhouses/listeners/GreenhouseEventsTest.java b/src/test/java/world/bentobox/greenhouses/listeners/GreenhouseEventsTest.java index 27093f7..b3c27d2 100644 --- a/src/test/java/world/bentobox/greenhouses/listeners/GreenhouseEventsTest.java +++ b/src/test/java/world/bentobox/greenhouses/listeners/GreenhouseEventsTest.java @@ -27,6 +27,7 @@ import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; +import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; import org.junit.Before; @@ -137,7 +138,7 @@ public void testOnPlayerInteractInNetherInGreenhouse() { when(nextBlock.getLocation()).thenReturn(location); ItemStack item = mock(ItemStack.class); when(item.getType()).thenReturn(Material.WATER_BUCKET); - PlayerBucketEmptyEvent e = new PlayerBucketEmptyEvent(player, nextBlock, clickedBlock, BlockFace.UP, Material.WATER_BUCKET, item); + PlayerBucketEmptyEvent e = new PlayerBucketEmptyEvent(player, nextBlock, clickedBlock, BlockFace.UP, Material.WATER_BUCKET, item, EquipmentSlot.HAND); ghe.onPlayerInteractInNether(e); verify(nextBlock).setType(Material.WATER); } @@ -154,7 +155,7 @@ public void testOnPlayerInteractInNetherOutsideOfGreenhouse() { when(nextBlock.getLocation()).thenReturn(mock(Location.class)); ItemStack item = mock(ItemStack.class); when(item.getType()).thenReturn(Material.WATER_BUCKET); - PlayerBucketEmptyEvent e = new PlayerBucketEmptyEvent(player, nextBlock, clickedBlock, BlockFace.UP, Material.WATER_BUCKET, item); + PlayerBucketEmptyEvent e = new PlayerBucketEmptyEvent(player, nextBlock, clickedBlock, BlockFace.UP, Material.WATER_BUCKET, item, EquipmentSlot.HAND); ghe.onPlayerInteractInNether(e); verify(nextBlock, never()).setType(Material.WATER); } @@ -170,7 +171,7 @@ public void testOnPlayerInteractInNetherGreenhouse() { when(clickedBlock.getRelative(any())).thenReturn(nextBlock); ItemStack item = mock(ItemStack.class); when(item.getType()).thenReturn(Material.WATER_BUCKET); - PlayerBucketEmptyEvent e = new PlayerBucketEmptyEvent(player, nextBlock, clickedBlock, BlockFace.UP, Material.WATER_BUCKET, item); + PlayerBucketEmptyEvent e = new PlayerBucketEmptyEvent(player, nextBlock, clickedBlock, BlockFace.UP, Material.WATER_BUCKET, item, EquipmentSlot.HAND); ghe.onPlayerInteractInNether(e); verify(nextBlock, never()).setType(Material.WATER); } @@ -189,7 +190,7 @@ public void testOnPlayerInteractInNetherNotInNether() { when(nextBlock.getWorld()).thenReturn(world); ItemStack item = mock(ItemStack.class); when(item.getType()).thenReturn(Material.WATER_BUCKET); - PlayerBucketEmptyEvent e = new PlayerBucketEmptyEvent(player, nextBlock, clickedBlock, BlockFace.UP, Material.WATER_BUCKET, item); + PlayerBucketEmptyEvent e = new PlayerBucketEmptyEvent(player, nextBlock, clickedBlock, BlockFace.UP, Material.WATER_BUCKET, item, EquipmentSlot.HAND); ghe.onPlayerInteractInNether(e); verify(nextBlock, never()).setType(Material.WATER); } @@ -205,7 +206,7 @@ public void testOnPlayerInteractInNetherNotWaterBucket() { when(clickedBlock.getRelative(any())).thenReturn(nextBlock); ItemStack item = mock(ItemStack.class); when(item.getType()).thenReturn(Material.ACACIA_BOAT); - PlayerBucketEmptyEvent e = new PlayerBucketEmptyEvent(player, nextBlock, clickedBlock, BlockFace.UP, Material.WATER, item); + PlayerBucketEmptyEvent e = new PlayerBucketEmptyEvent(player, nextBlock, clickedBlock, BlockFace.UP, Material.WATER, item, EquipmentSlot.HAND); ghe.onPlayerInteractInNether(e); verify(nextBlock, never()).setType(Material.WATER); } @@ -222,7 +223,7 @@ public void testOnPlayerInteractInNetherNotInGreenhouse() { when(clickedBlock.getRelative(any())).thenReturn(nextBlock); ItemStack item = mock(ItemStack.class); when(item.getType()).thenReturn(Material.WATER_BUCKET); - PlayerBucketEmptyEvent e = new PlayerBucketEmptyEvent(player, nextBlock, clickedBlock, BlockFace.UP, Material.WATER_BUCKET, item); + PlayerBucketEmptyEvent e = new PlayerBucketEmptyEvent(player, nextBlock, clickedBlock, BlockFace.UP, Material.WATER_BUCKET, item, EquipmentSlot.HAND); ghe.onPlayerInteractInNether(e); verify(nextBlock, never()).setType(Material.WATER); } From e4bbb70acbb5c1679c458d91337d5e8a79fa86a4 Mon Sep 17 00:00:00 2001 From: tastybento Date: Wed, 1 Mar 2023 18:30:35 -0800 Subject: [PATCH 08/31] Added tests to cover #99 --- .../managers/EcoSystemManager.java | 19 +++-- .../managers/EcoSystemManagerTest.java | 70 ++++++++++++++++++- 2 files changed, 80 insertions(+), 9 deletions(-) diff --git a/src/main/java/world/bentobox/greenhouses/managers/EcoSystemManager.java b/src/main/java/world/bentobox/greenhouses/managers/EcoSystemManager.java index 9684e31..0e17a42 100644 --- a/src/main/java/world/bentobox/greenhouses/managers/EcoSystemManager.java +++ b/src/main/java/world/bentobox/greenhouses/managers/EcoSystemManager.java @@ -132,15 +132,21 @@ private void verify(Greenhouse gh) { } - private void addMobs(Greenhouse gh) { + /** + * Try to spawn mobs in a greenhouse + * @param gh greenhouse + * @return true if mobs were spawned, false if not + */ + boolean addMobs(Greenhouse gh) { final BoundingBox bb = gh.getBoundingBox(); if(gh.getLocation() == null || gh.getLocation().getWorld() == null || gh.getWorld() == null - || !gh.getLocation().getWorld().isChunkLoaded(((int) bb.getMaxX()) >> 4, ((int) bb.getMaxZ()) >> 4) || !gh.getLocation().getWorld().isChunkLoaded(((int) bb.getMinX()) >> 4, ((int) bb.getMinZ()) >> 4)){ + || !gh.getLocation().getWorld().isChunkLoaded(((int) bb.getMaxX()) >> 4, ((int) bb.getMaxZ()) >> 4) + || !gh.getLocation().getWorld().isChunkLoaded(((int) bb.getMinX()) >> 4, ((int) bb.getMinZ()) >> 4)){ // Skipping addmobs for unloaded greenhouse - return; + return false; } if (gh.getBiomeRecipe().noMobs()) { - return; + return false; } // Check greenhouse chunks are loaded for (double blockX = bb.getMinX(); blockX < bb.getMaxX(); blockX+=16) { @@ -148,7 +154,7 @@ private void addMobs(Greenhouse gh) { int chunkX = (int)(blockX / 16); int chunkZ = (int)(blockZ / 16); if (!gh.getWorld().isChunkLoaded(chunkX, chunkZ)) { - return; + return false; } } } @@ -162,7 +168,7 @@ private void addMobs(Greenhouse gh) { Iterator it = list.iterator(); // Check if the greenhouse is full if (sum >= gh.getBiomeRecipe().getMaxMob()) { - return; + return false; } while (it.hasNext() && (sum == 0 || gh.getArea() / sum >= gh.getBiomeRecipe().getMobLimit())) { // Spawn something if chance says so @@ -171,6 +177,7 @@ private void addMobs(Greenhouse gh) { sum++; } } + return sum > 0; } /** diff --git a/src/test/java/world/bentobox/greenhouses/managers/EcoSystemManagerTest.java b/src/test/java/world/bentobox/greenhouses/managers/EcoSystemManagerTest.java index 0961b7b..a81c9f8 100644 --- a/src/test/java/world/bentobox/greenhouses/managers/EcoSystemManagerTest.java +++ b/src/test/java/world/bentobox/greenhouses/managers/EcoSystemManagerTest.java @@ -1,6 +1,8 @@ package world.bentobox.greenhouses.managers; 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; import static org.mockito.ArgumentMatchers.anyString; @@ -9,11 +11,11 @@ import static org.mockito.Mockito.when; import java.util.List; +import java.util.Optional; import org.bukkit.Bukkit; import org.bukkit.Keyed; import org.bukkit.Location; -import org.bukkit.NamespacedKey; import org.bukkit.Tag; import org.bukkit.World; import org.bukkit.block.Block; @@ -25,13 +27,13 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.stubbing.OngoingStubbing; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import world.bentobox.bentobox.BentoBox; import world.bentobox.greenhouses.data.Greenhouse; +import world.bentobox.greenhouses.greenhouse.BiomeRecipe; import world.bentobox.greenhouses.managers.EcoSystemManager.GrowthBlock; /** @@ -39,7 +41,7 @@ * */ @RunWith(PowerMockRunner.class) -@PrepareForTest({Bukkit.class, BentoBox.class, Tag.class}) +@PrepareForTest({Bukkit.class, BentoBox.class, Tag.class, RecipeManager.class}) public class EcoSystemManagerTest { private Greenhouse gh; @@ -53,6 +55,8 @@ public class EcoSystemManagerTest { private Block liquid; @Mock private Block plant; + @Mock + private BiomeRecipe recipe; // CUT private EcoSystemManager eco; @@ -62,6 +66,7 @@ public class EcoSystemManagerTest { public void setUp() { PowerMockito.mockStatic(Tag.class, Mockito.RETURNS_MOCKS); PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS); + @SuppressWarnings("unchecked") Tag tag = mock(Tag.class); when(Bukkit.getTag(anyString(), any(), any())).thenReturn(tag); @@ -95,6 +100,12 @@ public void setUp() { // Liquid false when(block.getRelative(eq(BlockFace.UP))).thenReturn(air); + // Recipe + when(recipe.noMobs()).thenReturn(true); + PowerMockito.mockStatic(RecipeManager.class, Mockito.RETURNS_MOCKS); + when(RecipeManager.getBiomeRecipies(any())).thenReturn(Optional.of(recipe)); + + eco = new EcoSystemManager(null, null); } @@ -209,4 +220,57 @@ public void testGetAvailableBlocksAirAboveLiquidIgnoreLiquids() { assertEquals(liquid, value.block()); } } + + /** + * Test method for {@link world.bentobox.greenhouses.managers.EcoSystemManager#addMobs(Greenhouse)}. + */ + @Test + public void testAddMobsChunkNotLoaded() { + assertFalse(eco.addMobs(gh)); + } + + /** + * Test method for {@link world.bentobox.greenhouses.managers.EcoSystemManager#addMobs(Greenhouse)}. + */ + @Test + public void testAddMobsChunkLoadedNoMobs() { + when(world.isChunkLoaded(anyInt(), anyInt())).thenReturn(true); + assertFalse(eco.addMobs(gh)); + } + + /** + * Test method for {@link world.bentobox.greenhouses.managers.EcoSystemManager#addMobs(Greenhouse)}. + */ + @Test + public void testAddMobsChunkLoadedWithMobsInRecipeMaxMobsZero() { + when(world.isChunkLoaded(anyInt(), anyInt())).thenReturn(true); + when(recipe.noMobs()).thenReturn(false); + assertFalse(eco.addMobs(gh)); + } + + /** + * Test method for {@link world.bentobox.greenhouses.managers.EcoSystemManager#addMobs(Greenhouse)}. + */ + @Test + public void testAddMobsChunkLoadedWithMobsInRecipeMaxMobsNotZero() { + // Nothing spawned here + when(world.isChunkLoaded(anyInt(), anyInt())).thenReturn(true); + when(recipe.noMobs()).thenReturn(false); + when(recipe.getMaxMob()).thenReturn(10); + assertFalse(eco.addMobs(gh)); + } + + /** + * Test method for {@link world.bentobox.greenhouses.managers.EcoSystemManager#addMobs(Greenhouse)}. + */ + @Test + public void testAddMobsSpawnMob() { + // Nothing spawned here + when(world.isChunkLoaded(anyInt(), anyInt())).thenReturn(true); + when(recipe.noMobs()).thenReturn(false); + when(recipe.getMaxMob()).thenReturn(10); + when(recipe.spawnMob(any())).thenReturn(true); + assertTrue(eco.addMobs(gh)); + } + } From d2801dcd750fc51ea7b75fa8fa6ff5cd95e618fd Mon Sep 17 00:00:00 2001 From: tastybento Date: Fri, 10 Mar 2023 08:50:18 -0800 Subject: [PATCH 09/31] Fixes help text for user command. Fixes #105 --- .../java/world/bentobox/greenhouses/ui/user/UserCommand.java | 3 +-- src/main/resources/locales/en-US.yml | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/world/bentobox/greenhouses/ui/user/UserCommand.java b/src/main/java/world/bentobox/greenhouses/ui/user/UserCommand.java index 2ce4a12..f03583a 100644 --- a/src/main/java/world/bentobox/greenhouses/ui/user/UserCommand.java +++ b/src/main/java/world/bentobox/greenhouses/ui/user/UserCommand.java @@ -30,8 +30,7 @@ public UserCommand(Greenhouses gh, CompositeCommand parent) { public void setup() { this.setPermission("greenhouses.player"); this.setOnlyPlayer(true); - this.setParametersHelp("greenhouses.command.parameters"); - this.setDescription("greenhouses.command.description"); + this.setDescription("greenhouses.commands.user.description"); //new InfoCommand(this); //new ListCommand(this); diff --git a/src/main/resources/locales/en-US.yml b/src/main/resources/locales/en-US.yml index 8d1ecc6..894ab48 100644 --- a/src/main/resources/locales/en-US.yml +++ b/src/main/resources/locales/en-US.yml @@ -38,9 +38,10 @@ greenhouses: minimumblockstitle: "[Minimum blocks required]" nootherblocks: "No other blocks required." missing: "Greenhouse is missing" - + commands: user: + description: "Opens the Greenhouse selection GUI" remove: description: "Removes a greenhouse that you are standing in if you are the owner" make: From 95474d6c5328a0cd45bab7fe29971844dfbcb9a6 Mon Sep 17 00:00:00 2001 From: tastybento Date: Thu, 16 Mar 2023 22:40:43 -0400 Subject: [PATCH 10/31] Fixed maxmobs typo instead of maxmob --- .../java/world/bentobox/greenhouses/managers/RecipeManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/world/bentobox/greenhouses/managers/RecipeManager.java b/src/main/java/world/bentobox/greenhouses/managers/RecipeManager.java index 7e0f559..9b5750a 100644 --- a/src/main/java/world/bentobox/greenhouses/managers/RecipeManager.java +++ b/src/main/java/world/bentobox/greenhouses/managers/RecipeManager.java @@ -155,7 +155,7 @@ private BiomeRecipe getBiomeRecipe(ConfigurationSection biomeRecipeConfig, Strin b.setLavacoverage(biomeRecipeConfig.getInt("lavacoverage",-1)); b.setIcecoverage(biomeRecipeConfig.getInt("icecoverage",-1)); b.setMobLimit(biomeRecipeConfig.getInt("moblimit", 9)); - b.setMaxMob(biomeRecipeConfig.getInt("maxmob", -1)); + b.setMaxMob(biomeRecipeConfig.getInt("maxmobs", -1)); return b; } From 308dc225cd242a76080a553c0e989ea9d5fd5ae3 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 18 Mar 2023 11:17:52 -0400 Subject: [PATCH 11/31] Remove unused imports --- .../greenhouses/greenhouse/BiomeRecipe.java | 15 +++++++++++++-- .../greenhouses/managers/EcoSystemManager.java | 12 ++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/main/java/world/bentobox/greenhouses/greenhouse/BiomeRecipe.java b/src/main/java/world/bentobox/greenhouses/greenhouse/BiomeRecipe.java index 92ad899..cc2216b 100644 --- a/src/main/java/world/bentobox/greenhouses/greenhouse/BiomeRecipe.java +++ b/src/main/java/world/bentobox/greenhouses/greenhouse/BiomeRecipe.java @@ -38,6 +38,7 @@ import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Multimap; +import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.util.Util; import world.bentobox.greenhouses.Greenhouses; import world.bentobox.greenhouses.data.Greenhouse; @@ -376,27 +377,37 @@ public boolean spawnMob(Block b) { } // Center spawned mob Location spawnLoc = b.getLocation().clone().add(new Vector(0.5, 0, 0.5)); - return getRandomMob() + BentoBox.getInstance().logDebug("Spawning at " + spawnLoc.getBlock().getType() + " " + spawnLoc); + getRandomMob().ifPresent(m -> { + BentoBox.getInstance().logDebug("Mob is " + m.mobType()); + BentoBox.getInstance().logDebug("mobSpawnOn = " + m.mobSpawnOn()); + BentoBox.getInstance().logDebug("Block below is " + b.getRelative(BlockFace.DOWN).getType()); + }); + boolean result = getRandomMob() // Check if the spawn on block matches, if it exists .filter(m -> Optional.of(m.mobSpawnOn()) .map(b.getRelative(BlockFace.DOWN).getType()::equals) .orElse(true)) // If spawn occurs, check if it can fit inside greenhouse .map(m -> { + BentoBox.getInstance().logDebug("Mob is " + m); Entity entity = b.getWorld().spawnEntity(spawnLoc, m.mobType()); preventZombie(entity); return addon .getManager() .getMap() .getGreenhouse(b.getLocation()).map(gh -> { + BentoBox.getInstance().logDebug("Checking boundary"); if (!gh.getInternalBoundingBox().contains(entity.getBoundingBox())) { entity.remove(); + BentoBox.getInstance().logDebug("Removed"); return false; } return true; }).orElse(false); }).orElse(false); - + BentoBox.getInstance().logDebug("Result = " + result); + return result; } /** diff --git a/src/main/java/world/bentobox/greenhouses/managers/EcoSystemManager.java b/src/main/java/world/bentobox/greenhouses/managers/EcoSystemManager.java index 0e17a42..8a4a73b 100644 --- a/src/main/java/world/bentobox/greenhouses/managers/EcoSystemManager.java +++ b/src/main/java/world/bentobox/greenhouses/managers/EcoSystemManager.java @@ -19,6 +19,7 @@ import org.bukkit.util.BoundingBox; import org.bukkit.util.NumberConversions; +import world.bentobox.bentobox.BentoBox; import world.bentobox.greenhouses.Greenhouses; import world.bentobox.greenhouses.data.Greenhouse; import world.bentobox.greenhouses.greenhouse.BiomeRecipe; @@ -138,14 +139,17 @@ private void verify(Greenhouse gh) { * @return true if mobs were spawned, false if not */ boolean addMobs(Greenhouse gh) { + BentoBox.getInstance().logDebug("Adding mobs"); final BoundingBox bb = gh.getBoundingBox(); if(gh.getLocation() == null || gh.getLocation().getWorld() == null || gh.getWorld() == null || !gh.getLocation().getWorld().isChunkLoaded(((int) bb.getMaxX()) >> 4, ((int) bb.getMaxZ()) >> 4) || !gh.getLocation().getWorld().isChunkLoaded(((int) bb.getMinX()) >> 4, ((int) bb.getMinZ()) >> 4)){ // Skipping addmobs for unloaded greenhouse + BentoBox.getInstance().logDebug("unloaded gh"); return false; } if (gh.getBiomeRecipe().noMobs()) { + BentoBox.getInstance().logDebug("No mobs in recipe"); return false; } // Check greenhouse chunks are loaded @@ -154,6 +158,7 @@ boolean addMobs(Greenhouse gh) { int chunkX = (int)(blockX / 16); int chunkZ = (int)(blockZ / 16); if (!gh.getWorld().isChunkLoaded(chunkX, chunkZ)) { + BentoBox.getInstance().logDebug("Chunks not loaded"); return false; } } @@ -164,19 +169,26 @@ boolean addMobs(Greenhouse gh) { .filter(e -> gh.contains(e.getLocation())).count(); // Get the blocks in the greenhouse where spawning could occur List list = new ArrayList<>(getAvailableBlocks(gh, false)); + BentoBox.getInstance().logDebug("Entities = " + sum + " available blocks are " + list.size()); + list.forEach(gb -> BentoBox.getInstance().logDebug(gb.block.getType())); Collections.shuffle(list, new Random(System.currentTimeMillis())); Iterator it = list.iterator(); // Check if the greenhouse is full if (sum >= gh.getBiomeRecipe().getMaxMob()) { + BentoBox.getInstance().logDebug("GH is full"); return false; } while (it.hasNext() && (sum == 0 || gh.getArea() / sum >= gh.getBiomeRecipe().getMobLimit())) { // Spawn something if chance says so if (gh.getBiomeRecipe().spawnMob(it.next().block())) { // Add a mob to the sum in the greenhouse + BentoBox.getInstance().logDebug("Spawned a mob"); sum++; } } + if (sum == 0 ) { + BentoBox.getInstance().logDebug("Nothing spawned"); + } return sum > 0; } From 3740268dfcd71c5d4fdb48272e0ad008659dd660 Mon Sep 17 00:00:00 2001 From: BONNe Date: Sun, 26 Mar 2023 14:04:06 +0300 Subject: [PATCH 12/31] Update to new Bukkit Loader --- .../java/world/bentobox/greenhouses/GreenhousesPladdon.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/world/bentobox/greenhouses/GreenhousesPladdon.java b/src/main/java/world/bentobox/greenhouses/GreenhousesPladdon.java index f5531e0..dc4f6a3 100644 --- a/src/main/java/world/bentobox/greenhouses/GreenhousesPladdon.java +++ b/src/main/java/world/bentobox/greenhouses/GreenhousesPladdon.java @@ -1,7 +1,6 @@ package world.bentobox.greenhouses; -import org.bukkit.plugin.java.annotation.dependency.Dependency; import org.bukkit.plugin.java.annotation.plugin.ApiVersion; import org.bukkit.plugin.java.annotation.plugin.Plugin; @@ -12,9 +11,8 @@ /** * @author tastybento */ -@Plugin(name = "Pladdon", version = "1.0") +@Plugin(name = "Greenhouses", version = "1.0") @ApiVersion(ApiVersion.Target.v1_18) -@Dependency(value = "BentoBox") public class GreenhousesPladdon extends Pladdon { @Override From ac1d6e6638331681f3a7ba5c3e5d1619c79bc28a Mon Sep 17 00:00:00 2001 From: tastybento Date: Sun, 26 Mar 2023 10:25:40 -0700 Subject: [PATCH 13/31] Remove debug --- .../bentobox/greenhouses/greenhouse/BiomeRecipe.java | 11 ----------- .../greenhouses/managers/EcoSystemManager.java | 12 ------------ 2 files changed, 23 deletions(-) diff --git a/src/main/java/world/bentobox/greenhouses/greenhouse/BiomeRecipe.java b/src/main/java/world/bentobox/greenhouses/greenhouse/BiomeRecipe.java index cc2216b..a589f77 100644 --- a/src/main/java/world/bentobox/greenhouses/greenhouse/BiomeRecipe.java +++ b/src/main/java/world/bentobox/greenhouses/greenhouse/BiomeRecipe.java @@ -38,7 +38,6 @@ import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Multimap; -import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.util.Util; import world.bentobox.greenhouses.Greenhouses; import world.bentobox.greenhouses.data.Greenhouse; @@ -377,12 +376,6 @@ public boolean spawnMob(Block b) { } // Center spawned mob Location spawnLoc = b.getLocation().clone().add(new Vector(0.5, 0, 0.5)); - BentoBox.getInstance().logDebug("Spawning at " + spawnLoc.getBlock().getType() + " " + spawnLoc); - getRandomMob().ifPresent(m -> { - BentoBox.getInstance().logDebug("Mob is " + m.mobType()); - BentoBox.getInstance().logDebug("mobSpawnOn = " + m.mobSpawnOn()); - BentoBox.getInstance().logDebug("Block below is " + b.getRelative(BlockFace.DOWN).getType()); - }); boolean result = getRandomMob() // Check if the spawn on block matches, if it exists .filter(m -> Optional.of(m.mobSpawnOn()) @@ -390,23 +383,19 @@ public boolean spawnMob(Block b) { .orElse(true)) // If spawn occurs, check if it can fit inside greenhouse .map(m -> { - BentoBox.getInstance().logDebug("Mob is " + m); Entity entity = b.getWorld().spawnEntity(spawnLoc, m.mobType()); preventZombie(entity); return addon .getManager() .getMap() .getGreenhouse(b.getLocation()).map(gh -> { - BentoBox.getInstance().logDebug("Checking boundary"); if (!gh.getInternalBoundingBox().contains(entity.getBoundingBox())) { entity.remove(); - BentoBox.getInstance().logDebug("Removed"); return false; } return true; }).orElse(false); }).orElse(false); - BentoBox.getInstance().logDebug("Result = " + result); return result; } diff --git a/src/main/java/world/bentobox/greenhouses/managers/EcoSystemManager.java b/src/main/java/world/bentobox/greenhouses/managers/EcoSystemManager.java index 8a4a73b..0e17a42 100644 --- a/src/main/java/world/bentobox/greenhouses/managers/EcoSystemManager.java +++ b/src/main/java/world/bentobox/greenhouses/managers/EcoSystemManager.java @@ -19,7 +19,6 @@ import org.bukkit.util.BoundingBox; import org.bukkit.util.NumberConversions; -import world.bentobox.bentobox.BentoBox; import world.bentobox.greenhouses.Greenhouses; import world.bentobox.greenhouses.data.Greenhouse; import world.bentobox.greenhouses.greenhouse.BiomeRecipe; @@ -139,17 +138,14 @@ private void verify(Greenhouse gh) { * @return true if mobs were spawned, false if not */ boolean addMobs(Greenhouse gh) { - BentoBox.getInstance().logDebug("Adding mobs"); final BoundingBox bb = gh.getBoundingBox(); if(gh.getLocation() == null || gh.getLocation().getWorld() == null || gh.getWorld() == null || !gh.getLocation().getWorld().isChunkLoaded(((int) bb.getMaxX()) >> 4, ((int) bb.getMaxZ()) >> 4) || !gh.getLocation().getWorld().isChunkLoaded(((int) bb.getMinX()) >> 4, ((int) bb.getMinZ()) >> 4)){ // Skipping addmobs for unloaded greenhouse - BentoBox.getInstance().logDebug("unloaded gh"); return false; } if (gh.getBiomeRecipe().noMobs()) { - BentoBox.getInstance().logDebug("No mobs in recipe"); return false; } // Check greenhouse chunks are loaded @@ -158,7 +154,6 @@ boolean addMobs(Greenhouse gh) { int chunkX = (int)(blockX / 16); int chunkZ = (int)(blockZ / 16); if (!gh.getWorld().isChunkLoaded(chunkX, chunkZ)) { - BentoBox.getInstance().logDebug("Chunks not loaded"); return false; } } @@ -169,26 +164,19 @@ boolean addMobs(Greenhouse gh) { .filter(e -> gh.contains(e.getLocation())).count(); // Get the blocks in the greenhouse where spawning could occur List list = new ArrayList<>(getAvailableBlocks(gh, false)); - BentoBox.getInstance().logDebug("Entities = " + sum + " available blocks are " + list.size()); - list.forEach(gb -> BentoBox.getInstance().logDebug(gb.block.getType())); Collections.shuffle(list, new Random(System.currentTimeMillis())); Iterator it = list.iterator(); // Check if the greenhouse is full if (sum >= gh.getBiomeRecipe().getMaxMob()) { - BentoBox.getInstance().logDebug("GH is full"); return false; } while (it.hasNext() && (sum == 0 || gh.getArea() / sum >= gh.getBiomeRecipe().getMobLimit())) { // Spawn something if chance says so if (gh.getBiomeRecipe().spawnMob(it.next().block())) { // Add a mob to the sum in the greenhouse - BentoBox.getInstance().logDebug("Spawned a mob"); sum++; } } - if (sum == 0 ) { - BentoBox.getInstance().logDebug("Nothing spawned"); - } return sum > 0; } From db5ef4d5dadfd7753b3d2b46d41c9f204a112b43 Mon Sep 17 00:00:00 2001 From: BONNe Date: Sat, 8 Apr 2023 18:39:46 +0300 Subject: [PATCH 14/31] Create plugin.yml (#106) * Create plugin.yml * Update pom.xml * Update GreenhousesPladdon.java --- pom.xml | 6 ------ .../world/bentobox/greenhouses/GreenhousesPladdon.java | 5 ----- src/main/resources/plugin.yml | 9 +++++++++ 3 files changed, 9 insertions(+), 11 deletions(-) create mode 100644 src/main/resources/plugin.yml diff --git a/pom.xml b/pom.xml index 5efa26c..c940abd 100644 --- a/pom.xml +++ b/pom.xml @@ -116,12 +116,6 @@ ${spigot.version} provided - - org.spigotmc - plugin-annotations - 1.2.3-SNAPSHOT - provided - world.bentobox bentobox diff --git a/src/main/java/world/bentobox/greenhouses/GreenhousesPladdon.java b/src/main/java/world/bentobox/greenhouses/GreenhousesPladdon.java index dc4f6a3..336bdfb 100644 --- a/src/main/java/world/bentobox/greenhouses/GreenhousesPladdon.java +++ b/src/main/java/world/bentobox/greenhouses/GreenhousesPladdon.java @@ -1,9 +1,6 @@ package world.bentobox.greenhouses; -import org.bukkit.plugin.java.annotation.plugin.ApiVersion; -import org.bukkit.plugin.java.annotation.plugin.Plugin; - import world.bentobox.bentobox.api.addons.Addon; import world.bentobox.bentobox.api.addons.Pladdon; @@ -11,8 +8,6 @@ /** * @author tastybento */ -@Plugin(name = "Greenhouses", version = "1.0") -@ApiVersion(ApiVersion.Target.v1_18) public class GreenhousesPladdon extends Pladdon { @Override diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..49ec66d --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,9 @@ +name: BentoBox-Greenhouses +main: world.bentobox.greenhouses.GreenhousesPladdon +version: ${project.version}${build.number} +api-version: "1.19" + +authors: [tastybento] +contributors: ["The BentoBoxWorld Community"] +website: https://bentobox.world +description: ${project.description} From e6a1cd17bbc2704640e25731411105d7cc6ad095 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sun, 4 Jun 2023 08:44:55 -0700 Subject: [PATCH 15/31] Removed static getInstance usage --- .../bentobox/greenhouses/Greenhouses.java | 18 +++++--- .../greenhouses/greenhouse/BiomeRecipe.java | 2 +- .../bentobox/greenhouses/greenhouse/Roof.java | 44 ++++++++----------- .../greenhouses/greenhouse/Walls.java | 31 +++---------- .../managers/GreenhouseFinder.java | 17 +++++-- .../managers/GreenhouseManager.java | 28 ++++++------ .../greenhouses/world/AsyncWorldCache.java | 8 ++-- .../greenhouses/greenhouse/RoofTest.java | 34 +++++++------- .../greenhouses/greenhouse/WallsTest.java | 32 +++++++------- .../managers/GreenhouseFinderTest.java | 6 ++- 10 files changed, 106 insertions(+), 114 deletions(-) diff --git a/src/main/java/world/bentobox/greenhouses/Greenhouses.java b/src/main/java/world/bentobox/greenhouses/Greenhouses.java index d3ed568..995bddb 100644 --- a/src/main/java/world/bentobox/greenhouses/Greenhouses.java +++ b/src/main/java/world/bentobox/greenhouses/Greenhouses.java @@ -11,6 +11,7 @@ import world.bentobox.bentobox.api.flags.Flag; import world.bentobox.bentobox.api.flags.Flag.Mode; 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.RecipeManager; 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) .mode(Mode.BASIC) .type(Type.PROTECTION).build(); - private static Greenhouses instance; private final Config config; - public static Greenhouses getInstance() { - return instance; - } - /** * Constructor */ public Greenhouses() { super(); - instance = this; config = new Config<>(this, Settings.class); } @@ -122,4 +117,15 @@ public List getActiveWorlds() { 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()); + } + } diff --git a/src/main/java/world/bentobox/greenhouses/greenhouse/BiomeRecipe.java b/src/main/java/world/bentobox/greenhouses/greenhouse/BiomeRecipe.java index a589f77..998a0d5 100644 --- a/src/main/java/world/bentobox/greenhouses/greenhouse/BiomeRecipe.java +++ b/src/main/java/world/bentobox/greenhouses/greenhouse/BiomeRecipe.java @@ -209,7 +209,7 @@ public CompletableFuture> checkRecipe(Greenhouse gh) { * @return set of results from the check */ private Set checkRecipeAsync(CompletableFuture> r, Greenhouse gh) { - AsyncWorldCache cache = new AsyncWorldCache(gh.getWorld()); + AsyncWorldCache cache = new AsyncWorldCache(addon, gh.getWorld()); Set result = new HashSet<>(); long area = gh.getArea(); Map blockCount = new EnumMap<>(Material.class); diff --git a/src/main/java/world/bentobox/greenhouses/greenhouse/Roof.java b/src/main/java/world/bentobox/greenhouses/greenhouse/Roof.java index 1a62454..474e16b 100644 --- a/src/main/java/world/bentobox/greenhouses/greenhouse/Roof.java +++ b/src/main/java/world/bentobox/greenhouses/greenhouse/Roof.java @@ -23,33 +23,17 @@ * @author tastybento * */ -@SuppressWarnings("deprecation") public class Roof extends MinMaxXZ { - private static final List ROOF_BLOCKS; - static { - // Roof blocks - ROOF_BLOCKS = Arrays.stream(Material.values()) - .filter(m -> !m.isLegacy()) - .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 static final List ROOF_BLOCKS = Arrays.stream(Material.values()) + .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(); private final AsyncWorldCache cache; private int height; private final Location location; private boolean roofFound; - + private final Greenhouses addon; private final World world; @@ -58,13 +42,23 @@ public static boolean roofBlocks(@NonNull Material m) { * @param cache async world cache * @param loc - starting location */ - public Roof(AsyncWorldCache cache, Location loc) { + public Roof(AsyncWorldCache cache, Location loc, Greenhouses addon) { this.cache = cache; this.location = loc; + this.addon = addon; 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 @@ -211,7 +205,7 @@ private Vector spiralSearch(Vector v, int startY) { * @param z - z coord of current search */ private Optional 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 for (int y = startY; y < world.getMaxHeight() && !roofFound; y++) { if (roofBlocks(cache.getBlockType(x,y,z))) { diff --git a/src/main/java/world/bentobox/greenhouses/greenhouse/Walls.java b/src/main/java/world/bentobox/greenhouses/greenhouse/Walls.java index d4a0890..1f34937 100644 --- a/src/main/java/world/bentobox/greenhouses/greenhouse/Walls.java +++ b/src/main/java/world/bentobox/greenhouses/greenhouse/Walls.java @@ -9,25 +9,17 @@ import org.bukkit.Material; import world.bentobox.bentobox.BentoBox; -import world.bentobox.greenhouses.Greenhouses; import world.bentobox.greenhouses.world.AsyncWorldCache; -@SuppressWarnings("deprecation") public class Walls extends MinMaxXZ { - private static final List WALL_BLOCKS; - static { - // Hoppers - WALL_BLOCKS = Arrays.stream(Material.values()) - .filter(Material::isBlock) // Blocks only, no items - .filter(m -> !m.isLegacy()) - .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(); - } + public static final List WALL_BLOCKS = Arrays.stream(Material.values()) + .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") && !m.name().contains("GLASS_PANE")) // All glass blocks + || m.equals(Material.HOPPER)).toList(); private int floor; - private final AsyncWorldCache cache; static class WallFinder { @@ -177,17 +169,6 @@ int getFloorY(int y, int minX, int maxX, int minZ, int maxZ, int minY) { } - /** - * 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 */ diff --git a/src/main/java/world/bentobox/greenhouses/managers/GreenhouseFinder.java b/src/main/java/world/bentobox/greenhouses/managers/GreenhouseFinder.java index e7b29f5..37257ed 100644 --- a/src/main/java/world/bentobox/greenhouses/managers/GreenhouseFinder.java +++ b/src/main/java/world/bentobox/greenhouses/managers/GreenhouseFinder.java @@ -12,6 +12,7 @@ import org.bukkit.util.Vector; import world.bentobox.bentobox.BentoBox; +import world.bentobox.greenhouses.Greenhouses; import world.bentobox.greenhouses.data.Greenhouse; import world.bentobox.greenhouses.greenhouse.Roof; 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 private int otherBlockLayer = -1; private int wallBlockCount; + private final Greenhouses addon; /** * This is the count of the various items */ private CounterCheck cc = new CounterCheck(); + private Roof roof; static class CounterCheck { int doorCount; @@ -40,6 +43,13 @@ static class CounterCheck { boolean otherBlock; } + /** + * @param addon + */ + public GreenhouseFinder(Greenhouses addon) { + this.addon = addon; + } + /** * Find out if there is a greenhouse here * @param location - start location @@ -51,9 +61,9 @@ public CompletableFuture> find(Location location) { redGlass.clear(); // Get a world cache - AsyncWorldCache cache = new AsyncWorldCache(location.getWorld()); + AsyncWorldCache cache = new AsyncWorldCache(addon, location.getWorld()); // Find the roof - Roof roof = new Roof(cache, location); + roof = new Roof(cache, location, addon); roof.findRoof().thenAccept(found -> { if (Boolean.FALSE.equals(found)) { result.add(GreenhouseResult.FAIL_NO_ROOF); @@ -166,7 +176,8 @@ boolean checkBlock(CounterCheck cc, Material m, Roof roof, Walls walls, Vector v // Check wall blocks only 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 - 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)) { // Air hole found cc.airHole = true; diff --git a/src/main/java/world/bentobox/greenhouses/managers/GreenhouseManager.java b/src/main/java/world/bentobox/greenhouses/managers/GreenhouseManager.java index a18e569..13f1e70 100644 --- a/src/main/java/world/bentobox/greenhouses/managers/GreenhouseManager.java +++ b/src/main/java/world/bentobox/greenhouses/managers/GreenhouseManager.java @@ -96,19 +96,19 @@ private void loadGreenhouses() { handler.loadObjects().forEach(g -> { GreenhouseResult result = map.addGreenhouse(g); switch (result) { - case FAIL_NO_ISLAND -> - // Delete the failed greenhouse - toBeRemoved.add(g); - case FAIL_OVERLAPPING -> addon.logError("Greenhouse overlaps with another greenhouse. Skipping..."); - case NULL -> addon.logError("Null location of greenhouse. Cannot load. Skipping..."); - case SUCCESS -> activateGreenhouse(g); - case FAIL_NO_WORLD -> addon.logError("Database contains greenhouse for a non-loaded world. Skipping..."); - case FAIL_UNKNOWN_RECIPE -> { - addon.logError("Greenhouse uses a recipe that does not exist in the biomes.yml. Skipping..."); - addon.logError("Greenhouse Id " + g.getUniqueId()); - } - default -> { - } + case FAIL_NO_ISLAND -> + // Delete the failed greenhouse + toBeRemoved.add(g); + case FAIL_OVERLAPPING -> addon.logError("Greenhouse overlaps with another greenhouse. Skipping..."); + case NULL -> addon.logError("Null location of greenhouse. Cannot load. Skipping..."); + case SUCCESS -> activateGreenhouse(g); + case FAIL_NO_WORLD -> addon.logError("Database contains greenhouse for a non-loaded world. Skipping..."); + case FAIL_UNKNOWN_RECIPE -> { + addon.logError("Greenhouse uses a recipe that does not exist in the biomes.yml. Skipping..."); + addon.logError("Greenhouse Id " + g.getUniqueId()); + } + default -> { + } } }); addon.log("Loaded " + map.getSize() + " greenhouses."); @@ -153,7 +153,7 @@ public void removeGreenhouse(Greenhouse gh) { */ public CompletableFuture tryToMakeGreenhouse(Location location, BiomeRecipe greenhouseRecipe) { CompletableFuture r = new CompletableFuture<>(); - GreenhouseFinder finder = new GreenhouseFinder(); + GreenhouseFinder finder = new GreenhouseFinder(addon); finder.find(location).thenAccept(resultSet -> { if (!resultSet.isEmpty()) { // Failure! diff --git a/src/main/java/world/bentobox/greenhouses/world/AsyncWorldCache.java b/src/main/java/world/bentobox/greenhouses/world/AsyncWorldCache.java index 05c5ce0..4313fbc 100644 --- a/src/main/java/world/bentobox/greenhouses/world/AsyncWorldCache.java +++ b/src/main/java/world/bentobox/greenhouses/world/AsyncWorldCache.java @@ -27,14 +27,16 @@ public class AsyncWorldCache { private final World world; private final Map, ChunkSnapshot> cache; + private final Greenhouses addon; /** * Chunk cache. This class is designed to be run async and blocks futures * @param world - world to cache */ - public AsyncWorldCache(World world) { + public AsyncWorldCache(Greenhouses addon, World world) { this.world = world; cache = new HashMap<>(); + this.addon = addon; } /** @@ -59,7 +61,7 @@ public int getMaxHeight() { */ private CompletableFuture getAChunk(int x, int z) { CompletableFuture 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()))); return r; } @@ -104,7 +106,7 @@ public Material getBlockType(final int x, final int y, final int z) { try { return Objects.requireNonNull(getSnap(x, z)).getBlockType(xx, y, zz); } 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... Thread.currentThread().interrupt(); return Material.AIR; diff --git a/src/test/java/world/bentobox/greenhouses/greenhouse/RoofTest.java b/src/test/java/world/bentobox/greenhouses/greenhouse/RoofTest.java index 8b23894..b21e5e8 100644 --- a/src/test/java/world/bentobox/greenhouses/greenhouse/RoofTest.java +++ b/src/test/java/world/bentobox/greenhouses/greenhouse/RoofTest.java @@ -50,8 +50,6 @@ public class RoofTest { public void setUp() { 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(); when(addon.getSettings()).thenReturn(s); @@ -89,14 +87,14 @@ public void setUp() { when(location.clone()).thenReturn(location); // Test - roof = new Roof(cache, location); + roof = new Roof(cache, location, addon); assertTrue(roof.findRoof(new Vector(10,10,10))); } @Test public void testNoGlass() { 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))); } @@ -169,13 +167,13 @@ public void testToString() { */ @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)); + 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)); } /** @@ -185,12 +183,12 @@ public void testWallBlocks() { 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)); + 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 7231f34..5e4d279 100644 --- a/src/test/java/world/bentobox/greenhouses/greenhouse/WallsTest.java +++ b/src/test/java/world/bentobox/greenhouses/greenhouse/WallsTest.java @@ -64,12 +64,10 @@ public void setUp() { 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(); when(addon.getSettings()).thenReturn(s); when(addon.getPlugin()).thenReturn(plugin); - + when(addon.wallBlocks(any())).thenCallRealMethod(); walls = new Walls(cache); when(world.getMaxHeight()).thenReturn(255); when(location.getWorld()).thenReturn(world); @@ -201,13 +199,13 @@ public void testGetFloorY() { */ @Test 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)); + assertFalse(addon.wallBlocks(Material.ACACIA_BOAT)); + assertTrue(addon.wallBlocks(Material.GLASS)); + assertTrue(addon.wallBlocks(Material.GLOWSTONE)); + assertTrue(addon.wallBlocks(Material.ACACIA_DOOR)); + assertTrue(addon.wallBlocks(Material.HOPPER)); + assertTrue(addon.wallBlocks(Material.PURPLE_STAINED_GLASS_PANE)); + assertFalse(addon.wallBlocks(Material.BIRCH_TRAPDOOR)); } /** @@ -217,13 +215,13 @@ public void testWallBlocks() { 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)); + assertFalse(addon.wallBlocks(Material.ACACIA_BOAT)); + assertTrue(addon.wallBlocks(Material.GLASS)); + assertFalse(addon.wallBlocks(Material.GLOWSTONE)); + assertTrue(addon.wallBlocks(Material.ACACIA_DOOR)); + assertTrue(addon.wallBlocks(Material.HOPPER)); + assertFalse(addon.wallBlocks(Material.PURPLE_STAINED_GLASS_PANE)); + assertFalse(addon.wallBlocks(Material.BIRCH_TRAPDOOR)); } /** diff --git a/src/test/java/world/bentobox/greenhouses/managers/GreenhouseFinderTest.java b/src/test/java/world/bentobox/greenhouses/managers/GreenhouseFinderTest.java index ca8139f..d081a12 100644 --- a/src/test/java/world/bentobox/greenhouses/managers/GreenhouseFinderTest.java +++ b/src/test/java/world/bentobox/greenhouses/managers/GreenhouseFinderTest.java @@ -71,12 +71,14 @@ public void setUp() { when(Tag.TRAPDOORS.isTagged(Material.BIRCH_TRAPDOOR)).thenReturn(true); // Declare mock after mocking Bukkit roof = mock(Roof.class); + when(roof.roofBlocks(any())).thenCallRealMethod(); // Location when(location.getBlockX()).thenReturn(5); when(location.getBlockY()).thenReturn(14); when(location.getBlockZ()).thenReturn(25); when(location.getWorld()).thenReturn(world); - + // Addon + when(addon.wallBlocks(any())).thenCallRealMethod(); // Block when(cache.getBlockType(any())).thenReturn(Material.GLASS); when(cache.getBlockType(anyInt(), anyInt(), anyInt())).thenReturn(Material.GLASS); @@ -94,7 +96,7 @@ public void setUp() { when(cache.getMaxHeight()).thenReturn(30); - gf = new GreenhouseFinder(); + gf = new GreenhouseFinder(addon); cc = new CounterCheck(); } From a2c29753292c6ea764e10ed1131cccbece83dcb6 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sun, 4 Jun 2023 08:46:33 -0700 Subject: [PATCH 16/31] Version 1.7.4 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c940abd..30b55e0 100644 --- a/pom.xml +++ b/pom.xml @@ -51,7 +51,7 @@ ${build.version}-SNAPSHOT - 1.7.3 + 1.7.4 -LOCAL BentoBoxWorld_Greenhouses bentobox-world From cce4a655c6bdb74be918d5497704a9bb1815d761 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sun, 4 Jun 2023 08:55:02 -0700 Subject: [PATCH 17/31] Refactored to reduce complexity --- .../greenhouses/greenhouse/BiomeRecipe.java | 58 +++++++++++-------- 1 file changed, 35 insertions(+), 23 deletions(-) diff --git a/src/main/java/world/bentobox/greenhouses/greenhouse/BiomeRecipe.java b/src/main/java/world/bentobox/greenhouses/greenhouse/BiomeRecipe.java index 998a0d5..83b5412 100644 --- a/src/main/java/world/bentobox/greenhouses/greenhouse/BiomeRecipe.java +++ b/src/main/java/world/bentobox/greenhouses/greenhouse/BiomeRecipe.java @@ -210,23 +210,29 @@ public CompletableFuture> checkRecipe(Greenhouse gh) { */ private Set checkRecipeAsync(CompletableFuture> r, Greenhouse gh) { AsyncWorldCache cache = new AsyncWorldCache(addon, gh.getWorld()); - Set result = new HashSet<>(); long area = gh.getArea(); - Map blockCount = new EnumMap<>(Material.class); // Look through the greenhouse and count what is in there - for (int y = gh.getFloorHeight(); y< gh.getCeilingHeight();y++) { - for (int x = (int) (gh.getBoundingBox().getMinX()+1); x < gh.getBoundingBox().getMaxX(); x++) { - for (int z = (int) (gh.getBoundingBox().getMinZ()+1); z < gh.getBoundingBox().getMaxZ(); z++) { - Material t = cache.getBlockType(x, y, z); - if (!t.equals(Material.AIR)) { - blockCount.putIfAbsent(t, 0); - blockCount.merge(t, 1, Integer::sum); - } - } - } + Map blockCount = countBlocks(gh, cache); + + // Calculate % water, ice and lava ratios and check them + Set result = checkRatios(blockCount, area); + + // Compare to the required blocks + Map missingBlocks = requiredBlocks.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue() - blockCount.getOrDefault(e.getKey(), 0))); + // Remove any entries that are 0 or less + missingBlocks.values().removeIf(v -> v <= 0); + if (!missingBlocks.isEmpty()) { + result.add(GreenhouseResult.FAIL_INSUFFICIENT_BLOCKS); + gh.setMissingBlocks(missingBlocks); } - // Calculate % water, ice and lava ratios + // Return to main thread to complete + Bukkit.getScheduler().runTask(addon.getPlugin(), () -> r.complete(result)); + return result; + } + + private Set checkRatios(Map blockCount, long area) { + Set result = new HashSet<>(); double waterRatio = (double)blockCount.getOrDefault(Material.WATER, 0)/area * 100; double lavaRatio = (double)blockCount.getOrDefault(Material.LAVA, 0)/area * 100; int ice = blockCount.entrySet().stream().filter(en -> en.getKey().equals(Material.ICE) @@ -254,19 +260,25 @@ private Set checkRecipeAsync(CompletableFuture 0 && iceRatio < iceCoverage) { result.add(GreenhouseResult.FAIL_INSUFFICIENT_ICE); } - // Compare to the required blocks - Map missingBlocks = requiredBlocks.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue() - blockCount.getOrDefault(e.getKey(), 0))); - // Remove any entries that are 0 or less - missingBlocks.values().removeIf(v -> v <= 0); - if (!missingBlocks.isEmpty()) { - result.add(GreenhouseResult.FAIL_INSUFFICIENT_BLOCKS); - gh.setMissingBlocks(missingBlocks); - } - // Return to main thread to complete - Bukkit.getScheduler().runTask(addon.getPlugin(), () -> r.complete(result)); return result; } + private Map countBlocks(Greenhouse gh, AsyncWorldCache cache) { + Map blockCount = new EnumMap<>(Material.class); + for (int y = gh.getFloorHeight(); y< gh.getCeilingHeight();y++) { + for (int x = (int) (gh.getBoundingBox().getMinX()+1); x < gh.getBoundingBox().getMaxX(); x++) { + for (int z = (int) (gh.getBoundingBox().getMinZ()+1); z < gh.getBoundingBox().getMaxZ(); z++) { + Material t = cache.getBlockType(x, y, z); + if (!t.equals(Material.AIR)) { + blockCount.putIfAbsent(t, 0); + blockCount.merge(t, 1, Integer::sum); + } + } + } + } + return blockCount; + } + /** * Check if block should be converted * @param b - block to check From 3dd950459f865ee733bbb969e7957477355d6304 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sun, 4 Jun 2023 08:57:01 -0700 Subject: [PATCH 18/31] Update surefire plugin --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 30b55e0..bf9c2e5 100644 --- a/pom.xml +++ b/pom.xml @@ -191,7 +191,7 @@ org.apache.maven.plugins maven-surefire-plugin - 3.0.0-M5 + 3.1.0 ${argLine} From 2eed3dcd56d471dcbc77cef73311a4520068d9a8 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sun, 4 Jun 2023 09:03:38 -0700 Subject: [PATCH 19/31] Refactored to reduce complexity --- .../greenhouses/greenhouse/BiomeRecipe.java | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/main/java/world/bentobox/greenhouses/greenhouse/BiomeRecipe.java b/src/main/java/world/bentobox/greenhouses/greenhouse/BiomeRecipe.java index 83b5412..1f3f486 100644 --- a/src/main/java/world/bentobox/greenhouses/greenhouse/BiomeRecipe.java +++ b/src/main/java/world/bentobox/greenhouses/greenhouse/BiomeRecipe.java @@ -288,23 +288,27 @@ public void convertBlock(Block b) { // Check if there is a block conversion for this block, as while the rest of the method wont do anything if .get() returns nothing anyway it still seems to be quite expensive if(conversionBlocks.keySet().contains(bType)) { for(GreenhouseBlockConversions conversion_option : conversionBlocks.get(bType)) { + rollTheDice(b, conversion_option); + } + } + } - // Roll the dice before bothering with checking the surrounding block as I think it's more common for greenhouses to be filled with convertable blocks and thus this dice roll wont be "wasted" - if(ThreadLocalRandom.current().nextDouble() < conversion_option.probability()) { - // Check if any of the adjacent blocks matches the required LocalMaterial, if there are any required LocalMaterials - if(conversion_option.localMaterial() != null) { - for(BlockFace adjacent_block : ADJ_BLOCKS) { - if(b.getRelative(adjacent_block).getType() == conversion_option.localMaterial()) { - b.setType(conversion_option.newMaterial()); - break; - } - } - } else { + private void rollTheDice(Block b, GreenhouseBlockConversions conversion_option) { + // Roll the dice before bothering with checking the surrounding block as I think it's more common for greenhouses to be filled with convertable blocks and thus this dice roll wont be "wasted" + if(ThreadLocalRandom.current().nextDouble() < conversion_option.probability()) { + // Check if any of the adjacent blocks matches the required LocalMaterial, if there are any required LocalMaterials + if(conversion_option.localMaterial() != null) { + for(BlockFace adjacent_block : ADJ_BLOCKS) { + if(b.getRelative(adjacent_block).getType() == conversion_option.localMaterial()) { b.setType(conversion_option.newMaterial()); + break; } } + } else { + b.setType(conversion_option.newMaterial()); } } + } /** @@ -388,7 +392,7 @@ public boolean spawnMob(Block b) { } // Center spawned mob Location spawnLoc = b.getLocation().clone().add(new Vector(0.5, 0, 0.5)); - boolean result = getRandomMob() + return getRandomMob() // Check if the spawn on block matches, if it exists .filter(m -> Optional.of(m.mobSpawnOn()) .map(b.getRelative(BlockFace.DOWN).getType()::equals) @@ -408,7 +412,6 @@ public boolean spawnMob(Block b) { return true; }).orElse(false); }).orElse(false); - return result; } /** From 398c8e91d52ad68115c4caf613dc889e74388eb1 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sun, 4 Jun 2023 09:11:15 -0700 Subject: [PATCH 20/31] Minor typos and grammar fixes --- README.md | 6 +++--- .../world/bentobox/greenhouses/greenhouse/BiomeRecipe.java | 2 +- .../java/world/bentobox/greenhouses/greenhouse/Roof.java | 6 +++--- .../bentobox/greenhouses/listeners/GreenhouseGuard.java | 2 +- .../bentobox/greenhouses/managers/GreenhouseFinder.java | 4 ++-- src/main/resources/locales/en-US.yml | 6 +++--- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 3dd4bd7..a679ad8 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Greenhouses are made out of glass and must contain the blocks found in the Biome * Craft your own self-contained biome greenhouse on an island (or elsewhere if you like) * Greenhouses can grow plants that cannot normally be grown, like sunflowers -* Friendly mobs can spawn if your greenhouse is well designed - need slimes? Build a swamp greenhouse! +* Friendly mobs can spawn if your greenhouse is well-designed - need slimes? Build a swamp greenhouse! * Blocks change in biomes over time - dirt becomes sand in a desert, dirt becomes clay in a river, for example. * Greenhouses can run in multiple worlds. * Easy to use GUI shows greenhouse recipes (e.g. **/is greenhouses**) @@ -27,7 +27,7 @@ This example is for when you are in the BSkyBlock world. For AcidIsland, just us 1. Make glass blocks and build a rectangular set of walls with a flat roof. 2. Put a hopper in the wall or roof. -3. Put a door in the wall so you can get in and out. +3. Put a door in the wall, so you can get in and out. 4. Type **/island greenhouses** and read the rules for the greenhouse you want. 5. Exit the GUI and place blocks, water, lava, and ice so that you make your desired biome. 6. Type **/island greenhouses** again and click on the biome to make it. @@ -42,7 +42,7 @@ This example is for when you are in the BSkyBlock world. For AcidIsland, just us ## FAQ -* Can I use stained glass? Yes, you can. It's pretty. +* Can I use stained-glass? Yes, you can. It's pretty. * Can I fill my greenhouse full of water? Yes. That's an ocean. * Will a squid spawn there? Maybe... okay, yes it will if it's a big enough ocean. * How do I place a door high up in the wall if the wall is all glass? Place it on a hopper. diff --git a/src/main/java/world/bentobox/greenhouses/greenhouse/BiomeRecipe.java b/src/main/java/world/bentobox/greenhouses/greenhouse/BiomeRecipe.java index 1f3f486..abf2b27 100644 --- a/src/main/java/world/bentobox/greenhouses/greenhouse/BiomeRecipe.java +++ b/src/main/java/world/bentobox/greenhouses/greenhouse/BiomeRecipe.java @@ -285,7 +285,7 @@ private Map countBlocks(Greenhouse gh, AsyncWorldCache cache) */ public void convertBlock(Block b) { Material bType = b.getType(); - // Check if there is a block conversion for this block, as while the rest of the method wont do anything if .get() returns nothing anyway it still seems to be quite expensive + // Check if there is a block conversion for this block, as while the rest of the method won't do anything if .get() returns nothing anyway it still seems to be quite expensive if(conversionBlocks.keySet().contains(bType)) { for(GreenhouseBlockConversions conversion_option : conversionBlocks.get(bType)) { rollTheDice(b, conversion_option); diff --git a/src/main/java/world/bentobox/greenhouses/greenhouse/Roof.java b/src/main/java/world/bentobox/greenhouses/greenhouse/Roof.java index 474e16b..6720ba5 100644 --- a/src/main/java/world/bentobox/greenhouses/greenhouse/Roof.java +++ b/src/main/java/world/bentobox/greenhouses/greenhouse/Roof.java @@ -118,7 +118,7 @@ public CompletableFuture findRoof() { } boolean findRoof(Vector loc) { - // This does a ever-growing check around the player to find a wall block. It is possible for the player + // This does an ever-growing check around the player to find a wall block. It is possible for the player // to be outside the greenhouse in this situation, so a check is done later to make sure the player is inside int startY = loc.getBlockY(); for (int y = startY; y < world.getMaxHeight(); y++) { @@ -130,7 +130,7 @@ boolean findRoof(Vector loc) { } } // If the roof was not found start going around in circles until something is found - // Expand in ever increasing squares around location until a wall block is found + // Expand in ever-increasing squares around location until a wall block is found if (!roofFound) { loc = spiralSearch(loc, startY); if (!roofFound) { @@ -199,7 +199,7 @@ private Vector spiralSearch(Vector v, int startY) { } /** - * Get highest roof block + * Get the highest roof block * @param x - x coord of current search * @param startY - starting y coord * @param z - z coord of current search diff --git a/src/main/java/world/bentobox/greenhouses/listeners/GreenhouseGuard.java b/src/main/java/world/bentobox/greenhouses/listeners/GreenhouseGuard.java index 377f593..428b139 100644 --- a/src/main/java/world/bentobox/greenhouses/listeners/GreenhouseGuard.java +++ b/src/main/java/world/bentobox/greenhouses/listeners/GreenhouseGuard.java @@ -53,7 +53,7 @@ public void onFlow(final BlockFromToEvent e) { if (from.isPresent() && addon.getSettings().isAllowFlowOut()) { return; } - // Otherwise cancel - the flow is not allowed + // Otherwise, cancel - the flow is not allowed e.setCancelled(true); } diff --git a/src/main/java/world/bentobox/greenhouses/managers/GreenhouseFinder.java b/src/main/java/world/bentobox/greenhouses/managers/GreenhouseFinder.java index 37257ed..3c0417e 100644 --- a/src/main/java/world/bentobox/greenhouses/managers/GreenhouseFinder.java +++ b/src/main/java/world/bentobox/greenhouses/managers/GreenhouseFinder.java @@ -44,7 +44,7 @@ static class CounterCheck { } /** - * @param addon + * @param addon Addon */ public GreenhouseFinder(Greenhouses addon) { this.addon = addon; @@ -148,7 +148,7 @@ Collection checkErrors(Roof roof, int y) { // Roof blocks must be glass, glowstone, doors or a hopper. result.add(GreenhouseResult.FAIL_BAD_ROOF_BLOCKS); } else if (isOtherBlocks()) { - // "Wall blocks must be glass, glowstone, doors or a hopper. + // Wall blocks must be glass, glowstone, doors or a hopper. result.add(GreenhouseResult.FAIL_BAD_WALL_BLOCKS); } if (this.getWallDoors() > 8) { diff --git a/src/main/resources/locales/en-US.yml b/src/main/resources/locales/en-US.yml index 894ab48..73c9816 100644 --- a/src/main/resources/locales/en-US.yml +++ b/src/main/resources/locales/en-US.yml @@ -59,9 +59,9 @@ greenhouses: FAIL_TOO_MANY_DOORS: "&c You cannot have more than 4 doors in the greenhouse!" FAIL_TOO_MANY_HOPPERS: "&c Only one hopper is allowed in the walls or roof." FAIL_UNEVEN_WALLS: "&c The walls are uneven. Red glass blocks should show the problem blocks." - FAIL_INSUFFICIENT_ICE: "&c Insufficent ice to make this recipe" - FAIL_INSUFFICIENT_LAVA: "&c Insufficent lava to make this recipe" - FAIL_INSUFFICIENT_WATER: "&c Insufficent water to make this recipe" + FAIL_INSUFFICIENT_ICE: "&c Insufficient ice to make this recipe" + FAIL_INSUFFICIENT_LAVA: "&c Insufficient lava to make this recipe" + FAIL_INSUFFICIENT_WATER: "&c Insufficient water to make this recipe" FAIL_NO_ICE: "&c Ice is required to make this recipe" FAIL_NO_LAVA: "&c Lava is required to make this recipe" FAIL_NO_WATER: "&c Water is required to make this recipe" From 7e4f0764e660338d3d42bbc1fdc1ed6663debc2e Mon Sep 17 00:00:00 2001 From: tastybento Date: Sun, 4 Jun 2023 09:19:15 -0700 Subject: [PATCH 21/31] Reduced complexity --- .../greenhouses/managers/RecipeManager.java | 68 +++++++++++-------- 1 file changed, 39 insertions(+), 29 deletions(-) diff --git a/src/main/java/world/bentobox/greenhouses/managers/RecipeManager.java b/src/main/java/world/bentobox/greenhouses/managers/RecipeManager.java index 9b5750a..4ede103 100644 --- a/src/main/java/world/bentobox/greenhouses/managers/RecipeManager.java +++ b/src/main/java/world/bentobox/greenhouses/managers/RecipeManager.java @@ -30,6 +30,7 @@ public class RecipeManager { private static final int MAXIMUM_INVENTORY_SIZE = 49; private final Greenhouses addon; private static final List biomeRecipes = new ArrayList<>(); + private static final String COULD_NOT_PARSE = "Could not parse "; public RecipeManager(Greenhouses addon) { this.addon = addon; @@ -179,43 +180,52 @@ private void loadBlockConversions(ConfigurationSection biomeRecipeConfig, BiomeR ConfigurationSection conversionSec = biomeRecipeConfig.getConfigurationSection("conversions"); if (conversionSec != null) { for (String oldMat : conversionSec.getKeys(false)) { - try { - Material oldMaterial = Material.valueOf(oldMat.toUpperCase(Locale.ENGLISH)); - String conversions = conversionSec.getString(oldMat); - if (!Objects.requireNonNull(conversions).isEmpty()) { - String[] split = conversions.split(":"); - double convChance = Double.parseDouble(split[0]); - Material newMaterial = Material.valueOf(split[1]); - Material localMaterial = null; - if(split.length > 2) { - localMaterial = Material.valueOf(split[2]); - } - b.addConvBlocks(oldMaterial, newMaterial, convChance, localMaterial); - } - } catch (Exception e) { - addon.logError("Could not parse " + oldMat); - } - + parseConversions(oldMat, conversionSec, b); } } // Get the list of conversions for (String oldMat : biomeRecipeConfig.getStringList("conversion-list")) { - try { - // Split the string - String[] split = oldMat.split(":"); - Material oldMaterial = Material.valueOf(split[0].toUpperCase()); - double convChance = Double.parseDouble(split[1]); - Material newMaterial = Material.valueOf(split[2]); + parseConversionList(oldMat, conversionSec, b); + + } + } + + private void parseConversionList(String oldMat, ConfigurationSection conversionSec, BiomeRecipe b) { + try { + // Split the string + String[] split = oldMat.split(":"); + Material oldMaterial = Material.valueOf(split[0].toUpperCase()); + double convChance = Double.parseDouble(split[1]); + Material newMaterial = Material.valueOf(split[2]); + Material localMaterial = null; + if(split.length > 3) { + localMaterial = Material.valueOf(split[3]); + } + b.addConvBlocks(oldMaterial, newMaterial, convChance, localMaterial); + } catch (Exception e) { + addon.logError(COULD_NOT_PARSE + oldMat); + } + + } + + private void parseConversions(String oldMat, ConfigurationSection conversionSec, BiomeRecipe b) { + try { + Material oldMaterial = Material.valueOf(oldMat.toUpperCase(Locale.ENGLISH)); + String conversions = conversionSec.getString(oldMat); + if (!Objects.requireNonNull(conversions).isEmpty()) { + String[] split = conversions.split(":"); + double convChance = Double.parseDouble(split[0]); + Material newMaterial = Material.valueOf(split[1]); Material localMaterial = null; - if(split.length > 3) { - localMaterial = Material.valueOf(split[3]); + if(split.length > 2) { + localMaterial = Material.valueOf(split[2]); } b.addConvBlocks(oldMaterial, newMaterial, convChance, localMaterial); - } catch (Exception e) { - addon.logError("Could not parse " + oldMat); } - + } catch (Exception e) { + addon.logError(COULD_NOT_PARSE + oldMat); } + } private void loadMobs(ConfigurationSection biomeRecipeConfig, BiomeRecipe b) { @@ -235,7 +245,7 @@ private void parseMob(Entry s, BiomeRecipe b) { Material mobSpawnOn = Material.valueOf(split[1]); b.addMobs(mobType, mobProbability, mobSpawnOn); } catch (Exception e) { - addon.logError("Could not parse " + s.getKey()); + addon.logError(COULD_NOT_PARSE + s.getKey()); } } From e75780e7105084e753a35bc26ff9cc958a77c5d3 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sun, 4 Jun 2023 17:36:08 -0700 Subject: [PATCH 22/31] Refactor to reduce complexity --- .../managers/EcoSystemManager.java | 49 ++++++++++--------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/src/main/java/world/bentobox/greenhouses/managers/EcoSystemManager.java b/src/main/java/world/bentobox/greenhouses/managers/EcoSystemManager.java index 0e17a42..bbadf7d 100644 --- a/src/main/java/world/bentobox/greenhouses/managers/EcoSystemManager.java +++ b/src/main/java/world/bentobox/greenhouses/managers/EcoSystemManager.java @@ -241,36 +241,39 @@ protected List getAvailableBlocks(Greenhouse gh, boolean ignoreLiqu for (double z = ibb.getMinZ(); z < ibb.getMaxZ(); z++) { for (double y = ibb.getMaxY() - 1; y >= bb.getMinY(); y--) { Block b = gh.getWorld().getBlockAt(NumberConversions.floor(x), NumberConversions.floor(y), NumberConversions.floor(z)); - - // Check floor blocks - if (!ignoreLiquid) { - // Check ceiling blocks - if (b.isEmpty() && !b.getRelative(BlockFace.UP).isEmpty()) { - result.add(new GrowthBlock(b, false)); - } - if (!b.isEmpty() && !Tag.LEAVES.isTagged(b.getType()) - && (b.getRelative(BlockFace.UP).isEmpty() - || b.getRelative(BlockFace.UP).isPassable() - || Tag.LEAVES.isTagged(b.getRelative(BlockFace.UP).getType()) - ) - ) { - result.add(new GrowthBlock(b.getRelative(BlockFace.UP), true)); - break; - } - } else { - if (!b.isEmpty() && !b.isLiquid() && b.getRelative(BlockFace.UP).isLiquid()) { - result.add(new GrowthBlock(b.getRelative(BlockFace.UP), true)); - break; - } + if (checkBlock(result, b, ignoreLiquid)) { + break; } - } } } return result; } - + private boolean checkBlock(List result, Block b, boolean ignoreLiquid) { + // Check floor blocks + if (!ignoreLiquid) { + // Check ceiling blocks + if (b.isEmpty() && !b.getRelative(BlockFace.UP).isEmpty()) { + result.add(new GrowthBlock(b, false)); + } + if (!b.isEmpty() && !Tag.LEAVES.isTagged(b.getType()) + && (b.getRelative(BlockFace.UP).isEmpty() + || b.getRelative(BlockFace.UP).isPassable() + || Tag.LEAVES.isTagged(b.getRelative(BlockFace.UP).getType()) + ) + ) { + result.add(new GrowthBlock(b.getRelative(BlockFace.UP), true)); + return true; + } + } else { + if (!b.isEmpty() && !b.isLiquid() && b.getRelative(BlockFace.UP).isLiquid()) { + result.add(new GrowthBlock(b.getRelative(BlockFace.UP), true)); + return true; + } + } + return false; + } private int getBoneMeal(Greenhouse gh) { Hopper hopper = getHopper(gh); From 3f4647b547de6dfd3ece900ee1331c35775336ff Mon Sep 17 00:00:00 2001 From: tastybento Date: Sun, 4 Jun 2023 17:44:01 -0700 Subject: [PATCH 23/31] Refactor to reduce complexity --- .../managers/GreenhouseFinder.java | 34 ++++++++----------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/src/main/java/world/bentobox/greenhouses/managers/GreenhouseFinder.java b/src/main/java/world/bentobox/greenhouses/managers/GreenhouseFinder.java index 3c0417e..86b9d2e 100644 --- a/src/main/java/world/bentobox/greenhouses/managers/GreenhouseFinder.java +++ b/src/main/java/world/bentobox/greenhouses/managers/GreenhouseFinder.java @@ -33,7 +33,7 @@ public class GreenhouseFinder { /** * This is the count of the various items */ - private CounterCheck cc = new CounterCheck(); + private CounterCheck counterCheck = new CounterCheck(); private Roof roof; static class CounterCheck { @@ -97,30 +97,26 @@ public CompletableFuture> find(Location location) { */ CompletableFuture> checkGreenhouse(AsyncWorldCache cache, Roof roof, Walls walls) { CompletableFuture> r = new CompletableFuture<>(); - Bukkit.getScheduler().runTaskAsynchronously(BentoBox.getInstance(), () -> checkGHAsync(r, cache, roof, walls)); + Bukkit.getScheduler().runTaskAsynchronously(BentoBox.getInstance(), () -> checkGreenhouseAsync(r, cache, roof, walls)); return r; } - private Set checkGHAsync(CompletableFuture> r, AsyncWorldCache cache, + private Set checkGreenhouseAsync(CompletableFuture> r, AsyncWorldCache cache, Roof roof, Walls walls) { - cc = new CounterCheck(); + counterCheck = new CounterCheck(); int y; for (y = roof.getHeight(); y > walls.getFloor(); y--) { wallBlockCount = 0; for (int x = walls.getMinX(); x <= walls.getMaxX(); x++) { for (int z = walls.getMinZ(); z <= walls.getMaxZ(); z++) { - checkBlock(cc, cache.getBlockType(x,y,z), roof, walls, new Vector(x, y, z)); + checkBlock(counterCheck, cache.getBlockType(x,y,z), roof, walls, new Vector(x, y, z)); } } if (wallBlockCount == 0 && y < roof.getHeight()) { // This is the floor break; - } else { - if (cc.otherBlock) { - if (otherBlockLayer < 0) { - otherBlockLayer = y; - } - } + } else if (counterCheck.otherBlock && otherBlockLayer < 0) { + otherBlockLayer = y; } } @@ -252,28 +248,28 @@ public Set getRedGlass() { * @return the wallDoors */ int getWallDoors() { - return cc.doorCount; + return counterCheck.doorCount; } /** * @return the ghHopper */ int getGhHopper() { - return cc.hopperCount; + return counterCheck.hopperCount; } /** * @return the airHoles */ boolean isAirHoles() { - return cc.airHole; + return counterCheck.airHole; } /** * @return the otherBlocks */ boolean isOtherBlocks() { - return cc.otherBlock; + return counterCheck.otherBlock; } /** @@ -326,21 +322,21 @@ protected void setGh(Greenhouse gh) { } public void setGhHopper(int i) { - cc.hopperCount = i; + counterCheck.hopperCount = i; } public void setWallDoors(int i) { - cc.doorCount = i; + counterCheck.doorCount = i; } public void setAirHoles(boolean b) { - cc.airHole = b; + counterCheck.airHole = b; } public void setOtherBlocks(boolean b) { - cc.otherBlock = b; + counterCheck.otherBlock = b; } From 605144e9f93196b94c57ed39f9b0983148689f35 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 24 Jun 2023 13:03:05 -0700 Subject: [PATCH 24/31] Update Github Action build script --- .github/workflows/build.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c771fd5..ee925e9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,21 +11,21 @@ jobs: name: Build runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - name: Set up JDK 17 - uses: actions/setup-java@v1 + uses: actions/setup-java@v3 with: java-version: 17 - name: Cache SonarCloud packages - uses: actions/cache@v1 + uses: actions/cache@v3 with: path: ~/.sonar/cache key: ${{ runner.os }}-sonar restore-keys: ${{ runner.os }}-sonar - name: Cache Maven packages - uses: actions/cache@v1 + uses: actions/cache@v3 with: path: ~/.m2 key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} From 02c2135501c19f9944d0a2a35e64d9064cc59e30 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 24 Jun 2023 13:55:46 -0700 Subject: [PATCH 25/31] Added distribution required for Github Action --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ee925e9..825b18d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,6 +17,7 @@ jobs: - name: Set up JDK 17 uses: actions/setup-java@v3 with: + distribution: 'adopt' java-version: 17 - name: Cache SonarCloud packages uses: actions/cache@v3 From e05e2806fe68839e5890737d8f3edf9e4ae6bac8 Mon Sep 17 00:00:00 2001 From: tastybento Date: Mon, 10 Jul 2023 21:44:43 -0700 Subject: [PATCH 26/31] Update pom.xml --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index bf9c2e5..7eb7b4b 100644 --- a/pom.xml +++ b/pom.xml @@ -252,7 +252,7 @@ org.jacoco jacoco-maven-plugin - 0.8.7 + 0.8.10 true From 53cb40e7c454f3e3d4cd3ea281ccfa95d0c67ec0 Mon Sep 17 00:00:00 2001 From: tastybento Date: Tue, 19 Sep 2023 21:48:45 -0700 Subject: [PATCH 27/31] Fixes mob spawning when no maxmob value given. Found while doing #108 --- .../world/bentobox/greenhouses/managers/EcoSystemManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/world/bentobox/greenhouses/managers/EcoSystemManager.java b/src/main/java/world/bentobox/greenhouses/managers/EcoSystemManager.java index bbadf7d..80069da 100644 --- a/src/main/java/world/bentobox/greenhouses/managers/EcoSystemManager.java +++ b/src/main/java/world/bentobox/greenhouses/managers/EcoSystemManager.java @@ -167,7 +167,7 @@ boolean addMobs(Greenhouse gh) { Collections.shuffle(list, new Random(System.currentTimeMillis())); Iterator it = list.iterator(); // Check if the greenhouse is full - if (sum >= gh.getBiomeRecipe().getMaxMob()) { + if (gh.getBiomeRecipe().getMaxMob() > -1 && sum >= gh.getBiomeRecipe().getMaxMob()) { return false; } while (it.hasNext() && (sum == 0 || gh.getArea() / sum >= gh.getBiomeRecipe().getMobLimit())) { From a7eeef7edc69a667d07e3287f2ef0aaff90c30b3 Mon Sep 17 00:00:00 2001 From: tastybento Date: Tue, 19 Sep 2023 22:15:46 -0700 Subject: [PATCH 28/31] Code clean up. --- .../greenhouses/greenhouse/BiomeRecipe.java | 29 ++++++++-------- .../managers/EcoSystemManager.java | 18 +++++----- .../managers/GreenhouseFinder.java | 3 +- .../greenhouses/managers/GreenhouseMap.java | 3 +- .../greenhouses/managers/RecipeManager.java | 4 +-- .../greenhouses/data/GreenhouseTest.java | 3 +- .../greenhouse/BiomeRecipeTest.java | 34 +++++++++---------- .../managers/EcoSystemManagerTest.java | 8 ++--- 8 files changed, 49 insertions(+), 53 deletions(-) diff --git a/src/main/java/world/bentobox/greenhouses/greenhouse/BiomeRecipe.java b/src/main/java/world/bentobox/greenhouses/greenhouse/BiomeRecipe.java index abf2b27..700d5c0 100644 --- a/src/main/java/world/bentobox/greenhouses/greenhouse/BiomeRecipe.java +++ b/src/main/java/world/bentobox/greenhouses/greenhouse/BiomeRecipe.java @@ -287,8 +287,8 @@ public void convertBlock(Block b) { Material bType = b.getType(); // Check if there is a block conversion for this block, as while the rest of the method won't do anything if .get() returns nothing anyway it still seems to be quite expensive if(conversionBlocks.keySet().contains(bType)) { - for(GreenhouseBlockConversions conversion_option : conversionBlocks.get(bType)) { - rollTheDice(b, conversion_option); + for(GreenhouseBlockConversions conversionOption : conversionBlocks.get(bType)) { + rollTheDice(b, conversionOption); } } } @@ -450,7 +450,10 @@ private Optional getRandomPlant(boolean underwater) { // Grow a random plant that can grow double r = random.nextDouble(); Double key = underwater ? underwaterPlants.ceilingKey(r) : plantTree.ceilingKey(r); - return key == null ? Optional.empty() : Optional.ofNullable(underwater ? underwaterPlants.get(key) : plantTree.get(key)); + if (key == null) { + return Optional.empty(); + } + return Optional.ofNullable(underwater ? underwaterPlants.get(key) : plantTree.get(key)); } /** @@ -476,11 +479,9 @@ public int getWaterCoverage() { public boolean growPlant(GrowthBlock block, boolean underwater) { Block bl = block.block(); return getRandomPlant(underwater).map(p -> { - if (bl.getY() != 0 && canGrowOn(block, p)) { - if (plantIt(bl, p)) { - bl.getWorld().spawnParticle(Particle.SNOWBALL, bl.getLocation(), 10, 2, 2, 2); - return true; - } + if (bl.getY() != 0 && canGrowOn(block, p) && plantIt(bl, p)) { + bl.getWorld().spawnParticle(Particle.SNOWBALL, bl.getLocation(), 10, 2, 2, 2); + return true; } return false; }).orElse(false); @@ -569,14 +570,12 @@ private boolean placeLichen(Block bl) { BlockFace d = null; boolean waterLogged = false; for (BlockFace adj : ADJ_BLOCKS) { - if (b.getRelative(adj).getType().equals(Material.AIR)) { + Material type = b.getRelative(adj).getType(); + if (type.equals(Material.AIR) || type.equals(Material.WATER)) { d = adj; - break; - } - // Lichen can grow under water too - if (b.getRelative(adj).getType().equals(Material.WATER)) { - d = adj; - waterLogged = true; + if (type.equals(Material.WATER)) { + waterLogged = true; + } break; } } diff --git a/src/main/java/world/bentobox/greenhouses/managers/EcoSystemManager.java b/src/main/java/world/bentobox/greenhouses/managers/EcoSystemManager.java index 80069da..8ca43e2 100644 --- a/src/main/java/world/bentobox/greenhouses/managers/EcoSystemManager.java +++ b/src/main/java/world/bentobox/greenhouses/managers/EcoSystemManager.java @@ -95,17 +95,17 @@ private void convertBlocks(Greenhouse gh) { return; } final BoundingBox ibb = gh.getInternalBoundingBox(); - int gh_min_x = NumberConversions.floor(ibb.getMinX()); - int gh_max_x = NumberConversions.floor(ibb.getMaxX()); - int gh_min_y = NumberConversions.floor(gh.getBoundingBox().getMinY()); // Note: this gets the floor - int gh_max_y = NumberConversions.floor(ibb.getMaxY()); - int gh_min_z = NumberConversions.floor(ibb.getMinZ()); - int gh_max_z = NumberConversions.floor(ibb.getMaxZ()); + int ghMinX = NumberConversions.floor(ibb.getMinX()); + int ghMaxX = NumberConversions.floor(ibb.getMaxX()); + int ghMinY = NumberConversions.floor(gh.getBoundingBox().getMinY()); // Note: this gets the floor + int ghMaxY = NumberConversions.floor(ibb.getMaxY()); + int ghMinZ = NumberConversions.floor(ibb.getMinZ()); + int ghMaxZ = NumberConversions.floor(ibb.getMaxZ()); BiomeRecipe biomeRecipe = gh.getBiomeRecipe(); - for (int x = gh_min_x; x < gh_max_x; x++) { - for (int z = gh_min_z; z < gh_max_z; z++) { - for (int y = gh_min_y; y < gh_max_y; y++) { + for (int x = ghMinX; x < ghMaxX; x++) { + for (int z = ghMinZ; z < ghMaxZ; z++) { + for (int y = ghMinY; y < ghMaxY; y++) { Block b = world.getBlockAt(x, y, z); if(!b.isEmpty()) { diff --git a/src/main/java/world/bentobox/greenhouses/managers/GreenhouseFinder.java b/src/main/java/world/bentobox/greenhouses/managers/GreenhouseFinder.java index 86b9d2e..3ff6331 100644 --- a/src/main/java/world/bentobox/greenhouses/managers/GreenhouseFinder.java +++ b/src/main/java/world/bentobox/greenhouses/managers/GreenhouseFinder.java @@ -34,7 +34,6 @@ public class GreenhouseFinder { * This is the count of the various items */ private CounterCheck counterCheck = new CounterCheck(); - private Roof roof; static class CounterCheck { int doorCount; @@ -63,7 +62,7 @@ public CompletableFuture> find(Location location) { // Get a world cache AsyncWorldCache cache = new AsyncWorldCache(addon, location.getWorld()); // Find the roof - roof = new Roof(cache, location, addon); + Roof roof = new Roof(cache, location, addon); roof.findRoof().thenAccept(found -> { if (Boolean.FALSE.equals(found)) { result.add(GreenhouseResult.FAIL_NO_ROOF); diff --git a/src/main/java/world/bentobox/greenhouses/managers/GreenhouseMap.java b/src/main/java/world/bentobox/greenhouses/managers/GreenhouseMap.java index 91d2af4..b42f829 100644 --- a/src/main/java/world/bentobox/greenhouses/managers/GreenhouseMap.java +++ b/src/main/java/world/bentobox/greenhouses/managers/GreenhouseMap.java @@ -6,7 +6,6 @@ import java.util.List; import java.util.Map; import java.util.Optional; -import java.util.stream.Collectors; import org.bukkit.Location; @@ -138,7 +137,7 @@ public void removeGreenhouses(Island island) { * @return a list of all the Greenhouses */ public List getGreenhouses() { - return greenhouses.values().stream().flatMap(List::stream).collect(Collectors.toList()); + return greenhouses.values().stream().flatMap(List::stream).toList(); } /** diff --git a/src/main/java/world/bentobox/greenhouses/managers/RecipeManager.java b/src/main/java/world/bentobox/greenhouses/managers/RecipeManager.java index 4ede103..76700d5 100644 --- a/src/main/java/world/bentobox/greenhouses/managers/RecipeManager.java +++ b/src/main/java/world/bentobox/greenhouses/managers/RecipeManager.java @@ -185,12 +185,12 @@ private void loadBlockConversions(ConfigurationSection biomeRecipeConfig, BiomeR } // Get the list of conversions for (String oldMat : biomeRecipeConfig.getStringList("conversion-list")) { - parseConversionList(oldMat, conversionSec, b); + parseConversionList(oldMat, b); } } - private void parseConversionList(String oldMat, ConfigurationSection conversionSec, BiomeRecipe b) { + private void parseConversionList(String oldMat, BiomeRecipe b) { try { // Split the string String[] split = oldMat.split(":"); diff --git a/src/test/java/world/bentobox/greenhouses/data/GreenhouseTest.java b/src/test/java/world/bentobox/greenhouses/data/GreenhouseTest.java index 6665f0d..e352169 100644 --- a/src/test/java/world/bentobox/greenhouses/data/GreenhouseTest.java +++ b/src/test/java/world/bentobox/greenhouses/data/GreenhouseTest.java @@ -5,7 +5,6 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -61,7 +60,7 @@ public void setUp() { // RecipeManager PowerMockito.mockStatic(RecipeManager.class); when(br.getName()).thenReturn("test"); - when(RecipeManager.getBiomeRecipies(eq("test"))).thenReturn(Optional.of(br)); + when(RecipeManager.getBiomeRecipies("test")).thenReturn(Optional.of(br)); // Walls when(walls.getMinX()).thenReturn(MINX); when(walls.getMinZ()).thenReturn(MINZ); diff --git a/src/test/java/world/bentobox/greenhouses/greenhouse/BiomeRecipeTest.java b/src/test/java/world/bentobox/greenhouses/greenhouse/BiomeRecipeTest.java index db64690..407c869 100644 --- a/src/test/java/world/bentobox/greenhouses/greenhouse/BiomeRecipeTest.java +++ b/src/test/java/world/bentobox/greenhouses/greenhouse/BiomeRecipeTest.java @@ -151,7 +151,7 @@ public void testAddConvBlocks() { double convChance = 100D; Material localMaterial = Material.WATER; br.addConvBlocks(oldMaterial, newMaterial, convChance, localMaterial); - verify(addon).log(eq(" 100.0% chance for Sand to convert to Clay")); + verify(addon).log(" 100.0% chance for Sand to convert to Clay"); } /** @@ -163,7 +163,7 @@ public void testAddMobs() { int mobProbability = 50; Material mobSpawnOn = Material.GRASS_BLOCK; br.addMobs(mobType, mobProbability, mobSpawnOn); - verify(addon).log(eq(" 50.0% chance for Cat to spawn on Grass Block.")); + verify(addon).log(" 50.0% chance for Cat to spawn on Grass Block."); } /** @@ -177,7 +177,7 @@ public void testAddMobsOver100Percent() { br.addMobs(mobType, mobProbability, mobSpawnOn); br.addMobs(mobType, mobProbability, mobSpawnOn); br.addMobs(mobType, mobProbability, mobSpawnOn); - verify(addon).logError(eq("Mob chances add up to > 100% in BADLANDS biome recipe! Skipping CAT")); + verify(addon).logError("Mob chances add up to > 100% in BADLANDS biome recipe! Skipping CAT"); } /** @@ -190,7 +190,7 @@ public void testAddMobsOver100PercentDouble() { Material mobSpawnOn = Material.GRASS_BLOCK; br.addMobs(mobType, mobProbability, mobSpawnOn); br.addMobs(mobType, mobProbability, mobSpawnOn); - verify(addon).logError(eq("Mob chances add up to > 100% in BADLANDS biome recipe! Skipping CAT")); + verify(addon).logError("Mob chances add up to > 100% in BADLANDS biome recipe! Skipping CAT"); } /** @@ -202,7 +202,7 @@ public void testAddPlants() { int plantProbability = 20; Material plantGrowOn = Material.DIRT; br.addPlants(plantMaterial, plantProbability, plantGrowOn); - verify(addon).log(eq(" 20.0% chance for Jungle Sapling to grow on Dirt")); + verify(addon).log(" 20.0% chance for Jungle Sapling to grow on Dirt"); } /** @@ -215,7 +215,7 @@ public void testAddPlantsOver100Percent() { Material plantGrowOn = Material.DIRT; br.addPlants(plantMaterial, plantProbability, plantGrowOn); br.addPlants(plantMaterial, plantProbability, plantGrowOn); - verify(addon).logError(eq("Plant chances add up to > 100% in BADLANDS biome recipe! Skipping JUNGLE_SAPLING")); + verify(addon).logError("Plant chances add up to > 100% in BADLANDS biome recipe! Skipping JUNGLE_SAPLING"); } /** @@ -226,7 +226,7 @@ public void testAddReqBlocks() { Material blockMaterial = Material.BLACK_CONCRETE; int blockQty = 30; br.addReqBlocks(blockMaterial, blockQty); - verify(addon).log(eq(" BLACK_CONCRETE x 30")); + verify(addon).log(" BLACK_CONCRETE x 30"); } /** @@ -451,7 +451,7 @@ public void testSpawnMobOutsideWall() { br.addMobs(mobType, mobProbability, mobSpawnOn); assertFalse(br.spawnMob(block)); - verify(world).spawnEntity(eq(location), eq(EntityType.CAT)); + verify(world).spawnEntity(location, EntityType.CAT); verify(location).add(any(Vector.class)); } @@ -477,7 +477,7 @@ public void testSpawnMob() { br.addMobs(mobType, mobProbability, mobSpawnOn); assertTrue(br.spawnMob(block)); - verify(world).spawnEntity(eq(location), eq(EntityType.CAT)); + verify(world).spawnEntity(location, EntityType.CAT); verify(location).add(any(Vector.class)); } @@ -504,7 +504,7 @@ public void testSpawnMobHoglin() { br.addMobs(mobType, mobProbability, mobSpawnOn); assertTrue(br.spawnMob(block)); - verify(world).spawnEntity(eq(location), eq(EntityType.HOGLIN)); + verify(world).spawnEntity(location, EntityType.HOGLIN); verify(location).add(any(Vector.class)); verify(hoglin).setImmuneToZombification(true); } @@ -532,7 +532,7 @@ public void testSpawnMobPiglin() { br.addMobs(mobType, mobProbability, mobSpawnOn); assertTrue(br.spawnMob(block)); - verify(world).spawnEntity(eq(location), eq(EntityType.PIGLIN)); + verify(world).spawnEntity(location, EntityType.PIGLIN); verify(location).add(any(Vector.class)); verify(piglin).setImmuneToZombification(true); } @@ -562,7 +562,7 @@ public void testSpawnMobPiglinNether() { br.addMobs(mobType, mobProbability, mobSpawnOn); assertTrue(br.spawnMob(block)); - verify(world).spawnEntity(eq(location), eq(EntityType.PIGLIN)); + verify(world).spawnEntity(location, EntityType.PIGLIN); verify(location).add(any(Vector.class)); verify(piglin, never()).setImmuneToZombification(true); } @@ -586,7 +586,7 @@ public void testSpawnMobWrongSurface() { br.addMobs(mobType, mobProbability, mobSpawnOn); assertFalse(br.spawnMob(block)); - verify(world, never()).spawnEntity(eq(location), eq(EntityType.CAT)); + verify(world, never()).spawnEntity(location, EntityType.CAT); } /** @@ -706,8 +706,8 @@ public void testGrowPlantPlantsDoublePlant() { assertTrue(br.addPlants(Material.SUNFLOWER, 100, Material.GRASS_BLOCK)); assertTrue(br.growPlant(new GrowthBlock(block, true), false)); verify(world).spawnParticle(eq(Particle.SNOWBALL), any(Location.class), anyInt(), anyDouble(), anyDouble(), anyDouble()); - verify(bisected).setHalf(eq(Half.BOTTOM)); - verify(bisected).setHalf(eq(Half.TOP)); + verify(bisected).setHalf(Half.BOTTOM); + verify(bisected).setHalf(Half.TOP); } /** @@ -722,8 +722,8 @@ public void testGrowPlantPlantsDoublePlantNoRoom() { when(block.isEmpty()).thenReturn(true); Block ob = mock(Block.class); when(ob.getType()).thenReturn(Material.GRASS_BLOCK); - when(block.getRelative(eq(BlockFace.DOWN))).thenReturn(ob); - when(block.getRelative(eq(BlockFace.UP))).thenReturn(ob); + when(block.getRelative(BlockFace.DOWN)).thenReturn(ob); + when(block.getRelative(BlockFace.UP)).thenReturn(ob); assertTrue(br.addPlants(Material.SUNFLOWER, 100, Material.GRASS_BLOCK)); assertFalse(br.growPlant(new GrowthBlock(block, true), false)); } diff --git a/src/test/java/world/bentobox/greenhouses/managers/EcoSystemManagerTest.java b/src/test/java/world/bentobox/greenhouses/managers/EcoSystemManagerTest.java index a81c9f8..bce299d 100644 --- a/src/test/java/world/bentobox/greenhouses/managers/EcoSystemManagerTest.java +++ b/src/test/java/world/bentobox/greenhouses/managers/EcoSystemManagerTest.java @@ -83,22 +83,22 @@ public void setUp() { // Liquid false when(air.isEmpty()).thenReturn(true); when(air.isPassable()).thenReturn(true); - when(air.getRelative(eq(BlockFace.UP))).thenReturn(air); + when(air.getRelative(BlockFace.UP)).thenReturn(air); // Plant // Empty false // Liquid false when(plant.isPassable()).thenReturn(true); - when(plant.getRelative(eq(BlockFace.UP))).thenReturn(air); + when(plant.getRelative(BlockFace.UP)).thenReturn(air); // Liquid // Empty false when(liquid.isLiquid()).thenReturn(true); when(liquid.isPassable()).thenReturn(true); - when(liquid.getRelative(eq(BlockFace.UP))).thenReturn(air); + when(liquid.getRelative(BlockFace.UP)).thenReturn(air); // Default for block // Empty false // Passable false // Liquid false - when(block.getRelative(eq(BlockFace.UP))).thenReturn(air); + when(block.getRelative(BlockFace.UP)).thenReturn(air); // Recipe when(recipe.noMobs()).thenReturn(true); From 15c2cea4750f4515e8086490c729d1e8b0b607aa Mon Sep 17 00:00:00 2001 From: tastybento Date: Sun, 12 Nov 2023 13:53:05 -0800 Subject: [PATCH 29/31] BentoBox 2.0.0 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 7eb7b4b..8d017af 100644 --- a/pom.xml +++ b/pom.xml @@ -46,8 +46,8 @@ 17 2.0.9 - 1.19.3-R0.1-SNAPSHOT - 1.21.0 + 1.20.2-R0.1-SNAPSHOT + 2.0.0-SNAPSHOT ${build.version}-SNAPSHOT From 8ce5cc0e3cbe9b43413630c2d5d20a3d9829bece Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 13 Jan 2024 07:09:18 -0800 Subject: [PATCH 30/31] Update pom.xml 1.7.5 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 8d017af..6f05708 100644 --- a/pom.xml +++ b/pom.xml @@ -51,7 +51,7 @@ ${build.version}-SNAPSHOT - 1.7.4 + 1.7.5 -LOCAL BentoBoxWorld_Greenhouses bentobox-world From 3fc14f5cd895945f833025bc178e970db5e0b65b Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 13 Jan 2024 09:29:53 -0800 Subject: [PATCH 31/31] Update to latest Spigot API --- pom.xml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6f05708..c7eaf1a 100644 --- a/pom.xml +++ b/pom.xml @@ -46,7 +46,7 @@ 17 2.0.9 - 1.20.2-R0.1-SNAPSHOT + 1.20.4-R0.1-SNAPSHOT 2.0.0-SNAPSHOT ${build.version}-SNAPSHOT @@ -259,6 +259,8 @@ **/*Names* + + org/bukkit/Material*