mirror of
https://github.com/BentoBoxWorld/Greenhouses.git
synced 2024-11-28 21:56:17 +01:00
Code smell removal
This commit is contained in:
parent
6076f126b6
commit
64fcefe2d2
7
pom.xml
7
pom.xml
@ -264,9 +264,14 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.jacoco</groupId>
|
<groupId>org.jacoco</groupId>
|
||||||
<artifactId>jacoco-maven-plugin</artifactId>
|
<artifactId>jacoco-maven-plugin</artifactId>
|
||||||
<version>0.8.1</version>
|
<version>0.8.3</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<append>true</append>
|
<append>true</append>
|
||||||
|
<excludes>
|
||||||
|
<!-- This is required to prevent Jacoco from adding synthetic fields
|
||||||
|
to a JavaBean class (causes errors in testing) -->
|
||||||
|
<exclude>**/*Names*</exclude>
|
||||||
|
</excludes>
|
||||||
</configuration>
|
</configuration>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
|
@ -23,7 +23,7 @@ public class Greenhouses extends Addon {
|
|||||||
private Settings settings;
|
private Settings settings;
|
||||||
private RecipeManager recipes;
|
private RecipeManager recipes;
|
||||||
private final List<World> activeWorlds = new ArrayList<>();
|
private final List<World> activeWorlds = new ArrayList<>();
|
||||||
public final static Flag GREENHOUSES = new Flag.Builder("GREENHOUSE", Material.GREEN_STAINED_GLASS).build();
|
public static final Flag GREENHOUSES = new Flag.Builder("GREENHOUSE", Material.GREEN_STAINED_GLASS).build();
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see world.bentobox.bentobox.api.addons.Addon#onEnable()
|
* @see world.bentobox.bentobox.api.addons.Addon#onEnable()
|
||||||
|
@ -38,7 +38,7 @@ public class Greenhouse implements DataObject {
|
|||||||
private String biomeRecipeName;
|
private String biomeRecipeName;
|
||||||
|
|
||||||
private boolean broken;
|
private boolean broken;
|
||||||
|
|
||||||
private Map<Material, Integer> missingBlocks;
|
private Map<Material, Integer> missingBlocks;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -48,7 +48,7 @@ public class Greenhouse implements DataObject {
|
|||||||
|
|
||||||
public Greenhouse(World world, Walls walls, int ceilingHeight) {
|
public Greenhouse(World world, Walls walls, int ceilingHeight) {
|
||||||
this.location = new Location(world, walls.getMinX(), walls.getFloor(), walls.getMinZ());
|
this.location = new Location(world, walls.getMinX(), walls.getFloor(), walls.getMinZ());
|
||||||
Location location2 = new Location(world, walls.getMaxX() + 1, ceilingHeight + 1, walls.getMaxZ() + 1);
|
Location location2 = new Location(world, walls.getMaxX() + 1D, ceilingHeight + 1D, walls.getMaxZ() + 1D);
|
||||||
this.boundingBox = BoundingBox.of(location, location2);
|
this.boundingBox = BoundingBox.of(location, location2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
package world.bentobox.greenhouses.greenhouse;
|
package world.bentobox.greenhouses.greenhouse;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.EnumMap;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -31,6 +30,7 @@ import world.bentobox.greenhouses.data.Greenhouse;
|
|||||||
import world.bentobox.greenhouses.managers.GreenhouseManager.GreenhouseResult;
|
import world.bentobox.greenhouses.managers.GreenhouseManager.GreenhouseResult;
|
||||||
|
|
||||||
public class BiomeRecipe implements Comparable<BiomeRecipe> {
|
public class BiomeRecipe implements Comparable<BiomeRecipe> {
|
||||||
|
private static final String CHANCE_FOR = "% chance for ";
|
||||||
private Greenhouses addon;
|
private Greenhouses addon;
|
||||||
private Biome type;
|
private Biome type;
|
||||||
private Material icon; // Biome icon for control panel
|
private Material icon; // Biome icon for control panel
|
||||||
@ -38,11 +38,11 @@ public class BiomeRecipe implements Comparable<BiomeRecipe> {
|
|||||||
private String name;
|
private String name;
|
||||||
private String friendlyName;
|
private String friendlyName;
|
||||||
|
|
||||||
private final List<BlockFace> ADJ_BLOCKS = Arrays.asList( BlockFace.DOWN, BlockFace.EAST, BlockFace.NORTH, BlockFace.SOUTH, BlockFace.UP, BlockFace.WEST);
|
private final List<BlockFace> adjBlocks = Arrays.asList( BlockFace.DOWN, BlockFace.EAST, BlockFace.NORTH, BlockFace.SOUTH, BlockFace.UP, BlockFace.WEST);
|
||||||
|
|
||||||
// Content requirements
|
// Content requirements
|
||||||
// Material, Type, Qty. There can be more than one type of material required
|
// Material, Type, Qty. There can be more than one type of material required
|
||||||
private final Map<Material, Integer> requiredBlocks = new HashMap<>();
|
private final Map<Material, Integer> requiredBlocks = new EnumMap<>(Material.class);
|
||||||
// Plants
|
// Plants
|
||||||
private final TreeMap<Double, GreenhousePlant> plantTree = new TreeMap<>();
|
private final TreeMap<Double, GreenhousePlant> plantTree = new TreeMap<>();
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ public class BiomeRecipe implements Comparable<BiomeRecipe> {
|
|||||||
|
|
||||||
// Conversions
|
// Conversions
|
||||||
// Original Material, Original Type, New Material, New Type, Probability
|
// Original Material, Original Type, New Material, New Type, Probability
|
||||||
private final Map<Material, GreenhouseBlockConversions> conversionBlocks = new HashMap<>();
|
private final Map<Material, GreenhouseBlockConversions> conversionBlocks = new EnumMap<>(Material.class);
|
||||||
|
|
||||||
private int mobLimit;
|
private int mobLimit;
|
||||||
private int waterCoverage;
|
private int waterCoverage;
|
||||||
@ -85,7 +85,7 @@ public class BiomeRecipe implements Comparable<BiomeRecipe> {
|
|||||||
public void addConvBlocks(Material oldMaterial, Material newMaterial, double convChance, Material localMaterial) {
|
public void addConvBlocks(Material oldMaterial, Material newMaterial, double convChance, Material localMaterial) {
|
||||||
double probability = Math.min(convChance/100 , 1D);
|
double probability = Math.min(convChance/100 , 1D);
|
||||||
conversionBlocks.put(oldMaterial, new GreenhouseBlockConversions(oldMaterial, newMaterial, probability, localMaterial));
|
conversionBlocks.put(oldMaterial, new GreenhouseBlockConversions(oldMaterial, newMaterial, probability, localMaterial));
|
||||||
addon.log(" " + convChance + "% chance for " + Util.prettifyText(oldMaterial.toString()) + " to convert to " + Util.prettifyText(newMaterial.toString()));
|
addon.log(" " + convChance + CHANCE_FOR + Util.prettifyText(oldMaterial.toString()) + " to convert to " + Util.prettifyText(newMaterial.toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ public class BiomeRecipe implements Comparable<BiomeRecipe> {
|
|||||||
* @return true if add is successful
|
* @return true if add is successful
|
||||||
*/
|
*/
|
||||||
public boolean addMobs(EntityType mobType, int mobProbability, Material mobSpawnOn) {
|
public boolean addMobs(EntityType mobType, int mobProbability, Material mobSpawnOn) {
|
||||||
addon.log(" " + mobProbability + "% chance for " + Util.prettifyText(mobType.toString()) + " to spawn on " + Util.prettifyText(mobSpawnOn.toString())+ ".");
|
addon.log(" " + mobProbability + CHANCE_FOR + Util.prettifyText(mobType.toString()) + " to spawn on " + Util.prettifyText(mobSpawnOn.toString())+ ".");
|
||||||
double probability = ((double)mobProbability/100);
|
double probability = ((double)mobProbability/100);
|
||||||
double lastProb = mobTree.isEmpty() ? 0D : mobTree.lastKey();
|
double lastProb = mobTree.isEmpty() ? 0D : mobTree.lastKey();
|
||||||
// Add up all the probabilities in the list so far
|
// Add up all the probabilities in the list so far
|
||||||
@ -129,7 +129,7 @@ public class BiomeRecipe implements Comparable<BiomeRecipe> {
|
|||||||
addon.logError("Plant chances add up to > 100% in " + type.toString() + " biome recipe! Skipping " + plantMaterial.toString());
|
addon.logError("Plant chances add up to > 100% in " + type.toString() + " biome recipe! Skipping " + plantMaterial.toString());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
addon.log(" " + plantProbability + "% chance for " + Util.prettifyText(plantMaterial.toString()) + " to grow on " + Util.prettifyText(plantGrowOn.toString()));
|
addon.log(" " + plantProbability + CHANCE_FOR + Util.prettifyText(plantMaterial.toString()) + " to grow on " + Util.prettifyText(plantGrowOn.toString()));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,16 +150,16 @@ public class BiomeRecipe implements Comparable<BiomeRecipe> {
|
|||||||
public Set<GreenhouseResult> checkRecipe(Greenhouse gh) {
|
public Set<GreenhouseResult> checkRecipe(Greenhouse gh) {
|
||||||
Set<GreenhouseResult> result = new HashSet<>();
|
Set<GreenhouseResult> result = new HashSet<>();
|
||||||
long area = gh.getArea();
|
long area = gh.getArea();
|
||||||
Map<Material, Integer> blockCount = new HashMap<>();
|
Map<Material, Integer> blockCount = new EnumMap<>(Material.class);
|
||||||
// Look through the greenhouse and count what is in there
|
// Look through the greenhouse and count what is in there
|
||||||
for (int y = gh.getFloorHeight(); y< gh.getCeilingHeight();y++) {
|
for (int y = gh.getFloorHeight(); y< gh.getCeilingHeight();y++) {
|
||||||
for (int x = (int) (gh.getBoundingBox().getMinX()+1); x < gh.getBoundingBox().getMaxX(); x++) {
|
for (int x = (int) (gh.getBoundingBox().getMinX()+1); x < gh.getBoundingBox().getMaxX(); x++) {
|
||||||
for (int z = (int) (gh.getBoundingBox().getMinZ()+1); z < gh.getBoundingBox().getMaxZ(); z++) {
|
for (int z = (int) (gh.getBoundingBox().getMinZ()+1); z < gh.getBoundingBox().getMaxZ(); z++) {
|
||||||
Block b = gh.getWorld().getBlockAt(x, y, z);
|
Block b = gh.getWorld().getBlockAt(x, y, z);
|
||||||
Material type = b.getType();
|
Material t = b.getType();
|
||||||
if (!type.equals(Material.AIR)) {
|
if (!t.equals(Material.AIR)) {
|
||||||
blockCount.putIfAbsent(type, 0);
|
blockCount.putIfAbsent(t, 0);
|
||||||
blockCount.merge(type, 1, Integer::sum);
|
blockCount.merge(t, 1, Integer::sum);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -213,7 +213,7 @@ public class BiomeRecipe implements Comparable<BiomeRecipe> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Check if the block is in the right area, up, down, n,s,e,w
|
// Check if the block is in the right area, up, down, n,s,e,w
|
||||||
if (ADJ_BLOCKS.stream().map(b::getRelative).map(Block::getType).anyMatch(m -> bc.getLocalMaterial() == null || m == bc.getLocalMaterial())) {
|
if (adjBlocks.stream().map(b::getRelative).map(Block::getType).anyMatch(m -> bc.getLocalMaterial() == null || m == bc.getLocalMaterial())) {
|
||||||
// Convert!
|
// Convert!
|
||||||
b.setType(bc.getNewMaterial());
|
b.setType(bc.getNewMaterial());
|
||||||
}
|
}
|
||||||
@ -476,18 +476,20 @@ public class BiomeRecipe implements Comparable<BiomeRecipe> {
|
|||||||
return Integer.compare(o.getPriority(), this.getPriority());
|
return Integer.compare(o.getPriority(), this.getPriority());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if this recipe has no mobs that may spawn
|
* @return true if this recipe has no mobs that may spawn
|
||||||
*/
|
*/
|
||||||
public boolean noMobs() {
|
public boolean noMobs() {
|
||||||
return mobTree == null ? false : mobTree.isEmpty();
|
return mobTree.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the mob types that may spawn due to this recipe
|
* @return the mob types that may spawn due to this recipe
|
||||||
*/
|
*/
|
||||||
public Set<EntityType> getMobTypes() {
|
public Set<EntityType> getMobTypes() {
|
||||||
return mobTree == null ? Collections.emptySet() : mobTree.values().stream().map(GreenhouseMob::getMobType).collect(Collectors.toSet());
|
return mobTree.values().stream().map(GreenhouseMob::getMobType).collect(Collectors.toSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -23,14 +23,21 @@ public class Roof {
|
|||||||
private int maxZ;
|
private int maxZ;
|
||||||
private final int height;
|
private final int height;
|
||||||
private boolean roofFound;
|
private boolean roofFound;
|
||||||
public final static List<Material> ROOFBLOCKS = Arrays.stream(Material.values())
|
|
||||||
.filter(Material::isBlock) // Blocks only, no items
|
/**
|
||||||
.filter(m -> !m.name().contains("DOOR")) // No doors
|
* @return a list of valid roof blocks
|
||||||
.filter(m -> m.name().contains("TRAPDOOR") // All trapdoors
|
*/
|
||||||
|| m.name().contains("GLASS") // All glass blocks
|
public static List<Material> getRoofBlocks() {
|
||||||
|| m.equals(Material.HOPPER) // Hoppers
|
return Arrays.stream(Material.values())
|
||||||
|| m.equals(Material.GLOWSTONE)) // Glowstone
|
.filter(Material::isBlock) // Blocks only, no items
|
||||||
.collect(Collectors.toList());
|
.filter(m -> !m.name().contains("DOOR")) // No doors
|
||||||
|
.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
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds a roof from a starting location under the roof and characterizes it
|
* Finds a roof from a starting location under the roof and characterizes it
|
||||||
* @param loc - starting location
|
* @param loc - starting location
|
||||||
@ -55,10 +62,9 @@ public class Roof {
|
|||||||
if (!Walls.isWallBlock(b.getType())) {
|
if (!Walls.isWallBlock(b.getType())) {
|
||||||
// Look up
|
// Look up
|
||||||
for (int y = roofY; y < world.getMaxHeight(); y++) {
|
for (int y = roofY; y < world.getMaxHeight(); y++) {
|
||||||
if (ROOFBLOCKS.contains(world.getBlockAt(x,y,z).getType())) {
|
if (getRoofBlocks().contains(world.getBlockAt(x,y,z).getType())) {
|
||||||
roofFound = true;
|
roofFound = true;
|
||||||
loc = new Location(world,x,y,z);
|
loc = new Location(world,x,y,z);
|
||||||
//plugin.logger(3,"Roof block found at " + x + " " + y + " " + z + " of type " + loc.getBlock().getType().toString());
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -76,7 +82,7 @@ public class Roof {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//}
|
|
||||||
// Record the height
|
// Record the height
|
||||||
this.height = loc.getBlockY();
|
this.height = loc.getBlockY();
|
||||||
// Now we have a roof block, find how far we can go NSWE
|
// Now we have a roof block, find how far we can go NSWE
|
||||||
@ -118,7 +124,7 @@ public class Roof {
|
|||||||
Location maxz = height.toLocation(world);
|
Location maxz = height.toLocation(world);
|
||||||
Location minz = height.toLocation(world);
|
Location minz = height.toLocation(world);
|
||||||
int limit = 0;
|
int limit = 0;
|
||||||
while (ROOFBLOCKS
|
while (getRoofBlocks()
|
||||||
.contains(world.getBlockAt(maxx).getType()) && limit < 100) {
|
.contains(world.getBlockAt(maxx).getType()) && limit < 100) {
|
||||||
limit++;
|
limit++;
|
||||||
maxx.add(new Vector(1,0,0));
|
maxx.add(new Vector(1,0,0));
|
||||||
@ -127,7 +133,7 @@ public class Roof {
|
|||||||
maxX = maxx.getBlockX()-1;
|
maxX = maxx.getBlockX()-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (ROOFBLOCKS.contains(world.getBlockAt(minx).getType()) && limit < 200) {
|
while (getRoofBlocks().contains(world.getBlockAt(minx).getType()) && limit < 200) {
|
||||||
limit++;
|
limit++;
|
||||||
minx.subtract(new Vector(1,0,0));
|
minx.subtract(new Vector(1,0,0));
|
||||||
}
|
}
|
||||||
@ -135,7 +141,7 @@ public class Roof {
|
|||||||
minX = minx.getBlockX() + 1;
|
minX = minx.getBlockX() + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (ROOFBLOCKS.contains(world.getBlockAt(maxz).getType()) && limit < 300) {
|
while (getRoofBlocks().contains(world.getBlockAt(maxz).getType()) && limit < 300) {
|
||||||
limit++;
|
limit++;
|
||||||
maxz.add(new Vector(0,0,1));
|
maxz.add(new Vector(0,0,1));
|
||||||
}
|
}
|
||||||
@ -143,7 +149,7 @@ public class Roof {
|
|||||||
maxZ = maxz.getBlockZ() - 1;
|
maxZ = maxz.getBlockZ() - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (ROOFBLOCKS.contains(world.getBlockAt(minz).getType()) && limit < 400) {
|
while (getRoofBlocks().contains(world.getBlockAt(minz).getType()) && limit < 400) {
|
||||||
limit++;
|
limit++;
|
||||||
minz.subtract(new Vector(0,0,1));
|
minz.subtract(new Vector(0,0,1));
|
||||||
}
|
}
|
||||||
@ -151,28 +157,28 @@ public class Roof {
|
|||||||
minZ = minz.getBlockZ() + 1;
|
minZ = minz.getBlockZ() + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the minX
|
* @return the minX
|
||||||
*/
|
*/
|
||||||
public int getMinX() {
|
public int getMinX() {
|
||||||
return minX;
|
return minX;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the maxX
|
* @return the maxX
|
||||||
*/
|
*/
|
||||||
public int getMaxX() {
|
public int getMaxX() {
|
||||||
return maxX;
|
return maxX;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the minZ
|
* @return the minZ
|
||||||
*/
|
*/
|
||||||
public int getMinZ() {
|
public int getMinZ() {
|
||||||
return minZ;
|
return minZ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the maxZ
|
* @return the maxZ
|
||||||
*/
|
*/
|
||||||
|
@ -16,16 +16,21 @@ public class Walls {
|
|||||||
private int maxZ;
|
private int maxZ;
|
||||||
private int floor;
|
private int floor;
|
||||||
|
|
||||||
public final static List<Material> WALL_BLOCKS = Arrays.stream(Material.values())
|
public static final List<BlockFace> ORDINALS = Arrays.asList(BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST);
|
||||||
.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
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
public final static List<BlockFace> ORDINALS = Arrays.asList(BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST);
|
/**
|
||||||
|
* @return list of valid wall blocks
|
||||||
|
*/
|
||||||
|
public static List<Material> getWallBlocks() {
|
||||||
|
return 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
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
public Walls(Roof roof) {
|
public Walls(Roof roof) {
|
||||||
// The player is under the roof
|
// The player is under the roof
|
||||||
@ -63,25 +68,25 @@ public class Walls {
|
|||||||
switch (bf) {
|
switch (bf) {
|
||||||
case EAST:
|
case EAST:
|
||||||
// positive x
|
// positive x
|
||||||
if (WALL_BLOCKS.contains(world.getBlockAt(x, y, z).getRelative(bf).getType())) {
|
if (getWallBlocks().contains(world.getBlockAt(x, y, z).getRelative(bf).getType())) {
|
||||||
stopMaxX = true;
|
stopMaxX = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case WEST:
|
case WEST:
|
||||||
// negative x
|
// negative x
|
||||||
if (WALL_BLOCKS.contains(world.getBlockAt(x, y, z).getRelative(bf).getType())) {
|
if (getWallBlocks().contains(world.getBlockAt(x, y, z).getRelative(bf).getType())) {
|
||||||
stopMinX = true;
|
stopMinX = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case NORTH:
|
case NORTH:
|
||||||
// negative Z
|
// negative Z
|
||||||
if (WALL_BLOCKS.contains(world.getBlockAt(x, y, z).getRelative(bf).getType())) {
|
if (getWallBlocks().contains(world.getBlockAt(x, y, z).getRelative(bf).getType())) {
|
||||||
stopMinZ = true;
|
stopMinZ = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SOUTH:
|
case SOUTH:
|
||||||
// positive Z
|
// positive Z
|
||||||
if (WALL_BLOCKS.contains(world.getBlockAt(x, y, z).getRelative(bf).getType())) {
|
if (getWallBlocks().contains(world.getBlockAt(x, y, z).getRelative(bf).getType())) {
|
||||||
stopMaxZ = true;
|
stopMaxZ = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -135,7 +140,7 @@ public class Walls {
|
|||||||
wallBlockCount = 0;
|
wallBlockCount = 0;
|
||||||
for (int x = minX; x <= maxX; x++) {
|
for (int x = minX; x <= maxX; x++) {
|
||||||
for (int z = minZ; z <= maxZ; z++) {
|
for (int z = minZ; z <= maxZ; z++) {
|
||||||
if (WALL_BLOCKS.contains(world.getBlockAt(x, y, z).getType())) {
|
if (getWallBlocks().contains(world.getBlockAt(x, y, z).getType())) {
|
||||||
wallBlockCount++;
|
wallBlockCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -184,7 +189,7 @@ public class Walls {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isWallBlock(Material blockType) {
|
public static boolean isWallBlock(Material blockType) {
|
||||||
return WALL_BLOCKS.contains(blockType);
|
return getWallBlocks().contains(blockType);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -27,6 +27,7 @@ import world.bentobox.greenhouses.data.Greenhouse;
|
|||||||
* This class listens for changes to greenhouses and reacts to them
|
* This class listens for changes to greenhouses and reacts to them
|
||||||
*/
|
*/
|
||||||
public class GreenhouseEvents implements Listener {
|
public class GreenhouseEvents implements Listener {
|
||||||
|
private static final String BIOME = "[biome]";
|
||||||
private final Greenhouses plugin;
|
private final Greenhouses plugin;
|
||||||
|
|
||||||
public GreenhouseEvents(final Greenhouses plugin) {
|
public GreenhouseEvents(final Greenhouses plugin) {
|
||||||
@ -83,26 +84,26 @@ public class GreenhouseEvents implements Listener {
|
|||||||
if (!to.isPresent() && !from.isPresent()) {
|
if (!to.isPresent() && !from.isPresent()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (to.isPresent() && from.isPresent() && to.equals(from)) {
|
if (to.isPresent() && from.isPresent()) {
|
||||||
// Same greenhouse
|
if (!to.get().equals(from.get())) {
|
||||||
return;
|
// Leaving greenhouse, entering another
|
||||||
}
|
user.sendMessage("greenhouses.event.leaving", BIOME, to.get().getBiomeRecipe().getFriendlyName());
|
||||||
// to is a greenhouse
|
user.sendMessage("greenhouses.event.entering", BIOME, from.get().getBiomeRecipe().getFriendlyName());
|
||||||
if (to.isPresent() && from.isPresent() && !to.equals(from)) {
|
return;
|
||||||
// Leaving greenhouse, entering another
|
} else {
|
||||||
user.sendMessage("greenhouses.event.leaving", "[biome]", to.get().getBiomeRecipe().getFriendlyName());
|
// Same greenhouse
|
||||||
user.sendMessage("greenhouses.event.entering", "[biome]", from.get().getBiomeRecipe().getFriendlyName());
|
return;
|
||||||
return;
|
}
|
||||||
}
|
}
|
||||||
// from is a greenhouse
|
// from is a greenhouse
|
||||||
if (from.isPresent() && !to.isPresent()) {
|
if (from.isPresent() && !to.isPresent()) {
|
||||||
// Exiting
|
// Exiting
|
||||||
user.sendMessage("greenhouses.event.leaving", "[biome]", from.get().getBiomeRecipe().getFriendlyName());
|
user.sendMessage("greenhouses.event.leaving", "BIOME", from.get().getBiomeRecipe().getFriendlyName());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!from.isPresent()) {
|
if (!from.isPresent()) {
|
||||||
// Entering
|
// Entering
|
||||||
user.sendMessage("greenhouses.event.entering", "[biome]", to.get().getBiomeRecipe().getFriendlyName());
|
user.sendMessage("greenhouses.event.entering", "BIOME", to.get().getBiomeRecipe().getFriendlyName());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -132,7 +133,7 @@ public class GreenhouseEvents implements Listener {
|
|||||||
|| e.getBlock().getLocation().getBlockZ() == (int)g.getBoundingBox().getMinZ()
|
|| e.getBlock().getLocation().getBlockZ() == (int)g.getBoundingBox().getMinZ()
|
||||||
|| e.getBlock().getLocation().getBlockZ() == (int)g.getBoundingBox().getMaxZ() - 1
|
|| e.getBlock().getLocation().getBlockZ() == (int)g.getBoundingBox().getMaxZ() - 1
|
||||||
) {
|
) {
|
||||||
user.sendMessage("greenhouses.event.broke", "[biome]", Util.prettifyText(g.getOriginalBiome().name()));
|
user.sendMessage("greenhouses.event.broke", "BIOME", Util.prettifyText(g.getOriginalBiome().name()));
|
||||||
plugin.getManager().removeGreenhouse(g);
|
plugin.getManager().removeGreenhouse(g);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -26,6 +26,7 @@ import world.bentobox.greenhouses.data.Greenhouse;
|
|||||||
public class EcoSystemManager {
|
public class EcoSystemManager {
|
||||||
|
|
||||||
private static final int PLANTS_PER_BONEMEAL = 6;
|
private static final int PLANTS_PER_BONEMEAL = 6;
|
||||||
|
private static final String MINUTES = " minutes";
|
||||||
private final Greenhouses addon;
|
private final Greenhouses addon;
|
||||||
private final GreenhouseManager g;
|
private final GreenhouseManager g;
|
||||||
private BukkitTask plantTask;
|
private BukkitTask plantTask;
|
||||||
@ -41,36 +42,36 @@ public class EcoSystemManager {
|
|||||||
|
|
||||||
private void setup() {
|
private void setup() {
|
||||||
// Kick off flower growing
|
// Kick off flower growing
|
||||||
long plantTick = addon.getSettings().getPlantTick() * 60 * 20; // In minutes
|
long plantTick = addon.getSettings().getPlantTick() * 60 * 20L; // In minutes
|
||||||
if (plantTick > 0) {
|
if (plantTick > 0) {
|
||||||
addon.log("Kicking off flower growing scheduler every " + addon.getSettings().getPlantTick() + " minutes");
|
addon.log("Kicking off flower growing scheduler every " + addon.getSettings().getPlantTick() + MINUTES);
|
||||||
plantTask = addon.getServer().getScheduler().runTaskTimer(addon.getPlugin(), () -> g.getMap().getGreenhouses().forEach(this::growPlants), 80L, plantTick);
|
plantTask = addon.getServer().getScheduler().runTaskTimer(addon.getPlugin(), () -> g.getMap().getGreenhouses().forEach(this::growPlants), 80L, plantTick);
|
||||||
} else {
|
} else {
|
||||||
addon.log("Flower growth disabled.");
|
addon.log("Flower growth disabled.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Kick block conversion growing
|
// Kick block conversion growing
|
||||||
long blockTick = addon.getSettings().getBlockTick() * 60 * 20; // In minutes
|
long blockTick = addon.getSettings().getBlockTick() * 60 * 20l; // In minutes
|
||||||
|
|
||||||
if (blockTick > 0) {
|
if (blockTick > 0) {
|
||||||
addon.log("Kicking off block conversion scheduler every " + addon.getSettings().getBlockTick() + " minutes");
|
addon.log("Kicking off block conversion scheduler every " + addon.getSettings().getBlockTick() + MINUTES);
|
||||||
blockTask = addon.getServer().getScheduler().runTaskTimer(addon.getPlugin(), () -> g.getMap().getGreenhouses().forEach(this::convertBlocks), 60L, blockTick);
|
blockTask = addon.getServer().getScheduler().runTaskTimer(addon.getPlugin(), () -> g.getMap().getGreenhouses().forEach(this::convertBlocks), 60L, blockTick);
|
||||||
} else {
|
} else {
|
||||||
addon.log("Block conversion disabled.");
|
addon.log("Block conversion disabled.");
|
||||||
}
|
}
|
||||||
// Kick off g/h verification
|
// Kick off g/h verification
|
||||||
long ecoTick = addon.getSettings().getEcoTick() * 60 * 20; // In minutes
|
long ecoTick = addon.getSettings().getEcoTick() * 60 * 20L; // In minutes
|
||||||
if (ecoTick > 0) {
|
if (ecoTick > 0) {
|
||||||
addon.log("Kicking off greenhouse verify scheduler every " + addon.getSettings().getEcoTick() + " minutes");
|
addon.log("Kicking off greenhouse verify scheduler every " + addon.getSettings().getEcoTick() + MINUTES);
|
||||||
ecoTask = addon.getServer().getScheduler().runTaskTimer(addon.getPlugin(), () -> g.getMap().getGreenhouses().forEach(this::verify), ecoTick, ecoTick);
|
ecoTask = addon.getServer().getScheduler().runTaskTimer(addon.getPlugin(), () -> g.getMap().getGreenhouses().forEach(this::verify), ecoTick, ecoTick);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
addon.log("Greenhouse verification disabled.");
|
addon.log("Greenhouse verification disabled.");
|
||||||
}
|
}
|
||||||
// Kick off mob population
|
// Kick off mob population
|
||||||
long mobTick = addon.getSettings().getMobTick() * 60 * 20; // In minutes
|
long mobTick = addon.getSettings().getMobTick() * 60 * 20L; // In minutes
|
||||||
if (mobTick > 0) {
|
if (mobTick > 0) {
|
||||||
addon.log("Kicking off mob populator scheduler every " + addon.getSettings().getMobTick() + " minutes");
|
addon.log("Kicking off mob populator scheduler every " + addon.getSettings().getMobTick() + MINUTES);
|
||||||
mobTask = addon.getServer().getScheduler().runTaskTimer(addon.getPlugin(), () -> g.getMap().getGreenhouses().forEach(this::addMobs), 120L, mobTick);
|
mobTask = addon.getServer().getScheduler().runTaskTimer(addon.getPlugin(), () -> g.getMap().getGreenhouses().forEach(this::addMobs), 120L, mobTick);
|
||||||
} else {
|
} else {
|
||||||
addon.log("Mob disabled.");
|
addon.log("Mob disabled.");
|
||||||
|
@ -80,9 +80,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) {
|
||||||
//Greenhouses.addon.logDebug("DEBUG: Checking " + x + " " + y + " " + z);
|
if ((y != roof.getHeight() && !Walls.getWallBlocks().contains(blockType))
|
||||||
if ((y != roof.getHeight() && !Walls.WALL_BLOCKS.contains(blockType))
|
|| (y == roof.getHeight() && !Roof.getRoofBlocks().contains(blockType))) {
|
||||||
|| (y == roof.getHeight() && !Roof.ROOFBLOCKS.contains(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;
|
||||||
@ -136,18 +135,16 @@ public class GreenhouseFinder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//addon.logDebug("Floor is at height y = " + y);
|
|
||||||
// Check that the player is vertically in the greenhouse
|
// Check that the player is vertically in the greenhouse
|
||||||
if (roof.getLocation().getBlockY() <= y) {
|
if (roof.getLocation().getBlockY() <= y) {
|
||||||
result.add(GreenhouseResult.FAIL_BELOW);
|
result.add(GreenhouseResult.FAIL_BELOW);
|
||||||
}
|
}
|
||||||
// Show errors
|
// Show errors
|
||||||
if (airHoles & !inCeiling) {
|
if (airHoles && !inCeiling) {
|
||||||
result.add(GreenhouseResult.FAIL_HOLE_IN_WALL);
|
result.add(GreenhouseResult.FAIL_HOLE_IN_WALL);
|
||||||
} else if (airHoles & inCeiling) {
|
} else if (airHoles && inCeiling) {
|
||||||
result.add(GreenhouseResult.FAIL_HOLE_IN_ROOF);
|
result.add(GreenhouseResult.FAIL_HOLE_IN_ROOF);
|
||||||
}
|
}
|
||||||
//Greenhouses.addon.logDebug("DEBUG: otherBlockLayer = " + otherBlockLayer);
|
|
||||||
if (otherBlocks && otherBlockLayer == y + 1) {
|
if (otherBlocks && otherBlockLayer == y + 1) {
|
||||||
// Walls must be even all the way around
|
// Walls must be even all the way around
|
||||||
result.add(GreenhouseResult.FAIL_UNEVEN_WALLS);
|
result.add(GreenhouseResult.FAIL_UNEVEN_WALLS);
|
||||||
|
@ -95,6 +95,7 @@ public class GreenhouseManager implements Listener {
|
|||||||
case FAIL_NO_ISLAND:
|
case FAIL_NO_ISLAND:
|
||||||
// Delete the failed greenhouse
|
// Delete the failed greenhouse
|
||||||
toBeRemoved.add(g);
|
toBeRemoved.add(g);
|
||||||
|
break;
|
||||||
case FAIL_OVERLAPPING:
|
case FAIL_OVERLAPPING:
|
||||||
case NULL:
|
case NULL:
|
||||||
addon.logError(result.name());
|
addon.logError(result.name());
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package world.bentobox.greenhouses.managers;
|
package world.bentobox.greenhouses.managers;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map.Entry;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
@ -31,8 +31,6 @@ public class RecipeManager {
|
|||||||
loadBiomeRecipes();
|
loadBiomeRecipes();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
addon.logError(e.getMessage());
|
addon.logError(e.getMessage());
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,9 +47,8 @@ public class RecipeManager {
|
|||||||
* Loads all the biome recipes from the file biomes.yml.
|
* Loads all the biome recipes from the file biomes.yml.
|
||||||
* @throws InvalidConfigurationException - bad YAML
|
* @throws InvalidConfigurationException - bad YAML
|
||||||
* @throws IOException - io exception
|
* @throws IOException - io exception
|
||||||
* @throws FileNotFoundException - no file found
|
|
||||||
*/
|
*/
|
||||||
private void loadBiomeRecipes() throws FileNotFoundException, IOException, InvalidConfigurationException {
|
private void loadBiomeRecipes() throws IOException, InvalidConfigurationException {
|
||||||
biomeRecipes.clear();
|
biomeRecipes.clear();
|
||||||
YamlConfiguration biomes = new YamlConfiguration();
|
YamlConfiguration biomes = new YamlConfiguration();
|
||||||
File biomeFile = new File(addon.getDataFolder(), "biomes.yml");
|
File biomeFile = new File(addon.getDataFolder(), "biomes.yml");
|
||||||
@ -97,11 +94,7 @@ public class RecipeManager {
|
|||||||
ConfigurationSection reqContents = biomeRecipe.getConfigurationSection("contents");
|
ConfigurationSection reqContents = biomeRecipe.getConfigurationSection("contents");
|
||||||
if (reqContents != null) {
|
if (reqContents != null) {
|
||||||
for (String rq : reqContents.getKeys(false)) {
|
for (String rq : reqContents.getKeys(false)) {
|
||||||
try {
|
parseReqBlock(b, rq, reqContents);
|
||||||
b.addReqBlocks(Material.valueOf(rq.toUpperCase()), reqContents.getInt(rq));
|
|
||||||
} catch(Exception e) {
|
|
||||||
addon.logError("Could not parse required block " + rq);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Load plants
|
// Load plants
|
||||||
@ -110,10 +103,10 @@ public class RecipeManager {
|
|||||||
if (temp != null) {
|
if (temp != null) {
|
||||||
HashMap<String,Object> plants = (HashMap<String,Object>)temp.getValues(false);
|
HashMap<String,Object> plants = (HashMap<String,Object>)temp.getValues(false);
|
||||||
if (plants != null) {
|
if (plants != null) {
|
||||||
for (String s: plants.keySet()) {
|
for (Entry<String, Object> s: plants.entrySet()) {
|
||||||
Material plantMaterial = Material.valueOf(s);
|
Material plantMaterial = Material.valueOf(s.getKey());
|
||||||
String[] split = ((String)plants.get(s)).split(":");
|
String[] split = ((String)s.getValue()).split(":");
|
||||||
int plantProbability = Integer.valueOf(split[0]);
|
int plantProbability = Integer.parseInt(split[0]);
|
||||||
Material plantGrowOn = Material.valueOf(split[1]);
|
Material plantGrowOn = Material.valueOf(split[1]);
|
||||||
b.addPlants(plantMaterial, plantProbability, plantGrowOn);
|
b.addPlants(plantMaterial, plantProbability, plantGrowOn);
|
||||||
}
|
}
|
||||||
@ -125,16 +118,8 @@ public class RecipeManager {
|
|||||||
if (temp != null) {
|
if (temp != null) {
|
||||||
HashMap<String,Object> mobs = (HashMap<String,Object>)temp.getValues(false);
|
HashMap<String,Object> mobs = (HashMap<String,Object>)temp.getValues(false);
|
||||||
if (mobs != null) {
|
if (mobs != null) {
|
||||||
for (String s: mobs.keySet()) {
|
for (Entry<String, Object> s: mobs.entrySet()) {
|
||||||
try {
|
parseMob(s,b);
|
||||||
EntityType mobType = EntityType.valueOf(s.toUpperCase());
|
|
||||||
String[] split = ((String)mobs.get(s)).split(":");
|
|
||||||
int mobProbability = Integer.valueOf(split[0]);
|
|
||||||
Material mobSpawnOn = Material.valueOf(split[1]);
|
|
||||||
b.addMobs(mobType, mobProbability, mobSpawnOn);
|
|
||||||
} catch (Exception e) {
|
|
||||||
addon.logError("Could not parse " + s);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -147,7 +132,7 @@ public class RecipeManager {
|
|||||||
String conversions = conversionSec.getString(oldMat);
|
String conversions = conversionSec.getString(oldMat);
|
||||||
if (!conversions.isEmpty()) {
|
if (!conversions.isEmpty()) {
|
||||||
String[] split = conversions.split(":");
|
String[] split = conversions.split(":");
|
||||||
int convChance = Integer.valueOf(split[0]);
|
int convChance = Integer.parseInt(split[0]);
|
||||||
Material newMaterial = Material.valueOf(split[1]);
|
Material newMaterial = Material.valueOf(split[1]);
|
||||||
Material localMaterial = Material.valueOf(split[2]);
|
Material localMaterial = Material.valueOf(split[2]);
|
||||||
b.addConvBlocks(oldMaterial, newMaterial, convChance, localMaterial);
|
b.addConvBlocks(oldMaterial, newMaterial, convChance, localMaterial);
|
||||||
@ -179,6 +164,26 @@ public class RecipeManager {
|
|||||||
addon.log("Loaded " + biomeRecipes.size() + " biome recipes.");
|
addon.log("Loaded " + biomeRecipes.size() + " biome recipes.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void parseMob(Entry<String, Object> s, BiomeRecipe b) {
|
||||||
|
try {
|
||||||
|
EntityType mobType = EntityType.valueOf(s.getKey().toUpperCase());
|
||||||
|
String[] split = ((String)s.getValue()).split(":");
|
||||||
|
int mobProbability = Integer.parseInt(split[0]);
|
||||||
|
Material mobSpawnOn = Material.valueOf(split[1]);
|
||||||
|
b.addMobs(mobType, mobProbability, mobSpawnOn);
|
||||||
|
} catch (Exception e) {
|
||||||
|
addon.logError("Could not parse " + s.getKey());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void parseReqBlock(BiomeRecipe b, String rq, ConfigurationSection reqContents) {
|
||||||
|
try {
|
||||||
|
b.addReqBlocks(Material.valueOf(rq.toUpperCase()), reqContents.getInt(rq));
|
||||||
|
} catch(Exception e) {
|
||||||
|
addon.logError("Could not parse required block " + rq);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the biomeRecipes
|
* @return the biomeRecipes
|
||||||
*/
|
*/
|
||||||
|
@ -19,7 +19,7 @@ public class Panel {
|
|||||||
this.addon = addon;
|
this.addon = addon;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ShowPanel(User user) {
|
public void showPanel(User user) {
|
||||||
PanelBuilder pb = new PanelBuilder().name(user.getTranslation("greenhouses.general.greenhouses"));
|
PanelBuilder pb = new PanelBuilder().name(user.getTranslation("greenhouses.general.greenhouses"));
|
||||||
for (BiomeRecipe br : addon.getRecipes().getBiomeRecipes()) {
|
for (BiomeRecipe br : addon.getRecipes().getBiomeRecipes()) {
|
||||||
if (user.hasPermission(br.getPermission())) {
|
if (user.hasPermission(br.getPermission())) {
|
||||||
|
@ -52,7 +52,7 @@ class MakeCommand extends CompositeCommand {
|
|||||||
@Override
|
@Override
|
||||||
public boolean execute(User user, String label, List<String> args) {
|
public boolean execute(User user, String label, List<String> args) {
|
||||||
if (args.isEmpty()) {
|
if (args.isEmpty()) {
|
||||||
new Panel((Greenhouses)this.getAddon()).ShowPanel(user);
|
new Panel((Greenhouses)this.getAddon()).showPanel(user);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// Check recipe given matches
|
// Check recipe given matches
|
||||||
|
Loading…
Reference in New Issue
Block a user