Fixed team spawns

This commit is contained in:
taoneill 2011-01-09 20:39:59 -05:00
parent 07b3b21077
commit 84f6abb0d5
6 changed files with 49 additions and 36 deletions

View File

@ -137,7 +137,7 @@ public class Monument {
int y = location.getBlockY(); int y = location.getBlockY();
int z = location.getBlockZ(); int z = location.getBlockZ();
((CenteredVolume)volume).setCenter(warzone.getWorld().getBlockAt(x, y, z)); // resets the volume blocks volume.changeCenter(location);
this.addMonumentBlocks(); this.addMonumentBlocks();
} }

View File

@ -35,8 +35,7 @@ public class Team {
this.teamSpawn = teamSpawn; this.teamSpawn = teamSpawn;
// this resets the block to old state // this resets the block to old state
volume.setCenter(warzone.getWorld().getBlockAt(teamSpawn.getBlockX(), teamSpawn.getBlockY(), teamSpawn.getBlockZ())); volume.changeCenter(teamSpawn);
volume.setSideSize(5);
volume.saveBlocks(); volume.saveBlocks();
// Set the spawn // Set the spawn

View File

@ -9,7 +9,7 @@ import com.tommytony.war.Warzone;
public class WarMapper { public class WarMapper {
public static void load(War war) { public static void load(War war) {
war.getLogger().info("Loading war config..."); //war.getLogger().info("Loading war config...");
(new File(war.getName())).mkdir(); (new File(war.getName())).mkdir();
PropertiesFile warConfig = new PropertiesFile(war.getName() + "/war.txt"); PropertiesFile warConfig = new PropertiesFile(war.getName() + "/war.txt");
try { try {
@ -69,7 +69,7 @@ public class WarMapper {
} }
public static void save(War war) { public static void save(War war) {
war.getLogger().info("Saving war config..."); //war.getLogger().info("Saving war config...");
PropertiesFile warConfig = new PropertiesFile(war.getName() + "/war.txt"); PropertiesFile warConfig = new PropertiesFile(war.getName() + "/war.txt");
String warzonesStr = ""; String warzonesStr = "";
@ -95,6 +95,6 @@ public class WarMapper {
warConfig.save(); warConfig.save();
warConfig.close(); warConfig.close();
war.getLogger().info("Saved war config."); //war.getLogger().info("Saved war config.");
} }
} }

View File

@ -18,7 +18,7 @@ import java.util.List;
public class WarzoneMapper { public class WarzoneMapper {
public static Warzone load(War war, String name, boolean loadBlocks) { public static Warzone load(War war, String name, boolean loadBlocks) {
war.getLogger().info("Loading warzone " + name + " config and blocks..."); //war.getLogger().info("Loading warzone " + name + " config and blocks...");
PropertiesFile warzoneConfig = new PropertiesFile(war.getName() + "/warzone-" + name + ".txt"); PropertiesFile warzoneConfig = new PropertiesFile(war.getName() + "/warzone-" + name + ".txt");
try { try {
warzoneConfig.load(); warzoneConfig.load();
@ -38,7 +38,7 @@ public class WarzoneMapper {
try { try {
warzoneConfig.load(); warzoneConfig.load();
} catch (IOException e) { } catch (IOException e) {
war.getLogger().info("Failed to reload warzone-" + name + ".txt file after creating it."); //war.getLogger().info("Failed to reload warzone-" + name + ".txt file after creating it.");
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -154,9 +154,9 @@ public class WarzoneMapper {
} }
warzoneBlocksFile.close(); warzoneBlocksFile.close();
war.getLogger().info("Loaded warzone " + name + " config and blocks."); //war.getLogger().info("Loaded warzone " + name + " config and blocks.");
} else { } else {
war.getLogger().info("Loaded warzone " + name + " config."); //war.getLogger().info("Loaded warzone " + name + " config.");
} }
return warzone; return warzone;
@ -165,7 +165,7 @@ public class WarzoneMapper {
public static void save(War war, Warzone warzone, boolean saveBlocks) { public static void save(War war, Warzone warzone, boolean saveBlocks) {
PropertiesFile warzoneConfig = new PropertiesFile(war.getName() + "/warzone-" + warzone.getName() + ".txt"); PropertiesFile warzoneConfig = new PropertiesFile(war.getName() + "/warzone-" + warzone.getName() + ".txt");
war.getLogger().info("Saving warzone " + warzone.getName() + "..."); //war.getLogger().info("Saving warzone " + warzone.getName() + "...");
// name // name
warzoneConfig.setString("name", warzone.getName()); warzoneConfig.setString("name", warzone.getName());
@ -253,11 +253,11 @@ public class WarzoneMapper {
warzoneBlocksFile.close(); warzoneBlocksFile.close();
} }
if(saveBlocks) { // if(saveBlocks) {
war.getLogger().info("Saved warzone " + warzone.getName() + " config and blocks."); // war.getLogger().info("Saved warzone " + warzone.getName() + " config and blocks.");
} else { // } else {
war.getLogger().info("Saved warzone " + warzone.getName() + " config."); // war.getLogger().info("Saved warzone " + warzone.getName() + " config.");
} // }
} }
public static void delete(War war, String name) { public static void delete(War war, String name) {

View File

@ -17,12 +17,22 @@ public class CenteredVolume extends Volume {
setSideSize(sideSize); setSideSize(sideSize);
} }
public void setCenter(Block block) { public void changeCenter(Location newCenter) {
this.resetBlocks(); changeCenter(getWarzone().getWorld().getBlockAt(newCenter.getBlockX(),
this.center = block; newCenter.getBlockY(),
if(sideSize != -1) { newCenter.getBlockZ()),
calculateCorners(); this.sideSize);
} }
public void changeCenter(Block newCenter, int sideSize) {
this.resetBlocks();
this.center = newCenter;
this.sideSize = sideSize;
this.calculateCorners();
}
private void setCenter(Block block) {
this.center = block;
} }
private void calculateCorners() { private void calculateCorners() {
@ -34,20 +44,24 @@ public class CenteredVolume extends Volume {
Block cornerOne = getWarzone().getWorld().getBlockAt(x, y, z); Block cornerOne = getWarzone().getWorld().getBlockAt(x, y, z);
setCornerOne(cornerOne); setCornerOne(cornerOne);
if(sideSize % 2 == 0) { // not a real center, bottom half is larger by 1
int bottomHalfOfSide = sideSize - topHalfOfSide; int bottomHalfOfSide = sideSize - topHalfOfSide;
x = center.getX() - bottomHalfOfSide; x = center.getX() - bottomHalfOfSide;
y = center.getY() - bottomHalfOfSide; y = center.getY() - bottomHalfOfSide;
z = center.getZ() - bottomHalfOfSide; z = center.getZ() - bottomHalfOfSide;
Block cornerTwo = getWarzone().getWorld().getBlockAt(x, y, z); Block cornerTwo = getWarzone().getWorld().getBlockAt(x, y, z);
setCornerTwo(cornerTwo); setCornerTwo(cornerTwo);
} else {
x = center.getX() - topHalfOfSide;
y = center.getY() - topHalfOfSide;
z = center.getZ() - topHalfOfSide;
Block cornerTwo = getWarzone().getWorld().getBlockAt(x, y, z);
setCornerTwo(cornerTwo);
}
} }
public void setSideSize(int sideSize) { private void setSideSize(int sideSize) {
this.resetBlocks();
this.sideSize = sideSize; this.sideSize = sideSize;
if(center != null) {
calculateCorners();
}
} }
} }

View File

@ -169,15 +169,15 @@ public class Volume {
} }
public int getSizeX() { public int getSizeX() {
return getMaxX() - getMinX(); return getMaxX() - getMinX() + 1;
} }
public int getSizeY() { public int getSizeY() {
return getMaxY() - getMinY(); return getMaxY() - getMinY() + 1;
} }
public int getSizeZ() { public int getSizeZ() {
return getMaxZ() - getMinZ(); return getMaxZ() - getMinZ() + 1;
} }
public boolean isSaved() { public boolean isSaved() {