Skip to content

Commit

Permalink
Release 1.7.0 (#91)
Browse files Browse the repository at this point in the history
* Version 1.6.1

* Version 1.6.1

* Added Blue Orchids spawning in the Swamp biome

* Version 1.7.0

1.18.1 update

* German translation (#86)

* Translate de.yml via GitLocalize

* Translate de.yml via GitLocalize

Co-authored-by: mt-gitlocalize <mt@gitlocalize.com>
Co-authored-by: xXjojojXx <sven.f92@gmx.de>

* Translate hu.yml via GitLocalize (#87)

Co-authored-by: driverdakid <tamascsiszar99@icloud.com>

* Translate ja.yml via GitLocalize (#88)

Co-authored-by: tastybento <tastybento@wasteofplastic.com>

* Translate zh-CN.yml via GitLocalize (#89)

Co-authored-by: tastybento <tastybento@wasteofplastic.com>

* Code refactoring around BoundingBox

* Fix test.

* Remove saving of greenhouses on exit.

#85

* Add Pladdon Class (#90)

* Add Pladdon Class

Add Greenhouses Pladdon class.

* Add Spigot Annotations API

* Fix test. Avoid ambiguity.

* Add natural spawn protection listener.

Fixes #84

* Update gitignore for Eclipse

* Remove some code smells.

Co-authored-by: tastybento <tastybento@wasteofplastic.com>
Co-authored-by: Florian CUNY <poslovitch@bentobox.world>
Co-authored-by: gitlocalize-app[bot] <55277160+gitlocalize-app[bot]@users.noreply.github.com>
Co-authored-by: mt-gitlocalize <mt@gitlocalize.com>
Co-authored-by: xXjojojXx <sven.f92@gmx.de>
Co-authored-by: driverdakid <tamascsiszar99@icloud.com>
  • Loading branch information
7 people committed May 16, 2022
1 parent 4aec983 commit a96d4d4
Show file tree
Hide file tree
Showing 17 changed files with 541 additions and 357 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/target/
/.classpath
/.project
14 changes: 10 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@
<java.version>16</java.version>
<powermock.version>2.0.9</powermock.version>
<!-- More visible way how to change dependency versions -->
<spigot.version>1.17.1-R0.1-SNAPSHOT</spigot.version>
<bentobox.version>1.16.0</bentobox.version>
<spigot.version>1.18.1-R0.1-SNAPSHOT</spigot.version>
<bentobox.version>1.18.1</bentobox.version>
<!-- Revision variable removes warning about dynamic version -->
<revision>${build.version}-SNAPSHOT</revision>
<!-- This allows to change between versions and snapshots. -->
<build.version>1.6.0</build.version>
<build.version>1.7.0</build.version>
<build.number>-LOCAL</build.number>
<sonar.projectKey>BentoBoxWorld_Greenhouses</sonar.projectKey>
<sonar.organization>bentobox-world</sonar.organization>
Expand Down Expand Up @@ -116,6 +116,12 @@
<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 @@ -277,4 +283,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
5 changes: 2 additions & 3 deletions src/main/java/world/bentobox/greenhouses/Greenhouses.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,8 @@ public void onEnable() {
*/
@Override
public void onDisable() {
if (manager != null) {
manager.saveGreenhouses();
if (manager.getEcoMgr() != null) manager.getEcoMgr().cancel();
if (manager != null && manager.getEcoMgr() != null) {
manager.getEcoMgr().cancel();
}
}

Expand Down
25 changes: 25 additions & 0 deletions src/main/java/world/bentobox/greenhouses/GreenhousesPladdon.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
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
public Addon getAddon()
{
return new Greenhouses();
}
}
15 changes: 9 additions & 6 deletions src/main/java/world/bentobox/greenhouses/data/Greenhouse.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public void setRoofHopperLocation(@Nullable Vector v) {
*/
@NonNull
public BoundingBox getBoundingBox() {
return Objects.requireNonNullElseGet(boundingBox, BoundingBox::new);
return Objects.requireNonNull(boundingBox);
}

/**
Expand Down Expand Up @@ -220,7 +220,9 @@ public World getWorld() {
* @return true if inside the greenhouse
*/
public boolean contains(Location location2) {
return location.getWorld() != null && location.getWorld().equals(location2.getWorld()) && boundingBox.contains(location2.toVector());
return getLocation().getWorld() != null
&& getLocation().getWorld().equals(location2.getWorld())
&& getBoundingBox().contains(location2.toVector());
}

/**
Expand Down Expand Up @@ -262,12 +264,13 @@ public Map<Material, Integer> getMissingBlocks() {
* @return true if wall or roof block
*/
public boolean isRoofOrWallBlock(Location l) {
final BoundingBox bb = getBoundingBox();
return (l.getBlockY() > this.getFloorHeight()
&& ((l.getBlockY() == getCeilingHeight() - 1)
|| l.getBlockX() == (int)getBoundingBox().getMinX()
|| l.getBlockX() == (int)getBoundingBox().getMaxX() - 1
|| l.getBlockZ() == (int)getBoundingBox().getMinZ()
|| l.getBlockZ() == (int)getBoundingBox().getMaxZ() - 1
|| l.getBlockX() == (int)bb.getMinX()
|| l.getBlockX() == (int)bb.getMaxX() - 1
|| l.getBlockZ() == (int)bb.getMinZ()
|| l.getBlockZ() == (int)bb.getMaxZ() - 1
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Hoglin;
import org.bukkit.entity.Piglin;
import org.bukkit.util.BoundingBox;
import org.bukkit.util.Vector;

import com.google.common.base.Enums;
Expand Down Expand Up @@ -367,9 +366,7 @@ public boolean spawnMob(Block b) {
.getManager()
.getMap()
.getGreenhouse(b.getLocation()).map(gh -> {
BoundingBox interior = gh.getBoundingBox().clone();
interior.expand(-1, -1, -1);
if (!interior.contains(entity.getBoundingBox())) {
if (!gh.getInternalBoundingBox().contains(entity.getBoundingBox())) {
entity.remove();
return false;
}
Expand Down Expand Up @@ -422,7 +419,7 @@ private Optional<GreenhousePlant> getRandomPlant() {
* @return a list of blocks that are required for this recipe
*/
public List<String> getRecipeBlocks() {
return requiredBlocks.entrySet().stream().map(en -> Util.prettifyText(en.getKey().toString()) + " x " + en.getValue()).collect(Collectors.toList());
return requiredBlocks.entrySet().stream().map(en -> Util.prettifyText(en.getKey().toString()) + " x " + en.getValue()).toList();
}

/**
Expand Down Expand Up @@ -474,10 +471,10 @@ private boolean isBisected(Block bl, GreenhousePlant p) {

private boolean canGrowOn(GrowthBlock block, GreenhousePlant p) {
// Ceiling plants can only grow on ceiling blocks
if (CEILING_PLANTS.contains(p.plantMaterial()) && block.floor()) {
if (CEILING_PLANTS.contains(p.plantMaterial()) && Boolean.TRUE.equals(block.floor())) {
return false;
}
return p.plantGrownOn().equals(block.block().getRelative(block.floor() ? BlockFace.DOWN : BlockFace.UP).getType());
return p.plantGrownOn().equals(block.block().getRelative(Boolean.TRUE.equals(block.floor()) ? BlockFace.DOWN : BlockFace.UP).getType());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent;
import org.bukkit.event.entity.CreatureSpawnEvent;

import world.bentobox.greenhouses.Greenhouses;
import world.bentobox.greenhouses.data.Greenhouse;
Expand Down Expand Up @@ -78,6 +79,23 @@ public void onPistonPull(BlockPistonRetractEvent e) {
.anyMatch(this::inGreenhouse));
}


/**
* Guard Greenhouse from natural entity spawning.
*
* @param spawnEvent the spawn event
*/
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onCreatureSpawn(CreatureSpawnEvent spawnEvent)
{
if (CreatureSpawnEvent.SpawnReason.NATURAL == spawnEvent.getSpawnReason())
{
// Natural spawn events should be cancelled. Greenhouse spawns its own mobs.
spawnEvent.setCancelled(this.inGreenhouse(spawnEvent.getLocation()));
}
}


private boolean inGreenhouse(Location l) {
return addon.getManager().getMap().getGreenhouse(l).map(g -> g.isRoofOrWallBlock(l)).orElse(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;

import org.bukkit.Bukkit;
import org.bukkit.Material;
Expand All @@ -21,9 +22,9 @@
import org.bukkit.event.weather.WeatherChangeEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.util.BoundingBox;

import com.google.common.base.Enums;
import com.google.common.base.Optional;

import world.bentobox.bentobox.util.Util;
import world.bentobox.greenhouses.Greenhouses;
Expand Down Expand Up @@ -58,9 +59,10 @@ private boolean getAirBlocks(Greenhouse gh) {
}
boolean createdSnow = false;
List<Block> waterBlocks = new ArrayList<>();
for (int x = (int)gh.getBoundingBox().getMinX() + 1; x < (int)gh.getBoundingBox().getMaxX() -1; x++) {
for (int z = (int)gh.getBoundingBox().getMinZ() + 1; z < (int)gh.getBoundingBox().getMaxZ() - 1; z++) {
for (int y = (int)gh.getBoundingBox().getMaxY() - 2; y >= (int)gh.getBoundingBox().getMinY(); y--) {
final BoundingBox bb = gh.getBoundingBox();
for (int x = (int)bb.getMinX() + 1; x < (int)bb.getMaxX() -1; x++) {
for (int z = (int)bb.getMinZ() + 1; z < (int)bb.getMaxZ() - 1; z++) {
for (int y = (int)bb.getMaxY() - 2; y >= (int)bb.getMinY(); y--) {
Block b = Objects.requireNonNull(gh.getLocation().getWorld()).getBlockAt(x, y, z);
Material type = b.getType();
if (type.equals(Material.AIR) || type.equals(Material.SNOW)) {
Expand Down Expand Up @@ -98,7 +100,7 @@ private boolean getAirBlocks(Greenhouse gh) {
}

private boolean placeSnow(Block b) {
Optional<Material> snowCauldron = Enums.getIfPresent(Material.class, "POWDER_SNOW_CAULDRON");
Optional<Material> snowCauldron = Enums.getIfPresent(Material.class, "POWDER_SNOW_CAULDRON").toJavaUtil();
if (snowCauldron.isPresent()) {
if (b.getType().equals(Material.CAULDRON)) {
b.setType(snowCauldron.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.bukkit.block.Hopper;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.util.BoundingBox;
import org.bukkit.util.NumberConversions;

import world.bentobox.greenhouses.Greenhouses;
Expand Down Expand Up @@ -85,18 +86,20 @@ void setup() {
}

private void convertBlocks(Greenhouse gh) {
World world = gh.getWorld();
final World world = gh.getWorld();
final BoundingBox bb = gh.getBoundingBox();
if(world == null || gh.getLocation() == null || gh.getLocation().getWorld() == null
|| !gh.getLocation().getWorld().isChunkLoaded(((int) gh.getBoundingBox().getMaxX()) >> 4, ((int) gh.getBoundingBox().getMaxZ()) >> 4)
|| !gh.getLocation().getWorld().isChunkLoaded(((int) gh.getBoundingBox().getMinX()) >> 4, ((int) gh.getBoundingBox().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)){
return;
}
int gh_min_x = NumberConversions.floor(gh.getInternalBoundingBox().getMinX());
int gh_max_x = NumberConversions.floor(gh.getInternalBoundingBox().getMaxX());
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(gh.getInternalBoundingBox().getMaxY());
int gh_min_z = NumberConversions.floor(gh.getInternalBoundingBox().getMinZ());
int gh_max_z = NumberConversions.floor(gh.getInternalBoundingBox().getMaxZ());
int gh_max_y = NumberConversions.floor(ibb.getMaxY());
int gh_min_z = NumberConversions.floor(ibb.getMinZ());
int gh_max_z = NumberConversions.floor(ibb.getMaxZ());
BiomeRecipe biomeRecipe = gh.getBiomeRecipe();

for (int x = gh_min_x; x < gh_max_x; x++) {
Expand Down Expand Up @@ -129,17 +132,18 @@ private void verify(Greenhouse gh) {
}

private void addMobs(Greenhouse gh) {
final BoundingBox bb = gh.getBoundingBox();
if(gh.getLocation() == null || gh.getLocation().getWorld() == null || gh.getWorld() == null
|| !gh.getLocation().getWorld().isChunkLoaded(((int) gh.getBoundingBox().getMaxX()) >> 4, ((int) gh.getBoundingBox().getMaxZ()) >> 4) || !gh.getLocation().getWorld().isChunkLoaded(((int) gh.getBoundingBox().getMinX()) >> 4, ((int) gh.getBoundingBox().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;
}
if (gh.getBiomeRecipe().noMobs()) {
return;
}
// Check greenhouse chunks are loaded
for (double blockX = gh.getBoundingBox().getMinX(); blockX < gh.getBoundingBox().getMaxX(); blockX+=16) {
for (double blockZ = gh.getBoundingBox().getMinZ(); blockZ < gh.getBoundingBox().getMaxZ(); blockZ+=16) {
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)) {
Expand Down Expand Up @@ -170,8 +174,9 @@ private void addMobs(Greenhouse gh) {
* @param gh - greenhouse
*/
private void growPlants(Greenhouse gh) {
final BoundingBox bb = gh.getBoundingBox();
if (gh.getLocation() == null || gh.getLocation().getWorld() == null
|| !gh.getLocation().getWorld().isChunkLoaded(((int) gh.getBoundingBox().getMaxX()) >> 4, ((int) gh.getBoundingBox().getMaxZ()) >> 4) || !gh.getLocation().getWorld().isChunkLoaded(((int) gh.getBoundingBox().getMinX()) >> 4, ((int) gh.getBoundingBox().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 growplants for unloaded greenhouse
return;
}
Expand Down Expand Up @@ -212,11 +217,13 @@ private void setBoneMeal(Greenhouse gh, int value) {
* @return List of blocks
*/
protected List<GrowthBlock> getAvailableBlocks(Greenhouse gh, boolean ignoreLiquid) {
final BoundingBox bb = gh.getBoundingBox();
final BoundingBox ibb = gh.getInternalBoundingBox();
List<GrowthBlock> result = new ArrayList<>();
if (gh.getWorld() == null) return result;
for (double x = gh.getInternalBoundingBox().getMinX(); x < gh.getInternalBoundingBox().getMaxX(); x++) {
for (double z = gh.getInternalBoundingBox().getMinZ(); z < gh.getInternalBoundingBox().getMaxZ(); z++) {
for (double y = gh.getInternalBoundingBox().getMaxY() - 1; y >= gh.getBoundingBox().getMinY(); y--) {
for (double x = ibb.getMinX(); x < ibb.getMaxX(); x++) {
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 ceiling blocks
if (b.isEmpty() && !b.getRelative(BlockFace.UP).isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.bukkit.block.Biome;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.util.BoundingBox;

import world.bentobox.bentobox.api.events.BentoBoxReadyEvent;
import world.bentobox.bentobox.database.Database;
Expand Down Expand Up @@ -125,35 +126,28 @@ private void loadGreenhouses() {
toBeRemoved.forEach(handler::deleteObject);
}

/**
* Saves all the greenhouses to database
*/
public void saveGreenhouses() {
addon.log("Saving greenhouses...");
map.getGreenhouses().forEach(handler::saveObjectAsync);
}

/**
* Removes the greenhouse from the world and resets biomes
* @param g - greenhouse
* @param gh - greenhouse
*/
public void removeGreenhouse(Greenhouse g) {
handler.deleteObject(g);
map.removeGreenhouse(g);
if (g.getOriginalBiome() == null) {
addon.logError("Greenhouse had no original biome: " + g.getLocation());
public void removeGreenhouse(Greenhouse gh) {
handler.deleteObject(gh);
map.removeGreenhouse(gh);
if (gh.getOriginalBiome() == null) {
addon.logError("Greenhouse had no original biome: " + gh.getLocation());
return;
}
if (g.getLocation() == null || g.getLocation().getWorld() == null) {
if (gh.getLocation() == null || gh.getLocation().getWorld() == null) {
// Greenhouse is messed up. It's being deleted anyway.
return;
}
addon.log("Returning biome to original state: " + g.getOriginalBiome().toString());
for (int x = (int)g.getBoundingBox().getMinX(); x<= (int)g.getBoundingBox().getMaxX(); x+=4) {
for (int z = (int)g.getBoundingBox().getMinZ(); z<= (int)g.getBoundingBox().getMaxZ(); z+=4) {
for (int y = (int)g.getBoundingBox().getMinY(); y<= (int)g.getBoundingBox().getMaxY(); y+=4) {
addon.log("Returning biome to original state: " + gh.getOriginalBiome().toString());
final BoundingBox bb = gh.getBoundingBox();
for (int x = (int)bb.getMinX(); x<= (int)bb.getMaxX(); x+=4) {
for (int z = (int)bb.getMinZ(); z<= (int)bb.getMaxZ(); z+=4) {
for (int y = (int)bb.getMinY(); y<= (int)bb.getMaxY(); y+=4) {
// Set back to the original biome
g.getLocation().getWorld().setBiome(x, y, z, g.getOriginalBiome());
gh.getLocation().getWorld().setBiome(x, y, z, gh.getOriginalBiome());
}
}
}
Expand Down Expand Up @@ -250,9 +244,10 @@ private void activateGreenhouse(Greenhouse gh) {
addon.logError("Biome recipe error - no such biome for " + gh.getBiomeRecipe().getName());
return;
}
for (int x = (int)gh.getBoundingBox().getMinX(); x < gh.getBoundingBox().getMaxX(); x+=4) {
for (int z = (int)gh.getBoundingBox().getMinZ(); z < gh.getBoundingBox().getMaxZ(); z+=4) {
for (int y = (int)gh.getBoundingBox().getMinY(); y < gh.getBoundingBox().getMaxY(); y+=4) {
final BoundingBox bb = gh.getBoundingBox();
for (int x = (int)bb.getMinX(); x < bb.getMaxX(); x+=4) {
for (int z = (int)bb.getMinZ(); z < bb.getMaxZ(); z+=4) {
for (int y = (int)bb.getMinY(); y < bb.getMaxY(); y+=4) {
Objects.requireNonNull(gh.getWorld()).setBiome(x, y, z, ghBiome);
}
}
Expand Down

0 comments on commit a96d4d4

Please sign in to comment.