Remove deprecated BlockInfo in favor of Location/BlockState

BlockInfo kept making me cringe every time I had to look at the code. More importantly it only had support for storing item IDs and no data. It was way obsolete versus new API.
This commit is contained in:
cmastudios 2013-10-05 02:04:28 -05:00
parent 6e9efc7a8a
commit 1722c86a71
18 changed files with 452 additions and 1050 deletions

View File

@ -39,6 +39,9 @@
<url>http://ci.tommytony.com</url>
</ciManagement>
<scm>
<connection>scm:git:git://github.com/taoneill/war.git</connection>
<developerConnection>scm:git:git@github.com:taoneill/war.git</developerConnection>
<tag>HEAD</tag>
<url>https://github.com/taoneill/war</url>
</scm>
<build>

View File

@ -36,7 +36,6 @@ import com.tommytony.war.config.TeamSpawnStyle;
import com.tommytony.war.structure.Bomb;
import com.tommytony.war.structure.Cake;
import com.tommytony.war.utility.Direction;
import com.tommytony.war.volume.BlockInfo;
import com.tommytony.war.volume.Volume;
/**
@ -580,19 +579,13 @@ public class Team {
public void initializeTeamFlag() {
// make air (old two-high above floor)
Volume airGap = new Volume("airgap", this.warzone.getWorld());
airGap.setCornerOne(new BlockInfo(
this.flagVolume.getCornerOne().getX(),
this.flagVolume.getCornerOne().getY() + 1,
this.flagVolume.getCornerOne().getZ(),
0,
(byte)0));
airGap.setCornerTwo(new BlockInfo(
this.flagVolume.getCornerTwo().getX(),
this.flagVolume.getCornerOne().getY() + 2,
this.flagVolume.getCornerTwo().getZ(),
0,
(byte)0));
Volume airGap = new Volume(new Location(this.flagVolume.getWorld(),
this.flagVolume.getCornerOne().getX(), this.flagVolume
.getCornerOne().getY() + 1, this.flagVolume
.getCornerOne().getZ()), new Location(
this.flagVolume.getWorld(), this.flagVolume.getCornerTwo()
.getX(), this.flagVolume.getCornerOne().getY() + 2,
this.flagVolume.getCornerTwo().getZ()));
airGap.setToMaterial(Material.AIR);
// Set the flag blocks

View File

@ -61,7 +61,6 @@ import com.tommytony.war.utility.Loadout;
import com.tommytony.war.utility.LoadoutSelection;
import com.tommytony.war.utility.PlayerState;
import com.tommytony.war.utility.PotionEffectHelper;
import com.tommytony.war.volume.BlockInfo;
import com.tommytony.war.volume.Volume;
import com.tommytony.war.volume.ZoneVolume;
@ -252,11 +251,11 @@ public class Warzone {
}
}
int saved = this.volume.saveBlocks();
this.volume.saveBlocks();
if (clearArtifacts) {
this.initializeZone(); // bring back stuff
}
return saved;
return this.volume.size();
}
return 0;
}
@ -1552,10 +1551,15 @@ public class Warzone {
for (Team maybeOpponent : this.getTeams()) {
if (maybeOpponent != team) {
for (Volume teamSpawnVolume : maybeOpponent.getSpawnVolumes().values()) {
Volume periphery = new Volume("periphery", this.getWorld());
periphery.setCornerOne(new BlockInfo(teamSpawnVolume.getMinX()-1 , teamSpawnVolume.getMinY()-1, teamSpawnVolume.getMinZ()-1, 0, (byte)0));
periphery.setCornerTwo(new BlockInfo(teamSpawnVolume.getMaxX()+1, teamSpawnVolume.getMaxY()+1, teamSpawnVolume.getMaxZ()+1, 0, (byte)0));
Volume periphery = new Volume(new Location(
teamSpawnVolume.getWorld(),
teamSpawnVolume.getMinX() - 1,
teamSpawnVolume.getMinY() - 1,
teamSpawnVolume.getMinZ() - 1), new Location(
teamSpawnVolume.getWorld(),
teamSpawnVolume.getMaxX() + 1,
teamSpawnVolume.getMaxY() + 1,
teamSpawnVolume.getMaxZ() + 1));
if (periphery.contains(block)) {
return true;
}

View File

@ -41,7 +41,7 @@ public class ZoneSetter {
warzone = new Warzone(this.player.getLocation().getWorld(), this.zoneName);
warzone.addAuthor(player.getName());
War.war.getIncompleteZones().add(warzone);
warzone.getVolume().setNorthwest(northwestBlock);
warzone.getVolume().setNorthwest(northwestBlock.getLocation());
War.war.msg(this.player, "Warzone " + warzone.getName() + " created. Northwesternmost point set to x:" + warzone.getVolume().getNorthwestX() + " z:" + warzone.getVolume().getNorthwestZ() + ". ");
War.war.log(player.getName() + " created warzone " + zoneName + " by setting its nw corner", Level.INFO);
} else if (!this.isPlayerAuthorOfZoneOrAdmin(warzone)) {
@ -49,7 +49,7 @@ public class ZoneSetter {
} else {
// change existing warzone
this.resetWarzone(warzone, msgString);
warzone.getVolume().setNorthwest(northwestBlock);
warzone.getVolume().setNorthwest(northwestBlock.getLocation());
msgString.append("Warzone " + warzone.getName() + " modified. Northwesternmost point set to x:" + warzone.getVolume().getNorthwestX() + " z:" + warzone.getVolume().getNorthwestZ() + ". ");
War.war.log(player.getName() + " updated warzone " + zoneName + " by setting its nw corner", Level.INFO);
}
@ -86,7 +86,7 @@ public class ZoneSetter {
warzone = new Warzone(this.player.getLocation().getWorld(), this.zoneName);
warzone.addAuthor(player.getName());
War.war.getIncompleteZones().add(warzone);
warzone.getVolume().setSoutheast(southeastBlock);
warzone.getVolume().setSoutheast(southeastBlock.getLocation());
War.war.msg(this.player, "Warzone " + warzone.getName() + " created. Southeasternmost point set to x:" + warzone.getVolume().getSoutheastX() + " z:" + warzone.getVolume().getSoutheastZ() + ". ");
War.war.log(player.getName() + " created warzone " + zoneName + " by setting its se corner", Level.INFO);
} else if (!this.isPlayerAuthorOfZoneOrAdmin(warzone)) {
@ -94,7 +94,7 @@ public class ZoneSetter {
} else {
// change existing warzone
this.resetWarzone(warzone, msgString);
warzone.getVolume().setSoutheast(southeastBlock);
warzone.getVolume().setSoutheast(southeastBlock.getLocation());
msgString.append("Warzone " + warzone.getName() + " modified. Southeasternmost point set to x:" + warzone.getVolume().getSoutheastX() + " z:" + warzone.getVolume().getSoutheastZ() + ". ");
War.war.log(player.getName() + " updated warzone " + zoneName + " by setting its se corner", Level.INFO);
}
@ -220,8 +220,8 @@ public class ZoneSetter {
if (warzone.getLobby() != null && warzone.getLobby().getVolume() != null) {
warzone.getLobby().getVolume().resetBlocks();
}
int reset = warzone.getVolume().resetBlocks();
msgString.append(reset + " blocks reset. ");
warzone.getVolume().resetBlocks();
msgString.append(warzone.getVolume().size() + " blocks reset. ");
}
}

View File

@ -7,27 +7,9 @@ import org.bukkit.inventory.ItemStack;
import com.tommytony.war.War;
@SuppressWarnings("deprecation")
public class LoadoutTxtMapper {
public static String fromLoadoutToString(HashMap<Integer, ItemStack> loadout) {
String loadoutString = "";
for (Integer slot : loadout.keySet()) {
ItemStack item = loadout.get(slot);
if (item != null) {
loadoutString += item.getTypeId() + "," + item.getAmount() + "," + slot + "," + item.getDurability() + "," + item.getData().getData();
if (item.getEnchantments().keySet().size() > 0) {
String enchantmentsStr = "";
for (Enchantment enchantment : item.getEnchantments().keySet()) {
enchantmentsStr += enchantment.getId() + ":" + item.getEnchantments().get(enchantment) + "::";
}
loadoutString += "," + enchantmentsStr;
}
}
loadoutString += ";";
}
return loadoutString;
}
public static void fromStringToLoadout(String loadoutString, HashMap<Integer, ItemStack> destinationLoadout) {
String[] rewardStrSplit = loadoutString.split(";");
destinationLoadout.clear();

View File

@ -298,19 +298,19 @@ public class PreDeGaulleZoneVolumeMapper {
out.write("corner1");
out.newLine();
out.write(Integer.toString(volume.getCornerOne().getX()));
out.write(Integer.toString(volume.getCornerOne().getBlockX()));
out.newLine();
out.write(Integer.toString(volume.getCornerOne().getY()));
out.write(Integer.toString(volume.getCornerOne().getBlockY()));
out.newLine();
out.write(Integer.toString(volume.getCornerOne().getZ()));
out.write(Integer.toString(volume.getCornerOne().getBlockZ()));
out.newLine();
out.write("corner2");
out.newLine();
out.write(Integer.toString(volume.getCornerTwo().getX()));
out.write(Integer.toString(volume.getCornerTwo().getBlockX()));
out.newLine();
out.write(Integer.toString(volume.getCornerTwo().getY()));
out.write(Integer.toString(volume.getCornerTwo().getBlockY()));
out.newLine();
out.write(Integer.toString(volume.getCornerTwo().getZ()));
out.write(Integer.toString(volume.getCornerTwo().getBlockZ()));
out.newLine();
int x = 0;

View File

@ -152,19 +152,19 @@ public class VolumeMapper {
out.write("corner1");
out.newLine();
out.write(Integer.toString(volume.getCornerOne().getX()));
out.write(Integer.toString(volume.getCornerOne().getBlockX()));
out.newLine();
out.write(Integer.toString(volume.getCornerOne().getY()));
out.write(Integer.toString(volume.getCornerOne().getBlockY()));
out.newLine();
out.write(Integer.toString(volume.getCornerOne().getZ()));
out.write(Integer.toString(volume.getCornerOne().getBlockZ()));
out.newLine();
out.write("corner2");
out.newLine();
out.write(Integer.toString(volume.getCornerTwo().getX()));
out.write(Integer.toString(volume.getCornerTwo().getBlockX()));
out.newLine();
out.write(Integer.toString(volume.getCornerTwo().getY()));
out.write(Integer.toString(volume.getCornerTwo().getBlockY()));
out.newLine();
out.write(Integer.toString(volume.getCornerTwo().getZ()));
out.write(Integer.toString(volume.getCornerTwo().getBlockZ()));
out.newLine();
int blockWrites = 0;
for (int i = 0; i < volume.getSizeX(); i++) {

View File

@ -299,19 +299,19 @@ public class ZoneVolumeMapper {
cornersWriter.write("corner1");
cornersWriter.newLine();
cornersWriter.write(Integer.toString(volume.getCornerOne().getX()));
cornersWriter.write(Integer.toString(volume.getCornerOne().getBlockX()));
cornersWriter.newLine();
cornersWriter.write(Integer.toString(volume.getCornerOne().getY()));
cornersWriter.write(Integer.toString(volume.getCornerOne().getBlockY()));
cornersWriter.newLine();
cornersWriter.write(Integer.toString(volume.getCornerOne().getZ()));
cornersWriter.write(Integer.toString(volume.getCornerOne().getBlockZ()));
cornersWriter.newLine();
cornersWriter.write("corner2");
cornersWriter.newLine();
cornersWriter.write(Integer.toString(volume.getCornerTwo().getX()));
cornersWriter.write(Integer.toString(volume.getCornerTwo().getBlockX()));
cornersWriter.newLine();
cornersWriter.write(Integer.toString(volume.getCornerTwo().getY()));
cornersWriter.write(Integer.toString(volume.getCornerTwo().getBlockY()));
cornersWriter.newLine();
cornersWriter.write(Integer.toString(volume.getCornerTwo().getZ()));
cornersWriter.write(Integer.toString(volume.getCornerTwo().getBlockZ()));
cornersWriter.newLine();
int x = 0;

View File

@ -9,7 +9,6 @@ import org.bukkit.entity.Player;
import com.tommytony.war.Warzone;
import com.tommytony.war.utility.Direction;
import com.tommytony.war.volume.BlockInfo;
import com.tommytony.war.volume.Volume;
/**
@ -35,19 +34,12 @@ public class Bomb {
public void addBombBlocks() {
// make air (old two-high above floor)
Volume airGap = new Volume("airgap", this.warzone.getWorld());
airGap.setCornerOne(new BlockInfo(
this.volume.getCornerOne().getX(),
this.volume.getCornerOne().getY() + 1,
this.volume.getCornerOne().getZ(),
0,
(byte)0));
airGap.setCornerTwo(new BlockInfo(
this.volume.getCornerTwo().getX(),
this.volume.getCornerOne().getY() + 3,
this.volume.getCornerTwo().getZ(),
0,
(byte)0));
Volume airGap = new Volume(new Location(this.volume.getWorld(),
this.volume.getCornerOne().getX(), this.volume.getCornerOne()
.getY() + 1, this.volume.getCornerOne().getZ()),
new Location(this.volume.getWorld(), this.volume.getCornerTwo()
.getX(), this.volume.getCornerOne().getY() + 3,
this.volume.getCornerTwo().getZ()));
airGap.setToMaterial(Material.AIR);
int x = this.location.getBlockX();

View File

@ -9,7 +9,6 @@ import org.bukkit.entity.Player;
import com.tommytony.war.Warzone;
import com.tommytony.war.utility.Direction;
import com.tommytony.war.volume.BlockInfo;
import com.tommytony.war.volume.Volume;
/**
@ -35,19 +34,12 @@ public class Cake {
public void addCakeBlocks() {
// make air (old two-high above floor)
Volume airGap = new Volume("airgap", this.warzone.getWorld());
airGap.setCornerOne(new BlockInfo(
this.volume.getCornerOne().getX(),
this.volume.getCornerOne().getY() + 1,
this.volume.getCornerOne().getZ(),
0,
(byte)0));
airGap.setCornerTwo(new BlockInfo(
this.volume.getCornerTwo().getX(),
this.volume.getCornerOne().getY() + 2,
this.volume.getCornerTwo().getZ(),
0,
(byte)0));
Volume airGap = new Volume(new Location(this.volume.getWorld(),
this.volume.getCornerOne().getX(), this.volume.getCornerOne()
.getY() + 1, this.volume.getCornerOne().getZ()),
new Location(this.volume.getWorld(), this.volume.getCornerTwo()
.getX(), this.volume.getCornerOne().getY() + 2,
this.volume.getCornerTwo().getZ()));
airGap.setToMaterial(Material.AIR);
int x = this.location.getBlockX();

View File

@ -10,7 +10,6 @@ import org.bukkit.material.MaterialData;
import com.tommytony.war.Team;
import com.tommytony.war.Warzone;
import com.tommytony.war.utility.Direction;
import com.tommytony.war.volume.BlockInfo;
import com.tommytony.war.volume.Volume;
/**
@ -36,19 +35,12 @@ public class Monument {
public void addMonumentBlocks() {
// make air (old three-high above floor)
Volume airGap = new Volume("airgap", this.warzone.getWorld());
airGap.setCornerOne(new BlockInfo(
this.volume.getCornerOne().getX(),
this.volume.getCornerOne().getY() + 1,
this.volume.getCornerOne().getZ(),
0,
(byte)0));
airGap.setCornerTwo(new BlockInfo(
this.volume.getCornerTwo().getX(),
this.volume.getCornerOne().getY() + 3,
this.volume.getCornerTwo().getZ(),
0,
(byte)0));
Volume airGap = new Volume(new Location(this.volume.getWorld(),
this.volume.getCornerOne().getX(), this.volume.getCornerOne()
.getY() + 1, this.volume.getCornerOne().getZ()),
new Location(this.volume.getWorld(), this.volume.getCornerTwo()
.getX(), this.volume.getCornerOne().getY() + 3,
this.volume.getCornerTwo().getZ()));
airGap.setToMaterial(Material.AIR);
this.ownerTeam = null;

View File

@ -18,7 +18,6 @@ import com.tommytony.war.Warzone;
import com.tommytony.war.config.TeamConfig;
import com.tommytony.war.config.WarzoneConfig;
import com.tommytony.war.utility.Direction;
import com.tommytony.war.volume.BlockInfo;
import com.tommytony.war.volume.Volume;
/**
@ -171,7 +170,7 @@ public class WarHub {
warhubTpVolume.setToMaterial(Material.AIR);
// draw gates
Block currentGateBlock = BlockInfo.getBlock(this.location.getWorld(), this.volume.getCornerOne()).getRelative(BlockFace.UP).getRelative(front, hubDepth).getRelative(right, 2);
Block currentGateBlock = this.volume.getCornerOne().getBlock().getRelative(BlockFace.UP).getRelative(front, hubDepth).getRelative(right, 2);
for (Warzone zone : War.war.getWarzones()) { // gonna use the index to find it again
if (!zone.getWarzoneConfig().getBoolean(WarzoneConfig.DISABLED)) {

View File

@ -22,7 +22,6 @@ import com.tommytony.war.config.TeamConfig;
import com.tommytony.war.config.TeamKind;
import com.tommytony.war.config.WarzoneConfig;
import com.tommytony.war.utility.Direction;
import com.tommytony.war.volume.BlockInfo;
import com.tommytony.war.volume.Volume;
import com.tommytony.war.volume.ZoneVolume;
@ -35,14 +34,14 @@ public class ZoneLobby {
private final Warzone warzone;
private BlockFace wall;
private Volume volume;
BlockInfo lobbyMiddleWallBlock = null; // on the zone wall, one above the zone lobby floor
Location lobbyMiddleWallBlock = null; // on the zone wall, one above the zone lobby floor
BlockInfo warHubLinkGate = null;
Location warHubLinkGate = null;
Map<String, BlockInfo> teamGateBlocks = new HashMap<String, BlockInfo>();
BlockInfo autoAssignGate = null;
Map<String, Location> teamGateBlocks = new HashMap<String, Location>();
Location autoAssignGate = null;
BlockInfo zoneTeleportBlock = null;
Location zoneTeleportBlock = null;
private final int lobbyHeight = 3;
private int lobbyHalfSide;
@ -99,13 +98,13 @@ public class ZoneLobby {
// we're setting the zoneVolume directly, so we need to figure out the lobbyMiddleWallBlock on our own
if (wall == Direction.NORTH()) {
this.lobbyMiddleWallBlock = new BlockInfo(BlockInfo.getBlock(warzone.getWorld(), volume.getCornerOne()).getRelative(BlockFace.UP).getRelative(Direction.EAST(), this.lobbyHalfSide));
this.lobbyMiddleWallBlock = volume.getCornerOne().getBlock().getRelative(BlockFace.UP).getRelative(Direction.EAST(), this.lobbyHalfSide).getLocation();
} else if (wall == Direction.EAST()) {
this.lobbyMiddleWallBlock = new BlockInfo(BlockInfo.getBlock(warzone.getWorld(), volume.getCornerOne()).getRelative(BlockFace.UP).getRelative(Direction.SOUTH(), this.lobbyHalfSide));
this.lobbyMiddleWallBlock = volume.getCornerOne().getBlock().getRelative(BlockFace.UP).getRelative(Direction.SOUTH(), this.lobbyHalfSide).getLocation();
} else if (wall == Direction.SOUTH()) {
this.lobbyMiddleWallBlock = new BlockInfo(BlockInfo.getBlock(warzone.getWorld(), volume.getCornerOne()).getRelative(BlockFace.UP).getRelative(Direction.WEST(), this.lobbyHalfSide));
this.lobbyMiddleWallBlock = volume.getCornerOne().getBlock().getRelative(BlockFace.UP).getRelative(Direction.WEST(), this.lobbyHalfSide).getLocation();
} else if (wall == Direction.WEST()) {
this.lobbyMiddleWallBlock = new BlockInfo(BlockInfo.getBlock(warzone.getWorld(), volume.getCornerOne()).getRelative(BlockFace.UP).getRelative(Direction.NORTH(), this.lobbyHalfSide));
this.lobbyMiddleWallBlock = volume.getCornerOne().getBlock().getRelative(BlockFace.UP).getRelative(Direction.NORTH(), this.lobbyHalfSide).getLocation();
}
}
@ -157,13 +156,13 @@ public class ZoneLobby {
this.wall = opposite; // a player facing south places a lobby that looks just like a lobby stuck to the north wall
this.calculateLobbyWidth();
this.lobbyMiddleWallBlock = new BlockInfo(lobbyWorld.getBlockAt(playerLocation.getBlockX(), playerLocation.getBlockY(), playerLocation.getBlockZ()).getRelative(facing, 6));
this.lobbyMiddleWallBlock = lobbyWorld.getBlockAt(playerLocation.getBlockX(), playerLocation.getBlockY(), playerLocation.getBlockZ()).getRelative(facing, 6).getLocation();
Block corner1 = null;
Block corner2 = null;
int x = this.lobbyMiddleWallBlock.getX();
int y = this.lobbyMiddleWallBlock.getY();
int z = this.lobbyMiddleWallBlock.getZ();
int x = this.lobbyMiddleWallBlock.getBlockX();
int y = this.lobbyMiddleWallBlock.getBlockY();
int z = this.lobbyMiddleWallBlock.getBlockZ();
if (this.wall == Direction.NORTH()) {
corner1 = lobbyWorld.getBlockAt(x, y - 1, z + this.lobbyHalfSide);
@ -204,7 +203,7 @@ public class ZoneLobby {
int wallLength = wallEnd - wallStart + 1;
int wallCenterPos = wallStart + wallLength / 2;
int y = zoneVolume.getCenterY();
this.lobbyMiddleWallBlock = new BlockInfo(this.warzone.getWorld().getBlockAt(x, y, wallCenterPos));
this.lobbyMiddleWallBlock = this.warzone.getWorld().getBlockAt(x, y, wallCenterPos).getLocation();
corner1 = this.warzone.getWorld().getBlockAt(x, y - 1, wallCenterPos + this.lobbyHalfSide);
corner2 = this.warzone.getWorld().getBlockAt(x - this.lobbyDepth, y + 1 + this.lobbyHeight, wallCenterPos - this.lobbyHalfSide);
} else if (this.wall == Direction.EAST()) {
@ -214,7 +213,7 @@ public class ZoneLobby {
int wallLength = wallEnd - wallStart + 1;
int wallCenterPos = wallStart + wallLength / 2;
int y = zoneVolume.getCenterY();
this.lobbyMiddleWallBlock = new BlockInfo(this.warzone.getWorld().getBlockAt(wallCenterPos, y, z));
this.lobbyMiddleWallBlock = this.warzone.getWorld().getBlockAt(wallCenterPos, y, z).getLocation();
corner1 = this.warzone.getWorld().getBlockAt(wallCenterPos - this.lobbyHalfSide, y - 1, z);
corner2 = this.warzone.getWorld().getBlockAt(wallCenterPos + this.lobbyHalfSide, y + 1 + this.lobbyHeight, z - this.lobbyDepth);
} else if (this.wall == Direction.SOUTH()) {
@ -224,7 +223,7 @@ public class ZoneLobby {
int wallLength = wallEnd - wallStart + 1;
int wallCenterPos = wallStart + wallLength / 2;
int y = zoneVolume.getCenterY();
this.lobbyMiddleWallBlock = new BlockInfo(this.warzone.getWorld().getBlockAt(x, y, wallCenterPos));
this.lobbyMiddleWallBlock = this.warzone.getWorld().getBlockAt(x, y, wallCenterPos).getLocation();
corner1 = this.warzone.getWorld().getBlockAt(x, y - 1, wallCenterPos - this.lobbyHalfSide);
corner2 = this.warzone.getWorld().getBlockAt(x + this.lobbyDepth, y + 1 + this.lobbyHeight, wallCenterPos + this.lobbyHalfSide);
} else if (this.wall == Direction.WEST()) {
@ -234,7 +233,7 @@ public class ZoneLobby {
int wallLength = wallEnd - wallStart + 1;
int wallCenterPos = wallStart + wallLength / 2;
int y = zoneVolume.getCenterY();
this.lobbyMiddleWallBlock = new BlockInfo(this.warzone.getWorld().getBlockAt(wallCenterPos, y, z));
this.lobbyMiddleWallBlock = this.warzone.getWorld().getBlockAt(wallCenterPos, y, z).getLocation();
corner1 = this.warzone.getWorld().getBlockAt(wallCenterPos + this.lobbyHalfSide, y - 1, z);
corner2 = this.warzone.getWorld().getBlockAt(wallCenterPos - this.lobbyHalfSide, y + 1 + this.lobbyHeight, z + this.lobbyDepth);
}
@ -276,7 +275,7 @@ public class ZoneLobby {
public void initialize() {
// maybe the number of teams change, now reset the gate positions
if (this.lobbyMiddleWallBlock != null && this.volume != null) {
this.setGatePositions(BlockInfo.getBlock(this.volume.getWorld(), this.lobbyMiddleWallBlock));
this.setGatePositions(this.lobbyMiddleWallBlock.getBlock());
if (!warzone.getLobbyMaterials().getFloorBlock().getType().equals(Material.AIR)) {
// If air, leave original blocks.
this.volume.setFaceMaterial(BlockFace.DOWN, warzone.getLobbyMaterials().getFloorBlock());
@ -289,7 +288,7 @@ public class ZoneLobby {
// add war hub link gate
if (War.war.getWarHub() != null) {
Block linkGateBlock = BlockInfo.getBlock(this.volume.getWorld(), this.warHubLinkGate);
Block linkGateBlock = this.warHubLinkGate.getBlock();
this.placeWarhubLinkGate(linkGateBlock, warzone.getLobbyMaterials().getGateBlock());
// add warhub sign
String[] lines = War.war.getString("sign.lobby.warhub").split("\n");
@ -299,15 +298,15 @@ public class ZoneLobby {
// add team gates or single auto assign gate
this.placeAutoAssignGate();
for (String teamName : this.teamGateBlocks.keySet()) {
BlockInfo gateInfo = this.teamGateBlocks.get(teamName);
this.placeTeamGate(BlockInfo.getBlock(this.volume.getWorld(), gateInfo), TeamKind.teamKindFromString(teamName));
Block gateInfo = this.teamGateBlocks.get(teamName).getBlock();
this.placeTeamGate(gateInfo, TeamKind.teamKindFromString(teamName));
}
for (Team t : this.warzone.getTeams()) {
this.resetTeamGateSign(t);
}
// set zone tp
this.zoneTeleportBlock = new BlockInfo(BlockInfo.getBlock(this.volume.getWorld(), this.lobbyMiddleWallBlock).getRelative(this.wall, 6));
this.zoneTeleportBlock = this.lobbyMiddleWallBlock.getBlock().getRelative(this.wall, 6).getLocation();
int yaw = 0;
if (this.wall == Direction.WEST()) {
yaw = 180;
@ -339,7 +338,7 @@ public class ZoneLobby {
rightSide = Direction.SOUTH();
}
Block clearedPathStartBlock = BlockInfo.getBlock(this.warzone.getWorld(), this.lobbyMiddleWallBlock).getRelative(this.wall, 2);
Block clearedPathStartBlock = this.lobbyMiddleWallBlock.getBlock().getRelative(this.wall, 2);
Volume warzoneTeleportAir = new Volume("warzoneTeleport", clearedPathStartBlock.getWorld());
warzoneTeleportAir.setCornerOne(clearedPathStartBlock.getRelative(leftSide));
warzoneTeleportAir.setCornerTwo(clearedPathStartBlock.getRelative(rightSide).getRelative(front, 4).getRelative(BlockFace.UP));
@ -359,7 +358,7 @@ public class ZoneLobby {
clearedPathStartBlock.getRelative(this.wall).getRelative(this.wall).getRelative(this.wall).getRelative(this.wall).getRelative(this.wall).getRelative(BlockFace.UP).setType(Material.AIR);
// set zone sign
Block zoneSignBlock = BlockInfo.getBlock(this.volume.getWorld(), this.lobbyMiddleWallBlock).getRelative(this.wall, 4);
Block zoneSignBlock = this.lobbyMiddleWallBlock.getBlock().getRelative(this.wall, 4);
zoneSignBlock.setType(Material.SIGN_POST);
org.bukkit.block.Sign block = (org.bukkit.block.Sign) zoneSignBlock.getState();
org.bukkit.material.Sign data = (Sign) block.getData();
@ -377,20 +376,20 @@ public class ZoneLobby {
block.update(true);
// lets get some light in here
if (this.wall == Direction.NORTH() || this.wall == Direction.SOUTH()) {
BlockState one = BlockInfo.getBlock(this.volume.getWorld(), this.lobbyMiddleWallBlock).getRelative(BlockFace.DOWN).getRelative(Direction.WEST(), this.lobbyHalfSide - 1).getRelative(this.wall, 9).getState();
BlockState one = this.lobbyMiddleWallBlock.getBlock().getRelative(BlockFace.DOWN).getRelative(Direction.WEST(), this.lobbyHalfSide - 1).getRelative(this.wall, 9).getState();
one.setType(warzone.getLobbyMaterials().getLightBlock().getType());
one.setData(warzone.getLobbyMaterials().getLightBlock().getData());
one.update(true);
one = BlockInfo.getBlock(this.volume.getWorld(), this.lobbyMiddleWallBlock).getRelative(BlockFace.DOWN).getRelative(Direction.EAST(), this.lobbyHalfSide - 1).getRelative(this.wall, 9).getState();
one = this.lobbyMiddleWallBlock.getBlock().getRelative(BlockFace.DOWN).getRelative(Direction.EAST(), this.lobbyHalfSide - 1).getRelative(this.wall, 9).getState();
one.setType(warzone.getLobbyMaterials().getLightBlock().getType());
one.setData(warzone.getLobbyMaterials().getLightBlock().getData());
one.update(true);
} else {
BlockState one = BlockInfo.getBlock(this.volume.getWorld(), this.lobbyMiddleWallBlock).getRelative(BlockFace.DOWN).getRelative(Direction.NORTH(), this.lobbyHalfSide - 1).getRelative(this.wall, 9).getState();
BlockState one = this.lobbyMiddleWallBlock.getBlock().getRelative(BlockFace.DOWN).getRelative(Direction.NORTH(), this.lobbyHalfSide - 1).getRelative(this.wall, 9).getState();
one.setType(warzone.getLobbyMaterials().getLightBlock().getType());
one.setData(warzone.getLobbyMaterials().getLightBlock().getData());
one.update(true);
one = BlockInfo.getBlock(this.volume.getWorld(), this.lobbyMiddleWallBlock).getRelative(BlockFace.DOWN).getRelative(Direction.SOUTH(), this.lobbyHalfSide - 1).getRelative(this.wall, 9).getState();
one = this.lobbyMiddleWallBlock.getBlock().getRelative(BlockFace.DOWN).getRelative(Direction.SOUTH(), this.lobbyHalfSide - 1).getRelative(this.wall, 9).getState();
one.setType(warzone.getLobbyMaterials().getLightBlock().getType());
one.setData(warzone.getLobbyMaterials().getLightBlock().getData());
one.update(true);
@ -418,7 +417,7 @@ public class ZoneLobby {
}
this.teamGateBlocks.clear();
if (this.warzone.getWarzoneConfig().getBoolean(WarzoneConfig.AUTOASSIGN)) {
this.autoAssignGate = new BlockInfo(lobbyMiddleWallBlock);
this.autoAssignGate = lobbyMiddleWallBlock.getLocation();
} else {
this.autoAssignGate = null;
for (int doorIndex = 0; doorIndex < this.warzone.getTeams().size(); doorIndex++) {
@ -427,23 +426,23 @@ public class ZoneLobby {
if (this.warzone.getTeams().size() % 2 == 0) {
// even number of teams
if (doorIndex % 2 == 0) {
this.teamGateBlocks.put(team.getName(), new BlockInfo(lobbyMiddleWallBlock.getRelative(rightSide, doorIndex * 2 + 2)));
this.teamGateBlocks.put(team.getName(), lobbyMiddleWallBlock.getRelative(rightSide, doorIndex * 2 + 2).getLocation());
} else {
this.teamGateBlocks.put(team.getName(), new BlockInfo(lobbyMiddleWallBlock.getRelative(leftSide, doorIndex * 2)));
this.teamGateBlocks.put(team.getName(), lobbyMiddleWallBlock.getRelative(leftSide, doorIndex * 2).getLocation());
}
} else {
if (doorIndex == 0) {
this.teamGateBlocks.put(team.getName(), new BlockInfo(lobbyMiddleWallBlock));
this.teamGateBlocks.put(team.getName(), lobbyMiddleWallBlock.getLocation());
} else if (doorIndex % 2 == 0) {
this.teamGateBlocks.put(team.getName(), new BlockInfo(lobbyMiddleWallBlock.getRelative(rightSide, doorIndex * 2)));
this.teamGateBlocks.put(team.getName(), lobbyMiddleWallBlock.getRelative(rightSide, doorIndex * 2).getLocation());
} else {
this.teamGateBlocks.put(team.getName(), new BlockInfo(lobbyMiddleWallBlock.getRelative(leftSide, doorIndex * 2 + 2)));
this.teamGateBlocks.put(team.getName(), lobbyMiddleWallBlock.getRelative(leftSide, doorIndex * 2 + 2).getLocation());
}
}
}
}
this.warHubLinkGate = new BlockInfo(lobbyMiddleWallBlock.getRelative(this.wall, 9));
this.warHubLinkGate = lobbyMiddleWallBlock.getRelative(this.wall, 9).getLocation();
}
private void placeTeamGate(Block block, TeamKind teamKind) {
@ -573,7 +572,7 @@ public class ZoneLobby {
List<Team> teams = this.warzone.getTeams();
Block autoAssignGateBlock = BlockInfo.getBlock(this.volume.getWorld(), this.autoAssignGate);
Block autoAssignGateBlock = this.autoAssignGate.getBlock();
// minimal air path
this.clearGatePath(autoAssignGateBlock, front, leftSide, rightSide, false);
@ -601,7 +600,7 @@ public class ZoneLobby {
}
public boolean isInTeamGate(Team team, Location location) {
BlockInfo info = this.teamGateBlocks.get(team.getName());
Location info = this.teamGateBlocks.get(team.getName());
if (info != null) {
if (location.getBlockX() == info.getX() && location.getBlockY() == info.getY() && location.getBlockZ() == info.getZ()) {
return true;
@ -648,13 +647,13 @@ public class ZoneLobby {
public boolean blockIsAGateBlock(Block block, BlockFace blockWall) {
if (blockWall == this.wall) {
for (String teamName : this.teamGateBlocks.keySet()) {
BlockInfo gateInfo = this.teamGateBlocks.get(teamName);
if (this.isPartOfGate(BlockInfo.getBlock(this.volume.getWorld(), gateInfo), block)) {
Location gateInfo = this.teamGateBlocks.get(teamName);
if (this.isPartOfGate(gateInfo.getBlock(), block)) {
return true;
}
}
if (this.autoAssignGate != null && this.isPartOfGate(BlockInfo.getBlock(this.volume.getWorld(), this.autoAssignGate), block)) {
if (this.autoAssignGate != null && this.isPartOfGate(this.autoAssignGate.getBlock(), block)) {
// auto assign
return true;
}
@ -689,9 +688,9 @@ public class ZoneLobby {
}
public void resetTeamGateSign(Team team) {
BlockInfo info = this.teamGateBlocks.get(team.getName());
Location info = this.teamGateBlocks.get(team.getName());
if (info != null) {
this.resetTeamGateSign(team, BlockInfo.getBlock(this.volume.getWorld(), info));
this.resetTeamGateSign(team, info.getBlock());
}
}
@ -783,14 +782,14 @@ public class ZoneLobby {
right = Direction.NORTH();
}
if (this.autoAssignGate != null) {
if (this.leaving(location, BlockInfo.getBlock(this.volume.getWorld(), this.autoAssignGate), inside, left, right)) {
if (this.leaving(location, this.autoAssignGate.getBlock(), inside, left, right)) {
return true;
}
}
for (String teamName : this.teamGateBlocks.keySet()) {
BlockInfo info = this.teamGateBlocks.get(teamName);
if (this.leaving(location, BlockInfo.getBlock(this.volume.getWorld(), info), inside, left, right)) {
Location info = this.teamGateBlocks.get(teamName);
if (this.leaving(location, info.getBlock(), inside, left, right)) {
return true;
}
}

View File

@ -1,110 +0,0 @@
package com.tommytony.war.volume;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
/**
*
* @author tommytony
*
*/
public class BlockInfo {
private int x;
private int y;
private int z;
private int type;
private byte data;
// private String[] signLines;
public static Block getBlock(World world, BlockInfo info) {
return world.getBlockAt(info.getX(), info.getY(), info.getZ());
}
public BlockInfo(int x, int y, int z, int type, byte data) {
this.x = x;
this.y = y;
this.z = z;
this.type = type;
this.data = data;
}
public BlockInfo(Block block) {
this.x = block.getX();
this.y = block.getY();
this.z = block.getZ();
this.type = block.getTypeId();
this.data = block.getData();
// if (is(Material.SIGN) || is(Material.SIGN_POST)) {
// Sign sign = (Sign)block.getState();
// this.signLines = sign.getLines();
// }
}
// public BlockInfo(BlockState blockState) {
// this.x = blockState.getX();
// this.y = blockState.getY();
// this.z = blockState.getZ();
// this.type = blockState.getTypeId();
// this.data = blockState.getData().getData();
// // if (is(Material.SIGN) || is(Material.SIGN_POST)) {
// // Sign sign = (Sign)blockState;
// // this.signLines = sign.getLines();
// // }
// }
// public BlockInfo(int typeID, byte data, String[] lines) {
// type = typeID;
// this.data = data;
// //signLines = lines;
// }
public int getX() {
return this.x;
}
public int getY() {
return this.y;
}
public int getZ() {
return this.z;
}
// letting us mutate the BlockInfos might be a bad idea; use setters with care
public void setX(int x) {
this.x = x;
}
public void setY(int y) {
this.y = y;
}
public void setZ(int z) {
this.z = z;
}
public int getTypeId() {
return this.type;
}
public Material getType() {
return Material.getMaterial(this.type);
}
public byte getData() {
return this.data;
}
public boolean is(Material material) {
return this.getType() == material;
}
// public String[] getSignLines() {
// if (is(Material.SIGN) || is(Material.SIGN_POST)){
// return new String[4] {"", ""};
// }
// return null;
// }
}

