Skip to content

Commit

Permalink
Refactor Walls and Roof code
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Nov 1, 2019
1 parent 64fcefe commit f7796d7
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 81 deletions.
49 changes: 49 additions & 0 deletions src/main/java/world/bentobox/greenhouses/greenhouse/MinMaxXZ.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
40 changes: 1 addition & 39 deletions src/main/java/world/bentobox/greenhouses/greenhouse/Roof.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,8 @@
* @author tastybento
*
*/
public class Roof {
public class Roof extends MinMaxXZ {
private final Location location;
private int minX;
private int maxX;
private int minZ;
private int maxZ;
private final int height;
private boolean roofFound;

Expand Down Expand Up @@ -158,40 +154,6 @@ private void expandCoords(World world, Vector height) {
}
}

/**
* @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
*/
Expand Down
38 changes: 2 additions & 36 deletions src/main/java/world/bentobox/greenhouses/greenhouse/Walls.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,10 @@
import org.bukkit.World;
import org.bukkit.block.BlockFace;

public class Walls {
private int minX;
private int maxX;
private int minZ;
private int maxZ;
public class Walls extends MinMaxXZ {
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
Expand Down Expand Up @@ -151,36 +147,6 @@ private int getFloorY(World world, int y, int minX, int maxX, int minZ, int maxZ

}

/**
* @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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ private void handleTransition(User user, Location toLoc, Location fromLoc) {
// 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());
}

}
Expand Down Expand Up @@ -133,7 +133,7 @@ public void onBlockBreak(final BlockBreakEvent e) {
|| 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);
}
});
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/world/bentobox/greenhouses/ui/panel/Panel.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

public class Panel {

private static final String COVERAGE = "[coverage]";
private Greenhouses addon;

public Panel(Greenhouses addon) {
Expand Down Expand Up @@ -41,13 +42,13 @@ private List<String> getDescription(User user, BiomeRecipe br) {
br.getRecipeBlocks().forEach(b -> d.add(user.getTranslation("greenhouses.recipe.blockscolor") + b));
}
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) {
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) {
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()) {
d.add(user.getTranslation("greenhouses.recipe.nootherblocks"));
Expand Down

0 comments on commit f7796d7

Please sign in to comment.