Skip to content

Commit

Permalink
Fixes issue where greenhouse biome was not reverted on breakage
Browse files Browse the repository at this point in the history
Also removed greenhouses that no longer have an island.

#11
  • Loading branch information
tastybento committed Aug 1, 2019
1 parent 96936bd commit 815caa7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion 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>0.3.1</build.version>
<build.version>0.3.2</build.version>
<build.number>-LOCAL</build.number>
</properties>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package world.bentobox.greenhouses.managers;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import org.bukkit.Location;
Expand Down Expand Up @@ -85,10 +87,13 @@ public GreenhouseMap getMap() {
private void loadGreenhouses() {
map.clear();
addon.log("Loading greenhouses...");
List<Greenhouse> toBeRemoved = new ArrayList<>();
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:
case NULL:
addon.logError(result.name());
Expand All @@ -102,6 +107,8 @@ private void loadGreenhouses() {
}
});
addon.log("Loaded " + map.getSize() + " greenhouses.");
// Remove the old or outdated greenhouses
toBeRemoved.forEach(handler::deleteObject);
}

/**
Expand All @@ -120,12 +127,12 @@ public void removeGreenhouse(Greenhouse g) {
handler.deleteObject(g);
map.removeGreenhouse(g);
addon.log("Returning biome to original state: " + g.getOriginalBiome().toString());
if (g.getOriginalBiome().equals(Biome.NETHER) || g.getOriginalBiome().equals(Biome.DESERT)
|| g.getOriginalBiome().equals(Biome.DESERT_HILLS)) {
for (int x = (int)g.getBoundingBox().getMinX(); x<= (int)g.getBoundingBox().getMaxX(); x++) {
for (int z = (int)g.getBoundingBox().getMinZ(); z<= (int)g.getBoundingBox().getMinZ(); z++) {
// Set back to the original biome
g.getLocation().getWorld().setBiome(x, z, g.getOriginalBiome());
for (int x = (int)g.getBoundingBox().getMinX(); x<= (int)g.getBoundingBox().getMaxX(); x++) {
for (int z = (int)g.getBoundingBox().getMinZ(); z<= (int)g.getBoundingBox().getMaxZ(); z++) {
// Set back to the original biome
g.getLocation().getWorld().setBiome(x, z, g.getOriginalBiome());
if (g.getOriginalBiome().equals(Biome.NETHER) || g.getOriginalBiome().equals(Biome.DESERT)
|| g.getOriginalBiome().equals(Biome.DESERT_HILLS)) {
for (int y = g.getFloorHeight(); y< g.getCeilingHeight(); y++) {
Block b = g.getLocation().getWorld().getBlockAt(x, y, z);
// Remove any water
Expand Down

0 comments on commit 815caa7

Please sign in to comment.