Totally broken. Factoring out the volume mapping and adding warhubs

This commit is contained in:
unknown 2011-01-13 17:19:27 -05:00
parent f2be251106
commit e33a19cc4f
11 changed files with 457 additions and 404 deletions

View File

@ -1,8 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java"/> <classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/> <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry kind="src" path="src/main/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/> <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry combineaccessrules="false" kind="src" path="/bukkit"/> <classpathentry combineaccessrules="false" kind="src" path="/bukkit"/>

View File

@ -187,6 +187,13 @@ public class War extends JavaPlugin {
return zoneMakerNames; return zoneMakerNames;
} }
public boolean isZoneMaker(String playerName) {
for(String zoneMaker : zoneMakerNames) {
if(zoneMaker.equals(playerName)) return true;
}
return false;
}
public boolean getDefaultDrawZoneOutline() { public boolean getDefaultDrawZoneOutline() {
return defaultDrawZoneOutline ; return defaultDrawZoneOutline ;
} }

View File

@ -201,10 +201,11 @@ public class WarPlayerListener extends PlayerListener {
event.setCancelled(true); event.setCancelled(true);
} }
if(war.isZoneMaker(player.getName())) {
// Mod commands : /nextbattle // Mod commands : /nextbattle
// /restartbattle // /restartbattle
else if(command.equals("nextbattle") || command.equals("restartbattle")) { if(command.equals("nextbattle") || command.equals("restartbattle")) {
if(!war.inAnyWarzone(player.getLocation())) { if(!war.inAnyWarzone(player.getLocation())) {
player.sendMessage(war.str("Usage: /nextbattle. Resets the zone blocks and all teams' life pools. Must be in warzone.")); player.sendMessage(war.str("Usage: /nextbattle. Resets the zone blocks and all teams' life pools. Must be in warzone."));
} else { } else {
@ -220,7 +221,6 @@ public class WarPlayerListener extends PlayerListener {
event.setCancelled(true); event.setCancelled(true);
} }
// Warzone maker commands: /setzone, /savezone, /setteam, /setmonument, /resetzone // Warzone maker commands: /setzone, /savezone, /setteam, /setmonument, /resetzone
// /setzone // /setzone
@ -474,6 +474,7 @@ public class WarPlayerListener extends PlayerListener {
} }
} }
} }
}
public void onPlayerMove(PlayerMoveEvent event) { public void onPlayerMove(PlayerMoveEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();

View File

@ -15,7 +15,7 @@ import com.tommytony.war.volumes.Volume;
*/ */
public class Monument { public class Monument {
private Location location; private Location location;
private CenteredVolume volume; private Volume volume;
private Team ownerTeam = null; private Team ownerTeam = null;
private final String name; private final String name;
@ -29,7 +29,7 @@ public class Monument {
warzone.getWorld().getBlockAt(location.getBlockX(), warzone.getWorld().getBlockAt(location.getBlockX(),
location.getBlockY() + 2, location.getBlockY() + 2,
location.getBlockZ()), location.getBlockZ()),
7, war, warzone); 7, war, warzone.getWorld());
volume.saveBlocks(); volume.saveBlocks();
this.addMonumentBlocks(); this.addMonumentBlocks();
} }
@ -155,5 +155,8 @@ public class Monument {
return volume; return volume;
} }
public void setVolume(Volume newVolume) {
this.volume = newVolume;
}
} }

View File

@ -0,0 +1,23 @@
package com.tommytony.war;
import org.bukkit.Location;
import org.bukkit.World;
import com.tommytony.war.volumes.Volume;
import bukkit.tommytony.war.War;
public class WarHub {
private final War war;
private final World world;
private final Location location;
private Volume volume;
public WarHub(War war, World world, Location location) {
this.war = war;
this.world = world;
this.location = location;
this.volume = new Volume("warHub", war, warzone);
}
}

View File

