2019-01-22 00:44:01 +01:00
|
|
|
package world.bentobox.greenhouses.data;
|
|
|
|
|
2019-10-12 03:52:32 +02:00
|
|
|
import java.util.Map;
|
2019-01-22 00:44:01 +01:00
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
import org.bukkit.Location;
|
2019-10-12 03:52:32 +02:00
|
|
|
import org.bukkit.Material;
|
2019-01-22 00:44:01 +01:00
|
|
|
import org.bukkit.World;
|
|
|
|
import org.bukkit.block.Biome;
|
2019-05-09 00:21:11 +02:00
|
|
|
import org.bukkit.util.BoundingBox;
|
2020-10-03 23:44:20 +02:00
|
|
|
import org.eclipse.jdt.annotation.NonNull;
|
|
|
|
import org.eclipse.jdt.annotation.Nullable;
|
2019-01-22 00:44:01 +01:00
|
|
|
|
2019-01-30 17:09:55 +01:00
|
|
|
import com.google.gson.annotations.Expose;
|
|
|
|
|
2019-01-22 00:44:01 +01:00
|
|
|
import world.bentobox.bentobox.database.objects.DataObject;
|
2020-06-11 06:35:38 +02:00
|
|
|
import world.bentobox.bentobox.database.objects.Table;
|
2019-01-22 00:44:01 +01:00
|
|
|
import world.bentobox.greenhouses.greenhouse.BiomeRecipe;
|
2019-01-23 05:54:43 +01:00
|
|
|
import world.bentobox.greenhouses.greenhouse.Walls;
|
2019-05-09 00:21:11 +02:00
|
|
|
import world.bentobox.greenhouses.managers.RecipeManager;
|
2019-01-22 00:44:01 +01:00
|
|
|
|
|
|
|
/**
|
2019-01-26 20:10:30 +01:00
|
|
|
* Greenhouse object
|
2019-01-22 00:44:01 +01:00
|
|
|
* @author tastybento
|
|
|
|
*
|
|
|
|
*/
|
2020-06-11 06:35:38 +02:00
|
|
|
@Table(name = "Greenhouses")
|
2019-01-22 00:44:01 +01:00
|
|
|
public class Greenhouse implements DataObject {
|
|
|
|
|
2019-01-30 17:09:55 +01:00
|
|
|
@Expose
|
2019-01-22 00:44:01 +01:00
|
|
|
private String uniqueId = UUID.randomUUID().toString();
|
2019-01-30 17:09:55 +01:00
|
|
|
@Expose
|
2019-01-22 00:44:01 +01:00
|
|
|
private Location location;
|
2019-01-30 17:09:55 +01:00
|
|
|
@Expose
|
2019-05-17 23:08:59 +02:00
|
|
|
// Min coords are inside, max coords are outside
|
2019-05-09 00:21:11 +02:00
|
|
|
private BoundingBox boundingBox;
|
2019-01-30 17:09:55 +01:00
|
|
|
@Expose
|
2019-01-22 00:44:01 +01:00
|
|
|
private Biome originalBiome;
|
2019-01-30 17:09:55 +01:00
|
|
|
@Expose
|
2019-01-22 00:44:01 +01:00
|
|
|
private Location roofHopperLocation;
|
2019-01-30 17:09:55 +01:00
|
|
|
@Expose
|
2019-05-09 00:21:11 +02:00
|
|
|
private String biomeRecipeName;
|
2019-01-30 17:09:55 +01:00
|
|
|
|
2019-01-22 00:44:01 +01:00
|
|
|
private boolean broken;
|
2019-11-01 05:36:05 +01:00
|
|
|
|
2019-10-12 03:52:32 +02:00
|
|
|
private Map<Material, Integer> missingBlocks;
|
2019-01-22 00:44:01 +01:00
|
|
|
|
|
|
|
/**
|
2019-01-23 05:54:43 +01:00
|
|
|
* Constructor for database
|
2019-01-22 00:44:01 +01:00
|
|
|
*/
|
2019-01-23 05:54:43 +01:00
|
|
|
public Greenhouse() {}
|
|
|
|
|
|
|
|
public Greenhouse(World world, Walls walls, int ceilingHeight) {
|
|
|
|
this.location = new Location(world, walls.getMinX(), walls.getFloor(), walls.getMinZ());
|
2019-11-01 05:36:05 +01:00
|
|
|
Location location2 = new Location(world, walls.getMaxX() + 1D, ceilingHeight + 1D, walls.getMaxZ() + 1D);
|
2019-05-09 00:21:11 +02:00
|
|
|
this.boundingBox = BoundingBox.of(location, location2);
|
2019-01-22 00:44:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-10-03 23:44:20 +02:00
|
|
|
* @return the biomeRecipe or null if none has been set
|
2019-01-22 00:44:01 +01:00
|
|
|
*/
|
2020-10-03 23:44:20 +02:00
|
|
|
@Nullable
|
2019-05-09 00:21:11 +02:00
|
|
|
public String getBiomeRecipeName() {
|
|
|
|
return biomeRecipeName;
|
2019-01-22 00:44:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the ceilingHeight
|
|
|
|
*/
|
|
|
|
public int getCeilingHeight() {
|
2019-05-09 00:21:11 +02:00
|
|
|
return (int) boundingBox.getMaxY();
|
2019-01-22 00:44:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the floorHeight
|
|
|
|
*/
|
|
|
|
public int getFloorHeight() {
|
|
|
|
return location.getBlockY();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the location
|
|
|
|
*/
|
2020-10-03 23:44:20 +02:00
|
|
|
@Nullable
|
2019-01-22 00:44:01 +01:00
|
|
|
public Location getLocation() {
|
|
|
|
return location;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the originalBiome
|
|
|
|
*/
|
2020-10-03 23:44:20 +02:00
|
|
|
@Nullable
|
2019-01-22 00:44:01 +01:00
|
|
|
public Biome getOriginalBiome() {
|
|
|
|
return originalBiome;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the roofHopperLocation
|
|
|
|
*/
|
2020-10-03 23:44:20 +02:00
|
|
|
@Nullable
|
2019-01-22 00:44:01 +01:00
|
|
|
public Location getRoofHopperLocation() {
|
|
|
|
return roofHopperLocation;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
* @see world.bentobox.bentobox.database.objects.DataObject#getUniqueId()
|
|
|
|
*/
|
|
|
|
@Override
|
2020-10-03 23:44:20 +02:00
|
|
|
@NonNull
|
2019-01-22 00:44:01 +01:00
|
|
|
public String getUniqueId() {
|
|
|
|
return uniqueId;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the broken
|
|
|
|
*/
|
|
|
|
public boolean isBroken() {
|
|
|
|
return broken;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-05-09 00:21:11 +02:00
|
|
|
* @param biomeRecipeName the biomeRecipe to set
|
2019-01-22 00:44:01 +01:00
|
|
|
*/
|
2019-05-09 00:21:11 +02:00
|
|
|
public void setBiomeRecipeName(String biomeRecipeName) {
|
|
|
|
this.biomeRecipeName = biomeRecipeName;
|
2019-01-22 00:44:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param broken the broken to set
|
|
|
|
*/
|
|
|
|
public void setBroken(boolean broken) {
|
|
|
|
this.broken = broken;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param location the location to set
|
|
|
|
*/
|
|
|
|
public void setLocation(Location location) {
|
|
|
|
this.location = location;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param originalBiome the originalBiome to set
|
|
|
|
*/
|
|
|
|
public void setOriginalBiome(Biome originalBiome) {
|
|
|
|
this.originalBiome = originalBiome;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param roofHopperLocation the roofHopperLocation to set
|
|
|
|
*/
|
|
|
|
public void setRoofHopperLocation(Location roofHopperLocation) {
|
|
|
|
this.roofHopperLocation = roofHopperLocation;
|
|
|
|
}
|
|
|
|
|
2019-05-09 00:21:11 +02:00
|
|
|
/**
|
|
|
|
* @return the boundingBox
|
|
|
|
*/
|
2020-10-03 23:44:20 +02:00
|
|
|
@Nullable
|
2019-05-09 00:21:11 +02:00
|
|
|
public BoundingBox getBoundingBox() {
|
|
|
|
return boundingBox;
|
|
|
|
}
|
|
|
|
|
2021-01-10 20:57:02 +01:00
|
|
|
/**
|
|
|
|
* @return a bounding box of the greenhouse that does not include the walls or roof
|
|
|
|
*/
|
|
|
|
@Nullable
|
|
|
|
public BoundingBox getInternalBoundingBox() {
|
|
|
|
return boundingBox == null ? null : boundingBox.clone().expand(-1D);
|
|
|
|
}
|
|
|
|
|
2019-05-09 00:21:11 +02:00
|
|
|
/**
|
|
|
|
* @param boundingBox the boundingBox to set
|
|
|
|
*/
|
|
|
|
public void setBoundingBox(BoundingBox boundingBox) {
|
|
|
|
this.boundingBox = boundingBox;
|
|
|
|
}
|
|
|
|
|
2019-01-22 00:44:01 +01:00
|
|
|
/* (non-Javadoc)
|
|
|
|
* @see world.bentobox.bentobox.database.objects.DataObject#setUniqueId(java.lang.String)
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public void setUniqueId(String uniqueId) {
|
|
|
|
this.uniqueId = uniqueId;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-03-02 19:53:15 +01:00
|
|
|
*
|
|
|
|
* @return internal area of greenhouse
|
2019-01-22 00:44:01 +01:00
|
|
|
*/
|
|
|
|
public int getArea() {
|
2019-05-09 00:21:11 +02:00
|
|
|
return ((int)boundingBox.getWidthX() - 2) * ((int)boundingBox.getWidthZ() - 2);
|
2019-01-22 00:44:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the world
|
|
|
|
*/
|
2020-10-03 23:44:20 +02:00
|
|
|
@NonNull
|
2019-01-22 00:44:01 +01:00
|
|
|
public World getWorld() {
|
|
|
|
return this.getLocation().getWorld();
|
|
|
|
}
|
|
|
|
|
2019-01-22 02:53:34 +01:00
|
|
|
/**
|
|
|
|
* Checks if a location is inside the greenhouse
|
|
|
|
* @param location2 - location to check
|
|
|
|
* @return true if inside the greenhouse
|
|
|
|
*/
|
|
|
|
public boolean contains(Location location2) {
|
2019-05-09 00:21:11 +02:00
|
|
|
return location.getWorld().equals(location2.getWorld()) && boundingBox.contains(location2.toVector());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the biome recipe
|
|
|
|
* @param greenhouseRecipe - biome recipe
|
|
|
|
*/
|
|
|
|
public void setBiomeRecipe(BiomeRecipe greenhouseRecipe) {
|
|
|
|
this.biomeRecipeName = greenhouseRecipe.getName();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the biome recipe for this greenhouse
|
|
|
|
* @return biome recipe or null
|
|
|
|
*/
|
2020-10-03 23:44:20 +02:00
|
|
|
@Nullable
|
2019-05-09 00:21:11 +02:00
|
|
|
public BiomeRecipe getBiomeRecipe() {
|
|
|
|
return RecipeManager.getBiomeRecipies(biomeRecipeName).orElse(null);
|
2019-01-22 02:53:34 +01:00
|
|
|
}
|
|
|
|
|
2019-10-12 03:52:32 +02:00
|
|
|
/**
|
|
|
|
* @param missingBlocks the missingBlocks to set
|
|
|
|
*/
|
|
|
|
public void setMissingBlocks(Map<Material, Integer> missingBlocks) {
|
|
|
|
this.missingBlocks = missingBlocks;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the missingBlocks
|
|
|
|
*/
|
2020-10-03 23:44:20 +02:00
|
|
|
@Nullable
|
2019-10-12 03:52:32 +02:00
|
|
|
public Map<Material, Integer> getMissingBlocks() {
|
|
|
|
return missingBlocks;
|
|
|
|
}
|
2019-01-22 00:44:01 +01:00
|
|
|
}
|