Refactor Walls and Roof code

This commit is contained in:
tastybento 2019-10-31 21:51:24 -07:00
parent 64fcefe2d2
commit f7796d7996
5 changed files with 59 additions and 81 deletions

View File

@ -0,0 +1,49 @@
package world.bentobox.greenhouses.greenhouse;
/**
* Holds min, max x and z coords and provides the area
* @author tastybento
*
*/
public abstract class MinMaxXZ {
protected int minX;
protected int maxX;
protected int minZ;
protected int maxZ;
/**
* @return the minX
*/
public int getMinX() {
return minX;
}
/**
* @return the maxX
*/
public int getMaxX() {
return maxX;
}
/**
* @return the minZ
*/
public int getMinZ() {
return minZ;
}
/**
* @return the maxZ
*/
public int getMaxZ() {
return maxZ;
}
/**
* @return the area
*/
public int getArea() {
return (maxX - minX) * (maxZ - minZ);
}
}

View File

@ -15,12 +15,8 @@ import org.bukkit.util.Vector;
* @author tastybento * @author tastybento
* *
*/ */
public class Roof { public class Roof extends MinMaxXZ {
private final Location location; private final Location location;
private int minX;
private int maxX;
private int minZ;
private int maxZ;
private final int height; private final int height;
private boolean roofFound; private boolean roofFound;
@ -158,40 +154,6 @@ public class Roof {
} }
} }
/**
* @return the minX
*/
public int getMinX() {
return minX;
}
/**
* @return the maxX
*/
public int getMaxX() {
return maxX;
}
/**
* @return the minZ
*/
public int getMinZ() {
return minZ;
}
/**
* @return the maxZ
*/
public int getMaxZ() {
return maxZ;
}
/**
* @return the area
*/
public int getArea() {
return (maxX - minX) * (maxZ - minZ);
}
/** /**
* @return the roofFound * @return the roofFound
*/ */

View File

@ -9,14 +9,10 @@ import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
public class Walls { public class Walls extends MinMaxXZ {
private int minX;
private int maxX;
private int minZ;
private int maxZ;
private int floor; private int floor;
public static final List<BlockFace> ORDINALS = Arrays.asList(BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST); private static final List<BlockFace> ORDINALS = Arrays.asList(BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST);
/** /**
* @return list of valid wall blocks * @return list of valid wall blocks
@ -151,36 +147,6 @@ public class Walls {
} }
/**
* @return the minXX
*/
public int getMinX() {
return minX;
}
/**
* @return the maxXX
*/
public int getMaxX() {
return maxX;
}
/**
* @return the minZZ
*/
public int getMinZ() {
return minZ;
}
/**
* @return the maxZZ
*/
public int getMaxZ() {
return maxZ;
}
public int getArea() {
// Get interior area
return (maxX - minX) * (maxZ - minZ);
}
/** /**
* @return the floor * @return the floor
*/ */

View File

@ -98,12 +98,12 @@ public class GreenhouseEvents implements Listener {
// 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());
} }
} }
@ -133,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);
} }
}); });

View File

@ -12,6 +12,7 @@ import world.bentobox.greenhouses.greenhouse.BiomeRecipe;
public class Panel { public class Panel {
private static final String COVERAGE = "[coverage]";
private Greenhouses addon; private Greenhouses addon;
public Panel(Greenhouses addon) { public Panel(Greenhouses addon) {
@ -41,13 +42,13 @@ public class Panel {
br.getRecipeBlocks().forEach(b -> d.add(user.getTranslation("greenhouses.recipe.blockscolor") + b)); br.getRecipeBlocks().forEach(b -> d.add(user.getTranslation("greenhouses.recipe.blockscolor") + b));
} }
if (br.getWaterCoverage() > 0) { if (br.getWaterCoverage() > 0) {
d.add(user.getTranslation("greenhouses.recipe.watermustbe", "[coverage]", String.valueOf(br.getWaterCoverage()))); d.add(user.getTranslation("greenhouses.recipe.watermustbe", COVERAGE, String.valueOf(br.getWaterCoverage())));
} }
if (br.getLavaCoverage() > 0) { if (br.getLavaCoverage() > 0) {
d.add(user.getTranslation("greenhouses.recipe.lavamustbe", "[coverage]", String.valueOf(br.getLavaCoverage()))); d.add(user.getTranslation("greenhouses.recipe.lavamustbe", COVERAGE, String.valueOf(br.getLavaCoverage())));
} }
if (br.getIceCoverage() > 0) { if (br.getIceCoverage() > 0) {
d.add(user.getTranslation("greenhouses.recipe.icemustbe", "[coverage]", String.valueOf(br.getIceCoverage()))); d.add(user.getTranslation("greenhouses.recipe.icemustbe", COVERAGE, String.valueOf(br.getIceCoverage())));
} }
if (br.getRecipeBlocks().isEmpty()) { if (br.getRecipeBlocks().isEmpty()) {
d.add(user.getTranslation("greenhouses.recipe.nootherblocks")); d.add(user.getTranslation("greenhouses.recipe.nootherblocks"));