mirror of
https://github.com/BentoBoxWorld/Greenhouses.git
synced 2024-11-24 19:46:31 +01:00
Release 1.7.3 (#107)
* Version 1.7.3 * Add ${argLine} to get jacoco coverage * Updated Jacoco POM entry * Address bugs reported by SonarCloud * Updated ReadMe * Add max mobs option #99 * Use updated Bucket event * Added tests to cover #99 * Fixes help text for user command. Fixes #105 * Fixed maxmobs typo instead of maxmob * Remove unused imports * Update to new Bukkit Loader * Remove debug * Create plugin.yml (#106) * Create plugin.yml * Update pom.xml * Update GreenhousesPladdon.java --------- Co-authored-by: tastybento <tastybento@wasteofplastic.com> Co-authored-by: tastybento <tastybento@users.noreply.github.com>
This commit is contained in:
parent
de6a939bb9
commit
5fd9cbfd36
@ -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
|
||||
|
||||
|
20
pom.xml
20
pom.xml
@ -51,7 +51,7 @@
|
||||
<!-- Revision variable removes warning about dynamic version -->
|
||||
<revision>${build.version}-SNAPSHOT</revision>
|
||||
<!-- This allows to change between versions and snapshots. -->
|
||||
<build.version>1.7.2</build.version>
|
||||
<build.version>1.7.3</build.version>
|
||||
<build.number>-LOCAL</build.number>
|
||||
<sonar.projectKey>BentoBoxWorld_Greenhouses</sonar.projectKey>
|
||||
<sonar.organization>bentobox-world</sonar.organization>
|
||||
@ -116,12 +116,6 @@
|
||||
<version>${spigot.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>plugin-annotations</artifactId>
|
||||
<version>1.2.3-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>world.bentobox</groupId>
|
||||
<artifactId>bentobox</artifactId>
|
||||
@ -200,6 +194,7 @@
|
||||
<version>3.0.0-M5</version>
|
||||
<configuration>
|
||||
<argLine>
|
||||
${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
|
||||
@ -257,7 +252,7 @@
|
||||
<plugin>
|
||||
<groupId>org.jacoco</groupId>
|
||||
<artifactId>jacoco-maven-plugin</artifactId>
|
||||
<version>0.8.3</version>
|
||||
<version>0.8.7</version>
|
||||
<configuration>
|
||||
<append>true</append>
|
||||
<excludes>
|
||||
@ -268,16 +263,21 @@
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>pre-unit-test</id>
|
||||
<id>prepare-agent</id>
|
||||
<goals>
|
||||
<goal>prepare-agent</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>post-unit-test</id>
|
||||
<id>report</id>
|
||||
<goals>
|
||||
<goal>report</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<formats>
|
||||
<format>XML</format>
|
||||
</formats>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
@ -1,10 +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;
|
||||
|
||||
import world.bentobox.bentobox.api.addons.Addon;
|
||||
import world.bentobox.bentobox.api.addons.Pladdon;
|
||||
|
||||
@ -12,9 +8,6 @@ import world.bentobox.bentobox.api.addons.Pladdon;
|
||||
/**
|
||||
* @author tastybento
|
||||
*/
|
||||
@Plugin(name = "Pladdon", version = "1.0")
|
||||
@ApiVersion(ApiVersion.Target.v1_18)
|
||||
@Dependency(value = "BentoBox")
|
||||
public class GreenhousesPladdon extends Pladdon
|
||||
{
|
||||
@Override
|
||||
|
@ -220,7 +220,7 @@ public class Greenhouse implements DataObject {
|
||||
* @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());
|
||||
}
|
||||
|
@ -32,7 +32,6 @@ import org.bukkit.entity.Entity;
|
||||
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<BiomeRecipe> {
|
||||
|
||||
private String permission = "";
|
||||
private final Random random = new Random();
|
||||
private int maxMob;
|
||||
|
||||
|
||||
/**
|
||||
@ -376,7 +376,7 @@ public class BiomeRecipe implements Comparable<BiomeRecipe> {
|
||||
}
|
||||
// Center spawned mob
|
||||
Location spawnLoc = b.getLocation().clone().add(new Vector(0.5, 0, 0.5));
|
||||
return getRandomMob()
|
||||
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)
|
||||
@ -396,7 +396,7 @@ public class BiomeRecipe implements Comparable<BiomeRecipe> {
|
||||
return true;
|
||||
}).orElse(false);
|
||||
}).orElse(false);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -715,5 +715,20 @@ public class BiomeRecipe implements Comparable<BiomeRecipe> {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -132,15 +132,21 @@ public class EcoSystemManager {
|
||||
|
||||
}
|
||||
|
||||
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 @@ public class EcoSystemManager {
|
||||
int chunkX = (int)(blockX / 16);
|
||||
int chunkZ = (int)(blockZ / 16);
|
||||
if (!gh.getWorld().isChunkLoaded(chunkX, chunkZ)) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -161,6 +167,9 @@ public class EcoSystemManager {
|
||||
Collections.shuffle(list, new Random(System.currentTimeMillis()));
|
||||
Iterator<GrowthBlock> it = list.iterator();
|
||||
// Check if the greenhouse is full
|
||||
if (sum >= gh.getBiomeRecipe().getMaxMob()) {
|
||||
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())) {
|
||||
@ -168,6 +177,7 @@ public class EcoSystemManager {
|
||||
sum++;
|
||||
}
|
||||
}
|
||||
return sum > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -155,6 +155,7 @@ public class RecipeManager {
|
||||
b.setLavacoverage(biomeRecipeConfig.getInt("lavacoverage",-1));
|
||||
b.setIcecoverage(biomeRecipeConfig.getInt("icecoverage",-1));
|
||||
b.setMobLimit(biomeRecipeConfig.getInt("moblimit", 9));
|
||||
b.setMaxMob(biomeRecipeConfig.getInt("maxmobs", -1));
|
||||
return b;
|
||||
}
|
||||
|
||||
|
@ -43,10 +43,6 @@ public class PanelClick implements ClickHandler {
|
||||
}
|
||||
|
||||
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");
|
||||
|
@ -92,10 +92,6 @@ class MakeCommand extends CompositeCommand {
|
||||
* @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");
|
||||
|
@ -35,10 +35,6 @@ class RemoveCommand extends CompositeCommand {
|
||||
*/
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> 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");
|
||||
|
@ -30,8 +30,7 @@ public class UserCommand extends CompositeCommand {
|
||||
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);
|
||||
|
@ -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
|
||||
@ -305,3 +345,7 @@ biomes:
|
||||
skeleton: 5:STONE
|
||||
glow_squid: 5:WATER
|
||||
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
|
@ -41,6 +41,7 @@ greenhouses:
|
||||
|
||||
commands:
|
||||
user:
|
||||
description: "Opens the Greenhouse selection GUI"
|
||||
remove:
|
||||
description: "Removes a greenhouse that you are standing in if you are the owner"
|
||||
make:
|
||||
|
9
src/main/resources/plugin.yml
Normal file
9
src/main/resources/plugin.yml
Normal file
@ -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}
|
@ -27,6 +27,7 @@ import org.bukkit.event.player.PlayerBucketEmptyEvent;
|
||||
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 class GreenhouseEventsTest {
|
||||
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 class GreenhouseEventsTest {
|
||||
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 class GreenhouseEventsTest {
|
||||
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 class GreenhouseEventsTest {
|
||||
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 class GreenhouseEventsTest {
|
||||
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 class GreenhouseEventsTest {
|
||||
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);
|
||||
}
|
||||
|
@ -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.mock;
|
||||
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.Test;
|
||||
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 @@ import world.bentobox.greenhouses.managers.EcoSystemManager.GrowthBlock;
|
||||
*
|
||||
*/
|
||||
@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<Keyed> tag = mock(Tag.class);
|
||||
when(Bukkit.getTag(anyString(), any(), any())).thenReturn(tag);
|
||||
|
||||
@ -95,6 +100,12 @@ public class EcoSystemManagerTest {
|
||||
// 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 class EcoSystemManagerTest {
|
||||
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));
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user