Bug fixing
Greenhouses store correctly. Sizes work and entrance/exit works.
This commit is contained in:
parent
3a05faace0
commit
fb3d150820
|
@ -10,9 +10,6 @@ import org.bukkit.World;
|
|||
|
||||
import world.bentobox.bentobox.api.addons.Addon;
|
||||
import world.bentobox.bentobox.api.configuration.Config;
|
||||
import world.bentobox.greenhouses.listeners.GreenhouseEvents;
|
||||
import world.bentobox.greenhouses.listeners.GreenhouseGuard;
|
||||
import world.bentobox.greenhouses.listeners.SnowTracker;
|
||||
import world.bentobox.greenhouses.managers.GreenhouseManager;
|
||||
import world.bentobox.greenhouses.managers.RecipeManager;
|
||||
import world.bentobox.greenhouses.ui.user.UserCommand;
|
||||
|
@ -42,11 +39,10 @@ public class Greenhouses extends Addon {
|
|||
this.setState(State.DISABLED);
|
||||
return;
|
||||
}
|
||||
// Load manager
|
||||
manager = new GreenhouseManager(this);
|
||||
// Load recipes
|
||||
recipes = new RecipeManager(this);
|
||||
|
||||
// Load manager
|
||||
manager = new GreenhouseManager(this);
|
||||
// Register commands for AcidIsland and BSkyBlock
|
||||
getPlugin().getAddonsManager().getGameModeAddons().stream()
|
||||
.filter(gm -> gm.getDescription().getName().equals("AcidIsland") || gm.getDescription().getName().equals("BSkyBlock"))
|
||||
|
@ -57,10 +53,7 @@ public class Greenhouses extends Addon {
|
|||
activeWorlds.add(gm.getOverWorld());
|
||||
});
|
||||
|
||||
// Register listeners
|
||||
this.registerListener(new SnowTracker(this));
|
||||
this.registerListener(new GreenhouseEvents(this));
|
||||
this.registerListener(new GreenhouseGuard(this));
|
||||
this.registerListener(manager);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package world.bentobox.greenhouses.data;
|
||||
|
||||
import world.bentobox.bentobox.database.objects.adapters.AdapterInterface;
|
||||
import world.bentobox.greenhouses.greenhouse.BiomeRecipe;
|
||||
import world.bentobox.greenhouses.managers.RecipeManager;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
public class BiomeRecipeSerializer implements AdapterInterface<BiomeRecipe, String> {
|
||||
|
||||
@Override
|
||||
public BiomeRecipe deserialize(Object object) {
|
||||
return RecipeManager.getBiomeRecipies((String)object).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serialize(Object object) {
|
||||
return ((BiomeRecipe)object).getName();
|
||||
}
|
||||
|
||||
}
|
|
@ -11,7 +11,9 @@ import org.bukkit.World;
|
|||
import org.bukkit.block.Biome;
|
||||
|
||||
import world.bentobox.bentobox.database.objects.DataObject;
|
||||
import world.bentobox.bentobox.database.objects.adapters.Adapter;
|
||||
import world.bentobox.greenhouses.greenhouse.BiomeRecipe;
|
||||
import world.bentobox.greenhouses.greenhouse.Walls;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
|
@ -25,32 +27,31 @@ public class Greenhouse implements DataObject {
|
|||
@Override
|
||||
public String toString() {
|
||||
return "Greenhouse [uniqueId=" + uniqueId + ", location=" + location + ", footprint=" + footprint
|
||||
+ ", ceilingHeight=" + ceilingHeight + ", originalBiome=" + originalBiome + ", greenhouseBiome="
|
||||
+ greenhouseBiome + ", roofHopperLocation=" + roofHopperLocation + ", biomeRecipe=" + biomeRecipe.getName()
|
||||
+ ", ceilingHeight=" + ceilingHeight + ", originalBiome=" + originalBiome
|
||||
+ ", roofHopperLocation=" + roofHopperLocation + ", biomeRecipe=" + biomeRecipe.getName()
|
||||
+ ", broken=" + broken + "]";
|
||||
}
|
||||
|
||||
private String uniqueId = UUID.randomUUID().toString();
|
||||
private Location location;
|
||||
@Adapter(RectangleSerializer.class)
|
||||
private Rectangle footprint;
|
||||
private int ceilingHeight;
|
||||
private Biome originalBiome;
|
||||
private Biome greenhouseBiome;
|
||||
private Location roofHopperLocation;
|
||||
@Adapter(BiomeRecipeSerializer.class)
|
||||
private BiomeRecipe biomeRecipe;
|
||||
private boolean broken;
|
||||
|
||||
/**
|
||||
* Constructor for database
|
||||
*/
|
||||
public Greenhouse() {}
|
||||
|
||||
/**
|
||||
* @param world
|
||||
* @param footprint
|
||||
* @param ceilingHeight
|
||||
*/
|
||||
public Greenhouse(World world, Rectangle footprint, int floorHeight, int ceilingHeight) {
|
||||
this.location = new Location(world, footprint.getMinX(), floorHeight, footprint.getMinY());
|
||||
this.footprint = footprint;
|
||||
public Greenhouse(World world, Walls walls, int ceilingHeight) {
|
||||
this.location = new Location(world, walls.getMinX(), walls.getFloor(), walls.getMinZ());
|
||||
this.ceilingHeight = ceilingHeight;
|
||||
this.footprint = new Rectangle(walls.getMinX(), walls.getMinZ(), walls.getWidth(), walls.getLength());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -81,13 +82,6 @@ public class Greenhouse implements DataObject {
|
|||
return footprint;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the greenhouseBiome
|
||||
*/
|
||||
public Biome getGreenhouseBiome() {
|
||||
return greenhouseBiome;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the location
|
||||
*/
|
||||
|
@ -152,13 +146,6 @@ public class Greenhouse implements DataObject {
|
|||
this.footprint = floor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param greenhouseBiome the greenhouseBiome to set
|
||||
*/
|
||||
public void setGreenhouseBiome(Biome greenhouseBiome) {
|
||||
this.greenhouseBiome = greenhouseBiome;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param location the location to set
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package world.bentobox.greenhouses.data;
|
||||
|
||||
import java.awt.Rectangle;
|
||||
|
||||
import world.bentobox.bentobox.database.objects.adapters.AdapterInterface;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
public class RectangleSerializer implements AdapterInterface<Rectangle, String> {
|
||||
|
||||
@Override
|
||||
public Rectangle deserialize(Object object) {
|
||||
if (object instanceof String) {
|
||||
String[] s = ((String)object).split(",");
|
||||
if (s.length == 4) {
|
||||
return new Rectangle(Integer.valueOf(s[0]), Integer.valueOf(s[1]), Integer.valueOf(s[2]), Integer.valueOf(s[3]));
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serialize(Object object) {
|
||||
Rectangle r = (Rectangle)object;
|
||||
return r == null ? "" : r.x + ","+ r.y + "," + r.width + "," + r.height;
|
||||
}
|
||||
|
||||
}
|
|
@ -228,6 +228,20 @@ public class Walls {
|
|||
return WALL_BLOCKS.contains(blockType);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return width of the space
|
||||
*/
|
||||
public int getWidth() {
|
||||
return Math.abs(maxX - minX);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return length of the space
|
||||
*/
|
||||
public int getLength() {
|
||||
return Math.abs(maxZ - minZ);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
|
@ -236,4 +250,6 @@ public class Walls {
|
|||
return "Walls [minX=" + minX + ", maxX=" + maxX + ", minZ=" + minZ + ", maxZ=" + maxZ + ", floor=" + floor
|
||||
+ "]";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -95,12 +95,12 @@ public class GreenhouseEvents implements Listener {
|
|||
// from is a greenhouse
|
||||
if (from.isPresent() && !to.isPresent()) {
|
||||
// Exiting
|
||||
user.sendRawMessage("Leaving " + to.get().getBiomeRecipe().getFriendlyName() + " greenhouse");
|
||||
user.sendRawMessage("Leaving " + from.get().getBiomeRecipe().getFriendlyName() + " greenhouse");
|
||||
return;
|
||||
}
|
||||
if (!from.isPresent() && to.isPresent()) {
|
||||
// Entering
|
||||
user.sendRawMessage("Entering " + from.get().getBiomeRecipe().getFriendlyName() + " greenhouse");
|
||||
user.sendRawMessage("Entering " + to.get().getBiomeRecipe().getFriendlyName() + " greenhouse");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -151,7 +151,7 @@ public class EcoSystemManager {
|
|||
gh.setRoofHopperLocation(null);
|
||||
return null;
|
||||
}
|
||||
return (Hopper)gh.getRoofHopperLocation().getBlock().getBlockData();
|
||||
return (Hopper)gh.getRoofHopperLocation().getBlock().getState();
|
||||
}
|
||||
|
||||
public void cancel() {
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
package world.bentobox.greenhouses.managers;
|
||||
|
||||
import java.awt.Rectangle;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
|
@ -33,9 +31,8 @@ public class GreenhouseFinder {
|
|||
}
|
||||
// Find the walls
|
||||
Walls walls = new Walls(roof);
|
||||
Bukkit.getLogger().info("DEBUG: walls = " + walls.toString());
|
||||
// Make the initial greenhouse
|
||||
gh = new Greenhouse(location.getWorld(), new Rectangle(walls.getMinX(), walls.getMinZ(), walls.getMaxX(), walls.getMaxZ()), walls.getFloor(), roof.getHeight());
|
||||
gh = new Greenhouse(location.getWorld(), walls, roof.getHeight());
|
||||
// Set the original biome
|
||||
gh.setOriginalBiome(location.getBlock().getBiome());
|
||||
|
||||
|
@ -173,7 +170,7 @@ public class GreenhouseFinder {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return the gh
|
||||
* @return the greenhouse
|
||||
*/
|
||||
public Greenhouse getGh() {
|
||||
return gh;
|
||||
|
|
|
@ -7,13 +7,19 @@ import org.bukkit.Material;
|
|||
import org.bukkit.Particle;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import world.bentobox.bentobox.api.events.BentoBoxReadyEvent;
|
||||
import world.bentobox.bentobox.database.Database;
|
||||
import world.bentobox.greenhouses.Greenhouses;
|
||||
import world.bentobox.greenhouses.data.Greenhouse;
|
||||
import world.bentobox.greenhouses.greenhouse.BiomeRecipe;
|
||||
import world.bentobox.greenhouses.listeners.GreenhouseEvents;
|
||||
import world.bentobox.greenhouses.listeners.GreenhouseGuard;
|
||||
import world.bentobox.greenhouses.listeners.SnowTracker;
|
||||
|
||||
public class GreenhouseManager {
|
||||
public class GreenhouseManager implements Listener {
|
||||
|
||||
/**
|
||||
* Result of greenhouse making
|
||||
|
@ -52,9 +58,17 @@ public class GreenhouseManager {
|
|||
this.addon = addon;
|
||||
handler = new Database<>(addon, Greenhouse.class);
|
||||
map = new GreenhouseMap(addon);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void startManager(BentoBoxReadyEvent e) {
|
||||
loadGreenhouses();
|
||||
// Start ecosystems
|
||||
new EcoSystemManager(addon, this);
|
||||
// Register listeners
|
||||
addon.registerListener(new SnowTracker(addon));
|
||||
addon.registerListener(new GreenhouseEvents(addon));
|
||||
addon.registerListener(new GreenhouseGuard(addon));
|
||||
}
|
||||
|
||||
public GreenhouseMap getMap() {
|
||||
|
@ -75,13 +89,14 @@ public class GreenhouseManager {
|
|||
addon.logError(result.name());
|
||||
break;
|
||||
case SUCCESS:
|
||||
activateGreenhouse(g);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
});
|
||||
addon.log("Loaded greenhouses.");
|
||||
addon.log("Loaded " + map.getSize() + " greenhouses.");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -145,6 +160,7 @@ public class GreenhouseManager {
|
|||
// Success - set recipe and add to map
|
||||
finder.getGh().setBiomeRecipe(greenhouseRecipe);
|
||||
map.addGreenhouse(finder.getGh());
|
||||
activateGreenhouse(finder.getGh());
|
||||
}
|
||||
return new GhResult().setFinder(finder).setResults(resultSet);
|
||||
}
|
||||
|
@ -155,11 +171,21 @@ public class GreenhouseManager {
|
|||
.map(r -> {
|
||||
// Success - set recipe and add to map
|
||||
finder.getGh().setBiomeRecipe(r);
|
||||
activateGreenhouse(finder.getGh());
|
||||
return map.addGreenhouse(finder.getGh());
|
||||
}).orElse(GreenhouseResult.FAIL_NO_RECIPE_FOUND));
|
||||
return new GhResult().setFinder(finder).setResults(resultSet);
|
||||
}
|
||||
|
||||
private void activateGreenhouse(Greenhouse gh) {
|
||||
for (int x = gh.getFootprint().x; x < gh.getFootprint().x + gh.getFootprint().width; x++) {
|
||||
for (int z = gh.getFootprint().y; z < gh.getFootprint().y + gh.getFootprint().height; z++) {
|
||||
gh.getWorld().setBiome(x, z, gh.getBiomeRecipe().getBiome());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Result of the greenhouse make effort
|
||||
*
|
||||
|
|
|
@ -36,7 +36,10 @@ public class GreenhouseMap {
|
|||
if (greenhouse.getLocation() == null) {
|
||||
return GreenhouseResult.NULL;
|
||||
}
|
||||
Bukkit.getLogger().info("Adding greenhouse " + greenhouse.getLocation());
|
||||
Bukkit.getLogger().info("Island = " + addon.getIslands().getIslandAt(greenhouse.getLocation()).isPresent());
|
||||
return addon.getIslands().getIslandAt(greenhouse.getLocation()).map(i -> {
|
||||
Bukkit.getLogger().info("Island found!");
|
||||
greenhouses.putIfAbsent(i, new ArrayList<>());
|
||||
// Check if overlapping
|
||||
if (!isOverlapping(greenhouse)) {
|
||||
|
@ -60,18 +63,8 @@ public class GreenhouseMap {
|
|||
private Optional<Greenhouse> getXZGreenhouse(Location location) {
|
||||
return addon.getIslands().getIslandAt(location)
|
||||
.filter(i -> greenhouses.containsKey(i))
|
||||
.map(i -> {
|
||||
for (Greenhouse gh : greenhouses.get(i)) {
|
||||
Bukkit.getLogger().info("Trying " + location);
|
||||
Bukkit.getLogger().info(gh.toString());
|
||||
if (gh.contains(location)) {
|
||||
Bukkit.getLogger().info("inside gh");
|
||||
return Optional.of(gh);
|
||||
}
|
||||
}
|
||||
Bukkit.getLogger().info("None found");
|
||||
return null;
|
||||
}).orElse(Optional.empty());
|
||||
.map(i -> greenhouses.get(i).stream().filter(g -> g.contains(location)).findFirst())
|
||||
.orElse(Optional.empty());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -117,4 +110,11 @@ public class GreenhouseMap {
|
|||
public List<Greenhouse> getGreenhouses() {
|
||||
return greenhouses.values().stream().flatMap(List::stream).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return number of greenhouses loaded
|
||||
*/
|
||||
public int getSize() {
|
||||
return greenhouses.values().stream().mapToInt(List::size).sum();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import java.io.IOException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
|
@ -22,7 +23,7 @@ public class RecipeManager {
|
|||
|
||||
private static final int MAXIMUM_INVENTORY_SIZE = 49;
|
||||
private Greenhouses addon;
|
||||
private List<BiomeRecipe> biomeRecipes = new ArrayList<>();
|
||||
private static List<BiomeRecipe> biomeRecipes = new ArrayList<>();
|
||||
|
||||
public RecipeManager(Greenhouses addon) {
|
||||
this.addon = addon;
|
||||
|
@ -35,6 +36,15 @@ public class RecipeManager {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get BiomeRecipe by name
|
||||
* @param name - name
|
||||
* @return Optional BiomeRecipe found
|
||||
*/
|
||||
public static Optional<BiomeRecipe> getBiomeRecipies(String name) {
|
||||
return biomeRecipes.stream().filter(r -> r.getName().equals(name)).findFirst();
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads all the biome recipes from the file biomes.yml.
|
||||
* @throws InvalidConfigurationException
|
||||
|
|
Loading…
Reference in New Issue