mirror of
https://github.com/BentoBoxWorld/Greenhouses.git
synced 2024-11-25 12:05:55 +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>
|
||||
<groupId>org.jacoco</groupId>
|
||||
<artifactId>jacoco-maven-plugin</artifactId>
|
||||
<version>0.8.1</version>
|
||||
<version>0.8.3</version>
|
||||
<configuration>
|
||||
<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>
|
||||
<executions>
|
||||
<execution>
|
||||
|
@ -23,7 +23,7 @@ public class Greenhouses extends Addon {
|
||||
private Settings settings;
|
||||
private RecipeManager recipes;
|
||||
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)
|
||||
* @see world.bentobox.bentobox.api.addons.Addon#onEnable()
|
||||
|
@ -48,7 +48,7 @@ public class Greenhouse implements DataObject {
|
||||
|
||||
public Greenhouse(World world, Walls walls, int ceilingHeight) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,7 @@
|
||||
package world.bentobox.greenhouses.greenhouse;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -31,6 +30,7 @@ import world.bentobox.greenhouses.data.Greenhouse;
|
||||
import world.bentobox.greenhouses.managers.GreenhouseManager.GreenhouseResult;
|
||||
|
||||
public class BiomeRecipe implements Comparable<BiomeRecipe> {
|
||||
private static final String CHANCE_FOR = "% chance for ";
|
||||
private Greenhouses addon;
|
||||
private Biome type;
|
||||
private Material icon; // Biome icon for control panel
|
||||
@ -38,11 +38,11 @@ public class BiomeRecipe implements Comparable<BiomeRecipe> {
|
||||
private String name;
|
||||
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
|
||||
// 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
|
||||
private final TreeMap<Double, GreenhousePlant> plantTree = new TreeMap<>();
|
||||
|
||||
@ -52,7 +52,7 @@ public class BiomeRecipe implements Comparable<BiomeRecipe> {
|
||||
|
||||
// Conversions
|
||||
// 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 waterCoverage;
|
||||
@ -85,7 +85,7 @@ public class BiomeRecipe implements Comparable<BiomeRecipe> {
|
||||
public void addConvBlocks(Material oldMaterial, Material newMaterial, double convChance, Material localMaterial) {
|
||||
double probability = Math.min(convChance/100 , 1D);
|
||||
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
|
||||
*/
|
||||
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 lastProb = mobTree.isEmpty() ? 0D : mobTree.lastKey();
|
||||
// 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());
|
||||
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;
|
||||
}
|
||||
|
||||
@ -150,16 +150,16 @@ public class BiomeRecipe implements Comparable<BiomeRecipe> {
|
||||
public Set<GreenhouseResult> checkRecipe(Greenhouse gh) {
|
||||
Set<GreenhouseResult> result = new HashSet<>();
|
||||
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
|
||||
for (int y = gh.getFloorHeight(); y< gh.getCeilingHeight();y++) {
|
||||
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++) {
|
||||
Block b = gh.getWorld().getBlockAt(x, y, z);
|
||||
Material type = b.getType();
|
||||
if (!type.equals(Material.AIR)) {
|
||||
blockCount.putIfAbsent(type, 0);
|
||||
blockCount.merge(type, 1, Integer::sum);
|
||||
Material t = b.getType();
|
||||
if (!t.equals(Material.AIR)) {
|
||||
blockCount.putIfAbsent(t, 0);
|
||||
blockCount.merge(t, 1, Integer::sum);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -213,7 +213,7 @@ public class BiomeRecipe implements Comparable<BiomeRecipe> {
|
||||
return;
|
||||
}
|
||||
// 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!
|
||||
b.setType(bc.getNewMaterial());
|
||||
}
|
||||
@ -476,18 +476,20 @@ public class BiomeRecipe implements Comparable<BiomeRecipe> {
|
||||
return Integer.compare(o.getPriority(), this.getPriority());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return true if this recipe has no mobs that may spawn
|
||||
*/
|
||||
public boolean noMobs() {
|
||||
return mobTree == null ? false : mobTree.isEmpty();
|
||||
return mobTree.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the mob types that may spawn due to this recipe
|
||||
*/
|
||||
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 final int height;
|
||||
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
|
||||
.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());
|
||||
|
||||
/**
|
||||
* @return a list of valid roof blocks
|
||||
*/
|
||||
public static List<Material> getRoofBlocks() {
|
||||
return Arrays.stream(Material.values())
|
||||
.filter(Material::isBlock) // Blocks only, no items
|
||||
.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
|
||||
* @param loc - starting location
|
||||
@ -55,10 +62,9 @@ public class Roof {
|
||||
if (!Walls.isWallBlock(b.getType())) {
|
||||
// Look up
|
||||
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;
|
||||
loc = new Location(world,x,y,z);
|
||||
//plugin.logger(3,"Roof block found at " + x + " " + y + " " + z + " of type " + loc.getBlock().getType().toString());
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -76,7 +82,7 @@ public class Roof {
|
||||
break;
|
||||
}
|
||||
}
|
||||
//}
|
||||
|
||||
// Record the height
|
||||
this.height = loc.getBlockY();
|
||||
// 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 minz = height.toLocation(world);
|
||||
int limit = 0;
|
||||
while (ROOFBLOCKS
|
||||
while (getRoofBlocks()
|
||||
.contains(world.getBlockAt(maxx).getType()) && limit < 100) {
|
||||
limit++;
|
||||
maxx.add(new Vector(1,0,0));
|
||||
@ -127,7 +133,7 @@ public class Roof {
|
||||
maxX = maxx.getBlockX()-1;
|
||||
}
|
||||
|
||||
while (ROOFBLOCKS.contains(world.getBlockAt(minx).getType()) && limit < 200) {
|
||||
while (getRoofBlocks().contains(world.getBlockAt(minx).getType()) && limit < 200) {
|
||||
limit++;
|
||||
minx.subtract(new Vector(1,0,0));
|
||||
}
|
||||
@ -135,7 +141,7 @@ public class Roof {
|
||||
minX = minx.getBlockX() + 1;
|
||||
}
|
||||
|
||||
while (ROOFBLOCKS.contains(world.getBlockAt(maxz).getType()) && limit < 300) {
|
||||
while (getRoofBlocks().contains(world.getBlockAt(maxz).getType()) && limit < 300) {
|
||||
limit++;
|
||||
maxz.add(new Vector(0,0,1));
|
||||
}
|
||||
@ -143,7 +149,7 @@ public class Roof {
|
||||
maxZ = maxz.getBlockZ() - 1;
|
||||
}
|
||||
|
||||
while (ROOFBLOCKS.contains(world.getBlockAt(minz).getType()) && limit < 400) {
|
||||
while (getRoofBlocks().contains(world.getBlockAt(minz).getType()) && limit < 400) {
|
||||
limit++;
|
||||
minz.subtract(new Vector(0,0,1));
|
||||
}
|
||||
|
@ -16,16 +16,21 @@ public class Walls {
|
||||
private int maxZ;
|
||||
private int floor;
|
||||
|
||||
public final static List<Material> WALL_BLOCKS = 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 static final List<BlockFace> ORDINALS = Arrays.asList(BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST);
|
||||
|
||||
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) {
|
||||
// The player is under the roof
|
||||
@ -63,25 +68,25 @@ public class Walls {
|
||||
switch (bf) {
|
||||
case EAST:
|
||||
// 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;
|
||||
}
|
||||
break;
|
||||
case WEST:
|
||||
// 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;
|
||||
}
|
||||
break;
|
||||
case NORTH:
|
||||
// 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;
|
||||
}
|
||||
break;
|
||||
case SOUTH:
|
||||
// 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;
|
||||
}
|
||||
break;
|
||||
@ -135,7 +140,7 @@ public class Walls {
|
||||
wallBlockCount = 0;
|
||||
for (int x = minX; x <= maxX; x++) {
|
||||
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++;
|
||||
}
|
||||
}
|
||||
@ -184,7 +189,7 @@ public class Walls {
|
||||
}
|
||||
|
||||
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
|
||||
*/
|
||||
public class GreenhouseEvents implements Listener {
|
||||
private static final String BIOME = "[biome]";
|
||||
private final Greenhouses plugin;
|
||||
|
||||
public GreenhouseEvents(final Greenhouses plugin) {
|
||||
@ -83,26 +84,26 @@ public class GreenhouseEvents implements Listener {
|
||||
if (!to.isPresent() && !from.isPresent()) {
|
||||
return;
|
||||
}
|
||||
if (to.isPresent() && from.isPresent() && to.equals(from)) {
|
||||
// Same greenhouse
|
||||
return;
|
||||
}
|
||||
// to is a greenhouse
|
||||
if (to.isPresent() && from.isPresent() && !to.equals(from)) {
|
||||
// Leaving greenhouse, entering another
|
||||
user.sendMessage("greenhouses.event.leaving", "[biome]", to.get().getBiomeRecipe().getFriendlyName());
|
||||
user.sendMessage("greenhouses.event.entering", "[biome]", from.get().getBiomeRecipe().getFriendlyName());
|
||||
return;
|
||||
if (to.isPresent() && from.isPresent()) {
|
||||
if (!to.get().equals(from.get())) {
|
||||
// Leaving greenhouse, entering another
|
||||
user.sendMessage("greenhouses.event.leaving", BIOME, to.get().getBiomeRecipe().getFriendlyName());
|
||||
user.sendMessage("greenhouses.event.entering", BIOME, from.get().getBiomeRecipe().getFriendlyName());
|
||||
return;
|
||||
} else {
|
||||
// Same greenhouse
|
||||
return;
|
||||
}
|
||||
}
|
||||
// from is a greenhouse
|
||||
if (from.isPresent() && !to.isPresent()) {
|
||||
// Exiting
|
||||
user.sendMessage("greenhouses.event.leaving", "[biome]", from.get().getBiomeRecipe().getFriendlyName());
|
||||
user.sendMessage("greenhouses.event.leaving", "BIOME", from.get().getBiomeRecipe().getFriendlyName());
|
||||
return;
|
||||
}
|
||||
if (!from.isPresent()) {
|
||||
// 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().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);
|
||||
}
|
||||
});
|
||||
|
@ -26,6 +26,7 @@ import world.bentobox.greenhouses.data.Greenhouse;
|
||||
public class EcoSystemManager {
|
||||
|
||||
private static final int PLANTS_PER_BONEMEAL = 6;
|
||||
private static final String MINUTES = " minutes";
|
||||
private final Greenhouses addon;
|
||||
private final GreenhouseManager g;
|
||||
private BukkitTask plantTask;
|
||||
@ -41,36 +42,36 @@ public class EcoSystemManager {
|
||||
|
||||
private void setup() {
|
||||
// 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) {
|
||||
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);
|
||||
} else {
|
||||
addon.log("Flower growth disabled.");
|
||||
}
|
||||
|
||||
// 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) {
|
||||
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);
|
||||
} else {
|
||||
addon.log("Block conversion disabled.");
|
||||
}
|
||||
// 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) {
|
||||
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);
|
||||
|
||||
} else {
|
||||
addon.log("Greenhouse verification disabled.");
|
||||
}
|
||||
// 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) {
|
||||
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);
|
||||
} else {
|
||||
addon.log("Mob disabled.");
|
||||
|
@ -80,9 +80,8 @@ public class GreenhouseFinder {
|
||||
} else {
|
||||
// Check just the walls
|
||||
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.WALL_BLOCKS.contains(blockType))
|
||||
|| (y == roof.getHeight() && !Roof.ROOFBLOCKS.contains(blockType))) {
|
||||
if ((y != roof.getHeight() && !Walls.getWallBlocks().contains(blockType))
|
||||
|| (y == roof.getHeight() && !Roof.getRoofBlocks().contains(blockType))) {
|
||||
//logger(2,"DEBUG: bad block found at " + x + "," + y+ "," + z + " " + blockType);
|
||||
if (blockType == Material.AIR) {
|
||||
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
|
||||
if (roof.getLocation().getBlockY() <= y) {
|
||||
result.add(GreenhouseResult.FAIL_BELOW);
|
||||
}
|
||||
// Show errors
|
||||
if (airHoles & !inCeiling) {
|
||||
if (airHoles && !inCeiling) {
|
||||
result.add(GreenhouseResult.FAIL_HOLE_IN_WALL);
|
||||
} else if (airHoles & inCeiling) {
|
||||
} else if (airHoles && inCeiling) {
|
||||
result.add(GreenhouseResult.FAIL_HOLE_IN_ROOF);
|
||||
}
|
||||
//Greenhouses.addon.logDebug("DEBUG: otherBlockLayer = " + otherBlockLayer);
|
||||
if (otherBlocks && otherBlockLayer == y + 1) {
|
||||
// Walls must be even all the way around
|
||||
result.add(GreenhouseResult.FAIL_UNEVEN_WALLS);
|
||||
|
@ -95,6 +95,7 @@ public class GreenhouseManager implements Listener {
|
||||
case FAIL_NO_ISLAND:
|
||||
// Delete the failed greenhouse
|
||||
toBeRemoved.add(g);
|
||||
break;
|
||||
case FAIL_OVERLAPPING:
|
||||
case NULL:
|
||||
addon.logError(result.name());
|
||||
|
@ -1,10 +1,10 @@
|
||||
package world.bentobox.greenhouses.managers;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
@ -31,8 +31,6 @@ public class RecipeManager {
|
||||
loadBiomeRecipes();
|
||||
} catch (Exception e) {
|
||||
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.
|
||||
* @throws InvalidConfigurationException - bad YAML
|
||||
* @throws IOException - io exception
|
||||
* @throws FileNotFoundException - no file found
|
||||
*/
|
||||
private void loadBiomeRecipes() throws FileNotFoundException, IOException, InvalidConfigurationException {
|
||||
private void loadBiomeRecipes() throws IOException, InvalidConfigurationException {
|
||||
biomeRecipes.clear();
|
||||
YamlConfiguration biomes = new YamlConfiguration();
|
||||
File biomeFile = new File(addon.getDataFolder(), "biomes.yml");
|
||||
@ -97,11 +94,7 @@ public class RecipeManager {
|
||||
ConfigurationSection reqContents = biomeRecipe.getConfigurationSection("contents");
|
||||
if (reqContents != null) {
|
||||
for (String rq : reqContents.getKeys(false)) {
|
||||
try {
|
||||
b.addReqBlocks(Material.valueOf(rq.toUpperCase()), reqContents.getInt(rq));
|
||||
} catch(Exception e) {
|
||||
addon.logError("Could not parse required block " + rq);
|
||||
}
|
||||
parseReqBlock(b, rq, reqContents);
|
||||
}
|
||||
}
|
||||
// Load plants
|
||||
@ -110,10 +103,10 @@ public class RecipeManager {
|
||||
if (temp != null) {
|
||||
HashMap<String,Object> plants = (HashMap<String,Object>)temp.getValues(false);
|
||||
if (plants != null) {
|
||||
for (String s: plants.keySet()) {
|
||||
Material plantMaterial = Material.valueOf(s);
|
||||
String[] split = ((String)plants.get(s)).split(":");
|
||||
int plantProbability = Integer.valueOf(split[0]);
|
||||
for (Entry<String, Object> s: plants.entrySet()) {
|
||||
Material plantMaterial = Material.valueOf(s.getKey());
|
||||
String[] split = ((String)s.getValue()).split(":");
|
||||
int plantProbability = Integer.parseInt(split[0]);
|
||||
Material plantGrowOn = Material.valueOf(split[1]);
|
||||
b.addPlants(plantMaterial, plantProbability, plantGrowOn);
|
||||
}
|
||||
@ -125,16 +118,8 @@ public class RecipeManager {
|
||||
if (temp != null) {
|
||||
HashMap<String,Object> mobs = (HashMap<String,Object>)temp.getValues(false);
|
||||
if (mobs != null) {
|
||||
for (String s: mobs.keySet()) {
|
||||
try {
|
||||
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);
|
||||
}
|
||||
for (Entry<String, Object> s: mobs.entrySet()) {
|
||||
parseMob(s,b);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -147,7 +132,7 @@ public class RecipeManager {
|
||||
String conversions = conversionSec.getString(oldMat);
|
||||
if (!conversions.isEmpty()) {
|
||||
String[] split = conversions.split(":");
|
||||
int convChance = Integer.valueOf(split[0]);
|
||||
int convChance = Integer.parseInt(split[0]);
|
||||
Material newMaterial = Material.valueOf(split[1]);
|
||||
Material localMaterial = Material.valueOf(split[2]);
|
||||
b.addConvBlocks(oldMaterial, newMaterial, convChance, localMaterial);
|
||||
@ -179,6 +164,26 @@ public class RecipeManager {
|
||||
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
|
||||
*/
|
||||
|
@ -19,7 +19,7 @@ public class Panel {
|
||||
this.addon = addon;
|
||||
}
|
||||
|
||||
public void ShowPanel(User user) {
|
||||
public void showPanel(User user) {
|
||||
PanelBuilder pb = new PanelBuilder().name(user.getTranslation("greenhouses.general.greenhouses"));
|
||||
for (BiomeRecipe br : addon.getRecipes().getBiomeRecipes()) {
|
||||
if (user.hasPermission(br.getPermission())) {
|
||||
|
@ -52,7 +52,7 @@ class MakeCommand extends CompositeCommand {
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
if (args.isEmpty()) {
|
||||
new Panel((Greenhouses)this.getAddon()).ShowPanel(user);
|
||||
new Panel((Greenhouses)this.getAddon()).showPanel(user);
|
||||
return true;
|
||||
}
|
||||
// Check recipe given matches
|
||||
|
Loading…
Reference in New Issue
Block a user