mirror of
https://github.com/BentoBoxWorld/Greenhouses.git
synced 2025-02-08 08:11:23 +01:00
Added setting to remove glowstone as an option for walls and roof.
Fixes https://github.com/BentoBoxWorld/Greenhouses/issues/57
This commit is contained in:
parent
a7e454065d
commit
ad82941452
2
pom.xml
2
pom.xml
@ -51,7 +51,7 @@
|
|||||||
<!-- Revision variable removes warning about dynamic version -->
|
<!-- Revision variable removes warning about dynamic version -->
|
||||||
<revision>${build.version}-SNAPSHOT</revision>
|
<revision>${build.version}-SNAPSHOT</revision>
|
||||||
<!-- This allows to change between versions and snapshots. -->
|
<!-- This allows to change between versions and snapshots. -->
|
||||||
<build.version>1.3.0</build.version>
|
<build.version>1.4.0</build.version>
|
||||||
<build.number>-LOCAL</build.number>
|
<build.number>-LOCAL</build.number>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
@ -28,6 +28,21 @@ public class Greenhouses extends Addon {
|
|||||||
public static final Flag GREENHOUSES = new Flag.Builder("GREENHOUSE", Material.GREEN_STAINED_GLASS)
|
public static final Flag GREENHOUSES = new Flag.Builder("GREENHOUSE", Material.GREEN_STAINED_GLASS)
|
||||||
.mode(Mode.BASIC)
|
.mode(Mode.BASIC)
|
||||||
.type(Type.PROTECTION).build();
|
.type(Type.PROTECTION).build();
|
||||||
|
private static Greenhouses instance;
|
||||||
|
private final Config<Settings> config;
|
||||||
|
|
||||||
|
public static Greenhouses getInstance() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*/
|
||||||
|
public Greenhouses() {
|
||||||
|
super();
|
||||||
|
instance = this;
|
||||||
|
config = new Config<>(this, Settings.class);
|
||||||
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see world.bentobox.bentobox.api.addons.Addon#onEnable()
|
* @see world.bentobox.bentobox.api.addons.Addon#onEnable()
|
||||||
@ -36,13 +51,14 @@ public class Greenhouses extends Addon {
|
|||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
saveDefaultConfig();
|
saveDefaultConfig();
|
||||||
this.saveResource("biomes.yml", false);
|
this.saveResource("biomes.yml", false);
|
||||||
settings = new Config<>(this, Settings.class).loadConfigObject();
|
settings = config.loadConfigObject();
|
||||||
if (settings == null) {
|
if (settings == null) {
|
||||||
// Settings did no load correctly. Disable.
|
// Settings did no load correctly. Disable.
|
||||||
logError("Settings did not load correctly - disabling Greenhouses - please check config.yml");
|
logError("Settings did not load correctly - disabling Greenhouses - please check config.yml");
|
||||||
this.setState(State.DISABLED);
|
this.setState(State.DISABLED);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
config.saveConfigObject(settings);
|
||||||
// Load recipes
|
// Load recipes
|
||||||
recipes = new RecipeManager(this);
|
recipes = new RecipeManager(this);
|
||||||
// Load manager
|
// Load manager
|
||||||
|
@ -64,6 +64,10 @@ public class Settings implements ConfigObject {
|
|||||||
@ConfigEntry(path = "greenhouses.allowflowin")
|
@ConfigEntry(path = "greenhouses.allowflowin")
|
||||||
private boolean allowFlowIn;
|
private boolean allowFlowIn;
|
||||||
|
|
||||||
|
@ConfigComment("Allow glowstone to be used as well as glass in roof and walls")
|
||||||
|
@ConfigEntry(path = "greenhouses.allowglowstone")
|
||||||
|
private boolean allowGlowstone = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the gameModes
|
* @return the gameModes
|
||||||
*/
|
*/
|
||||||
@ -196,5 +200,17 @@ public class Settings implements ConfigObject {
|
|||||||
public void setAllowFlowIn(boolean allowFlowIn) {
|
public void setAllowFlowIn(boolean allowFlowIn) {
|
||||||
this.allowFlowIn = allowFlowIn;
|
this.allowFlowIn = allowFlowIn;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @return the allowGlowstone
|
||||||
|
*/
|
||||||
|
public boolean isAllowGlowstone() {
|
||||||
|
return allowGlowstone;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @param allowGlowstone the allowGlowstone to set
|
||||||
|
*/
|
||||||
|
public void setAllowGlowstone(boolean allowGlowstone) {
|
||||||
|
this.allowGlowstone = allowGlowstone;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -11,20 +11,21 @@ import org.bukkit.World;
|
|||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import world.bentobox.greenhouses.Greenhouses;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains the parameters of a greenhouse roof
|
* Contains the parameters of a greenhouse roof
|
||||||
* @author tastybento
|
* @author tastybento
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class Roof extends MinMaxXZ {
|
public class Roof extends MinMaxXZ {
|
||||||
public static final List<Material> ROOF_BLOCKS;
|
private static final List<Material> ROOF_BLOCKS;
|
||||||
static {
|
static {
|
||||||
List<Material> r = Arrays.stream(Material.values())
|
List<Material> r = Arrays.stream(Material.values())
|
||||||
.filter(Material::isBlock) // Blocks only, no items
|
.filter(Material::isBlock) // Blocks only, no items
|
||||||
.filter(m -> m.name().contains("TRAPDOOR") // All trapdoors
|
.filter(m -> m.name().contains("TRAPDOOR") // All trapdoors
|
||||||
|| m.name().contains("GLASS") // All glass blocks
|
|| m.name().contains("GLASS") // All glass blocks
|
||||||
|| m.equals(Material.HOPPER) // Hoppers
|
|| m.equals(Material.HOPPER)) // Hoppers
|
||||||
|| m.equals(Material.GLOWSTONE)) // Glowstone
|
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
ROOF_BLOCKS = Collections.unmodifiableList(r);
|
ROOF_BLOCKS = Collections.unmodifiableList(r);
|
||||||
}
|
}
|
||||||
@ -52,7 +53,7 @@ public class Roof extends MinMaxXZ {
|
|||||||
// to be outside the greenhouse in this situation, so a check is done later to make sure the player is inside
|
// to be outside the greenhouse in this situation, so a check is done later to make sure the player is inside
|
||||||
int roofY = loc.getBlockY();
|
int roofY = loc.getBlockY();
|
||||||
for (int y = roofY; y < world.getMaxHeight(); y++) {
|
for (int y = roofY; y < world.getMaxHeight(); y++) {
|
||||||
if (ROOF_BLOCKS.contains(world.getBlockAt(loc.getBlockX(),y,loc.getBlockZ()).getType())) {
|
if (roofBlocks(world.getBlockAt(loc.getBlockX(),y,loc.getBlockZ()).getType())) {
|
||||||
roofFound = true;
|
roofFound = true;
|
||||||
loc = new Location(world,loc.getBlockX(),y,loc.getBlockZ());
|
loc = new Location(world,loc.getBlockX(),y,loc.getBlockZ());
|
||||||
break;
|
break;
|
||||||
@ -65,10 +66,10 @@ public class Roof extends MinMaxXZ {
|
|||||||
for (int z = loc.getBlockZ() - radius; z <= loc.getBlockZ() + radius && !roofFound; z++) {
|
for (int z = loc.getBlockZ() - radius; z <= loc.getBlockZ() + radius && !roofFound; z++) {
|
||||||
if (!((x > loc.getBlockX() - radius && x < loc.getBlockX() + radius) && (z > loc.getBlockZ() - radius && z < loc.getBlockZ() + radius))) {
|
if (!((x > loc.getBlockX() - radius && x < loc.getBlockX() + radius) && (z > loc.getBlockZ() - radius && z < loc.getBlockZ() + radius))) {
|
||||||
Block b = world.getBlockAt(x, roofY, z);
|
Block b = world.getBlockAt(x, roofY, z);
|
||||||
if (!Walls.WALL_BLOCKS.contains(b.getType())) {
|
if (!Walls.wallBlocks(b.getType())) {
|
||||||
// Look up
|
// Look up
|
||||||
for (int y = roofY; y < world.getMaxHeight() && !roofFound; y++) {
|
for (int y = roofY; y < world.getMaxHeight() && !roofFound; y++) {
|
||||||
if (ROOF_BLOCKS.contains(world.getBlockAt(x,y,z).getType())) {
|
if (roofBlocks(world.getBlockAt(x,y,z).getType())) {
|
||||||
roofFound = true;
|
roofFound = true;
|
||||||
loc = new Location(world,x,y,z);
|
loc = new Location(world,x,y,z);
|
||||||
}
|
}
|
||||||
@ -129,7 +130,7 @@ public class Roof extends MinMaxXZ {
|
|||||||
maxX = maxx.getBlockX()-1;
|
maxX = maxx.getBlockX()-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (ROOF_BLOCKS.contains(world.getBlockAt(minx).getType()) && limit < 200) {
|
while (roofBlocks(world.getBlockAt(minx).getType()) && limit < 200) {
|
||||||
limit++;
|
limit++;
|
||||||
minx.subtract(new Vector(1,0,0));
|
minx.subtract(new Vector(1,0,0));
|
||||||
}
|
}
|
||||||
@ -137,7 +138,7 @@ public class Roof extends MinMaxXZ {
|
|||||||
minX = minx.getBlockX() + 1;
|
minX = minx.getBlockX() + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (ROOF_BLOCKS.contains(world.getBlockAt(maxz).getType()) && limit < 300) {
|
while (roofBlocks(world.getBlockAt(maxz).getType()) && limit < 300) {
|
||||||
limit++;
|
limit++;
|
||||||
maxz.add(new Vector(0,0,1));
|
maxz.add(new Vector(0,0,1));
|
||||||
}
|
}
|
||||||
@ -145,7 +146,7 @@ public class Roof extends MinMaxXZ {
|
|||||||
maxZ = maxz.getBlockZ() - 1;
|
maxZ = maxz.getBlockZ() - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (ROOF_BLOCKS.contains(world.getBlockAt(minz).getType()) && limit < 400) {
|
while (roofBlocks(world.getBlockAt(minz).getType()) && limit < 400) {
|
||||||
limit++;
|
limit++;
|
||||||
minz.subtract(new Vector(0,0,1));
|
minz.subtract(new Vector(0,0,1));
|
||||||
}
|
}
|
||||||
@ -154,6 +155,15 @@ public class Roof extends MinMaxXZ {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if material is a roof material
|
||||||
|
* @param m - material
|
||||||
|
* @return true if roof material
|
||||||
|
*/
|
||||||
|
public static boolean roofBlocks(Material m) {
|
||||||
|
return ROOF_BLOCKS.contains(m) || (m.equals(Material.GLOWSTONE) && Greenhouses.getInstance().getSettings().isAllowGlowstone());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the roofFound
|
* @return the roofFound
|
||||||
*/
|
*/
|
||||||
|
@ -10,16 +10,17 @@ import org.bukkit.Material;
|
|||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
|
|
||||||
|
import world.bentobox.greenhouses.Greenhouses;
|
||||||
|
|
||||||
public class Walls extends MinMaxXZ {
|
public class Walls extends MinMaxXZ {
|
||||||
public static final List<Material> WALL_BLOCKS;
|
private static final List<Material> WALL_BLOCKS;
|
||||||
static {
|
static {
|
||||||
List<Material> w = Arrays.stream(Material.values())
|
List<Material> w = Arrays.stream(Material.values())
|
||||||
.filter(Material::isBlock) // Blocks only, no items
|
.filter(Material::isBlock) // Blocks only, no items
|
||||||
.filter(m -> !m.name().contains("TRAPDOOR")) // No trap doors
|
.filter(m -> !m.name().contains("TRAPDOOR")) // No trap doors
|
||||||
.filter(m -> m.name().contains("DOOR") // All doors
|
.filter(m -> m.name().contains("DOOR") // All doors
|
||||||
|| m.name().contains("GLASS") // All glass blocks
|
|| m.name().contains("GLASS") // All glass blocks
|
||||||
|| m.equals(Material.HOPPER) // Hoppers
|
|| m.equals(Material.HOPPER)) // Hoppers
|
||||||
|| m.equals(Material.GLOWSTONE)) // Glowstone
|
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
WALL_BLOCKS = Collections.unmodifiableList(w);
|
WALL_BLOCKS = Collections.unmodifiableList(w);
|
||||||
}
|
}
|
||||||
@ -147,6 +148,15 @@ public class Walls extends MinMaxXZ {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if material is a wall material
|
||||||
|
* @param m - material
|
||||||
|
* @return true if wall material
|
||||||
|
*/
|
||||||
|
public static boolean wallBlocks(Material m) {
|
||||||
|
return WALL_BLOCKS.contains(m) || (m.equals(Material.GLOWSTONE) && Greenhouses.getInstance().getSettings().isAllowGlowstone());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the floor
|
* @return the floor
|
||||||
*/
|
*/
|
||||||
|
@ -19,6 +19,11 @@ public class GreenhouseFinder {
|
|||||||
private final Set<Location> redGlass = new HashSet<>();
|
private final Set<Location> redGlass = new HashSet<>();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find out if there is a greenhouse here
|
||||||
|
* @param location - start location
|
||||||
|
* @return GreenhouseResult class
|
||||||
|
*/
|
||||||
public Set<GreenhouseResult> find(Location location) {
|
public Set<GreenhouseResult> find(Location location) {
|
||||||
Set<GreenhouseResult> result = new HashSet<>();
|
Set<GreenhouseResult> result = new HashSet<>();
|
||||||
redGlass.clear();
|
redGlass.clear();
|
||||||
@ -80,8 +85,8 @@ public class GreenhouseFinder {
|
|||||||
} else {
|
} else {
|
||||||
// Check just the walls
|
// Check just the walls
|
||||||
if (y == roof.getHeight() || x == minX || x == maxX || z == minZ || z== maxZ) {
|
if (y == roof.getHeight() || x == minX || x == maxX || z == minZ || z== maxZ) {
|
||||||
if ((y != roof.getHeight() && !Walls.WALL_BLOCKS.contains(blockType))
|
if ((y != roof.getHeight() && !Walls.wallBlocks(blockType))
|
||||||
|| (y == roof.getHeight() && !Roof.ROOF_BLOCKS.contains(blockType))) {
|
|| (y == roof.getHeight() && !Roof.roofBlocks(blockType))) {
|
||||||
//logger(2,"DEBUG: bad block found at " + x + "," + y+ "," + z + " " + blockType);
|
//logger(2,"DEBUG: bad block found at " + x + "," + y+ "," + z + " " + blockType);
|
||||||
if (blockType == Material.AIR) {
|
if (blockType == Material.AIR) {
|
||||||
airHole = true;
|
airHole = true;
|
||||||
|
@ -31,3 +31,5 @@ greenhouses:
|
|||||||
allowflowout: false
|
allowflowout: false
|
||||||
# Allow lava or water to flow into a greenhouse, e.g., through the door
|
# Allow lava or water to flow into a greenhouse, e.g., through the door
|
||||||
allowflowin: false
|
allowflowin: false
|
||||||
|
# Allow glowstone to be used as well as glass in roof and walls
|
||||||
|
allowglowstone: true
|
Loading…
Reference in New Issue
Block a user