@ -4,15 +4,17 @@ import java.util.List;
import org.bukkit.Block; import org.bukkit.Block;
import org.bukkit.BlockFace; import org.bukkit.BlockFace;
import org.bukkit.HumanEntity;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Player; import org.bukkit.Player;
import bukkit.tommytony.war.War; import bukkit.tommytony.war.War;
import com.tommytony.war.volumes.CenteredVolume; /**
*
* @author tommytony
*
*/
public class ZoneWallGuard { public class ZoneWallGuard {
private Player player; private Player player;
private Warzone warzone; private Warzone warzone;

View File

@ -0,0 +1,135 @@
package com.tommytony.war.mappers;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import org.bukkit.Material;
import org.bukkit.World;
import bukkit.tommytony.war.War;
import com.tommytony.war.volumes.BlockInfo;
import com.tommytony.war.volumes.Volume;
public class VolumeMapper {
public static Volume load(String zoneName, String volumeName, War war, World world) {
BufferedReader in = null;
Volume volume = null;
try {
in = new BufferedReader(new FileReader(new File("War/warzone-" + zoneName + "/volume-" + volumeName)));
String firstLine = in.readLine();
if(firstLine != null && !firstLine.equals("")) {
int x1 = Integer.parseInt(in.readLine());
int y1 = Integer.parseInt(in.readLine());
int z1 = Integer.parseInt(in.readLine());
int x2 = Integer.parseInt(in.readLine());
int y2 = Integer.parseInt(in.readLine());
int z2 = Integer.parseInt(in.readLine());
volume = new Volume(volumeName, war, world);
volume.setCornerOne(world.getBlockAt(x1, y1, z1));
volume.setCornerTwo(world.getBlockAt(x2, y2, z2));
volume.setBlockInfos(new BlockInfo[volume.getSizeX()][volume.getSizeY()][volume.getSizeZ()]);
for(int i = 0; i < volume.getSizeX(); i++){
for(int j = 0; j < volume.getSizeY(); j++) {
for(int k = 0; k < volume.getSizeZ(); k++) {
String blockLine = in.readLine();
String[] blockSplit = blockLine.split(",");
int typeID = Integer.parseInt(blockSplit[0]);
byte data = Byte.parseByte(blockSplit[1]);
String[] lines = null;
if(typeID == Material.Sign.getID() || typeID == Material.SignPost.getID()) {
String signLines = blockSplit[2];
if(blockSplit.length > 3) {
// sign includes commas
for(int splitI = 3; splitI < blockSplit.length; splitI++) {
signLines.concat(blockSplit[splitI]);
}
}
String[] signLinesSplit = signLines.split("[line]");
lines = new String[4];
lines[0] = signLinesSplit[0];
lines[1] = signLinesSplit[1];
lines[2] = signLinesSplit[2];
lines[3] = signLinesSplit[3];
}
volume.getBlockInfos()[i][j][k] = new BlockInfo(typeID, data, lines);
}
}
}
}
} catch (IOException e) {
war.getLogger().warning("Failed to read volume file " + volumeName +
" for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage());
e.printStackTrace();
} finally {
if(in != null)
try {
in.close();
} catch (IOException e) {
war.getLogger().warning("Failed to close file reader for volume " + volumeName +
" for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage());
e.printStackTrace();
}
}
return volume;
}
public static void save(Volume volume, String zoneName, War war) {
if(volume.isSaved() && volume.getBlockInfos() != null) {
BufferedWriter out = null;
try {
out = new BufferedWriter(new FileWriter(new File("War/warzone-" + zoneName + "/volume-" + volume.getName() + ".dat")));
out.write("corner1"); out.newLine();
out.write(volume.getCornerOne().getX()); out.newLine();
out.write(volume.getCornerOne().getY()); out.newLine();
out.write(volume.getCornerOne().getZ()); out.newLine();
out.write("corner2"); out.newLine();
out.write(volume.getCornerTwo().getX()); out.newLine();
out.write(volume.getCornerTwo().getY()); out.newLine();
out.write(volume.getCornerTwo().getZ()); out.newLine();
for(int i = 0; i < volume.getSizeX(); i++){
for(int j = 0; j < volume.getSizeY(); j++) {
for(int k = 0; k < volume.getSizeZ(); k++) {
BlockInfo info = volume.getBlockInfos()[i][j][k];
if(info == null) {
out.write("0,0,"); out.newLine();
} else {
if(info.getType() == Material.Sign || info.getType() == Material.SignPost) {
String[] lines = info.getSignLines();
out.write(info.getTypeID() + "," + info.getData() + "," + lines[0] + "[line]" + lines[1]
+ "[line]" + lines[2] + "[line]"+ lines[3]);
} else {
out.write(info.getTypeID() + "," + info.getData() + ",");
}
}
}
}
}
} catch (IOException e) {
war.getLogger().warning("Failed to write volume file " + zoneName +
" for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage());
e.printStackTrace();
}
finally {
if(out != null)
try {
out.close();
} catch (IOException e) {
war.getLogger().warning("Failed to close file writer for volume " + volume.getName() +
" for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage());
e.printStackTrace();
}
}
}
}
}

View File

@ -16,6 +16,7 @@ import com.tommytony.war.Team;
import com.tommytony.war.TeamMaterials; import com.tommytony.war.TeamMaterials;
import com.tommytony.war.Warzone; import com.tommytony.war.Warzone;
import com.tommytony.war.volumes.VerticalVolume; import com.tommytony.war.volumes.VerticalVolume;
import com.tommytony.war.volumes.Volume;
/** /**
* *
@ -26,7 +27,7 @@ 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 + "/warzone-" + name + ".txt");
try { try {
warzoneConfig.load(); warzoneConfig.load();
} catch (IOException e) { } catch (IOException e) {
@ -152,17 +153,11 @@ public class WarzoneMapper {
if(loadBlocks && warzone.getNorthwest() != null && warzone.getSoutheast() != null) { if(loadBlocks && warzone.getNorthwest() != null && warzone.getSoutheast() != null) {
// zone blocks // zone blocks
VerticalVolume zoneVolume = new VerticalVolume("zone", war, warzone); VerticalVolume zoneVolume = VolumeMapper.load(warzone.getName(), "zone", war, warzone.getWorld());
try {
zoneVolume.fromDisk();
} catch (IOException e) {
war.getLogger().warning("Failed to read volume file " + warzone.getVolume().getName() +
" for warzone " + warzone.getName() + ". " + e.getClass().getName() + " " + e.getMessage());
e.printStackTrace();
}
// monument blocks // monument blocks
for(Monument monument: warzone.getMonuments()) { for(Monument monument: warzone.getMonuments()) {
monument.setVolume(VolumeMapper.load(warzone.getName(), monument.getName(), war, world));
try { try {
monument.getVolume().fromDisk(); monument.getVolume().fromDisk();
} catch (IOException e) { } catch (IOException e) {
@ -193,7 +188,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() + "/warzone-" + warzone.getName() + ".txt");
//war.getLogger().info("Saving warzone " + warzone.getName() + "..."); //war.getLogger().info("Saving warzone " + warzone.getName() + "...");
// name // name
@ -264,34 +259,16 @@ public class WarzoneMapper {
if(saveBlocks) { if(saveBlocks) {
(new File(war.getName()+"/"+warzone.getName())).mkdir(); (new File(war.getName()+"/"+warzone.getName())).mkdir();
// zone blocks // zone blocks
try { VolumeMapper.save(warzone.getVolume(), "zone", war);
warzone.getVolume().toDisk();
} catch (IOException e) {
war.getLogger().warning("Failed to write volume file " + warzone.getVolume().getName() +
" for warzone " + warzone.getName() + ". " + e.getClass().getName() + " " + e.getMessage());
e.printStackTrace();
}
// monument blocks // monument blocks
for(Monument monument: monuments) { for(Monument monument: monuments) {
try { VolumeMapper.save(monument.getVolume(), warzone.getName(), war);
monument.getVolume().toDisk();
} catch (IOException e) {
war.getLogger().warning("Failed to write volume file " + warzone.getVolume().getName() +
" for warzone " + warzone.getName() + ". " + e.getClass().getName() + " " + e.getMessage());
e.printStackTrace();
}
} }
// team spawn blocks // team spawn blocks
for(Team team : teams) { for(Team team : teams) {
try { VolumeMapper.save(team.getVolume(), warzone.getName(), war);
team.getVolume().toDisk();
} catch (IOException e) {
war.getLogger().warning("Failed to write volume file " + warzone.getVolume().getName() +
" for warzone " + warzone.getName() + ". " + e.getClass().getName() + " " + e.getMessage());
e.printStackTrace();
}
} }
} }
@ -303,12 +280,6 @@ public class WarzoneMapper {
} }
public static void delete(War war, String name) { public static void delete(War war, String name) {
File warzoneConfig = new File(war.getName() + "/warzone-" + name + ".txt");
boolean deletedConfig = warzoneConfig.delete();
if(!deletedConfig) {
war.getLogger().warning("Failed to delete file " + war.getName() + "/warzone-"+name+".txt");
}
File zoneFolder = new File(war.getName() + "/warzone-" + name); File zoneFolder = new File(war.getName() + "/warzone-" + name);
File[] files = zoneFolder.listFiles(); File[] files = zoneFolder.listFiles();
for(File file : files) { for(File file : files) {

View File

@ -2,24 +2,25 @@ package com.tommytony.war.volumes;
import org.bukkit.Block; import org.bukkit.Block;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World;
import bukkit.tommytony.war.War; import bukkit.tommytony.war.War;
import com.tommytony.war.Warzone;
public class CenteredVolume extends Volume { public class CenteredVolume extends Volume {
private Block center; private Block center;
private int sideSize = -1; private int sideSize = -1;
private final World world;
public CenteredVolume(String name, Block center, int sideSize, War war, Warzone warzone) { public CenteredVolume(String name, Block center, int sideSize, War war, World world) {
super(name, war, warzone); super(name, war, world);
this.world = world;
setCenter(center); setCenter(center);
setSideSize(sideSize); setSideSize(sideSize);
} }
public void changeCenter(Location newCenter) { public void changeCenter(Location newCenter) {
changeCenter(getWarzone().getWorld().getBlockAt(newCenter.getBlockX(), changeCenter(world.getBlockAt(newCenter.getBlockX(),
newCenter.getBlockY(), newCenter.getBlockY(),
newCenter.getBlockZ()), newCenter.getBlockZ()),
this.sideSize); this.sideSize);
@ -42,7 +43,7 @@ public class CenteredVolume extends Volume {
int x = center.getX() + topHalfOfSide; int x = center.getX() + topHalfOfSide;
int y = center.getY() + topHalfOfSide; int y = center.getY() + topHalfOfSide;
int z = center.getZ() + topHalfOfSide; int z = center.getZ() + topHalfOfSide;
Block cornerOne = getWarzone().getWorld().getBlockAt(x, y, z); Block cornerOne = world.getBlockAt(x, y, z);
setCornerOne(cornerOne); setCornerOne(cornerOne);
if(sideSize % 2 == 0) { // not a real center, bottom half is larger by 1 if(sideSize % 2 == 0) { // not a real center, bottom half is larger by 1
@ -50,13 +51,13 @@ public class CenteredVolume extends Volume {
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 = world.getBlockAt(x, y, z);
setCornerTwo(cornerTwo); setCornerTwo(cornerTwo);
} else { } else {
x = center.getX() - topHalfOfSide; x = center.getX() - topHalfOfSide;
y = center.getY() - topHalfOfSide; y = center.getY() - topHalfOfSide;
z = center.getZ() - topHalfOfSide; z = center.getZ() - topHalfOfSide;
Block cornerTwo = getWarzone().getWorld().getBlockAt(x, y, z); Block cornerTwo = world.getBlockAt(x, y, z);
setCornerTwo(cornerTwo); setCornerTwo(cornerTwo);
} }
} }

View File

@ -3,17 +3,16 @@ package com.tommytony.war.volumes;
import org.bukkit.Block; import org.bukkit.Block;
import org.bukkit.BlockFace; import org.bukkit.BlockFace;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
import bukkit.tommytony.war.War; import bukkit.tommytony.war.War;
import com.tommytony.war.Warzone;
public class VerticalVolume extends Volume{ public class VerticalVolume extends Volume{
public VerticalVolume(String name, War war, Warzone warzone) { public VerticalVolume(String name, War war, World world) {
super(name, war, warzone); super(name, war, world);
} }

View File

@ -32,17 +32,16 @@ import com.tommytony.war.Warzone;
public class Volume { public class Volume {
private final String name; private final String name;
private final World world; private final World world;
private final Warzone warzone; //private final Warzone warzone;
private Block cornerOne; private Block cornerOne;
private Block cornerTwo; private Block cornerTwo;
private BlockInfo[][][] blockInfos = null; private BlockInfo[][][] blockInfos = null;
private final War war; private final War war;
public Volume(String name, War war, Warzone warzone) { public Volume(String name, War war, World world) {
this.name = name; this.name = name;
this.war = war; this.war = war;
this.warzone = warzone; this.world = world;
this.world = warzone.getWorld();
} }
public World getWorld() { public World getWorld() {
@ -280,100 +279,13 @@ public class Volume {
// } // }
// } // }
public void fromDisk() throws IOException {
BufferedReader in = null;
try {
in = new BufferedReader(new FileReader(new File(war.getName() + "/warzone-" + warzone.getName() + "/" + name)));
;
String firstLine = in.readLine();
if(firstLine != null && !firstLine.equals("")) {
int x1 = Integer.parseInt(in.readLine());
int y1 = Integer.parseInt(in.readLine());
int z1 = Integer.parseInt(in.readLine());
int x2 = Integer.parseInt(in.readLine());
int y2 = Integer.parseInt(in.readLine());
int z2 = Integer.parseInt(in.readLine());
cornerOne = getWorld().getBlockAt(x1, y1, z1);
cornerTwo = getWorld().getBlockAt(x2, y2, z2);
setBlockInfos(new BlockInfo[getSizeX()][getSizeY()][getSizeZ()]); public Block getCornerOne() {
for(int i = 0; i < getSizeX(); i++){ return cornerOne;
for(int j = 0; j < getSizeY(); j++) {
for(int k = 0; k < getSizeZ(); k++) {
String blockLine = in.readLine();
String[] blockSplit = blockLine.split(",");
int typeID = Integer.parseInt(blockSplit[0]);
byte data = Byte.parseByte(blockSplit[1]);
String[] lines = null;
if(typeID == Material.Sign.getID() || typeID == Material.SignPost.getID()) {
String signLines = blockSplit[2];
if(blockSplit.length > 3) {
// sign includes commas
for(int splitI = 3; splitI < blockSplit.length; splitI++) {
signLines.concat(blockSplit[splitI]);
}
}
String[] signLinesSplit = signLines.split("[line]");
lines = new String[4];
lines[0] = signLinesSplit[0];
lines[1] = signLinesSplit[1];
lines[2] = signLinesSplit[2];
lines[3] = signLinesSplit[3];
}
getBlockInfos()[i][j][k] = new BlockInfo(typeID, data, lines);
}
}
}
}
} finally {
if(in != null) in.close();
}
} }
public void toDisk() throws IOException { public Block getCornerTwo() {
if(isSaved() && getBlockInfos() != null) { return cornerOne;
BufferedWriter out = null;
try {
out = new BufferedWriter(new FileWriter(new File(war.getName() + "/warzone-" + warzone.getName() + "/" + name)));
out.write("corner1"); out.newLine();
out.write(cornerOne.getX()); out.newLine();
out.write(cornerOne.getY()); out.newLine();
out.write(cornerOne.getZ()); out.newLine();
out.write("corner2"); out.newLine();
out.write(cornerTwo.getX()); out.newLine();
out.write(cornerTwo.getY()); out.newLine();
out.write(cornerTwo.getZ()); out.newLine();
for(int i = 0; i < getSizeX(); i++){
for(int j = 0; j < getSizeY(); j++) {
for(int k = 0; k < getSizeZ(); k++) {
BlockInfo info = getBlockInfos()[i][j][k];
if(info == null) {
out.write("0,0,"); out.newLine();
} else {
if(info.getType() == Material.Sign || info.getType() == Material.SignPost) {
String[] lines = info.getSignLines();
out.write(info.getTypeID() + "," + info.getData() + "," + lines[0] + "[line]" + lines[1] + "[line]" + lines[2] + "[line]"+ lines[3]);
} else {
out.write(info.getTypeID() + "," + info.getData() + ",");
}
}
}
}
}
} finally {
if(out != null) out.close();
}
}
}
public Warzone getWarzone() {
return warzone;
} }
public boolean contains(Location location) { public boolean contains(Location location) {