mirror of
https://github.com/BentoBoxWorld/Greenhouses.git
synced 2025-02-01 12:51:31 +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>${build.version}-SNAPSHOT</revision>
|
||||
<!-- 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>
|
||||
</properties>
|
||||
|
||||
|
@ -28,6 +28,21 @@ public class Greenhouses extends Addon {
|
||||
public static final Flag GREENHOUSES = new Flag.Builder("GREENHOUSE", Material.GREEN_STAINED_GLASS)
|
||||
.mode(Mode.BASIC)
|
||||
.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)
|
||||
* @see world.bentobox.bentobox.api.addons.Addon#onEnable()
|
||||
@ -36,13 +51,14 @@ public class Greenhouses extends Addon {
|
||||
public void onEnable() {
|
||||
saveDefaultConfig();
|
||||
this.saveResource("biomes.yml", false);
|
||||
settings = new Config<>(this, Settings.class).loadConfigObject();
|
||||
settings = config.loadConfigObject();
|
||||
if (settings == null) {
|
||||
// Settings did no load correctly. Disable.
|
||||
logError("Settings did not load correctly - disabling Greenhouses - please check config.yml");
|
||||
this.setState(State.DISABLED);
|
||||
return;
|
||||
}
|
||||
config.saveConfigObject(settings);
|
||||
// Load recipes
|
||||
recipes = new RecipeManager(this);
|
||||
// Load manager
|
||||
|
@ -22,7 +22,7 @@ public class Settings implements ConfigObject {
|
||||
@ConfigComment("BentoBox GameModes that will use Greenhouses")
|
||||
@ConfigEntry(path = "greenhouses.game-modes")
|
||||
private List<String> gameModes = new ArrayList<>();
|
||||
|
||||
|
||||
@ConfigComment("Show loaded recipe details during startup of server")
|
||||
@ConfigEntry(path = "greenhouses.startup-log")
|
||||
private boolean startupLog = false;
|
||||
@ -64,6 +64,10 @@ public class Settings implements ConfigObject {
|
||||
@ConfigEntry(path = "greenhouses.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
|
||||
*/
|
||||
@ -196,5 +200,17 @@ public class Settings implements ConfigObject {
|
||||
public void setAllowFlowIn(boolean 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.util.Vector;
|
||||
|
||||
import world.bentobox.greenhouses.Greenhouses;
|
||||
|
||||
/**
|
||||
* Contains the parameters of a greenhouse roof
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
public class Roof extends MinMaxXZ {
|
||||
public static final List<Material> ROOF_BLOCKS;
|
||||
private static final List<Material> ROOF_BLOCKS;
|
||||
static {
|
||||
List<Material> r = Arrays.stream(Material.values())
|
||||
.filter(Material::isBlock) // Blocks only, no items
|
||||
.filter(m -> m.name().contains("TRAPDOOR") // All trapdoors
|
||||
|| m.name().contains("GLASS") // All glass blocks
|
||||
|| m.equals(Material.HOPPER) // Hoppers
|
||||
|| m.equals(Material.GLOWSTONE)) // Glowstone
|
||||
|| m.equals(Material.HOPPER)) // Hoppers
|
||||
.collect(Collectors.toList());
|
||||
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
|
||||
int roofY = loc.getBlockY();
|
||||
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;
|
||||
loc = new Location(world,loc.getBlockX(),y,loc.getBlockZ());
|
||||
break;
|
||||
@ -65,10 +66,10 @@ public class Roof extends MinMaxXZ {
|
||||
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))) {
|
||||
Block b = world.getBlockAt(x, roofY, z);
|
||||
if (!Walls.WALL_BLOCKS.contains(b.getType())) {
|
||||
if (!Walls.wallBlocks(b.getType())) {
|
||||
// Look up
|
||||
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;
|
||||
loc = new Location(world,x,y,z);
|
||||
}
|
||||
@ -129,7 +130,7 @@ public class Roof extends MinMaxXZ {
|
||||
maxX = maxx.getBlockX()-1;
|
||||
}
|
||||
|
||||
while (ROOF_BLOCKS.contains(world.getBlockAt(minx).getType()) && limit < 200) {
|
||||
while (roofBlocks(world.getBlockAt(minx).getType()) && limit < 200) {
|
||||
limit++;
|
||||
minx.subtract(new Vector(1,0,0));
|
||||
}
|
||||
@ -137,7 +138,7 @@ public class Roof extends MinMaxXZ {
|
||||
minX = minx.getBlockX() + 1;
|
||||
}
|
||||
|
||||
while (ROOF_BLOCKS.contains(world.getBlockAt(maxz).getType()) && limit < 300) {
|
||||
while (roofBlocks(world.getBlockAt(maxz).getType()) && limit < 300) {
|
||||
limit++;
|
||||
maxz.add(new Vector(0,0,1));
|
||||
}
|
||||
@ -145,7 +146,7 @@ public class Roof extends MinMaxXZ {
|
||||
maxZ = maxz.getBlockZ() - 1;
|
||||
}
|
||||
|
||||
while (ROOF_BLOCKS.contains(world.getBlockAt(minz).getType()) && limit < 400) {
|
||||
while (roofBlocks(world.getBlockAt(minz).getType()) && limit < 400) {
|
||||
limit++;
|
||||
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
|
||||
*/
|
||||
|
@ -10,16 +10,17 @@ import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.BlockFace;
|
||||
|
||||
import world.bentobox.greenhouses.Greenhouses;
|
||||
|
||||
public class Walls extends MinMaxXZ {
|
||||
public static final List<Material> WALL_BLOCKS;
|
||||
private static final List<Material> WALL_BLOCKS;
|
||||
static {
|
||||
List<Material> w = Arrays.stream(Material.values())
|
||||
.filter(Material::isBlock) // Blocks only, no items
|
||||
.filter(m -> !m.name().contains("TRAPDOOR")) // No trap doors
|
||||
.filter(m -> m.name().contains("DOOR") // All doors
|
||||
|| m.name().contains("GLASS") // All glass blocks
|
||||
|| m.equals(Material.HOPPER) // Hoppers
|
||||
|| m.equals(Material.GLOWSTONE)) // Glowstone
|
||||
|| m.equals(Material.HOPPER)) // Hoppers
|
||||
.collect(Collectors.toList());
|
||||
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
|
||||
*/
|
||||
|
@ -19,6 +19,11 @@ public class GreenhouseFinder {
|
||||
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) {
|
||||
Set<GreenhouseResult> result = new HashSet<>();
|
||||
redGlass.clear();
|
||||
@ -80,8 +85,8 @@ public class GreenhouseFinder {
|
||||
} else {
|
||||
// Check just the walls
|
||||
if (y == roof.getHeight() || x == minX || x == maxX || z == minZ || z== maxZ) {
|
||||
if ((y != roof.getHeight() && !Walls.WALL_BLOCKS.contains(blockType))
|
||||
|| (y == roof.getHeight() && !Roof.ROOF_BLOCKS.contains(blockType))) {
|
||||
if ((y != roof.getHeight() && !Walls.wallBlocks(blockType))
|
||||
|| (y == roof.getHeight() && !Roof.roofBlocks(blockType))) {
|
||||
//logger(2,"DEBUG: bad block found at " + x + "," + y+ "," + z + " " + blockType);
|
||||
if (blockType == Material.AIR) {
|
||||
airHole = true;
|
||||
|
@ -31,3 +31,5 @@ greenhouses:
|
||||
allowflowout: false
|
||||
# Allow lava or water to flow into a greenhouse, e.g., through the door
|
||||
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