Now saving zone blocks as soon as second corner is set. Also now saving blocks when changing corners. Now saving team lobby and monument blocks at all times.

This commit is contained in:
taoneill 2011-01-14 14:14:21 -05:00
parent 0753f76350
commit 0abd111f72
3 changed files with 75 additions and 67 deletions

View File

@ -256,6 +256,7 @@ public class WarPlayerListener extends PlayerListener {
"or /resetwarzone before changing the boundary). ")); "or /resetwarzone before changing the boundary). "));
} else { } else {
Warzone warzone = war.findWarzone(arguments[0]); Warzone warzone = war.findWarzone(arguments[0]);
String message = "";
if(warzone == null) { if(warzone == null) {
// create the warzone // create the warzone
warzone = new Warzone(war, player.getLocation().getWorld(), arguments[0]); warzone = new Warzone(war, player.getLocation().getWorld(), arguments[0]);
@ -270,8 +271,9 @@ public class WarPlayerListener extends PlayerListener {
player.sendMessage(war.str("Warzone " + warzone.getName() + " added. Southeasternmost point set at x=" player.sendMessage(war.str("Warzone " + warzone.getName() + " added. Southeasternmost point set at x="
+ (int)warzone.getSoutheast().getBlockX() + " z=" + (int)warzone.getSoutheast().getBlockZ() + ".")); + (int)warzone.getSoutheast().getBlockX() + " z=" + (int)warzone.getSoutheast().getBlockZ() + "."));
} }
WarzoneMapper.save(war, warzone, false);
} else { } else {
String message = ""; // change existing warzone
if(arguments[1].equals("northwest") || arguments[1].equals("nw")) { if(arguments[1].equals("northwest") || arguments[1].equals("nw")) {
int reset = warzone.getVolume().resetBlocks(); int reset = warzone.getVolume().resetBlocks();
warzone.setNorthwest(player.getLocation()); warzone.setNorthwest(player.getLocation());
@ -279,37 +281,36 @@ public class WarPlayerListener extends PlayerListener {
warzone.initializeZone(); warzone.initializeZone();
message += "Northwesternmost point set at x=" + (int)warzone.getNorthwest().getBlockX() message += "Northwesternmost point set at x=" + (int)warzone.getNorthwest().getBlockX()
+ " z=" + (int)warzone.getNorthwest().getBlockZ() + " on warzone " + warzone.getName() + ". " + + " z=" + (int)warzone.getNorthwest().getBlockZ() + " on warzone " + warzone.getName() + ". " +
reset + " blocks reset. New zone saved."; reset + " blocks reset. Zone saved.";
} else { } else {
int reset = warzone.getVolume().resetBlocks(); int reset = warzone.getVolume().resetBlocks();
warzone.setSoutheast(player.getLocation()); warzone.setSoutheast(player.getLocation());
warzone.saveState(); warzone.saveState();
warzone.initializeZone(); warzone.initializeZone();
message += "Southeasternmost point set at x=" + (int)warzone.getSoutheast().getBlockX() message += "Southeasternmost point set at x=" + (int)warzone.getSoutheast().getBlockX()
+ " z=" + (int)warzone.getSoutheast().getBlockZ() + " on warzone " + warzone.getName() + ". " + + " z=" + (int)warzone.getSoutheast().getBlockZ() + " on warzone " + warzone.getName() + ". " +
reset + " blocks reset. New zone saved."; reset + " blocks reset. Zone saved.";
} }
WarzoneMapper.save(war, warzone, true);
if(warzone.getNorthwest() == null) {
message += " Still missing northwesternmost point.";
}
if(warzone.getSoutheast() == null) {
message += " Still missing southeasternmost point.";
}
if(warzone.getNorthwest() != null && warzone.getSoutheast() != null) {
if(warzone.ready()) {
message += " Warzone " + warzone.getName() + " almost ready. Use /setteam while inside the warzone to create new teams. Make sure to use /savezone to " +
"set the warzone teleport point and initial state.";
} else if (warzone.tooSmall()) {
message += " Warzone " + warzone.getName() + " is too small. Min north-south size: 20. Min east-west size: 20.";
} else if (warzone.tooBig()) {
message += " Warzone " + warzone.getName() + " is too Big. Max north-south size: 1000. Max east-west size: 1000.";
}
}
player.sendMessage(war.str(message));
} }
WarzoneMapper.save(war, warzone, false); if(warzone.getNorthwest() == null) {
message += " Still missing northwesternmost point.";
}
if(warzone.getSoutheast() == null) {
message += " Still missing southeasternmost point.";
}
if(warzone.getNorthwest() != null && warzone.getSoutheast() != null) {
if(warzone.ready()) {
message += " Warzone " + warzone.getName() + " outline done. Use /setteam, /setmonument and /savezone to complete the zone.";
} else if (warzone.tooSmall()) {
message += " Warzone " + warzone.getName() + " is too small. Min north-south size: 20. Min east-west size: 20.";
} else if (warzone.tooBig()) {
message += " Warzone " + warzone.getName() + " is too Big. Max north-south size: 1000. Max east-west size: 1000.";
}
}
player.sendMessage(war.str(message));
} }
event.setCancelled(true); event.setCancelled(true);
} }

