Skip to content

Commit

Permalink
Added setting for glass panes
Browse files Browse the repository at this point in the history
Added test cases and class for settings

#66
  • Loading branch information
tastybento committed Jan 10, 2021
1 parent 7dd9212 commit fad9936
Show file tree
Hide file tree
Showing 7 changed files with 300 additions and 25 deletions.
22 changes: 22 additions & 0 deletions src/main/java/world/bentobox/greenhouses/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ public class Settings implements ConfigObject {
@ConfigEntry(path = "greenhouses.game-modes")
private List<String> gameModes = new ArrayList<>();


@ConfigComment("")
@ConfigComment("Show loaded recipe details during startup of server")
@ConfigEntry(path = "greenhouses.startup-log")
private boolean startupLog = false;

@ConfigComment("")
@ConfigComment("Weather and ecosystem settings")
@ConfigComment("How often it should snow in the g/h when the weather is raining, in seconds")
@ConfigEntry(path = "greenhouses.snowspeed")
Expand All @@ -40,6 +43,7 @@ public class Settings implements ConfigObject {
@ConfigEntry(path = "greenhouses.snowdensity")
private double snowDensity = 0.1;

@ConfigComment("")
@ConfigComment("Biome activity")
@ConfigComment("How often should greenhouse biomes be checked to make sure they are still valid")
@ConfigEntry(path = "greenhouses.ecotick")
Expand All @@ -56,6 +60,7 @@ public class Settings implements ConfigObject {
private int mobTick = 5;


@ConfigComment("")
@ConfigComment("Default settings for greenhouse actions")
@ConfigComment("Allow lava or water to flow out of a greenhouse, e.g. through the door, floor")
@ConfigEntry(path = "greenhouses.allowflowout")
Expand All @@ -64,10 +69,15 @@ public class Settings implements ConfigObject {
@ConfigEntry(path = "greenhouses.allowflowin")
private boolean allowFlowIn;

@ConfigComment("")
@ConfigComment("Allow glowstone to be used as well as glass in roof and walls")
@ConfigEntry(path = "greenhouses.allowglowstone")
private boolean allowGlowstone = true;

@ConfigComment("")
@ConfigComment("Allow glass panes to be used to build greenhouses")
@ConfigEntry(path = "greenhouses.allowpanes")
private boolean allowPanes = true;
/**
* @return the gameModes
*/
Expand Down Expand Up @@ -212,5 +222,17 @@ public boolean isAllowGlowstone() {
public void setAllowGlowstone(boolean allowGlowstone) {
this.allowGlowstone = allowGlowstone;
}
/**
* @return the allowPanes
*/
public boolean isAllowPanes() {
return allowPanes;
}
/**
* @param allowPanes the allowPanes to set
*/
public void setAllowPanes(boolean allowPanes) {
this.allowPanes = allowPanes;
}

}
6 changes: 4 additions & 2 deletions src/main/java/world/bentobox/greenhouses/greenhouse/Roof.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class Roof extends MinMaxXZ {
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.name().contains("GLASS") && !m.name().contains("GLASS_PANE")) // All glass blocks
|| m.equals(Material.HOPPER)) // Hoppers
.collect(Collectors.toList());
ROOF_BLOCKS = Collections.unmodifiableList(r);
Expand Down Expand Up @@ -172,7 +172,9 @@ private void expandCoords(World world, Vector height) {
* @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 ROOF_BLOCKS.contains(m)
|| (m.equals(Material.GLOWSTONE) && Greenhouses.getInstance().getSettings().isAllowGlowstone())
|| (m.name().endsWith("GLASS_PANE") && Greenhouses.getInstance().getSettings().isAllowPanes());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class Walls extends MinMaxXZ {
.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.name().contains("GLASS") && !m.name().contains("GLASS_PANE")) // All glass blocks
|| m.equals(Material.HOPPER)) // Hoppers
.collect(Collectors.toList());
WALL_BLOCKS = Collections.unmodifiableList(w);
Expand Down Expand Up @@ -175,7 +175,9 @@ int getFloorY(World world, int y, int minX, int maxX, int minZ, int maxZ) {
* @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 WALL_BLOCKS.contains(m)
|| (m.equals(Material.GLOWSTONE) && Greenhouses.getInstance().getSettings().isAllowGlowstone())
|| (m.name().endsWith("GLASS_PANE") && Greenhouses.getInstance().getSettings().isAllowPanes());
}

/**
Expand Down
13 changes: 10 additions & 3 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Greenhouses Configuration
# Greenhouses Configuration {$version}
#
greenhouses:
# BentoBox GameModes that will use Greenhouses
Expand All @@ -7,9 +7,10 @@ greenhouses:
- AcidIsland
- SkyGrid
- AOneBlock
- CaveBlock
#
# Show loaded recipe details during startup of server
startup-log: false
#
# Weather and ecosystem settings
# How often it should snow in the g/h when the weather is raining, in seconds
snowspeed: 30.0
Expand All @@ -18,6 +19,7 @@ greenhouses:
snowchance: 1.0
# How many blocks should get snow 1 = all of them, 0 = none, 0.1 = 1 in 10
snowdensity: 0.1
#
# Biome activity
# How often should greenhouse biomes be checked to make sure they are still valid
ecotick: 5
Expand All @@ -28,10 +30,15 @@ greenhouses:
blocktick: 2
# How often should mobs be potentially spawned in a greenhouse, in minutes
mobtick: 5
#
# Default settings for greenhouse actions
# Allow lava or water to flow out of a greenhouse, e.g. through the door, floor
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
allowglowstone: true
#
# Allow glass panes to be used to build greenhouses
allowpanes: true
175 changes: 175 additions & 0 deletions src/test/java/world/bentobox/greenhouses/SettingsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
package world.bentobox.greenhouses;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.util.Collections;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.modules.junit4.PowerMockRunner;

@RunWith(PowerMockRunner.class)
public class SettingsTest {

private Settings s;

@Before
public void setUp() throws Exception {
s = new Settings();
}

@Test
public void testGetGameModes() {
assertTrue(s.getGameModes().isEmpty());
}

@Test
public void testGetSnowSpeed() {
assertEquals(30D, s.getSnowSpeed(), 0D);
}

@Test
public void testGetSnowChanceGlobal() {
assertEquals(1D, s.getSnowChanceGlobal(), 0D);
}

@Test
public void testGetSnowDensity() {
assertEquals(0.1D, s.getSnowDensity(), 0D);
}

@Test
public void testGetEcoTick() {
assertEquals(5, s.getEcoTick());
}

@Test
public void testGetPlantTick() {
assertEquals(1, s.getPlantTick());
}

@Test
public void testGetBlockTick() {
assertEquals(2, s.getBlockTick());
}

@Test
public void testGetMobTick() {
assertEquals(5, s.getMobTick());
}

@Test
public void testIsStartupLog() {
assertFalse(s.isStartupLog());
}

@Test
public void testSetStartupLog() {
s.setStartupLog(true);
assertTrue(s.isStartupLog());
}

@Test
public void testIsAllowFlowOut() {
assertFalse(s.isAllowFlowOut());
}

@Test
public void testIsAllowFlowIn() {
assertFalse(s.isAllowFlowIn());
}

@Test
public void testSetGameModes() {
s.setGameModes(Collections.singletonList("BSkyBlock"));
assertEquals("BSkyBlock", s.getGameModes().get(0));
}

@Test
public void testSetSnowSpeed() {
s.setSnowSpeed(50);
assertEquals(50D, s.getSnowSpeed(), 0D);
}

@Test
public void testSetSnowChanceGlobal() {
s.setSnowChanceGlobal(50);
assertEquals(50D, s.getSnowChanceGlobal(), 0D);

}

@Test
public void testSetSnowDensity() {
s.setSnowDensity(50);
assertEquals(50D, s.getSnowDensity(), 0D);
}

@Test
public void testSetEcoTick() {
s.setEcoTick(50);
assertEquals(50, s.getEcoTick());
}

@Test
public void testSetPlantTick() {
s.setPlantTick(50);
assertEquals(50, s.getPlantTick());

}

@Test
public void testSetBlockTick() {
s.setBlockTick(50);
assertEquals(50, s.getBlockTick());

}

@Test
public void testSetMobTick() {
s.setMobTick(50);
assertEquals(50, s.getMobTick());

}

@Test
public void testSetAllowFlowOut() {
assertFalse(s.isAllowFlowOut());
s.setAllowFlowOut(true);
assertTrue(s.isAllowFlowOut());
}

@Test
public void testSetAllowFlowIn() {
assertFalse(s.isAllowFlowIn());
s.setAllowFlowIn(true);
assertTrue(s.isAllowFlowIn());
}

@Test
public void testIsAllowGlowstone() {
assertTrue(s.isAllowGlowstone());
}

@Test
public void testSetAllowGlowstone() {
assertTrue(s.isAllowGlowstone());
s.setAllowGlowstone(false);
assertFalse(s.isAllowGlowstone());
}

@Test
public void testIsAllowPanes() {
assertTrue(s.isAllowPanes());
}

@Test
public void testSetAllowPanes() {
assertTrue(s.isAllowPanes());
s.setAllowPanes(false);
assertFalse(s.isAllowPanes());
}

}

0 comments on commit fad9936

Please sign in to comment.