View File

@ -1,171 +0,0 @@
package com.tommytony.war.volume;
import java.util.logging.Level;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import com.tommytony.war.War;
import com.tommytony.war.utility.Direction;
/**
*
* @author tommytony
*
*/
@Deprecated
public class VerticalVolume extends Volume {
public VerticalVolume(String name, World world) {
super(name, world);
}
@Override
public void setCornerOne(Block block) {
// corner one defaults to topmost corner
Block topBlock = this.getWorld().getBlockAt(block.getX(), 127, block.getZ());
super.setCornerOne(topBlock);
}
@Override
public void setCornerTwo(Block block) {
// corner two defaults to bottom most corner
Block bottomBlock = this.getWorld().getBlockAt(block.getX(), 0, block.getZ());
super.setCornerTwo(bottomBlock);
}
public boolean isWallBlock(Block block) {
return this.isEastWallBlock(block) || this.isNorthWallBlock(block) || this.isSouthWallBlock(block) || this.isWestWallBlock(block);
}
public boolean isEastWallBlock(Block block) {
if (this.getMinZ() == block.getZ() && block.getX() <= this.getMaxX() && block.getX() >= this.getMinX()) {
return true; // east wall
}
return false;
}
public boolean isSouthWallBlock(Block block) {
if (this.getMaxX() == block.getX() && block.getZ() <= this.getMaxZ() && block.getZ() >= this.getMinZ()) {
return true; // south wall
}
return false;
}
public boolean isNorthWallBlock(Block block) {
if (this.getMinX() == block.getX() && block.getZ() <= this.getMaxZ() && block.getZ() >= this.getMinZ()) {
return true; // north wall
}
return false;
}
public boolean isWestWallBlock(Block block) {
if (this.getMaxZ() == block.getZ() && block.getX() <= this.getMaxX() && block.getX() >= this.getMinX()) {
return true; // west wall
}
return false;
}
public int resetWallBlocks(BlockFace wall) {
int noOfResetBlocks = 0;
try {
if (this.hasTwoCorners() && this.getBlockTypes() != null) {
if (wall == Direction.EAST()) {
int z = this.getMinZ();
int k = 0;
int y = this.getMinY();
for (int j = 0; j < this.getSizeY(); j++) {
int x = this.getMinX();
for (int i = 0; i < this.getSizeX(); i++) {
int oldBlockType = this.getBlockTypes()[i][j][k];
byte oldBlockData = this.getBlockDatas()[i][j][k];
Block currentBlock = this.getWorld().getBlockAt(x, y, z);
if (this.resetBlock(oldBlockType, oldBlockData, currentBlock)) {
noOfResetBlocks++;
}
x++;
}
y++;
}
} else if (wall == Direction.WEST()) {
int z = this.getMaxZ();
int k = this.getSizeZ() - 1;
int y = this.getMinY();
for (int j = 0; j < this.getSizeY(); j++) {
int x = this.getMinX();
for (int i = 0; i < this.getSizeX(); i++) {
int oldBlockType = this.getBlockTypes()[i][j][k];
byte oldBlockData = this.getBlockDatas()[i][j][k];
Block currentBlock = this.getWorld().getBlockAt(x, y, z);
if (this.resetBlock(oldBlockType, oldBlockData, currentBlock)) {
noOfResetBlocks++;
}
x++;
}
y++;
}
} else if (wall == Direction.NORTH()) {
int x = this.getMinX();
int i = 0;
int y = this.getMinY();
for (int j = 0; j < this.getSizeY(); j++) {
int z = this.getMinZ();
for (int k = 0; k < this.getSizeZ(); k++) {
int oldBlockType = this.getBlockTypes()[i][j][k];
byte oldBlockData = this.getBlockDatas()[i][j][k];
Block currentBlock = this.getWorld().getBlockAt(x, y, z);
if (this.resetBlock(oldBlockType, oldBlockData, currentBlock)) {
noOfResetBlocks++;
}
z++;
}
y++;
}
} else if (wall == Direction.SOUTH()) {
int x = this.getMaxX();
int i = this.getSizeX() - 1;
int y = this.getMinY();
for (int j = 0; j < this.getSizeY(); j++) {
int z = this.getMinZ();
for (int k = 0; k < this.getSizeZ(); k++) {
int oldBlockType = this.getBlockTypes()[i][j][k];
byte oldBlockData = this.getBlockDatas()[i][j][k];
Block currentBlock = this.getWorld().getBlockAt(x, y, z);
if (this.resetBlock(oldBlockType, oldBlockData, currentBlock)) {
noOfResetBlocks++;
}
z++;
}
y++;
}
}
}
} catch (Exception e) {
War.war.log("Failed to reset wall " + wall + " in volume " + this.getName() + ". " + e.getClass().toString() + " " + e.getMessage(), Level.WARNING);
}
return noOfResetBlocks;
}
private boolean resetBlock(int oldBlockType, byte oldBlockData, Block currentBlock) {
if (currentBlock.getTypeId() != oldBlockType || (currentBlock.getTypeId() == oldBlockType && currentBlock.getData() != oldBlockData) || (currentBlock.getTypeId() == oldBlockType && currentBlock.getData() == oldBlockData && (oldBlockType == Material.WALL_SIGN.getId() || oldBlockType == Material.SIGN_POST.getId()))) {
currentBlock.setTypeId(oldBlockType);
currentBlock.setData(oldBlockData);
// if (oldBlockInfo.is(Material.SIGN) || oldBlockInfo.is(Material.SIGN_POST)) {
// BlockState state = currentBlock.getState();
// Sign currentSign = (Sign) state;
// currentSign.setLine(0, oldBlockInfo.getSignLines()[0]);
// currentSign.setLine(1, oldBlockInfo.getSignLines()[0]);
// currentSign.setLine(2, oldBlockInfo.getSignLines()[0]);
// currentSign.setLine(3, oldBlockInfo.getSignLines()[0]);
// state.update();
// }
return true;
}
return false;
}
}