View File

@ -122,22 +122,22 @@ public class VolumeMapper {
else out = new BufferedWriter(new FileWriter(new File("War/warzone-" + zoneName + "/volume-" + volume.getName() + ".dat"))); else out = new BufferedWriter(new FileWriter(new File("War/warzone-" + zoneName + "/volume-" + volume.getName() + ".dat")));
if(volume instanceof CenteredVolume) { if(volume instanceof CenteredVolume) {
out.write("center"); out.newLine(); out.write("center"); out.newLine();
out.write(volume.getCornerOne().getX()); out.newLine(); out.write(Integer.toString(volume.getCornerOne().getX())); out.newLine();
out.write(volume.getCornerOne().getY()); out.newLine(); out.write(Integer.toString(volume.getCornerOne().getY())); out.newLine();
out.write(volume.getCornerOne().getZ()); out.newLine(); out.write(Integer.toString(volume.getCornerOne().getZ())); out.newLine();
out.write("nothing"); out.newLine(); out.write("nothing"); out.newLine();
out.write(0); out.newLine(); out.write(Integer.toString(0)); out.newLine();
out.write(0); out.newLine(); out.write(Integer.toString(0)); out.newLine();
out.write(0); out.newLine(); out.write(Integer.toString(0)); out.newLine();
} else { } else {
out.write("corner1"); out.newLine(); out.write("corner1"); out.newLine();
out.write(volume.getCornerOne().getX()); out.newLine(); out.write(Integer.toString(volume.getCornerOne().getX())); out.newLine();
out.write(volume.getCornerOne().getY()); out.newLine(); out.write(Integer.toString(volume.getCornerOne().getY())); out.newLine();
out.write(volume.getCornerOne().getZ()); out.newLine(); out.write(Integer.toString(volume.getCornerOne().getZ())); out.newLine();
out.write("corner2"); out.newLine(); out.write("corner2"); out.newLine();
out.write(volume.getCornerTwo().getX()); out.newLine(); out.write(Integer.toString(volume.getCornerTwo().getX())); out.newLine();
out.write(volume.getCornerTwo().getY()); out.newLine(); out.write(Integer.toString(volume.getCornerTwo().getY())); out.newLine();
out.write(volume.getCornerTwo().getZ()); out.newLine(); out.write(Integer.toString(volume.getCornerTwo().getZ())); out.newLine();
} }
for(int i = 0; i < volume.getSizeX(); i++){ for(int i = 0; i < volume.getSizeX(); i++){
@ -145,7 +145,7 @@ public class VolumeMapper {
for(int k = 0; k < volume.getSizeZ(); k++) { for(int k = 0; k < volume.getSizeZ(); k++) {
BlockInfo info = volume.getBlockInfos()[i][j][k]; BlockInfo info = volume.getBlockInfos()[i][j][k];
if(info == null) { if(info == null) {
out.write("0,0,"); out.newLine(); out.write("0,0,");
} else { } else {
if(info.getType() == Material.SIGN || info.getType() == Material.SIGN_POST) { if(info.getType() == Material.SIGN || info.getType() == Material.SIGN_POST) {
String[] lines = info.getSignLines(); String[] lines = info.getSignLines();
@ -156,6 +156,7 @@ public class VolumeMapper {
out.write(info.getTypeID() + "," + info.getData() + ","); out.write(info.getTypeID() + "," + info.getData() + ",");
} }
} }
out.newLine();
} }
} }
} }

View File

@ -153,16 +153,18 @@ public class WarzoneMapper {
// lobby // lobby
String lobbyStr = warzoneConfig.getString("lobby"); String lobbyStr = warzoneConfig.getString("lobby");
BlockFace lobbyFace = null; BlockFace lobbyFace = null;
if(lobbyStr.equals("south")) { if(lobbyStr != null && !lobbyStr.equals("")){
lobbyFace = BlockFace.South; if(lobbyStr.equals("south")) {
} else if(lobbyStr.equals("east")) { lobbyFace = BlockFace.South;
lobbyFace = BlockFace.East; } else if(lobbyStr.equals("east")) {
} else if(lobbyStr.equals("north")) { lobbyFace = BlockFace.East;
lobbyFace = BlockFace.North; } else if(lobbyStr.equals("north")) {
} else if(lobbyStr.equals("west")) { lobbyFace = BlockFace.North;
lobbyFace = BlockFace.West; } else if(lobbyStr.equals("west")) {
lobbyFace = BlockFace.West;
}
warzone.setLobby(new ZoneLobby(war, warzone, lobbyFace));
} }
warzone.setLobby(new ZoneLobby(war, warzone, lobbyFace));
warzoneConfig.close(); warzoneConfig.close();
@ -195,7 +197,7 @@ public class WarzoneMapper {
} }
public static void save(War war, Warzone warzone, boolean saveBlocks) { public static void save(War war, Warzone warzone, boolean saveAllBlocks) {
(new File(war.getName()+"/warzone-"+warzone.getName())).mkdir(); (new File(war.getName()+"/warzone-"+warzone.getName())).mkdir();
PropertiesFile warzoneConfig = new PropertiesFile(war.getName() + "/warzone-" + warzone.getName() + "/warzone-" + warzone.getName() + ".txt"); PropertiesFile warzoneConfig = new PropertiesFile(war.getName() + "/warzone-" + warzone.getName() + "/warzone-" + warzone.getName() + ".txt");
//war.getLogger().info("Saving warzone " + warzone.getName() + "..."); //war.getLogger().info("Saving warzone " + warzone.getName() + "...");
@ -265,34 +267,38 @@ public class WarzoneMapper {
// lobby // lobby
String lobbyStr = ""; String lobbyStr = "";
if(BlockFace.South == warzone.getLobby().getWall()) { if(warzone.getLobby() != null) {
lobbyStr = "south"; if(BlockFace.South == warzone.getLobby().getWall()) {
} else if(BlockFace.East == warzone.getLobby().getWall()) { lobbyStr = "south";
lobbyStr = "east"; } else if(BlockFace.East == warzone.getLobby().getWall()) {
} else if(BlockFace.North == warzone.getLobby().getWall()) { lobbyStr = "east";
lobbyStr = "north"; } else if(BlockFace.North == warzone.getLobby().getWall()) {
} else if(BlockFace.West == warzone.getLobby().getWall()) { lobbyStr = "north";
lobbyStr = "west"; } else if(BlockFace.West == warzone.getLobby().getWall()) {
lobbyStr = "west";
}
} }
warzoneConfig.setString("lobby", lobbyStr); warzoneConfig.setString("lobby", lobbyStr);
warzoneConfig.save(); warzoneConfig.save();
warzoneConfig.close(); warzoneConfig.close();
if(saveBlocks) { if(saveAllBlocks) {
// zone blocks // zone blocks
VolumeMapper.save(warzone.getVolume(), warzone.getName(), war); VolumeMapper.save(warzone.getVolume(), warzone.getName(), war);
}
// monument blocks // monument blocks
for(Monument monument: monuments) { for(Monument monument: monuments) {
VolumeMapper.save(monument.getVolume(), warzone.getName(), war); VolumeMapper.save(monument.getVolume(), warzone.getName(), war);
} }
// team spawn blocks // team spawn blocks
for(Team team : teams) { for(Team team : teams) {
VolumeMapper.save(team.getVolume(), warzone.getName(), war); VolumeMapper.save(team.getVolume(), warzone.getName(), war);
} }
if(warzone.getLobby() != null) {
VolumeMapper.save(warzone.getLobby().getVolume(), warzone.getName(), war); VolumeMapper.save(warzone.getLobby().getVolume(), warzone.getName(), war);
} }