Fixed broken build. Volume mapping is much cleaner now. Getting started on WarHub and ZoneLobby.

This commit is contained in:
taoneill 2011-01-13 18:34:26 -05:00
parent e33a19cc4f
commit e5497786f3
10 changed files with 62 additions and 41 deletions

View File

@ -53,8 +53,7 @@ public class War extends JavaPlugin {
public void onEnable() {
this.log = Logger.getLogger("Minecraft");
// Register hMod hooks
// Register hooks
PluginManager pm = getServer().getPluginManager();
pm.registerEvent(Event.Type.PLAYER_LOGIN, playerListener, Priority.Normal, this);
@ -71,7 +70,7 @@ public class War extends JavaPlugin {
pm.registerEvent(Event.Type.BLOCK_CANBUILD, blockListener, Priority.Normal, this); // BLOCK_PLACE
pm.registerEvent(Event.Type.BLOCK_DAMAGED, blockListener, Priority.Normal, this); // BROKEN
// Load files from disk or create them
// Load files from disk or create them (using these defaults)
this.defaultLoadout.put(0, new ItemStack(Material.StoneSword));
this.defaultLoadout.put(1, new ItemStack(Material.Bow));
this.defaultLoadout.put(2, new ItemStack(Material.Arrow, 7));
@ -176,7 +175,7 @@ public class War extends JavaPlugin {
return name;
}
public Warzone zoneOfTooCloseZoneWall(Location location) {
public Warzone zoneOfZoneWallAtProximity(Location location) {
for(Warzone zone : warzones) {
if(zone.isNearWall(location)) return zone;
}

View File

@ -483,7 +483,7 @@ public class WarPlayerListener extends PlayerListener {
// Zone walls
if(to != null) {
Warzone nearbyZone = war.zoneOfTooCloseZoneWall(to);
Warzone nearbyZone = war.zoneOfZoneWallAtProximity(to);
if(nearbyZone != null) {
nearbyZone.protectZoneWallAgainstPlayer(player);
} else {

View File

@ -15,7 +15,7 @@ import com.tommytony.war.volumes.Volume;
*/
public class Monument {
private Location location;
private Volume volume;
private CenteredVolume volume;
private Team ownerTeam = null;
private final String name;
@ -151,11 +151,11 @@ public class Monument {
this.addMonumentBlocks();
}
public Volume getVolume() {
public CenteredVolume getVolume() {
return volume;
}
public void setVolume(Volume newVolume) {
public void setVolume(CenteredVolume newVolume) {
this.volume = newVolume;
}

View File

@ -33,7 +33,7 @@ public class Team {
this.warzone = warzone;
this.setName(name);
this.teamSpawn = teamSpawn;
this.volume = new Volume(name, war, warzone);
this.setVolume(new Volume(name, war, warzone.getWorld()));
this.material = material;
}
@ -130,7 +130,7 @@ public class Team {
// this resets the block to old state
this.setVolume();
volume.saveBlocks();
getVolume().saveBlocks();
initializeTeamSpawn(teamSpawn);
}
@ -214,4 +214,8 @@ public class Team {
state.update(true);
}
public void setVolume(Volume volume) {
this.volume = volume;
}
}

View File

@ -17,7 +17,7 @@ public class WarHub {
this.war = war;
this.world = world;
this.location = location;
this.volume = new Volume("warHub", war, warzone);
this.volume = new Volume("warHub", war, world);
}
}

View File

@ -39,7 +39,7 @@ public class Warzone {
private World world;
private Material originalSouthEastBlock;
private Material originalNorthWestBlock;
private final int minSafeDistanceFromWall = 4;
private final int minSafeDistanceFromWall = 5;
private List<ZoneWallGuard> zoneWallGuards = new ArrayList<ZoneWallGuard>();
private War war;
@ -52,7 +52,7 @@ public class Warzone {
this.setLifePool(war.getDefaultLifepool());
this.setLoadout(war.getDefaultLoadout());
this.drawZoneOutline = war.getDefaultDrawZoneOutline();
this.volume = new VerticalVolume(name, war, this);
this.volume = new VerticalVolume(name, war, this.getWorld());
}
public boolean ready() {

View File

@ -0,0 +1,5 @@
package com.tommytony.war;
public class ZoneLobby {
}

View File

@ -13,14 +13,37 @@ import org.bukkit.World;
import bukkit.tommytony.war.War;
import com.tommytony.war.volumes.BlockInfo;
import com.tommytony.war.volumes.CenteredVolume;
import com.tommytony.war.volumes.VerticalVolume;
import com.tommytony.war.volumes.Volume;
public class VolumeMapper {
public static Volume load(String zoneName, String volumeName, War war, World world) {
public static Volume loadVolume(String volumeName, String zoneName,
War war, World world) {
Volume volume = new Volume(volumeName, war, world);
load(volume, zoneName, war, world);
return volume;
}
public static VerticalVolume loadVerticalVolume(String volumeName, String zoneName,
War war, World world) {
VerticalVolume volume = new VerticalVolume(volumeName, war, world);
load(volume, zoneName, war, world);
return volume;
}
public static CenteredVolume loadCenteredVolume(String volumeName, String zoneName, int sideSize,
War war, World world) {
CenteredVolume volume = new CenteredVolume(volumeName, null, sideSize, war, world);
load(volume, zoneName, war, world);
return volume;
}
public static void load(Volume volume, String zoneName, War war, World world) {
BufferedReader in = null;
Volume volume = null;
try {
in = new BufferedReader(new FileReader(new File("War/warzone-" + zoneName + "/volume-" + volumeName)));
in = new BufferedReader(new FileReader(new File("War/warzone-" + zoneName + "/volume-" + volume.getName())));
String firstLine = in.readLine();
if(firstLine != null && !firstLine.equals("")) {
int x1 = Integer.parseInt(in.readLine());
@ -30,9 +53,13 @@ public class VolumeMapper {
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));
if(volume instanceof CenteredVolume) {
((CenteredVolume)volume).setCenter(world.getBlockAt(x1, y1, z1));
((CenteredVolume)volume).calculateCorners();
} else {
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++){
@ -65,7 +92,7 @@ public class VolumeMapper {
}
}
} catch (IOException e) {
war.getLogger().warning("Failed to read volume file " + volumeName +
war.getLogger().warning("Failed to read volume file " + volume.getName() +
" for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage());
e.printStackTrace();
} finally {
@ -73,12 +100,11 @@ public class VolumeMapper {
try {
in.close();
} catch (IOException e) {
war.getLogger().warning("Failed to close file reader for volume " + volumeName +
war.getLogger().warning("Failed to close file reader for volume " + volume.getName() +
" for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage());
e.printStackTrace();
}
}
return volume;
}
public static void save(Volume volume, String zoneName, War war) {
@ -132,4 +158,5 @@ public class VolumeMapper {
}
}
}

View File

@ -16,7 +16,6 @@ import com.tommytony.war.Team;
import com.tommytony.war.TeamMaterials;
import com.tommytony.war.Warzone;
import com.tommytony.war.volumes.VerticalVolume;
import com.tommytony.war.volumes.Volume;
/**
*
@ -153,29 +152,16 @@ public class WarzoneMapper {
if(loadBlocks && warzone.getNorthwest() != null && warzone.getSoutheast() != null) {
// zone blocks
VerticalVolume zoneVolume = VolumeMapper.load(warzone.getName(), "zone", war, warzone.getWorld());
VerticalVolume zoneVolume = VolumeMapper.loadVerticalVolume(warzone.getName(), "zone", war, warzone.getWorld());
// monument blocks
for(Monument monument: warzone.getMonuments()) {
monument.setVolume(VolumeMapper.load(warzone.getName(), monument.getName(), war, world));
try {
monument.getVolume().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.setVolume(VolumeMapper.loadCenteredVolume(warzone.getName(), monument.getName(), 7, war, world));
}
// team spawn blocks
for(Team team : warzone.getTeams()) {
try {
team.getVolume().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();
}
team.setVolume(VolumeMapper.loadVolume(team.getName(), warzone.getName(), war, world));
}
//war.getLogger().info("Loaded warzone " + name + " config and blocks.");

View File

@ -33,11 +33,11 @@ public class CenteredVolume extends Volume {
this.calculateCorners();
}
private void setCenter(Block block) {
public void setCenter(Block block) {
this.center = block;
}
private void calculateCorners() {
public void calculateCorners() {
int topHalfOfSide = sideSize / 2;
int x = center.getX() + topHalfOfSide;