Skip to content

Commit

Permalink
Release 1.7.3 (#107)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
3 people committed Apr 15, 2023
1 parent de6a939 commit 5fd9cbf
Show file tree
Hide file tree
Showing 16 changed files with 181 additions and 55 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
20 changes: 10 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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>
Expand All @@ -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>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
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;


/**
* @author tastybento
*/
@Plugin(name = "Pladdon", version = "1.0")
@ApiVersion(ApiVersion.Target.v1_18)
@Dependency(value = "BentoBox")
public class GreenhousesPladdon extends Pladdon
{
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -102,6 +101,7 @@ public class BiomeRecipe implements Comparable<BiomeRecipe> {

private String permission = "";
private final Random random = new Random();
private int maxMob;


/**
Expand Down Expand Up @@ -376,7 +376,7 @@ public boolean spawnMob(Block b) {
}
// 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)
Expand All @@ -396,7 +396,7 @@ public boolean spawnMob(Block b) {
return true;
}).orElse(false);
}).orElse(false);

return result;
}

/**
Expand Down Expand Up @@ -715,5 +715,20 @@ public Set<EntityType> 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;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -132,23 +132,29 @@ 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) {
for (double blockZ = bb.getMinZ(); blockZ < bb.getMaxZ(); blockZ+=16) {
int chunkX = (int)(blockX / 16);
int chunkZ = (int)(blockZ / 16);
if (!gh.getWorld().isChunkLoaded(chunkX, chunkZ)) {
return;
return false;
}
}
}
Expand All @@ -161,13 +167,17 @@ private void addMobs(Greenhouse gh) {
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())) {
// Add a mob to the sum in the greenhouse
sum++;
}
}
return sum > 0;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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("maxmobs", -1));
return b;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,6 @@ private Map<String, BiomeRecipe> 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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ public void setup() {
*/
@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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
48 changes: 46 additions & 2 deletions src/main/resources/biomes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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"
Expand All @@ -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:
Expand All @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -304,4 +344,8 @@ biomes:
mobs:
skeleton: 5:STONE
glow_squid: 5:WATER
moblimit: 5
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

0 comments on commit 5fd9cbf

Please sign in to comment.