View File

@ -31,12 +31,12 @@ import com.tommytony.war.utility.Direction;
public class Volume {
private String name;
private World world;
private BlockInfo cornerOne;
private BlockInfo cornerTwo;
private int[][][] blockTypes = null;
private byte[][][] blockDatas = null;
private HashMap<String, String[]> signLines = new HashMap<String, String[]>();
private HashMap<String, List<ItemStack>> invBlockContents = new HashMap<String, List<ItemStack>>();
private Location cornerOne;
private Location cornerTwo;
public Volume(String name, World world) {
this.name = name;
@ -50,8 +50,8 @@ public class Volume {
public Volume(Location corner1, Location corner2) {
this(corner1.getWorld());
Validate.isTrue(corner1.getWorld() == corner2.getWorld(), "Cross-world volume");
this.cornerOne = new BlockInfo(corner1.getBlock());
this.cornerTwo = new BlockInfo(corner2.getBlock());
this.cornerOne = corner1;
this.cornerTwo = corner2;
}
public void setName(String newName) {
@ -71,11 +71,11 @@ public class Volume {
}
public void setCornerOne(Block block) {
this.cornerOne = new BlockInfo(block);
this.cornerOne = block.getLocation();
}
public void setCornerOne(BlockInfo blockInfo) {
this.cornerOne = blockInfo;
public void setCornerOne(Location location) {
this.cornerOne = location;
}
public int saveBlocks() {
@ -314,28 +314,28 @@ public class Volume {
}
public void setCornerTwo(Block block) {
this.cornerTwo = new BlockInfo(block);
this.cornerTwo = block.getLocation();
}
public void setCornerTwo(BlockInfo blockInfo) {
this.cornerTwo = blockInfo;
public void setCornerTwo(Location location) {
this.cornerTwo = location;
}
public BlockInfo getMinXBlock() {
public Location getMinXBlock() {
if (this.cornerOne.getX() < this.cornerTwo.getX()) {
return this.cornerOne;
}
return this.cornerTwo;
}
public BlockInfo getMinYBlock() {
public Location getMinYBlock() {
if (this.cornerOne.getY() < this.cornerTwo.getY()) {
return this.cornerOne;
}
return this.cornerTwo;
}
public BlockInfo getMinZBlock() {
public Location getMinZBlock() {
if (this.cornerOne.getZ() < this.cornerTwo.getZ()) {
return this.cornerOne;
}
@ -343,32 +343,32 @@ public class Volume {
}
public int getMinX() {
return this.getMinXBlock().getX();
return this.getMinXBlock().getBlockX();
}
public int getMinY() {
return this.getMinYBlock().getY();
return this.getMinYBlock().getBlockY();
}
public int getMinZ() {
return this.getMinZBlock().getZ();
return this.getMinZBlock().getBlockZ();
}
public BlockInfo getMaxXBlock() {
public Location getMaxXBlock() {
if (this.cornerOne.getX() < this.cornerTwo.getX()) {
return this.cornerTwo;
}
return this.cornerOne;
}
public BlockInfo getMaxYBlock() {
public Location getMaxYBlock() {
if (this.cornerOne.getY() < this.cornerTwo.getY()) {
return this.cornerTwo;
}
return this.cornerOne;
}
public BlockInfo getMaxZBlock() {
public Location getMaxZBlock() {
if (this.cornerOne.getZ() < this.cornerTwo.getZ()) {
return this.cornerTwo;
}
@ -376,15 +376,15 @@ public class Volume {
}
public int getMaxX() {
return this.getMaxXBlock().getX();
return this.getMaxXBlock().getBlockX();
}
public int getMaxY() {
return this.getMaxYBlock().getY();
return this.getMaxYBlock().getBlockY();
}
public int getMaxZ() {
return this.getMaxZBlock().getZ();
return this.getMaxZBlock().getBlockZ();
}
public int getSizeX() {
@ -407,11 +407,11 @@ public class Volume {
return this.blockTypes;
}
public BlockInfo getCornerOne() {
public Location getCornerOne() {
return this.cornerOne;
}
public BlockInfo getCornerTwo() {
public Location getCornerTwo() {
return this.cornerTwo;
}
@ -557,4 +557,8 @@ public class Volume {
this.invBlockContents.clear();
this.invBlockContents = null;
}
public int size() {
return this.getSizeX() * this.getSizeY() * this.getSizeZ();
}
}

View File

@ -1,5 +1,6 @@
package com.tommytony.war.volume;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
@ -63,11 +64,11 @@ public class ZoneVolume extends Volume {
return;
}
public void setNorthwest(Block block) throws NotNorthwestException, TooSmallException, TooBigException {
public void setNorthwest(Location block) throws NotNorthwestException, TooSmallException, TooBigException {
// northwest defaults to top block
BlockInfo topBlock = new BlockInfo(block.getX(), 127, block.getZ(), block.getTypeId(), block.getData());
BlockInfo oldCornerOne = this.getCornerOne();
BlockInfo oldCornerTwo = this.getCornerTwo();
Location topBlock = new Location(block.getWorld(), block.getX(), block.getWorld().getMaxHeight(), block.getZ());
Location oldCornerOne = this.getCornerOne();
Location oldCornerTwo = this.getCornerTwo();
if (this.getCornerOne() == null) {
if (this.getCornerTwo() == null) {
// northwest defaults to corner 1
@ -89,10 +90,8 @@ public class ZoneVolume extends Volume {
if (this.getSoutheastX() <= block.getX() || this.getSoutheastZ() >= block.getZ()) {
throw new NotNorthwestException();
}
BlockInfo minXBlock = this.getMinXBlock(); // north means min X
minXBlock.setX(block.getX()); // mutating, argh!
BlockInfo maxZBlock = this.getMaxZBlock(); // west means max Z
maxZBlock.setZ(block.getZ());
this.getMinXBlock().setX(block.getX()); // north means min X
this.getMaxZBlock().setZ(block.getZ()); // west means max Z
}
if (this.tooSmall() || this.zoneStructuresAreOutside()) {
super.setCornerOne(oldCornerOne);
@ -121,11 +120,11 @@ public class ZoneVolume extends Volume {
}
}
public void setSoutheast(Block block) throws NotSoutheastException, TooSmallException, TooBigException {
public void setSoutheast(Location block) throws NotSoutheastException, TooSmallException, TooBigException {
// southeast defaults to bottom block
BlockInfo bottomBlock = new BlockInfo(block.getX(), 0, block.getZ(), block.getTypeId(), block.getData());
BlockInfo oldCornerOne = this.getCornerOne();
BlockInfo oldCornerTwo = this.getCornerTwo();
Location bottomBlock = new Location(block.getWorld(), block.getX(), 0, block.getZ());
Location oldCornerOne = this.getCornerOne();
Location oldCornerTwo = this.getCornerTwo();
if (this.getCornerTwo() == null) {
if (this.getCornerOne() == null) {
// southeast defaults to corner 2
@ -147,10 +146,8 @@ public class ZoneVolume extends Volume {
if (this.getNorthwestX() >= block.getX() || this.getNorthwestZ() <= block.getZ()) {
throw new NotSoutheastException();
}
BlockInfo maxXBlock = this.getMaxXBlock(); // south means max X
maxXBlock.setX(block.getX()); // mutating, argh!
BlockInfo minZBlock = this.getMinZBlock(); // east means min Z
minZBlock.setZ(block.getZ());
this.getMaxXBlock().setX(block.getX()); // south means max X
this.getMinZBlock().setZ(block.getZ()); // east means min Z
}
if (this.tooSmall() || this.zoneStructuresAreOutside()) {
super.setCornerOne(oldCornerOne);
@ -189,7 +186,7 @@ public class ZoneVolume extends Volume {
}
public void setZoneCornerOne(Block block) throws TooSmallException, TooBigException {
BlockInfo oldCornerOne = this.getCornerOne();
Location oldCornerOne = this.getCornerOne();
super.setCornerOne(block);
if (this.tooSmall() || this.zoneStructuresAreOutside()) {
super.setCornerOne(oldCornerOne);
@ -201,7 +198,7 @@ public class ZoneVolume extends Volume {
}
public void setZoneCornerTwo(Block block) throws TooSmallException, TooBigException {
BlockInfo oldCornerTwo = this.getCornerTwo();
Location oldCornerTwo = this.getCornerTwo();
super.setCornerTwo(block);
if (this.tooSmall() || this.zoneStructuresAreOutside()) {
super.setCornerTwo(oldCornerTwo);
@ -251,8 +248,8 @@ public class ZoneVolume extends Volume {
return false;
}
private boolean isInside(BlockInfo info) {
if (info.getX() <= this.getMaxX() && info.getX() >= this.getMinX() && info.getY() <= this.getMaxY() && info.getY() >= this.getMinY() && info.getZ() <= this.getMaxZ() && info.getZ() >= this.getMinZ()) {
private boolean isInside(Location location) {
if (location.getX() <= this.getMaxX() && location.getX() >= this.getMinX() && location.getY() <= this.getMaxY() && location.getY() >= this.getMinY() && location.getZ() <= this.getMaxZ() && location.getZ() >= this.getMinZ()) {
return true;
}
return false;

View File

@ -1,52 +1,52 @@
package com.tommytony.war.spec.volumes;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.junit.Test;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import com.tommytony.war.*;
import com.tommytony.war.Team;
import com.tommytony.war.Warzone;
import com.tommytony.war.structure.Monument;
import com.tommytony.war.volume.*;
import com.tommytony.war.volume.NotNorthwestException;
import com.tommytony.war.volume.NotSoutheastException;
import com.tommytony.war.volume.TooBigException;
import com.tommytony.war.volume.TooSmallException;
import com.tommytony.war.volume.ZoneVolume;
public class ZoneVolumeSpecTest {
// setNorthwest
@Test
public void setNorthwest_whenCreatingAndNoCornersAreSet_shouldSetCorner1AtTop() throws NotNorthwestException, TooSmallException, TooBigException{
public void setNorthwest_whenCreatingAndNoCornersAreSet_shouldSetCorner1AtTop()
throws NotNorthwestException, TooSmallException, TooBigException {
// Arrange
World worldMock = mock(World.class);
when(worldMock.getMaxHeight()).thenReturn(256);
Warzone zoneMock = mock(Warzone.class);
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(0);
when(blockMock.getY()).thenReturn(64); // at sea level
when(blockMock.getZ()).thenReturn(0);
when(blockMock.getTypeId()).thenReturn(10);
when(blockMock.getData()).thenReturn((byte)2);
Location nw = new Location(worldMock, 0, 64, 0);
// Act
volume.setNorthwest(blockMock);
volume.setNorthwest(nw);
// Assert
assertEquals(null, volume.getCornerTwo());
assertEquals(0, volume.getCornerOne().getX());
assertEquals(127, volume.getCornerOne().getY()); // the corner should shoot up to the top
assertEquals(0, volume.getCornerOne().getZ());
assertEquals(10, volume.getCornerOne().getTypeId());
assertEquals((byte)2, volume.getCornerOne().getData());
Location movedOne = new Location(worldMock, 0, 256, 0);
assertEquals(movedOne, volume.getCornerOne());
}
@Test
public void setNorthwest_whenCreating_AndNoCorner1IsSet_ButCorner2Set_AndNewCornerBlockIsToEastOfCorner2_shouldThrowNotNorthwestException() throws TooSmallException, TooBigException{
@Test(expected = NotNorthwestException.class)
public void setNorthwest_whenCreating_AndNoCorner1IsSet_ButCorner2Set_AndNewCornerBlockIsToEastOfCorner2_shouldThrowNotNorthwestException()
throws TooSmallException, TooBigException, NotNorthwestException {
// Arrange
World worldMock = mock(World.class);
@ -54,33 +54,17 @@ public class ZoneVolumeSpecTest {
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(-64); // further north
when(blockMock.getY()).thenReturn(64); // at sea level
when(blockMock.getZ()).thenReturn(-64); // further east
when(blockMock.getTypeId()).thenReturn(10);
when(blockMock.getData()).thenReturn((byte)2);
Location nw = new Location(worldMock, -64, 64, -64);
// Act
BlockInfo existingCorner2 = new BlockInfo(0, 64, 0, 4, (byte)4);
Location existingCorner2 = new Location(worldMock, 0, 64, 0);
volume.setCornerTwo(existingCorner2); // corner 2 already set
boolean failed = false;
try {
volume.setNorthwest(blockMock);
}
catch(NotNorthwestException e) {
failed = true;
volume.setNorthwest(nw);
}
// Assert
// first corner shouldn't move
assertTrue(failed);
assertEquals(null, volume.getCornerOne());
assertEquals(existingCorner2, volume.getCornerTwo());
}
@Test
public void setNorthwest_whenCreating_AndNoCorner1IsSet_ButCorner2Set_AndNewCornerBlockIsToSouthOfCorner2_shouldThrowNotNorthwestException() throws TooSmallException, TooBigException{
@Test(expected = NotNorthwestException.class)
public void setNorthwest_whenCreating_AndNoCorner1IsSet_ButCorner2Set_AndNewCornerBlockIsToSouthOfCorner2_shouldThrowNotNorthwestException()
throws TooSmallException, TooBigException, NotNorthwestException {
// Arrange
World worldMock = mock(World.class);
@ -88,33 +72,17 @@ public class ZoneVolumeSpecTest {
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(64); // further south
when(blockMock.getY()).thenReturn(64); // at sea level
when(blockMock.getZ()).thenReturn(64); // further west
when(blockMock.getTypeId()).thenReturn(10);
when(blockMock.getData()).thenReturn((byte)2);
Location nw = new Location(worldMock, 64, 64, 64);
// Act
BlockInfo existingCorner2 = new BlockInfo(0, 64, 0, 4, (byte)4);
Location existingCorner2 = new Location(worldMock, 0, 64, 0);
volume.setCornerTwo(existingCorner2); // corner 2 already set
boolean failed = false;
try {
volume.setNorthwest(blockMock);
}
catch(NotNorthwestException e) {
failed = true;
volume.setNorthwest(nw);
}
// Assert
// first corner shouldn't move
assertTrue(failed);
assertEquals(null, volume.getCornerOne());
assertEquals(existingCorner2, volume.getCornerTwo());
}
@Test
public void setNorthwest_whenCreating_AndNoCorner1IsSet_ButCorner2Set_AndNewCornerBlockIsTooCloseToCorner2_shouldThrowTooSmallException() throws NotNorthwestException, TooBigException{
@Test(expected = TooSmallException.class)
public void setNorthwest_whenCreating_AndNoCorner1IsSet_ButCorner2Set_AndNewCornerBlockIsTooCloseToCorner2_shouldThrowTooSmallException()
throws NotNorthwestException, TooBigException, TooSmallException {
// Arrange
World worldMock = mock(World.class);
@ -122,33 +90,17 @@ public class ZoneVolumeSpecTest {
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(-5); // further south
when(blockMock.getY()).thenReturn(64); // at sea level
when(blockMock.getZ()).thenReturn(5); // further west
when(blockMock.getTypeId()).thenReturn(10);
when(blockMock.getData()).thenReturn((byte)2);
Location nw = new Location(worldMock, -5, 64, 5);
// Act
BlockInfo existingCorner2 = new BlockInfo(0, 64, 0, 4, (byte)4);
Location existingCorner2 = new Location(worldMock, 0, 64, 0);
volume.setCornerTwo(existingCorner2); // corner 2 already set
boolean failed = false;
try {
volume.setNorthwest(blockMock);
}
catch(TooSmallException e) {
failed = true;
volume.setNorthwest(nw);
}
// Assert
// first corner shouldn't move
assertTrue(failed);
assertEquals(null, volume.getCornerOne());
assertEquals(existingCorner2, volume.getCornerTwo());
}
@Test
public void setNorthwest_whenCreating_AndNoCorner1IsSet_ButCorner2Set_AndNewCornerBlockIsTooFarFromCorner2_shouldThrowTooBigException() throws NotNorthwestException, TooSmallException{
@Test(expected = TooBigException.class)
public void setNorthwest_whenCreating_AndNoCorner1IsSet_ButCorner2Set_AndNewCornerBlockIsTooFarFromCorner2_shouldThrowTooBigException()
throws NotNorthwestException, TooSmallException, TooBigException {
// Arrange
World worldMock = mock(World.class);
@ -156,103 +108,43 @@ public class ZoneVolumeSpecTest {
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(-1000); // further south
when(blockMock.getY()).thenReturn(64); // at sea level
when(blockMock.getZ()).thenReturn(1000); // further west
when(blockMock.getTypeId()).thenReturn(10);
when(blockMock.getData()).thenReturn((byte)2);
Location nw = new Location(worldMock, -1000, 64, 1000);
// Act
BlockInfo existingCorner2 = new BlockInfo(0, 64, 0, 4, (byte)4);
Location existingCorner2 = new Location(worldMock, 0, 64, 0);
volume.setCornerTwo(existingCorner2); // corner 2 already set
boolean failed = false;
try {
volume.setNorthwest(blockMock);
}
catch(TooBigException e) {
failed = true;
}
// Assert
// first corner shouldn't move
assertTrue(failed);
assertEquals(null, volume.getCornerOne());
assertEquals(existingCorner2, volume.getCornerTwo());
volume.setNorthwest(nw);
}
@Test
public void setNorthwest_whenCreatingAndCorner1AlreadySet_shouldSetCorner2AtTop() throws NotNorthwestException, TooSmallException, TooBigException{ // nw always goes to top
public void setNorthwest_whenCreatingAndCorner1AlreadySet_shouldSetCorner2AtTop()
throws NotNorthwestException, TooSmallException, TooBigException {
// Arrange
World worldMock = mock(World.class);
when(worldMock.getMaxHeight()).thenReturn(256);
Warzone zoneMock = mock(Warzone.class);
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(-64); // further north
when(blockMock.getY()).thenReturn(64); // at sea level
when(blockMock.getZ()).thenReturn(64); // further west
when(blockMock.getTypeId()).thenReturn(10);
when(blockMock.getData()).thenReturn((byte)2);
Location nw = new Location(worldMock, -64, 64, 64);
// Act
BlockInfo existingCorner1 = new BlockInfo(0, 64, 0, 4, (byte)4);
Location existingCorner1 = new Location(worldMock, 0, 64, 0);
volume.setCornerOne(existingCorner1); // corner 1 already set
volume.setNorthwest(blockMock);
volume.setNorthwest(nw);
// Assert
// first corner shouldn't move
assertEquals(0, volume.getCornerOne().getX());
assertEquals(64, volume.getCornerOne().getY());
assertEquals(0, volume.getCornerOne().getZ());
assertEquals(4, volume.getCornerOne().getTypeId());
assertEquals((byte)4, volume.getCornerOne().getData());
assertEquals(-64, volume.getCornerTwo().getX());
assertEquals(127, volume.getCornerTwo().getY()); // the new corner should shoot up to the top
assertEquals(64, volume.getCornerTwo().getZ());
assertEquals(10, volume.getCornerTwo().getTypeId());
assertEquals((byte)2, volume.getCornerTwo().getData());
}
@Test
public void setNorthwest_whenCreating_AndCorner1AlreadySet_ButNewCornerBlockIsEastOfCorner1_shouldThrowNotNorthwestException() throws TooSmallException, TooBigException{
// Arrange
World worldMock = mock(World.class);
Warzone zoneMock = mock(Warzone.class);
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(-64); // further north
when(blockMock.getY()).thenReturn(64); // at sea level
when(blockMock.getZ()).thenReturn(-64); // further east
when(blockMock.getTypeId()).thenReturn(10);
when(blockMock.getData()).thenReturn((byte)2);
// Act
BlockInfo existingCorner1 = new BlockInfo(0, 64, 0, 4, (byte)4);
volume.setCornerOne(existingCorner1); // corner 1 already set
boolean failed = false;
try {
volume.setNorthwest(blockMock);
}
catch(NotNorthwestException e) {
failed = true;
}
// Assert
// first corner shouldn't move
assertTrue(failed);
assertEquals(null, volume.getCornerTwo());
assertEquals(existingCorner1, volume.getCornerOne());
Location nwMax = new Location(worldMock, -64, 256, 64);
assertEquals(nwMax, volume.getCornerTwo());
}
@Test
public void setNorthwest_whenCreating_AndCorner1AlreadySet_ButNewCornerBlockIsSouthOfCorner1_shouldThrowNotNorthwestException() throws TooSmallException, TooBigException{
@Test(expected = NotNorthwestException.class)
public void setNorthwest_whenCreating_AndCorner1AlreadySet_ButNewCornerBlockIsEastOfCorner1_shouldThrowNotNorthwestException()
throws TooSmallException, TooBigException, NotNorthwestException {
// Arrange
World worldMock = mock(World.class);
@ -260,33 +152,17 @@ public class ZoneVolumeSpecTest {
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(64); // further south
when(blockMock.getY()).thenReturn(64); // at sea level
when(blockMock.getZ()).thenReturn(64); // further west
when(blockMock.getTypeId()).thenReturn(10);
when(blockMock.getData()).thenReturn((byte)2);
Location nw = new Location(worldMock, -64, 64, -64);
// Act
BlockInfo existingCorner1 = new BlockInfo(0, 64, 0, 4, (byte)4);
Location existingCorner1 = new Location(worldMock, 0, 64, 0);
volume.setCornerOne(existingCorner1); // corner 1 already set
boolean failed = false;
try {
volume.setNorthwest(blockMock);
}
catch(NotNorthwestException e) {
failed = true;
volume.setNorthwest(nw);
}
// Assert
// first corner shouldn't move
assertTrue(failed);
assertEquals(null, volume.getCornerTwo());
assertEquals(existingCorner1, volume.getCornerOne());
}
@Test
public void setNorthwest_whenChangingVolumeWithCorner1NwCorner2Se_shouldMoveCorner1() throws NotNorthwestException, TooSmallException, TooBigException{
@Test(expected = NotNorthwestException.class)
public void setNorthwest_whenCreating_AndCorner1AlreadySet_ButNewCornerBlockIsSouthOfCorner1_shouldThrowNotNorthwestException()
throws TooSmallException, TooBigException, NotNorthwestException {
// Arrange
World worldMock = mock(World.class);
@ -294,38 +170,45 @@ public class ZoneVolumeSpecTest {
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(-64); // further north
when(blockMock.getY()).thenReturn(64); // at sea level
when(blockMock.getZ()).thenReturn(64); // further west
when(blockMock.getTypeId()).thenReturn(10);
when(blockMock.getData()).thenReturn((byte)2);
Location nw = new Location(worldMock, 64, 64, 64);
// Act
BlockInfo existingCorner1 = new BlockInfo(-32, 32, 32, 2, (byte)2); // corner 1 at minX and maxZ (nw)
Location existingCorner1 = new Location(worldMock, 0, 64, 0);
volume.setCornerOne(existingCorner1); // corner 1 already set
BlockInfo existingCorner2 = new BlockInfo(32, 96, -32, 4, (byte)4); // corner 2 at maxX and minZ (se)
volume.setNorthwest(nw);
}
@Test
public void setNorthwest_whenChangingVolumeWithCorner1NwCorner2Se_shouldMoveCorner1()
throws NotNorthwestException, TooSmallException, TooBigException {
// Arrange
World worldMock = mock(World.class);
Warzone zoneMock = mock(Warzone.class);
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
Location nw = new Location(worldMock, -64, 64, 64);
// Act
Location existingCorner1 = new Location(worldMock, -32, 32, 32); // nw
volume.setCornerOne(existingCorner1); // corner 1 already set
Location existingCorner2 = new Location(worldMock, 32, 96, -32); // se
volume.setCornerTwo(existingCorner2); // corner 2 already set
volume.setNorthwest(blockMock);
volume.setNorthwest(nw);
// Assert
// first corner should move but not along y
assertEquals(-64, volume.getCornerOne().getX());
assertEquals(32, volume.getCornerOne().getY());
assertEquals(64, volume.getCornerOne().getZ());
assertEquals(2, volume.getCornerOne().getTypeId());
assertEquals((byte)2, volume.getCornerOne().getData());
Location movedOne = new Location(worldMock, -64, 32, 64);
assertEquals(movedOne, volume.getCornerOne());
// second corner shouldn't move
assertEquals(32, volume.getCornerTwo().getX());
assertEquals(96, volume.getCornerTwo().getY()); // moving an existing corner shouldn't change its height
assertEquals(-32, volume.getCornerTwo().getZ());
assertEquals(4, volume.getCornerTwo().getTypeId());
assertEquals((byte)4, volume.getCornerTwo().getData());
assertEquals(existingCorner2, volume.getCornerTwo());
}
@Test
public void setNorthwest_whenChangingVolumeWithCorner1SeCorner2Nw_shouldMoveCorner2() throws NotNorthwestException, TooSmallException, TooBigException{
public void setNorthwest_whenChangingVolumeWithCorner1SeCorner2Nw_shouldMoveCorner2()
throws NotNorthwestException, TooSmallException, TooBigException {
// Arrange
World worldMock = mock(World.class);
@ -333,38 +216,27 @@ public class ZoneVolumeSpecTest {
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(-64); // further north
when(blockMock.getY()).thenReturn(64); // at sea level
when(blockMock.getZ()).thenReturn(64); // further west
when(blockMock.getTypeId()).thenReturn(10);
when(blockMock.getData()).thenReturn((byte)2);
Location nw = new Location(worldMock, -64, 64, 64);
// Act
BlockInfo existingCorner1 = new BlockInfo(32, 32, -32, 2, (byte)2); // corner 1 at maxX and minZ (se)
Location existingCorner1 = new Location(worldMock, 32, 32, -32); // nw
volume.setCornerOne(existingCorner1); // corner 1 already set
BlockInfo existingCorner2 = new BlockInfo(-32, 96, 32, 4, (byte)4); // corner 2 at minX and maxZ (nw)
Location existingCorner2 = new Location(worldMock, -32, 96, 32); // se
volume.setCornerTwo(existingCorner2); // corner 2 already set
volume.setNorthwest(blockMock);
volume.setNorthwest(nw);
// Assert
// first corner shouldn't move
assertEquals(32, volume.getCornerOne().getX());
assertEquals(32, volume.getCornerOne().getY());
assertEquals(-32, volume.getCornerOne().getZ());
assertEquals(2, volume.getCornerOne().getTypeId());
assertEquals((byte)2, volume.getCornerOne().getData());
assertEquals(existingCorner1, volume.getCornerOne());
// second corner should move but not along y
assertEquals(-64, volume.getCornerTwo().getX());
assertEquals(96, volume.getCornerTwo().getY()); // moving an existing corner shouldn't change its height
assertEquals(64, volume.getCornerTwo().getZ());
assertEquals(4, volume.getCornerTwo().getTypeId());
assertEquals((byte)4, volume.getCornerTwo().getData());
Location movedTwo = new Location(worldMock, -64, 96, 64);
assertEquals(movedTwo, volume.getCornerTwo());
}
@Test
public void setNorthwest_whenChangingVolumeWithCorner1NeCorner2Sw_shouldMoveCorner1XAndCorner2Z() throws NotNorthwestException, TooSmallException, TooBigException{
public void setNorthwest_whenChangingVolumeWithCorner1NeCorner2Sw_shouldMoveCorner1XAndCorner2Z()
throws NotNorthwestException, TooSmallException, TooBigException {
// Arrange
World worldMock = mock(World.class);
@ -372,38 +244,28 @@ public class ZoneVolumeSpecTest {
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(-64); // further north
when(blockMock.getY()).thenReturn(64); // at sea level
when(blockMock.getZ()).thenReturn(64); // further west
when(blockMock.getTypeId()).thenReturn(10);
when(blockMock.getData()).thenReturn((byte)2);
Location nw = new Location(worldMock, -64, 64, 64);
// Act
BlockInfo existingCorner1 = new BlockInfo(-32, 32, -32, 2, (byte)2); // corner 1 at minX and minZ (ne)
Location existingCorner1 = new Location(worldMock, -32, 32, -32); // ne
volume.setCornerOne(existingCorner1); // corner 1 already set
BlockInfo existingCorner2 = new BlockInfo(32, 96, 32, 4, (byte)4); // corner 2 at maxX and maxZ (sw)
Location existingCorner2 = new Location(worldMock, 32, 96, 32); // sw
volume.setCornerTwo(existingCorner2); // corner 2 already set
volume.setNorthwest(blockMock);
volume.setNorthwest(nw);
// Assert
// first corner should move along x but not along y or z
assertEquals(-64, volume.getCornerOne().getX());
assertEquals(32, volume.getCornerOne().getY());
assertEquals(-32, volume.getCornerOne().getZ());
assertEquals(2, volume.getCornerOne().getTypeId());
assertEquals((byte)2, volume.getCornerOne().getData());
Location movedOne = new Location(worldMock, -64, 32, -32);
assertEquals(movedOne, volume.getCornerOne());
// second corner should move along z but not along x or y
assertEquals(32, volume.getCornerTwo().getX());
assertEquals(96, volume.getCornerTwo().getY());
assertEquals(64, volume.getCornerTwo().getZ());
assertEquals(4, volume.getCornerTwo().getTypeId());
assertEquals((byte)4, volume.getCornerTwo().getData());
Location movedTwo = new Location(worldMock, 32, 96, 64);
assertEquals(movedTwo, volume.getCornerTwo());
}
@Test
public void setNorthwest_whenChangingVolumeWithCorner1SwCorner2Ne_shouldMoveCorner1ZAndCorner2X() throws NotNorthwestException, TooSmallException, TooBigException{
public void setNorthwest_whenChangingVolumeWithCorner1SwCorner2Ne_shouldMoveCorner1ZAndCorner2X()
throws NotNorthwestException, TooSmallException, TooBigException {
// Arrange
World worldMock = mock(World.class);
@ -411,34 +273,23 @@ public class ZoneVolumeSpecTest {
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(-64); // further north
when(blockMock.getY()).thenReturn(64); // at sea level
when(blockMock.getZ()).thenReturn(64); // further west
when(blockMock.getTypeId()).thenReturn(10);
when(blockMock.getData()).thenReturn((byte)2);
Location nw = new Location(worldMock, -64, 64, 64);
// Act
BlockInfo existingCorner1 = new BlockInfo(32, 32, 32, 2, (byte)2); // corner 1 at maxX and maxZ (sw)
Location existingCorner1 = new Location(worldMock, 32, 32, 32); // sw
volume.setCornerOne(existingCorner1); // corner 1 already set
BlockInfo existingCorner2 = new BlockInfo(-32, 96, -32, 4, (byte)4); // corner 2 at minX and minZ (ne)
Location existingCorner2 = new Location(worldMock, -32, 96, -32); // ne
volume.setCornerTwo(existingCorner2); // corner 2 already set
volume.setNorthwest(blockMock);
volume.setNorthwest(nw);
// Assert
// first corner should move along z but not along x or y
assertEquals(32, volume.getCornerOne().getX());
assertEquals(32, volume.getCornerOne().getY());
assertEquals(64, volume.getCornerOne().getZ());
assertEquals(2, volume.getCornerOne().getTypeId());
assertEquals((byte)2, volume.getCornerOne().getData());
Location movedOne = new Location(worldMock, 32, 32, 64);
assertEquals(movedOne, volume.getCornerOne());
// second corner should move along x but not along y or z
assertEquals(-64, volume.getCornerTwo().getX());
assertEquals(96, volume.getCornerTwo().getY());
assertEquals(-32, volume.getCornerTwo().getZ());
assertEquals(4, volume.getCornerTwo().getTypeId());
assertEquals((byte)4, volume.getCornerTwo().getData());
Location movedTwo = new Location(worldMock, -64, 96, -32);
assertEquals(movedTwo, volume.getCornerTwo());
}
// getNorthwestX
@ -448,7 +299,8 @@ public class ZoneVolumeSpecTest {
// setSoutheast
@Test
public void setSoutheast_whenCreatingAndNoCornersAreSet_shouldSetCorner2AtBottom() throws NotSoutheastException, TooSmallException, TooBigException{
public void setSoutheast_whenCreatingAndNoCornersAreSet_shouldSetCorner2AtBottom()
throws NotSoutheastException, TooSmallException, TooBigException {
// Arrange
World worldMock = mock(World.class);
@ -456,27 +308,19 @@ public class ZoneVolumeSpecTest {
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(0);
when(blockMock.getY()).thenReturn(64); // at sea level
when(blockMock.getZ()).thenReturn(0);
when(blockMock.getTypeId()).thenReturn(10);
when(blockMock.getData()).thenReturn((byte)2);
Location se = new Location(worldMock, 0, 64, 0);
// Act
volume.setSoutheast(blockMock);
volume.setSoutheast(se);
// Assert
assertEquals(null, volume.getCornerOne());
assertEquals(0, volume.getCornerTwo().getX());
assertEquals(0, volume.getCornerTwo().getY()); // the corner should shoot down
assertEquals(0, volume.getCornerTwo().getZ());
assertEquals(10, volume.getCornerTwo().getTypeId());
assertEquals((byte)2, volume.getCornerTwo().getData());
Location movedOne = new Location(worldMock, 0, 0, 0);
assertEquals(movedOne, volume.getCornerTwo());
}
@Test
public void setSoutheast_whenCreatingAndNoCorner2IsSet_ButCorner1IsAlreadySet_AndNewCornerBlockIsToWestOfCorner1_shouldThrowNotSoutheastException() throws TooSmallException, TooBigException{
@Test(expected = NotSoutheastException.class)
public void setSoutheast_whenCreatingAndNoCorner2IsSet_ButCorner1IsAlreadySet_AndNewCornerBlockIsToWestOfCorner1_shouldThrowNotSoutheastException()
throws TooSmallException, TooBigException, NotSoutheastException {
// Arrange
World worldMock = mock(World.class);
@ -484,33 +328,17 @@ public class ZoneVolumeSpecTest {
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(64); // further south
when(blockMock.getY()).thenReturn(64); // at sea level
when(blockMock.getZ()).thenReturn(64); // further west
when(blockMock.getTypeId()).thenReturn(10);
when(blockMock.getData()).thenReturn((byte)2);
Location se = new Location(worldMock, 64, 64, 64);
// Act
BlockInfo existingCorner1 = new BlockInfo(0, 64, 0, 4, (byte)4);
Location existingCorner1 = new Location(worldMock, 0, 64, 0);
volume.setCornerOne(existingCorner1); // corner 1 already set
boolean failed = false;
try {
volume.setSoutheast(blockMock);
}
catch(NotSoutheastException e) {
failed = true;
volume.setSoutheast(se);
}
// Assert
// first corner shouldn't move
assertTrue(failed);
assertEquals(null, volume.getCornerTwo());
assertEquals(existingCorner1, volume.getCornerOne());
}
@Test
public void setSoutheast_whenCreatingAndNoCorner2IsSet_ButCorner1IsAlreadySet_AndNewCornerBlockIsToNorthOfCorner1_shouldThrowNotSoutheastException() throws TooSmallException, TooBigException{
@Test(expected = NotSoutheastException.class)
public void setSoutheast_whenCreatingAndNoCorner2IsSet_ButCorner1IsAlreadySet_AndNewCornerBlockIsToNorthOfCorner1_shouldThrowNotSoutheastException()
throws TooSmallException, TooBigException, NotSoutheastException {
// Arrange
World worldMock = mock(World.class);
@ -518,33 +346,17 @@ public class ZoneVolumeSpecTest {
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(-64); // further north
when(blockMock.getY()).thenReturn(64); // at sea level
when(blockMock.getZ()).thenReturn(-64); // further east
when(blockMock.getTypeId()).thenReturn(10);
when(blockMock.getData()).thenReturn((byte)2);
Location se = new Location(worldMock, -64, 64, -64);
// Act
BlockInfo existingCorner1 = new BlockInfo(0, 64, 0, 4, (byte)4);
Location existingCorner1 = new Location(worldMock, 0, 64, 0);
volume.setCornerOne(existingCorner1); // corner 1 already set
boolean failed = false;
try {
volume.setSoutheast(blockMock);
}
catch(NotSoutheastException e) {
failed = true;
}
// Assert
// first corner shouldn't move
assertTrue(failed);
assertEquals(null, volume.getCornerTwo());
assertEquals(existingCorner1, volume.getCornerOne());
volume.setSoutheast(se);
}
@Test
public void setSoutheast_whenCreatingAndCorner2AlreadySet_shouldSetCorner1AtBottom() throws NotSoutheastException, TooSmallException, TooBigException{ // se always goes to bottom
public void setSoutheast_whenCreatingAndCorner2AlreadySet_shouldSetCorner1AtBottom()
throws NotSoutheastException, TooSmallException, TooBigException {
// Arrange
World worldMock = mock(World.class);
@ -552,69 +364,24 @@ public class ZoneVolumeSpecTest {
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(64); // further south
when(blockMock.getY()).thenReturn(64); // at sea level
when(blockMock.getZ()).thenReturn(-64); // further east
when(blockMock.getTypeId()).thenReturn(10);
when(blockMock.getData()).thenReturn((byte)2);
Location se = new Location(worldMock, 64, 64, -64);
// Act
BlockInfo existingCorner2 = new BlockInfo(0, 64, 0, 4, (byte)4);
Location existingCorner2 = new Location(worldMock, 0, 64, 0);
volume.setCornerTwo(existingCorner2); // corner 2 already set
volume.setSoutheast(blockMock);
volume.setSoutheast(se);
// Assert
// first corner shouldn't move
assertEquals(0, volume.getCornerTwo().getX());
assertEquals(64, volume.getCornerTwo().getY());
assertEquals(0, volume.getCornerTwo().getZ());
assertEquals(4, volume.getCornerTwo().getTypeId());
assertEquals((byte)4, volume.getCornerTwo().getData());
assertEquals(64, volume.getCornerOne().getX());
assertEquals(0, volume.getCornerOne().getY()); // the new corner should shoot down
assertEquals(-64, volume.getCornerOne().getZ());
assertEquals(10, volume.getCornerOne().getTypeId());
assertEquals((byte)2, volume.getCornerOne().getData());
}
@Test
public void setSoutheast_whenCreating_AndCorner2AlreadySet_ButNewCornerBlockIsToWestOfCorner2_shouldThrowNotSoutheastException() throws TooSmallException, TooBigException{
// Arrange
World worldMock = mock(World.class);
Warzone zoneMock = mock(Warzone.class);
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(64); // further south
when(blockMock.getY()).thenReturn(64); // at sea level
when(blockMock.getZ()).thenReturn(64); // further west
when(blockMock.getTypeId()).thenReturn(10);
when(blockMock.getData()).thenReturn((byte)2);
// Act
BlockInfo existingCorner2 = new BlockInfo(0, 64, 0, 4, (byte)4);
volume.setCornerTwo(existingCorner2); // corner 2 already set
boolean failed = false;
try {
volume.setSoutheast(blockMock);
}
catch(NotSoutheastException e) {
failed = true;
}
// Assert
// first corner shouldn't move
assertTrue(failed);
assertEquals(null, volume.getCornerOne());
assertEquals(existingCorner2, volume.getCornerTwo());
Location movedSe = new Location(worldMock, 64, 0, -64);
assertEquals(movedSe, volume.getCornerOne());
}
@Test
public void setSoutheast_whenCreating_AndCorner2AlreadySet_ButNewCornerBlockIsToNorthOfCorner2_shouldThrowNotSoutheastException() throws TooSmallException, TooBigException{
@Test(expected = NotSoutheastException.class)
public void setSoutheast_whenCreating_AndCorner2AlreadySet_ButNewCornerBlockIsToWestOfCorner2_shouldThrowNotSoutheastException()
throws TooSmallException, TooBigException, NotSoutheastException {
// Arrange
World worldMock = mock(World.class);
@ -622,33 +389,17 @@ public class ZoneVolumeSpecTest {
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(-64); // further north
when(blockMock.getY()).thenReturn(64); // at sea level
when(blockMock.getZ()).thenReturn(-64); // further east
when(blockMock.getTypeId()).thenReturn(10);
when(blockMock.getData()).thenReturn((byte)2);
Location se = new Location(worldMock, 64, 64, 64);
// Act
BlockInfo existingCorner2 = new BlockInfo(0, 64, 0, 4, (byte)4);
Location existingCorner2 = new Location(worldMock, 0, 64, 0);
volume.setCornerTwo(existingCorner2); // corner 2 already set
boolean failed = false;
try {
volume.setSoutheast(blockMock);
}
catch(NotSoutheastException e) {
failed = true;
volume.setSoutheast(se);
}
// Assert
// first corner shouldn't move
assertTrue(failed);
assertEquals(null, volume.getCornerOne());
assertEquals(existingCorner2, volume.getCornerTwo());
}
@Test
public void setSoutheast_whenChangingVolumeWithCorner1NwCorner2Se_shouldMoveCorner2() throws NotSoutheastException, TooSmallException, TooBigException{
@Test(expected = NotSoutheastException.class)
public void setSoutheast_whenCreating_AndCorner2AlreadySet_ButNewCornerBlockIsToNorthOfCorner2_shouldThrowNotSoutheastException()
throws TooSmallException, TooBigException, NotSoutheastException {
// Arrange
World worldMock = mock(World.class);
@ -656,38 +407,45 @@ public class ZoneVolumeSpecTest {
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(64); // further south
when(blockMock.getY()).thenReturn(64); // at sea level
when(blockMock.getZ()).thenReturn(-64); // further east
when(blockMock.getTypeId()).thenReturn(10);
when(blockMock.getData()).thenReturn((byte)2);
Location se = new Location(worldMock, -64, 64, -64);
// Act
BlockInfo existingCorner1 = new BlockInfo(-32, 32, 32, 2, (byte)2); // corner 1 at minX and maxZ (nw)
Location existingCorner2 = new Location(worldMock, 0, 64, 0);
volume.setCornerTwo(existingCorner2); // corner 2 already set
volume.setSoutheast(se);
}
@Test
public void setSoutheast_whenChangingVolumeWithCorner1NwCorner2Se_shouldMoveCorner2()
throws NotSoutheastException, TooSmallException, TooBigException {
// Arrange
World worldMock = mock(World.class);
Warzone zoneMock = mock(Warzone.class);
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
Location se = new Location(worldMock, 64, 64, -64);
// Act
Location existingCorner1 = new Location(worldMock, -32, 32, 32); // nw
volume.setCornerOne(existingCorner1); // corner 1 already set
BlockInfo existingCorner2 = new BlockInfo(32, 96, -32, 4, (byte)4); // corner 2 at maxX and minZ (se)
Location existingCorner2 = new Location(worldMock, 32, 96, -32); // se
volume.setCornerTwo(existingCorner2); // corner 2 already set
volume.setSoutheast(blockMock);
volume.setSoutheast(se);
// Assert
// first corner shouldn't move
assertEquals(-32, volume.getCornerOne().getX());
assertEquals(32, volume.getCornerOne().getY());
assertEquals(32, volume.getCornerOne().getZ());
assertEquals(2, volume.getCornerOne().getTypeId());
assertEquals((byte)2, volume.getCornerOne().getData());
assertEquals(existingCorner1, volume.getCornerOne());
// second corner should move but not along y
assertEquals(64, volume.getCornerTwo().getX());
assertEquals(96, volume.getCornerTwo().getY());
assertEquals(-64, volume.getCornerTwo().getZ());
assertEquals(4, volume.getCornerTwo().getTypeId());
assertEquals((byte)4, volume.getCornerTwo().getData());
Location movedTwo = new Location(worldMock, 64, 96, -64);
assertEquals(movedTwo, volume.getCornerTwo());
}
@Test
public void setSoutheast_whenChangingVolumeWithCorner1SeCorner2Nw_shouldMoveCorner1() throws NotSoutheastException, TooSmallException, TooBigException{
public void setSoutheast_whenChangingVolumeWithCorner1SeCorner2Nw_shouldMoveCorner1()
throws NotSoutheastException, TooSmallException, TooBigException {
// Arrange
World worldMock = mock(World.class);
@ -695,38 +453,27 @@ public class ZoneVolumeSpecTest {
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(64); // further south
when(blockMock.getY()).thenReturn(64); // at sea level
when(blockMock.getZ()).thenReturn(-64); // further east
when(blockMock.getTypeId()).thenReturn(10);
when(blockMock.getData()).thenReturn((byte)2);
Location se = new Location(worldMock, 64, 64, -64);
// Act
BlockInfo existingCorner1 = new BlockInfo(32, 32, -32, 2, (byte)2); // corner 1 at maxX and minZ (se)
Location existingCorner1 = new Location(worldMock, 32, 32, -32); // se
volume.setCornerOne(existingCorner1); // corner 1 already set
BlockInfo existingCorner2 = new BlockInfo(-32, 96, 32, 4, (byte)4); // corner 2 at minX and maxZ (nw)
Location existingCorner2 = new Location(worldMock, -32, 96, 32); // nw
volume.setCornerTwo(existingCorner2); // corner 2 already set
volume.setSoutheast(blockMock);
volume.setSoutheast(se);
// Assert
// first corner should move but not along y
assertEquals(64, volume.getCornerOne().getX());
assertEquals(32, volume.getCornerOne().getY());
assertEquals(-64, volume.getCornerOne().getZ());
assertEquals(2, volume.getCornerOne().getTypeId());
assertEquals((byte)2, volume.getCornerOne().getData());
Location movedOne = new Location(worldMock, 64, 32, -64);
assertEquals(movedOne, volume.getCornerOne());
// second corner shouldn't move
assertEquals(-32, volume.getCornerTwo().getX());
assertEquals(96, volume.getCornerTwo().getY());
assertEquals(32, volume.getCornerTwo().getZ());
assertEquals(4, volume.getCornerTwo().getTypeId());
assertEquals((byte)4, volume.getCornerTwo().getData());
assertEquals(existingCorner2, volume.getCornerTwo());
}
@Test
public void setSoutheast_whenChangingVolumeWithCorner1NeCorner2Sw_shouldMoveCorner1ZAndCorner2X() throws NotSoutheastException, TooSmallException, TooBigException{
public void setSoutheast_whenChangingVolumeWithCorner1NeCorner2Sw_shouldMoveCorner1ZAndCorner2X()
throws NotSoutheastException, TooSmallException, TooBigException {
// Arrange
World worldMock = mock(World.class);
@ -734,38 +481,28 @@ public class ZoneVolumeSpecTest {
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(64); // further south
when(blockMock.getY()).thenReturn(64); // at sea level
when(blockMock.getZ()).thenReturn(-64); // further east
when(blockMock.getTypeId()).thenReturn(10);
when(blockMock.getData()).thenReturn((byte)2);
Location se = new Location(worldMock, 64, 64, -64);
// Act
BlockInfo existingCorner1 = new BlockInfo(-32, 32, -32, 2, (byte)2); // corner 1 at minX and minZ (ne)
Location existingCorner1 = new Location(worldMock, -32, 32, -32); // ne
volume.setCornerOne(existingCorner1); // corner 1 already set
BlockInfo existingCorner2 = new BlockInfo(32, 96, 32, 4, (byte)4); // corner 2 at maxX and maxZ (sw)
Location existingCorner2 = new Location(worldMock, 32, 96, 32); // sw
volume.setCornerTwo(existingCorner2); // corner 2 already set
volume.setSoutheast(blockMock);
volume.setSoutheast(se);
// Assert
// first corner should move along z but not along x or y
assertEquals(-32, volume.getCornerOne().getX());
assertEquals(32, volume.getCornerOne().getY());
assertEquals(-64, volume.getCornerOne().getZ());
assertEquals(2, volume.getCornerOne().getTypeId());
assertEquals((byte)2, volume.getCornerOne().getData());
Location movedOne = new Location(worldMock, -32, 32, -64);
assertEquals(movedOne, volume.getCornerOne());
// second corner should move along x but not along y or z
assertEquals(64, volume.getCornerTwo().getX());
assertEquals(96, volume.getCornerTwo().getY());
assertEquals(32, volume.getCornerTwo().getZ());
assertEquals(4, volume.getCornerTwo().getTypeId());
assertEquals((byte)4, volume.getCornerTwo().getData());
Location movedTwo = new Location(worldMock, 64, 96, 32);
assertEquals(movedTwo, volume.getCornerTwo());
}
@Test
public void setSoutheast_whenChangingVolumeWithCorner1SwCorner2Ne_shouldMoveCorner1XAndCorner2Z() throws NotSoutheastException, TooSmallException, TooBigException{
public void setSoutheast_whenChangingVolumeWithCorner1SwCorner2Ne_shouldMoveCorner1XAndCorner2Z()
throws NotSoutheastException, TooSmallException, TooBigException {
// Arrange
World worldMock = mock(World.class);
@ -773,34 +510,23 @@ public class ZoneVolumeSpecTest {
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(64); // further south
when(blockMock.getY()).thenReturn(64); // at sea level
when(blockMock.getZ()).thenReturn(-64); // further east
when(blockMock.getTypeId()).thenReturn(10);
when(blockMock.getData()).thenReturn((byte)2);
Location se = new Location(worldMock, 64, 64, -64);
// Act
BlockInfo existingCorner1 = new BlockInfo(32, 32, 32, 2, (byte)2); // corner 1 at maxX and maxZ (sw)
Location existingCorner1 = new Location(worldMock, 32, 32, 32); // sw
volume.setCornerOne(existingCorner1); // corner 1 already set
BlockInfo existingCorner2 = new BlockInfo(-32, 96, -32, 4, (byte)4); // corner 2 at minX and minZ (ne)
Location existingCorner2 = new Location(worldMock, -32, 96, -32); // ne
volume.setCornerTwo(existingCorner2); // corner 2 already set
volume.setSoutheast(blockMock);
volume.setSoutheast(se);
// Assert
// first corner should move along x but not along y or z
assertEquals(64, volume.getCornerOne().getX());
assertEquals(32, volume.getCornerOne().getY());
assertEquals(32, volume.getCornerOne().getZ());
assertEquals(2, volume.getCornerOne().getTypeId());
assertEquals((byte)2, volume.getCornerOne().getData());
Location movedOne = new Location(worldMock, 64, 32, 32);
assertEquals(movedOne, volume.getCornerOne());
// second corner should move along z but not along x or y
assertEquals(-32, volume.getCornerTwo().getX());
assertEquals(96, volume.getCornerTwo().getY());
assertEquals(-64, volume.getCornerTwo().getZ());
assertEquals(4, volume.getCornerTwo().getTypeId());
assertEquals((byte)4, volume.getCornerTwo().getData());
Location movedTwo = new Location(worldMock, -32, 96, -64);
assertEquals(movedTwo, volume.getCornerTwo());
}
// getSoutheastX