Skip to content

Commit

Permalink
Fixes errors when loading greenhouses.
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Nov 15, 2020
1 parent 0bbc25c commit 9ae9cdb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.Set;

import org.bukkit.Location;
import org.bukkit.block.Biome;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;

Expand Down Expand Up @@ -47,7 +48,8 @@ public enum GreenhouseResult {
NULL,
SUCCESS,
FAIL_NO_RECIPE_FOUND,
FAIL_INSUFFICIENT_BLOCKS
FAIL_INSUFFICIENT_BLOCKS,
FAIL_NO_WORLD, FAIL_UNKNOWN_RECIPE
}

private final Greenhouses addon;
Expand Down Expand Up @@ -94,12 +96,21 @@ private void loadGreenhouses() {
toBeRemoved.add(g);
break;
case FAIL_OVERLAPPING:
addon.logError("Greenhouse overlaps with another greenhouse. Skipping...");
break;
case NULL:
addon.logError(result.name());
addon.logError("Null location of greenhouse. Cannot load. Skipping...");
break;
case SUCCESS:
activateGreenhouse(g);
break;
case FAIL_NO_WORLD:
addon.logError("Database contains greenhouse for a non-loaded world. Skipping...");
break;
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());
break;
default:
break;

Expand Down Expand Up @@ -178,10 +189,15 @@ public GhResult tryToMakeGreenhouse(Location location, BiomeRecipe greenhouseRec
}

private void activateGreenhouse(Greenhouse gh) {
Biome ghBiome = gh.getBiomeRecipe().getBiome();
if (ghBiome == null) {
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) {
gh.getWorld().setBiome(x, y, z, gh.getBiomeRecipe().getBiome());
gh.getWorld().setBiome(x, y, z, ghBiome);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ public GreenhouseMap(Greenhouses addon) {
* @return result {@link GreenhouseResult}
*/
public GreenhouseResult addGreenhouse(Greenhouse greenhouse) {
// Validation checks
if (greenhouse.getBiomeRecipe() == null) {
return GreenhouseResult.FAIL_UNKNOWN_RECIPE;
}
if (greenhouse.getWorld() == null) {
return GreenhouseResult.FAIL_NO_WORLD;
}
if (greenhouse.getLocation() == null) {
return GreenhouseResult.NULL;
}
Expand Down

0 comments on commit 9ae9cdb

Please sign in to comment.