First draft of new no-blocks-in-memory zone volumes. Also changed how magic glass walls work. This is going to be so broken.

This commit is contained in:
taoneill 2011-06-04 23:59:41 -04:00
parent dbf5995337
commit 5b1ec9d994
14 changed files with 811 additions and 162 deletions

View File

@ -485,7 +485,7 @@ public class War extends JavaPlugin {
warzone.getTeams().remove(team);
if(warzone.getLobby() != null) {
warzone.getLobby().getVolume().resetBlocks();
warzone.getVolume().resetWallBlocks(warzone.getLobby().getWall());
//warzone.getVolume().resetWallBlocks(warzone.getLobby().getWall());
//warzone.addZoneOutline(warzone.getLobby().getWall());
warzone.getLobby().initialize();
}
@ -552,7 +552,7 @@ public class War extends JavaPlugin {
warzone.getTeams().add(newTeam);
if(warzone.getLobby() != null) {
warzone.getLobby().getVolume().resetBlocks();
warzone.getVolume().resetWallBlocks(warzone.getLobby().getWall());
//warzone.getVolume().resetWallBlocks(warzone.getLobby().getWall());
//warzone.addZoneOutline(warzone.getLobby().getWall());
warzone.getLobby().initialize();
}
@ -692,17 +692,20 @@ public class War extends JavaPlugin {
}
this.msg(player, "Saving warzone " + warzone.getName() + ".");
int savedBlocks = warzone.saveState(true);
updateZoneFromNamedParams(warzone, player, arguments);
WarzoneMapper.save(this, warzone, true);
warzone.getVolume().resetBlocks();
if(lobby != null) {
lobby.getVolume().resetBlocks();
}
warzone.initializeZone(); // bring back team spawns etc
if(warHub != null) { // maybe the zone was disabled/enabled
warHub.getVolume().resetBlocks();
warHub.initialize();
if(arguments.length > 0) {
// changed settings: must reinitialize with new settings
updateZoneFromNamedParams(warzone, player, arguments);
WarzoneMapper.save(this, warzone, true);
warzone.getVolume().resetBlocks();
if(lobby != null) {
lobby.getVolume().resetBlocks();
}
warzone.initializeZone(); // bring back team spawns etc
if(warHub != null) { // maybe the zone was disabled/enabled
warHub.getVolume().resetBlocks();
warHub.initialize();
}
}
this.msg(player, "Warzone " + warzone.getName() + " initial state changed. Saved " + savedBlocks + " blocks.");

View File

@ -250,7 +250,6 @@ public class WarPlayerListener extends PlayerListener {
}
}
boolean enteredGate = false;
// Warzone lobby gates
if(locLobby != null) {

View File

@ -115,10 +115,14 @@ public class Warzone {
if(ready()){
if(clearArtifacts) {
// removed everything to keep save clean
volume.resetWallBlocks(BlockFace.EAST);
volume.resetWallBlocks(BlockFace.WEST);
volume.resetWallBlocks(BlockFace.NORTH);
volume.resetWallBlocks(BlockFace.SOUTH);
for(ZoneWallGuard guard : zoneWallGuards) {
guard.deactivate();
}
zoneWallGuards.clear();
// volume.resetWallBlocks(BlockFace.EAST);
// volume.resetWallBlocks(BlockFace.WEST);
// volume.resetWallBlocks(BlockFace.NORTH);
// volume.resetWallBlocks(BlockFace.SOUTH);
for(Team team : teams) {
team.getSpawnVolume().resetBlocks();
@ -650,16 +654,17 @@ public class Warzone {
for(ZoneWallGuard guard : zoneWallGuards) {
if(guard.getPlayer().getName().equals(player.getName())){
playerGuards.add(guard);
BlockFace guardWall = guard.getWall();
getVolume().resetWallBlocks(guardWall);
guard.deactivate();
// BlockFace guardWall = guard.getWall();
// getVolume().resetWallBlocks(guardWall);
// if(isDrawZoneOutline()) {
// addZoneOutline(guard.getWall());
// }
if(lobby != null) {
lobby.getVolume().resetBlocks(); // always reset the lobby even if the guard is on another wall
// because player can go around corner
lobby.initialize();
}
// if(lobby != null) {
// lobby.getVolume().resetBlocks(); // always reset the lobby even if the guard is on another wall
// // because player can go around corner
// lobby.initialize();
// }
}
}
// now remove those zone guards

View File

@ -150,9 +150,7 @@ public class ZoneLobby {
// }
this.wall = opposite; // a player facing south places a lobby that looks just like a lobby stuck to the north wall
ZoneVolume zoneVolume = warzone.getVolume();
calculateLobbyWidth();
lobbyMiddleWallBlock = new BlockInfo(warzone.getWorld().getBlockAt(playerLocation.getBlockX(),
playerLocation.getBlockY(),
playerLocation.getBlockZ())

View File

@ -1,5 +1,6 @@
package com.tommytony.war;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Location;
@ -8,6 +9,8 @@ import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import com.tommytony.war.volumes.BlockInfo;
import bukkit.tommytony.war.War;
/**
@ -20,6 +23,7 @@ public class ZoneWallGuard {
private Warzone warzone;
private Location playerLocation;
private BlockFace wall;
private List<BlockInfo> glassified = new ArrayList<BlockInfo>();
public ZoneWallGuard(Player player, War war, Warzone warzone, BlockFace wall) {
this.player = player;
@ -34,152 +38,160 @@ public class ZoneWallGuard {
// add wall guard blocks
for(Block block : nearestWallBlocks) {
toGlass(block, wall);
glassify(block, wall);
if(this.wall != BlockFace.UP && this.wall != BlockFace.DOWN) {
toGlass(block.getFace(BlockFace.UP), wall);
toGlass(block.getFace(BlockFace.UP, 2), wall);
toGlass(block.getFace(BlockFace.DOWN), wall);
toGlass(block.getFace(BlockFace.DOWN, 2), wall);
glassify(block.getFace(BlockFace.UP), wall);
glassify(block.getFace(BlockFace.UP, 2), wall);
glassify(block.getFace(BlockFace.DOWN), wall);
glassify(block.getFace(BlockFace.DOWN, 2), wall);
}
if(this.wall == BlockFace.NORTH && warzone.getVolume().isNorthWallBlock(block)) {
toGlass(block.getFace(BlockFace.EAST), BlockFace.NORTH);
toGlass(block.getFace(BlockFace.EAST).getFace(BlockFace.UP), BlockFace.NORTH);
toGlass(block.getFace(BlockFace.EAST).getFace(BlockFace.DOWN), BlockFace.NORTH);
toGlass(block.getFace(BlockFace.EAST, 2), BlockFace.NORTH);
toGlass(block.getFace(BlockFace.EAST, 2).getFace(BlockFace.UP), BlockFace.NORTH);
toGlass(block.getFace(BlockFace.EAST, 2).getFace(BlockFace.DOWN), BlockFace.NORTH);
toGlass(block.getFace(BlockFace.EAST).getFace(BlockFace.UP, 2), BlockFace.NORTH);
toGlass(block.getFace(BlockFace.EAST).getFace(BlockFace.DOWN, 2), BlockFace.NORTH);
toGlass(block.getFace(BlockFace.WEST), BlockFace.NORTH);
toGlass(block.getFace(BlockFace.WEST).getFace(BlockFace.UP), BlockFace.NORTH);
toGlass(block.getFace(BlockFace.WEST).getFace(BlockFace.DOWN), BlockFace.NORTH);
toGlass(block.getFace(BlockFace.WEST, 2), BlockFace.NORTH);
toGlass(block.getFace(BlockFace.WEST, 2).getFace(BlockFace.UP), BlockFace.NORTH);
toGlass(block.getFace(BlockFace.WEST, 2).getFace(BlockFace.DOWN), BlockFace.NORTH);
toGlass(block.getFace(BlockFace.WEST).getFace(BlockFace.UP, 2), BlockFace.NORTH);
toGlass(block.getFace(BlockFace.WEST).getFace(BlockFace.DOWN, 2), BlockFace.NORTH);
glassify(block.getFace(BlockFace.EAST), BlockFace.NORTH);
glassify(block.getFace(BlockFace.EAST).getFace(BlockFace.UP), BlockFace.NORTH);
glassify(block.getFace(BlockFace.EAST).getFace(BlockFace.DOWN), BlockFace.NORTH);
glassify(block.getFace(BlockFace.EAST, 2), BlockFace.NORTH);
glassify(block.getFace(BlockFace.EAST, 2).getFace(BlockFace.UP), BlockFace.NORTH);
glassify(block.getFace(BlockFace.EAST, 2).getFace(BlockFace.DOWN), BlockFace.NORTH);
glassify(block.getFace(BlockFace.EAST).getFace(BlockFace.UP, 2), BlockFace.NORTH);
glassify(block.getFace(BlockFace.EAST).getFace(BlockFace.DOWN, 2), BlockFace.NORTH);
glassify(block.getFace(BlockFace.WEST), BlockFace.NORTH);
glassify(block.getFace(BlockFace.WEST).getFace(BlockFace.UP), BlockFace.NORTH);
glassify(block.getFace(BlockFace.WEST).getFace(BlockFace.DOWN), BlockFace.NORTH);
glassify(block.getFace(BlockFace.WEST, 2), BlockFace.NORTH);
glassify(block.getFace(BlockFace.WEST, 2).getFace(BlockFace.UP), BlockFace.NORTH);
glassify(block.getFace(BlockFace.WEST, 2).getFace(BlockFace.DOWN), BlockFace.NORTH);
glassify(block.getFace(BlockFace.WEST).getFace(BlockFace.UP, 2), BlockFace.NORTH);
glassify(block.getFace(BlockFace.WEST).getFace(BlockFace.DOWN, 2), BlockFace.NORTH);
} else if(this.wall == BlockFace.SOUTH && warzone.getVolume().isSouthWallBlock(block)) {
toGlass(block.getFace(BlockFace.EAST), BlockFace.SOUTH);
toGlass(block.getFace(BlockFace.EAST).getFace(BlockFace.UP), BlockFace.SOUTH);
toGlass(block.getFace(BlockFace.EAST).getFace(BlockFace.DOWN), BlockFace.SOUTH);
toGlass(block.getFace(BlockFace.EAST, 2), BlockFace.SOUTH);
toGlass(block.getFace(BlockFace.EAST, 2).getFace(BlockFace.UP), BlockFace.SOUTH);
toGlass(block.getFace(BlockFace.EAST, 2).getFace(BlockFace.DOWN), BlockFace.SOUTH);
toGlass(block.getFace(BlockFace.EAST).getFace(BlockFace.UP, 2), BlockFace.SOUTH);
toGlass(block.getFace(BlockFace.EAST).getFace(BlockFace.DOWN, 2), BlockFace.SOUTH);
toGlass(block.getFace(BlockFace.WEST), BlockFace.SOUTH);
toGlass(block.getFace(BlockFace.WEST).getFace(BlockFace.UP), BlockFace.SOUTH);
toGlass(block.getFace(BlockFace.WEST).getFace(BlockFace.DOWN), BlockFace.SOUTH);
toGlass(block.getFace(BlockFace.WEST, 2), BlockFace.SOUTH);
toGlass(block.getFace(BlockFace.WEST, 2).getFace(BlockFace.UP), BlockFace.SOUTH);
toGlass(block.getFace(BlockFace.WEST, 2).getFace(BlockFace.DOWN), BlockFace.SOUTH);
toGlass(block.getFace(BlockFace.WEST).getFace(BlockFace.UP, 2), BlockFace.SOUTH);
toGlass(block.getFace(BlockFace.WEST).getFace(BlockFace.DOWN, 2), BlockFace.SOUTH);
glassify(block.getFace(BlockFace.EAST), BlockFace.SOUTH);
glassify(block.getFace(BlockFace.EAST).getFace(BlockFace.UP), BlockFace.SOUTH);
glassify(block.getFace(BlockFace.EAST).getFace(BlockFace.DOWN), BlockFace.SOUTH);
glassify(block.getFace(BlockFace.EAST, 2), BlockFace.SOUTH);
glassify(block.getFace(BlockFace.EAST, 2).getFace(BlockFace.UP), BlockFace.SOUTH);
glassify(block.getFace(BlockFace.EAST, 2).getFace(BlockFace.DOWN), BlockFace.SOUTH);
glassify(block.getFace(BlockFace.EAST).getFace(BlockFace.UP, 2), BlockFace.SOUTH);
glassify(block.getFace(BlockFace.EAST).getFace(BlockFace.DOWN, 2), BlockFace.SOUTH);
glassify(block.getFace(BlockFace.WEST), BlockFace.SOUTH);
glassify(block.getFace(BlockFace.WEST).getFace(BlockFace.UP), BlockFace.SOUTH);
glassify(block.getFace(BlockFace.WEST).getFace(BlockFace.DOWN), BlockFace.SOUTH);
glassify(block.getFace(BlockFace.WEST, 2), BlockFace.SOUTH);
glassify(block.getFace(BlockFace.WEST, 2).getFace(BlockFace.UP), BlockFace.SOUTH);
glassify(block.getFace(BlockFace.WEST, 2).getFace(BlockFace.DOWN), BlockFace.SOUTH);
glassify(block.getFace(BlockFace.WEST).getFace(BlockFace.UP, 2), BlockFace.SOUTH);
glassify(block.getFace(BlockFace.WEST).getFace(BlockFace.DOWN, 2), BlockFace.SOUTH);
} else if(this.wall == BlockFace.EAST && warzone.getVolume().isEastWallBlock(block)) {
toGlass(block.getFace(BlockFace.NORTH), BlockFace.EAST);
toGlass(block.getFace(BlockFace.NORTH).getFace(BlockFace.UP), BlockFace.EAST);
toGlass(block.getFace(BlockFace.NORTH).getFace(BlockFace.DOWN), BlockFace.EAST);
toGlass(block.getFace(BlockFace.NORTH, 2), BlockFace.EAST);
toGlass(block.getFace(BlockFace.NORTH, 2).getFace(BlockFace.UP), BlockFace.EAST);
toGlass(block.getFace(BlockFace.NORTH, 2).getFace(BlockFace.DOWN), BlockFace.EAST);
toGlass(block.getFace(BlockFace.NORTH).getFace(BlockFace.UP, 2), BlockFace.EAST);
toGlass(block.getFace(BlockFace.NORTH).getFace(BlockFace.DOWN, 2), BlockFace.EAST);
toGlass(block.getFace(BlockFace.SOUTH), BlockFace.EAST);
toGlass(block.getFace(BlockFace.SOUTH).getFace(BlockFace.UP), BlockFace.EAST);
toGlass(block.getFace(BlockFace.SOUTH).getFace(BlockFace.DOWN), BlockFace.EAST);
toGlass(block.getFace(BlockFace.SOUTH, 2), BlockFace.EAST);
toGlass(block.getFace(BlockFace.SOUTH, 2).getFace(BlockFace.UP), BlockFace.EAST);
toGlass(block.getFace(BlockFace.SOUTH, 2).getFace(BlockFace.DOWN), BlockFace.EAST);
toGlass(block.getFace(BlockFace.SOUTH).getFace(BlockFace.UP, 2), BlockFace.EAST);
toGlass(block.getFace(BlockFace.SOUTH).getFace(BlockFace.DOWN, 2), BlockFace.EAST);
glassify(block.getFace(BlockFace.NORTH), BlockFace.EAST);
glassify(block.getFace(BlockFace.NORTH).getFace(BlockFace.UP), BlockFace.EAST);
glassify(block.getFace(BlockFace.NORTH).getFace(BlockFace.DOWN), BlockFace.EAST);
glassify(block.getFace(BlockFace.NORTH, 2), BlockFace.EAST);
glassify(block.getFace(BlockFace.NORTH, 2).getFace(BlockFace.UP), BlockFace.EAST);
glassify(block.getFace(BlockFace.NORTH, 2).getFace(BlockFace.DOWN), BlockFace.EAST);
glassify(block.getFace(BlockFace.NORTH).getFace(BlockFace.UP, 2), BlockFace.EAST);
glassify(block.getFace(BlockFace.NORTH).getFace(BlockFace.DOWN, 2), BlockFace.EAST);
glassify(block.getFace(BlockFace.SOUTH), BlockFace.EAST);
glassify(block.getFace(BlockFace.SOUTH).getFace(BlockFace.UP), BlockFace.EAST);
glassify(block.getFace(BlockFace.SOUTH).getFace(BlockFace.DOWN), BlockFace.EAST);
glassify(block.getFace(BlockFace.SOUTH, 2), BlockFace.EAST);
glassify(block.getFace(BlockFace.SOUTH, 2).getFace(BlockFace.UP), BlockFace.EAST);
glassify(block.getFace(BlockFace.SOUTH, 2).getFace(BlockFace.DOWN), BlockFace.EAST);
glassify(block.getFace(BlockFace.SOUTH).getFace(BlockFace.UP, 2), BlockFace.EAST);
glassify(block.getFace(BlockFace.SOUTH).getFace(BlockFace.DOWN, 2), BlockFace.EAST);
} else if(this.wall == BlockFace.WEST && warzone.getVolume().isWestWallBlock(block)) {
toGlass(block.getFace(BlockFace.NORTH), BlockFace.WEST);
toGlass(block.getFace(BlockFace.NORTH).getFace(BlockFace.UP), BlockFace.WEST);
toGlass(block.getFace(BlockFace.NORTH).getFace(BlockFace.DOWN), BlockFace.WEST);
toGlass(block.getFace(BlockFace.NORTH, 2), BlockFace.WEST);
toGlass(block.getFace(BlockFace.NORTH, 2).getFace(BlockFace.UP), BlockFace.WEST);
toGlass(block.getFace(BlockFace.NORTH, 2).getFace(BlockFace.DOWN), BlockFace.WEST);
toGlass(block.getFace(BlockFace.NORTH).getFace(BlockFace.UP, 2), BlockFace.WEST);
toGlass(block.getFace(BlockFace.NORTH).getFace(BlockFace.DOWN, 2), BlockFace.WEST);
toGlass(block.getFace(BlockFace.SOUTH), BlockFace.WEST);
toGlass(block.getFace(BlockFace.SOUTH).getFace(BlockFace.UP), BlockFace.WEST);
toGlass(block.getFace(BlockFace.SOUTH).getFace(BlockFace.DOWN), BlockFace.WEST);
toGlass(block.getFace(BlockFace.SOUTH, 2), BlockFace.WEST);
toGlass(block.getFace(BlockFace.SOUTH, 2).getFace(BlockFace.UP), BlockFace.WEST);
toGlass(block.getFace(BlockFace.SOUTH, 2).getFace(BlockFace.DOWN), BlockFace.WEST);
toGlass(block.getFace(BlockFace.SOUTH).getFace(BlockFace.UP, 2), BlockFace.WEST);
toGlass(block.getFace(BlockFace.SOUTH).getFace(BlockFace.DOWN, 2), BlockFace.WEST);
glassify(block.getFace(BlockFace.NORTH), BlockFace.WEST);
glassify(block.getFace(BlockFace.NORTH).getFace(BlockFace.UP), BlockFace.WEST);
glassify(block.getFace(BlockFace.NORTH).getFace(BlockFace.DOWN), BlockFace.WEST);
glassify(block.getFace(BlockFace.NORTH, 2), BlockFace.WEST);
glassify(block.getFace(BlockFace.NORTH, 2).getFace(BlockFace.UP), BlockFace.WEST);
glassify(block.getFace(BlockFace.NORTH, 2).getFace(BlockFace.DOWN), BlockFace.WEST);
glassify(block.getFace(BlockFace.NORTH).getFace(BlockFace.UP, 2), BlockFace.WEST);
glassify(block.getFace(BlockFace.NORTH).getFace(BlockFace.DOWN, 2), BlockFace.WEST);
glassify(block.getFace(BlockFace.SOUTH), BlockFace.WEST);
glassify(block.getFace(BlockFace.SOUTH).getFace(BlockFace.UP), BlockFace.WEST);
glassify(block.getFace(BlockFace.SOUTH).getFace(BlockFace.DOWN), BlockFace.WEST);
glassify(block.getFace(BlockFace.SOUTH, 2), BlockFace.WEST);
glassify(block.getFace(BlockFace.SOUTH, 2).getFace(BlockFace.UP), BlockFace.WEST);
glassify(block.getFace(BlockFace.SOUTH, 2).getFace(BlockFace.DOWN), BlockFace.WEST);
glassify(block.getFace(BlockFace.SOUTH).getFace(BlockFace.UP, 2), BlockFace.WEST);
glassify(block.getFace(BlockFace.SOUTH).getFace(BlockFace.DOWN, 2), BlockFace.WEST);
} else if(this.wall == BlockFace.UP && warzone.getVolume().isUpWallBlock(block)) {
toGlass(block.getFace(BlockFace.EAST), BlockFace.UP);
toGlass(block.getFace(BlockFace.EAST, 2), BlockFace.UP);
toGlass(block.getFace(BlockFace.WEST), BlockFace.UP);
toGlass(block.getFace(BlockFace.WEST, 2), BlockFace.UP);
toGlass(block.getFace(BlockFace.NORTH), BlockFace.UP);
toGlass(block.getFace(BlockFace.NORTH).getFace(BlockFace.EAST), BlockFace.UP);
toGlass(block.getFace(BlockFace.NORTH).getFace(BlockFace.WEST), BlockFace.UP);
toGlass(block.getFace(BlockFace.NORTH, 2), BlockFace.UP);
toGlass(block.getFace(BlockFace.NORTH, 2).getFace(BlockFace.EAST), BlockFace.UP);
toGlass(block.getFace(BlockFace.NORTH, 2).getFace(BlockFace.WEST), BlockFace.UP);
toGlass(block.getFace(BlockFace.NORTH).getFace(BlockFace.EAST, 2), BlockFace.UP);
toGlass(block.getFace(BlockFace.NORTH).getFace(BlockFace.WEST, 2), BlockFace.UP);
toGlass(block.getFace(BlockFace.SOUTH), BlockFace.UP);
toGlass(block.getFace(BlockFace.SOUTH).getFace(BlockFace.EAST), BlockFace.UP);
toGlass(block.getFace(BlockFace.SOUTH).getFace(BlockFace.WEST), BlockFace.UP);
toGlass(block.getFace(BlockFace.SOUTH, 2), BlockFace.UP);
toGlass(block.getFace(BlockFace.SOUTH, 2).getFace(BlockFace.EAST), BlockFace.UP);
toGlass(block.getFace(BlockFace.SOUTH, 2).getFace(BlockFace.WEST), BlockFace.UP);
toGlass(block.getFace(BlockFace.SOUTH).getFace(BlockFace.UP, 2), BlockFace.UP);
toGlass(block.getFace(BlockFace.SOUTH).getFace(BlockFace.DOWN, 2), BlockFace.UP);
glassify(block.getFace(BlockFace.EAST), BlockFace.UP);
glassify(block.getFace(BlockFace.EAST, 2), BlockFace.UP);
glassify(block.getFace(BlockFace.WEST), BlockFace.UP);
glassify(block.getFace(BlockFace.WEST, 2), BlockFace.UP);
glassify(block.getFace(BlockFace.NORTH), BlockFace.UP);
glassify(block.getFace(BlockFace.NORTH).getFace(BlockFace.EAST), BlockFace.UP);
glassify(block.getFace(BlockFace.NORTH).getFace(BlockFace.WEST), BlockFace.UP);
glassify(block.getFace(BlockFace.NORTH, 2), BlockFace.UP);
glassify(block.getFace(BlockFace.NORTH, 2).getFace(BlockFace.EAST), BlockFace.UP);
glassify(block.getFace(BlockFace.NORTH, 2).getFace(BlockFace.WEST), BlockFace.UP);
glassify(block.getFace(BlockFace.NORTH).getFace(BlockFace.EAST, 2), BlockFace.UP);
glassify(block.getFace(BlockFace.NORTH).getFace(BlockFace.WEST, 2), BlockFace.UP);
glassify(block.getFace(BlockFace.SOUTH), BlockFace.UP);
glassify(block.getFace(BlockFace.SOUTH).getFace(BlockFace.EAST), BlockFace.UP);
glassify(block.getFace(BlockFace.SOUTH).getFace(BlockFace.WEST), BlockFace.UP);
glassify(block.getFace(BlockFace.SOUTH, 2), BlockFace.UP);
glassify(block.getFace(BlockFace.SOUTH, 2).getFace(BlockFace.EAST), BlockFace.UP);
glassify(block.getFace(BlockFace.SOUTH, 2).getFace(BlockFace.WEST), BlockFace.UP);
glassify(block.getFace(BlockFace.SOUTH).getFace(BlockFace.UP, 2), BlockFace.UP);
glassify(block.getFace(BlockFace.SOUTH).getFace(BlockFace.DOWN, 2), BlockFace.UP);
} else if (this.wall == BlockFace.DOWN && warzone.getVolume().isDownWallBlock(block)) {
toGlass(block.getFace(BlockFace.EAST), BlockFace.DOWN);
toGlass(block.getFace(BlockFace.EAST, 2), BlockFace.DOWN);
toGlass(block.getFace(BlockFace.WEST), BlockFace.DOWN);
toGlass(block.getFace(BlockFace.WEST, 2), BlockFace.DOWN);
toGlass(block.getFace(BlockFace.NORTH), BlockFace.DOWN);
toGlass(block.getFace(BlockFace.NORTH).getFace(BlockFace.EAST), BlockFace.DOWN);
toGlass(block.getFace(BlockFace.NORTH).getFace(BlockFace.WEST), BlockFace.DOWN);
toGlass(block.getFace(BlockFace.NORTH, 2), BlockFace.DOWN);
toGlass(block.getFace(BlockFace.NORTH, 2).getFace(BlockFace.EAST), BlockFace.DOWN);
toGlass(block.getFace(BlockFace.NORTH, 2).getFace(BlockFace.WEST), BlockFace.DOWN);
toGlass(block.getFace(BlockFace.NORTH).getFace(BlockFace.EAST, 2), BlockFace.DOWN);
toGlass(block.getFace(BlockFace.NORTH).getFace(BlockFace.WEST, 2), BlockFace.DOWN);
toGlass(block.getFace(BlockFace.SOUTH), BlockFace.DOWN);
toGlass(block.getFace(BlockFace.SOUTH).getFace(BlockFace.EAST), BlockFace.DOWN);
toGlass(block.getFace(BlockFace.SOUTH).getFace(BlockFace.WEST), BlockFace.DOWN);
toGlass(block.getFace(BlockFace.SOUTH, 2), BlockFace.DOWN);
toGlass(block.getFace(BlockFace.SOUTH, 2).getFace(BlockFace.EAST), BlockFace.DOWN);
toGlass(block.getFace(BlockFace.SOUTH, 2).getFace(BlockFace.WEST), BlockFace.DOWN);
toGlass(block.getFace(BlockFace.SOUTH).getFace(BlockFace.DOWN, 2), BlockFace.DOWN);
toGlass(block.getFace(BlockFace.SOUTH).getFace(BlockFace.DOWN, 2), BlockFace.DOWN);
glassify(block.getFace(BlockFace.EAST), BlockFace.DOWN);
glassify(block.getFace(BlockFace.EAST, 2), BlockFace.DOWN);
glassify(block.getFace(BlockFace.WEST), BlockFace.DOWN);
glassify(block.getFace(BlockFace.WEST, 2), BlockFace.DOWN);
glassify(block.getFace(BlockFace.NORTH), BlockFace.DOWN);
glassify(block.getFace(BlockFace.NORTH).getFace(BlockFace.EAST), BlockFace.DOWN);
glassify(block.getFace(BlockFace.NORTH).getFace(BlockFace.WEST), BlockFace.DOWN);
glassify(block.getFace(BlockFace.NORTH, 2), BlockFace.DOWN);
glassify(block.getFace(BlockFace.NORTH, 2).getFace(BlockFace.EAST), BlockFace.DOWN);
glassify(block.getFace(BlockFace.NORTH, 2).getFace(BlockFace.WEST), BlockFace.DOWN);
glassify(block.getFace(BlockFace.NORTH).getFace(BlockFace.EAST, 2), BlockFace.DOWN);
glassify(block.getFace(BlockFace.NORTH).getFace(BlockFace.WEST, 2), BlockFace.DOWN);
glassify(block.getFace(BlockFace.SOUTH), BlockFace.DOWN);
glassify(block.getFace(BlockFace.SOUTH).getFace(BlockFace.EAST), BlockFace.DOWN);
glassify(block.getFace(BlockFace.SOUTH).getFace(BlockFace.WEST), BlockFace.DOWN);
glassify(block.getFace(BlockFace.SOUTH, 2), BlockFace.DOWN);
glassify(block.getFace(BlockFace.SOUTH, 2).getFace(BlockFace.EAST), BlockFace.DOWN);
glassify(block.getFace(BlockFace.SOUTH, 2).getFace(BlockFace.WEST), BlockFace.DOWN);
glassify(block.getFace(BlockFace.SOUTH).getFace(BlockFace.DOWN, 2), BlockFace.DOWN);
glassify(block.getFace(BlockFace.SOUTH).getFace(BlockFace.DOWN, 2), BlockFace.DOWN);
}
}
}
private void toGlass(Block block, BlockFace wall) {
private void glassify(Block block, BlockFace wall) {
// face here means which wall we are working on
if(warzone.getLobby() == null || (warzone.getLobby() != null && !warzone.getLobby().blockIsAGateBlock(block, wall))){
if((block.getTypeId() == Material.AIR.getId() || block.getTypeId() == Material.WATER.getId()) &&
(warzone.getLobby() == null || (warzone.getLobby() != null && !warzone.getLobby().blockIsAGateBlock(block, wall)))){
if(wall == BlockFace.NORTH) {
if(warzone.getVolume().isNorthWallBlock(block)) {
glassified.add(new BlockInfo(block));
block.setType(Material.GLASS);
}
} else if (wall == BlockFace.SOUTH) {
if(warzone.getVolume().isSouthWallBlock(block)) {
glassified.add(new BlockInfo(block));
block.setType(Material.GLASS);
}
} else if (wall == BlockFace.EAST) {
if(warzone.getVolume().isEastWallBlock(block)) {
glassified.add(new BlockInfo(block));
block.setType(Material.GLASS);
}
} else if (wall == BlockFace.WEST) {
if(warzone.getVolume().isWestWallBlock(block)) {
glassified.add(new BlockInfo(block));
block.setType(Material.GLASS);
}
} else if (wall == BlockFace.UP) {
if(warzone.getVolume().isUpWallBlock(block)) {
glassified.add(new BlockInfo(block));
block.setType(Material.GLASS);
}
} else if (wall == BlockFace.DOWN) {
if(warzone.getVolume().isDownWallBlock(block)) {
glassified.add(new BlockInfo(block));
block.setType(Material.GLASS);
}
}
@ -189,10 +201,20 @@ public class ZoneWallGuard {
public void updatePlayerPosition(Location location) {
if(warzone.isNearWall(location)) {
this.playerLocation = location;
deactivate();
activate();
}
}
public void deactivate() {
for(BlockInfo oldBlock : glassified) {
// return to original
Block glassifiedBlock = warzone.getWorld().getBlockAt(oldBlock.getX(), oldBlock.getY(), oldBlock.getZ());
glassifiedBlock.setTypeId(oldBlock.getTypeId());
glassifiedBlock.setData(oldBlock.getData());
}
}
public Player getPlayer() {
return player;
}

View File

@ -0,0 +1,67 @@
package com.tommytony.war.jobs;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.Dispenser;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import com.tommytony.war.Warzone;
import com.tommytony.war.utils.DeferredBlockReset;
public class DeferredBlockResetsJob implements Runnable {
List<DeferredBlockReset> deferred = new ArrayList<DeferredBlockReset>();
private final World world;
public DeferredBlockResetsJob(World world) {
this.world = world;
}
public void add(DeferredBlockReset pleaseResetLater) {
deferred.add(pleaseResetLater);
}
public boolean isEmpty() {
return deferred.isEmpty();
}
public void run() {
for(DeferredBlockReset reset : deferred) {
Block worldBlock = world.getBlockAt(reset.getX(), reset.getY(), reset.getZ());
worldBlock.setType(Material.getMaterial(reset.getBlockType()));
if(reset.getBlockType() == Material.SIGN_POST.getId()) {
BlockState state = worldBlock.getState();
state.setData(new org.bukkit.material.Sign(reset.getBlockType(), reset.getBlockData()));
if(state instanceof Sign) {
Sign sign = (Sign)state;
//String[] lines = this.getSignLines().get("sign-" + i + "-" + j + "-" + k);
if(reset.getLines() != null && sign.getLines() != null) {
if(reset.getLines().length>0)sign.setLine(0, reset.getLines()[0]);
if(reset.getLines().length>1)sign.setLine(1, reset.getLines()[1]);
if(reset.getLines().length>2)sign.setLine(2, reset.getLines()[2]);
if(reset.getLines().length>3)sign.setLine(3, reset.getLines()[3]);
sign.update(true);
}
}
} else {
// normal data reset
worldBlock.setData(reset.getBlockData());
}
}
}
}

View File

@ -34,12 +34,12 @@ public class VolumeMapper {
return volume;
}
public static ZoneVolume loadZoneVolume(String volumeName, String zoneName,
War war, World world, Warzone zone) {
ZoneVolume volume = new ZoneVolume(volumeName, war, world, zone);
load(volume, zoneName, war, world);
return volume;
}
// public static ZoneVolume loadZoneVolume(String volumeName, String zoneName,
// War war, World world, Warzone zone) {
// ZoneVolume volume = new ZoneVolume(volumeName, war, world, zone);
// load(volume, zoneName, war, world);
// return volume;
// }
public static void load(Volume volume, String zoneName, War war, World world) {
BufferedReader in = null;

View File

@ -28,7 +28,7 @@ import com.tommytony.war.volumes.ZoneVolume;
*/
public class WarzoneMapper {
public static Warzone load(War war, String name, boolean loadBlocks) {
public static Warzone load(War war, String name, boolean createNewVolume) {
//war.getLogger().info("Loading warzone " + name + " config and blocks...");
PropertiesFile warzoneConfig = new PropertiesFile(war.getDataFolder().getPath() + "/warzone-" + name + ".txt");
try {
@ -239,10 +239,8 @@ public class WarzoneMapper {
warzoneConfig.close();
if(loadBlocks) {
// zone blocks
ZoneVolume zoneVolume = VolumeMapper.loadZoneVolume(warzone.getName(), warzone.getName(), war, warzone.getWorld(), warzone);
if(createNewVolume) {
ZoneVolume zoneVolume = new ZoneVolume(warzone.getName(), war, world, warzone); //VolumeMapper.loadZoneVolume(warzone.getName(), warzone.getName(), war, warzone.getWorld(), warzone);
warzone.setVolume(zoneVolume);
}

View File

@ -0,0 +1,461 @@
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 java.util.ArrayList;
import java.util.List;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.Chest;
import org.bukkit.block.Dispenser;
import org.bukkit.block.Sign;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.MaterialData;
import bukkit.tommytony.war.War;
import com.tommytony.war.jobs.DeferredBlockResetsJob;
import com.tommytony.war.utils.DeferredBlockReset;
import com.tommytony.war.volumes.Volume;
import com.tommytony.war.volumes.ZoneVolume;
/**
* The ZoneVolumeMapper take the blocks from disk and sets them in the worlds, since
* the ZoneVolume doesn't hold its blocks in memory like regular Volumes.
*
* @author tommytony
*
*/
public class ZoneVolumeMapper {
public static int load(ZoneVolume volume, String zoneName, War war, World world) {
BufferedReader in = null;
int noOfResetBlocks = 0;
try {
if(zoneName.equals("")) in = new BufferedReader(new FileReader(new File(war.getDataFolder().getPath() +
"/dat/volume-" + volume.getName() + ".dat"))); // for the warhub
else in = new BufferedReader(new FileReader(new File(war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".dat")));
String firstLine = in.readLine();
if(firstLine != null && !firstLine.equals("")) {
boolean height129Fix = false;
int x1 = Integer.parseInt(in.readLine());
int y1 = Integer.parseInt(in.readLine());
if(y1 == 128) {
height129Fix = true;
y1 = 127;
}
int z1 = Integer.parseInt(in.readLine());
in.readLine();
int x2 = Integer.parseInt(in.readLine());
int y2 = Integer.parseInt(in.readLine());
if(y2 == 128) {
height129Fix = true;
y2 = 127;
}
int z2 = Integer.parseInt(in.readLine());
volume.setCornerOne(world.getBlockAt(x1, y1, z1));
volume.setCornerTwo(world.getBlockAt(x2, y2, z2));
DeferredBlockResetsJob deferred = new DeferredBlockResetsJob(world);
int blockReads = 0, visitedBlocks = 0, x = 0, y = 0, z = 0;
volume.clearBlocksThatDontFloat();
for(int i = 0; i < volume.getSizeX(); i++){
x = volume.getMinX();
for(int j = 0; j < volume.getSizeY(); j++) {
y = volume.getMinY();
for(int k = 0; k < volume.getSizeZ(); k++) {
z = volume.getMinZ();
try {
String blockLine = in.readLine();
if(blockLine != null && !blockLine.equals("")) {
String[] blockSplit = blockLine.split(",");
if(blockLine != null && !blockLine.equals("") && blockSplit.length > 1) {
int diskBlockType = Integer.parseInt(blockSplit[0]);
byte diskBlockData = Byte.parseByte(blockSplit[1]);
Block worldBlock = volume.getWorld().getBlockAt(x, y, z);
int worldBlockId = worldBlock.getTypeId();
if(worldBlockId != diskBlockType ||
(worldBlockId == diskBlockType && worldBlock.getData() != diskBlockData ) ||
(worldBlockId == diskBlockType && worldBlock.getData() == diskBlockData &&
(diskBlockType == Material.WALL_SIGN.getId() || diskBlockType == Material.SIGN_POST.getId()
|| diskBlockType == Material.CHEST.getId() || diskBlockType == Material.DISPENSER.getId())
)
) {
if(diskBlockType == Material.WALL_SIGN.getId()
|| diskBlockType == Material.SIGN_POST.getId()) {
// Signs read
String linesStr = "";
if(blockSplit.length > 2) {
for(int o = 2; o < blockSplit.length; o++) {
linesStr += blockSplit[o];
}
String[] lines = linesStr.split(";;");
// Signs set
// A sign post hanging on a wall south of here will
if(diskBlockType == Material.SIGN_POST.getId() && ((diskBlockData & 0x04) == 0x04)
&& i+1 != volume.getSizeX()) {
deferred.add(new DeferredBlockReset(x, y, z, diskBlockType, diskBlockData, lines));
} else {
worldBlock.setType(Material.getMaterial(diskBlockType));
BlockState state = worldBlock.getState();
state.setData(new org.bukkit.material.Sign(diskBlockType, diskBlockData));
if(state instanceof Sign) {
Sign sign = (Sign)state;
//String[] lines = this.getSignLines().get("sign-" + i + "-" + j + "-" + k);
if(lines != null && sign.getLines() != null) {
if(lines.length>0)sign.setLine(0, lines[0]);
if(lines.length>1)sign.setLine(1, lines[1]);
if(lines.length>2)sign.setLine(2, lines[2]);
if(lines.length>3)sign.setLine(3, lines[3]);
sign.update(true);
}
}
}
}
} else if(diskBlockType == Material.CHEST.getId()) {
// Chests read
List<ItemStack> items = new ArrayList<ItemStack>();
if(blockSplit.length > 2) {
String itemsStr = blockSplit[2];
String[] itemsStrSplit = itemsStr.split(";;");
for(String itemStr : itemsStrSplit) {
String[] itemStrSplit = itemStr.split(";");
if(itemStrSplit.length == 4) {
ItemStack stack = new ItemStack(Integer.parseInt(itemStrSplit[0]),
Integer.parseInt(itemStrSplit[1]));
stack.setData(new MaterialData(stack.getTypeId(),Byte.parseByte(itemStrSplit[3])));
short durability = (short)Integer.parseInt(itemStrSplit[2]);
stack.setDurability(durability);
items.add(stack);
} else if(itemStrSplit.length == 3) {
ItemStack stack = new ItemStack(Integer.parseInt(itemStrSplit[0]),
Integer.parseInt(itemStrSplit[1]));
short durability = (short)Integer.parseInt(itemStrSplit[2]);
stack.setDurability(durability);
items.add(stack);
} else {
items.add(new ItemStack(Integer.parseInt(itemStrSplit[0]),
Integer.parseInt(itemStrSplit[1])));
}
}
}
// Chests set
worldBlock.setType(Material.getMaterial(diskBlockType));
worldBlock.setData(diskBlockData);
BlockState state = worldBlock.getState();
if(state instanceof Chest) {
Chest chest = (Chest)state;
if(items != null) {
int ii = 0;
chest.getInventory().clear();
for(ItemStack item : items) {
if(item != null) {
chest.getInventory().setItem(ii, item);
ii++;
}
}
chest.update(true);
}
}
} else if(diskBlockType == Material.DISPENSER.getId()) {
// Dispensers read
List<ItemStack> items = new ArrayList<ItemStack>();
if(blockSplit.length > 2) {
String itemsStr = blockSplit[2];
String[] itemsStrSplit = itemsStr.split(";;");
for(String itemStr : itemsStrSplit) {
String[] itemStrSplit = itemStr.split(";");
if(itemStrSplit.length == 4) {
ItemStack stack = new ItemStack(Integer.parseInt(itemStrSplit[0]),
Integer.parseInt(itemStrSplit[1]));
stack.setData(new MaterialData(stack.getTypeId(),Byte.parseByte(itemStrSplit[3])));
short durability = (short)Integer.parseInt(itemStrSplit[2]);
stack.setDurability(durability);
items.add(stack);
} else if(itemStrSplit.length == 3) {
ItemStack stack = new ItemStack(Integer.parseInt(itemStrSplit[0]),
Integer.parseInt(itemStrSplit[1]));
short durability = (short)Integer.parseInt(itemStrSplit[2]);
stack.setDurability(durability);
items.add(stack);
} else {
items.add(new ItemStack(Integer.parseInt(itemStrSplit[0]),
Integer.parseInt(itemStrSplit[1])));
}
}
}
// Dispensers set
worldBlock.setType(Material.getMaterial(diskBlockType));
worldBlock.setData(diskBlockData);
BlockState state = worldBlock.getState();
if(state instanceof Dispenser) {
Dispenser dispenser = (Dispenser)state;
if(items != null) {
int ii = 0;
dispenser.getInventory().clear();
for(ItemStack item : items) {
if(item != null) {
dispenser.getInventory().setItem(ii, item);
ii++;
}
}
dispenser.update(true);
}
}
} else if(diskBlockType == Material.WOODEN_DOOR.getId() || diskBlockType == Material.IRON_DOOR_BLOCK.getId()){
// Door blocks
if(j-1 > 0) {
Block blockBelow = world.getBlockAt(x, y-1, z);
boolean belowIsGlass = blockBelow.getTypeId() == Material.GLASS.getId();
// Set current block to glass if block below isn't glass.
// Having a glass block below means the current block is a door top.
if(belowIsGlass) {
// Top door block. Set both it and the block below as door.
blockBelow.setType(Material.getMaterial(diskBlockType));
blockBelow.setData(diskBlockData);
worldBlock.setType(Material.getMaterial(diskBlockType));
worldBlock.setData(diskBlockData);
} else {
worldBlock.setType(Material.GLASS);
}
}
// Check if is bottom door block
// if(j+1 <= volume.getSizeY() && getBlockTypes()[i][j+1][k] == diskBlockType) {
// // set both door blocks right away
// worldBlock.setType(Material.getMaterial(diskBlockType));
// worldBlock.setData(diskBlockData);
// Block blockAbove = volume.getWorld().getBlockAt(x, y+1, z);
// blockAbove.setType(Material.getMaterial(diskBlockType));
// blockAbove.setData(getBlockDatas()[i][j+1][k]);
// }
} else if(((diskBlockType == Material.TORCH.getId() && ((diskBlockData & 0x02) == 0x02))
|| (diskBlockType == Material.REDSTONE_TORCH_OFF.getId() && ((diskBlockData & 0x02) == 0x02))
|| (diskBlockType == Material.REDSTONE_TORCH_ON.getId() && ((diskBlockData & 0x02) == 0x02))
|| (diskBlockType == Material.LEVER.getId() && ((diskBlockData & 0x02) == 0x02))
|| (diskBlockType == Material.STONE_BUTTON.getId() && ((diskBlockData & 0x02) == 0x02))
|| (diskBlockType == Material.LADDER.getId() && ((diskBlockData & 0x04) == 0x04))
|| (diskBlockType == Material.RAILS.getId() && ((diskBlockData & 0x02) == 0x02)))
&& i+1 != volume.getSizeX()){
// Blocks that hang on a block south of themselves need to make sure that block is there before placing themselves... lol
// Change the block itself later on:
deferred.add(new DeferredBlockReset(x, y, z, diskBlockType, diskBlockData));
} else {
// regular block
worldBlock.setType(Material.getMaterial(diskBlockType));
worldBlock.setData(diskBlockData);
}
noOfResetBlocks++;
}
visitedBlocks++;
}
blockReads++;
}
} catch (Exception e) {
volume.getWar().getLogger().warning("Failed to reset block in zone volume " + volume.getName() + ". "
+ "Blocks read: " + blockReads
+ ". Visited blocks so far:" + visitedBlocks
+ ". Blocks reset: "+ noOfResetBlocks +
". Error at x:" + x + " y:" + y + " z:" + z + ". Exception:" + e.getClass().toString() + " " + e.getMessage());
e.printStackTrace();
} finally {
z++;
}
}
if(height129Fix && j == volume.getSizeY() - 1) {
for(int skip = 0; skip < volume.getSizeZ(); skip++) {
in.readLine(); // throw away the extra vertical block I used to save pre 0.8
}
}
y++;
}
x++;
}
if(!deferred.isEmpty()) {
war.getServer().getScheduler().scheduleSyncDelayedTask(war, deferred, 1);
}
}
} catch (IOException e) {
war.logWarn("Failed to read volume file " + volume.getName() +
" for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage());
e.printStackTrace();
} catch (Exception e) {
war.logWarn("Unexpected error caused failure to read volume file " + zoneName +
" for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage());
e.printStackTrace();
} finally {
if(in != null)
try {
in.close();
} catch (IOException e) {
war.logWarn("Failed to close file reader for volume " + volume.getName() +
" for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage());
e.printStackTrace();
}
}
return noOfResetBlocks;
}
public static int save(Volume volume, String zoneName, War war) {
int noOfSavedBlocks = 0;
if(volume.hasTwoCorners()) {
BufferedWriter out = null;
try {
if(zoneName.equals("")) out = new BufferedWriter(new FileWriter(new File(war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".dat")));
else out = new BufferedWriter(new FileWriter(new File(war.getDataFolder().getPath() +
"/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".dat")));
out.write("corner1"); out.newLine();
out.write(Integer.toString(volume.getCornerOne().getX())); out.newLine();
out.write(Integer.toString(volume.getCornerOne().getY())); out.newLine();
out.write(Integer.toString(volume.getCornerOne().getZ())); out.newLine();
out.write("corner2"); out.newLine();
out.write(Integer.toString(volume.getCornerTwo().getX())); out.newLine();
out.write(Integer.toString(volume.getCornerTwo().getY())); out.newLine();
out.write(Integer.toString(volume.getCornerTwo().getZ())); out.newLine();
int x = 0;
int y = 0;
int z = 0;
for(int i = 0; i < volume.getSizeX(); i++){
x = volume.getMinX();
for(int j = 0; j < volume.getSizeY(); j++) {
y = volume.getMinY();
for(int k = 0; k < volume.getSizeZ(); k++) {
z = volume.getMaxZ();
try {
Block block = volume.getWorld().getBlockAt(x, y, z);
int typeId = block.getTypeId();
byte data = block.getData();
BlockState state = block.getState();
out.write(typeId + "," + data + ",");
if(state instanceof Sign) {
// Signs
String extra = "";
Sign sign = (Sign)state;
if(sign.getLines() != null) {
for(String line : sign.getLines()) {
extra += line + ";;";
}
out.write(extra);
}
} else if(state instanceof Chest) {
// Chests
Chest chest = (Chest)state;
Inventory inv = chest.getInventory();
int size = inv.getSize();
List<ItemStack> items = new ArrayList<ItemStack>();
for(int invIndex = 0; invIndex < size; invIndex++){
ItemStack item = inv.getItem(invIndex);
if(item != null && item.getType().getId() != Material.AIR.getId()) {
items.add(item);
}
}
String extra = "";
if(items != null) {
for(ItemStack item : items) {
if(item != null) {
extra += item.getTypeId() + ";"
+ item.getAmount() + ";"
+ item.getDurability();
if(item.getData() != null)
extra += ";" + item.getData().getData() ;
extra += ";;";
}
}
out.write(extra);
}
} else if(state instanceof Dispenser) {
// Dispensers
Dispenser dispenser = (Dispenser)state;
Inventory inv = dispenser.getInventory();
int size = inv.getSize();
List<ItemStack> items = new ArrayList<ItemStack>();
for(int invIndex = 0; invIndex < size; invIndex++){
ItemStack item = inv.getItem(invIndex);
if(item != null && item.getType().getId() != Material.AIR.getId()) {
items.add(item);
}
}
String extra = "";
if(items != null) {
for(ItemStack item : items) {
if(item != null) {
extra += item.getTypeId() + ";"
+ item.getAmount() + ";"
+ item.getDurability();
if(item.getData() != null)
extra += ";" + item.getData().getData() ;
extra += ";;";
}
}
out.write(extra);
}
}
noOfSavedBlocks++;
out.newLine();
}
catch (Exception e) {
war.logWarn("Unexpected error while saving a block to " +
" file for zone " + zoneName + ". Blocks saved so far: " + noOfSavedBlocks
+ "Position: x:" + x + " y:" + y + " z:" + z + ". " + e.getClass().getName() + " " + e.getMessage());
e.printStackTrace();
} finally {
z++;
}
}
y++;
}
x++;
}
} catch (IOException e) {
war.logWarn("Failed to write volume file " + zoneName +
" for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage());
e.printStackTrace();
} catch (Exception e) {
war.logWarn("Unexpected error caused failure 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.logWarn("Failed to close file writer for volume " + volume.getName() +
" for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage());
e.printStackTrace();
}
}
}
return noOfSavedBlocks;
}
public static void delete(Volume volume, War war) {
File volFile= new File("War/dat/volume-" + volume.getName());
boolean deletedData = volFile.delete();
if(!deletedData) {
war.logWarn("Failed to delete file " + volFile.getName());
}
}
}

View File

@ -0,0 +1,61 @@
package com.tommytony.war.utils;
import java.util.List;
import org.bukkit.inventory.ItemStack;
public class DeferredBlockReset {
private final int x;
private final int y;
private final int z;
private final int blockType;
private final byte blockData;
private String[] lines;
private List<ItemStack> items;
public DeferredBlockReset(int x, int y, int z, int blockType, byte blockData) {
this.x = x;
this.y = y;
this.z = z;
this.blockType = blockType;
this.blockData = blockData;
}
// Signs
public DeferredBlockReset(int x, int y, int z, int blockType, byte blockData, String[] signLines) {
this.x = x;
this.y = y;
this.z = z;
this.blockType = blockType;
this.blockData = blockData;
lines = signLines;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public int getZ() {
return z;
}
public int getBlockType() {
return blockType;
}
public byte getBlockData() {
return blockData;
}
public String[] getLines() {
return lines;
}
}

View File

@ -152,7 +152,7 @@ public class Volume {
int oldBlockType = 0;
clearBlocksThatDontFloat();
try {
if(hasTwoCorners() && getBlockTypes() != null) {
if(hasTwoCorners() && isSaved()) {
x = getMinX();
for(int i = 0; i < getSizeX(); i++){
y = getMinY();
@ -436,7 +436,7 @@ public class Volume {
public void setToMaterial(Material material) {
try {
if(hasTwoCorners() && getBlockTypes() != null) {
if(hasTwoCorners() && isSaved()) {
int x = getMinX();
for(int i = 0; i < getSizeX(); i++){
int y = getMaxY();
@ -459,7 +459,7 @@ public class Volume {
public void setFaceMaterial(BlockFace face, Material material) {
try {
if(hasTwoCorners() && getBlockTypes() != null) {
if(hasTwoCorners() && isSaved()) {
int x = getMinX();
for(int i = 0; i < getSizeX(); i++){
int y = getMinY();
@ -489,7 +489,7 @@ public class Volume {
private void switchMaterials(Material[] oldTypes, Material newType) {
try {
if(hasTwoCorners() && getBlockTypes() != null) {
if(hasTwoCorners() && isSaved()) {
int x = getMinX();
for(int i = 0; i < getSizeX(); i++){
int y = getMaxY();

View File

@ -1,16 +1,15 @@
package com.tommytony.war.volumes;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import com.tommytony.war.Warzone;
import com.tommytony.war.Team;
import com.tommytony.war.Monument;
import bukkit.tommytony.war.War;
import com.tommytony.war.Monument;
import com.tommytony.war.Team;
import com.tommytony.war.Warzone;
import com.tommytony.war.mappers.ZoneVolumeMapper;
/**
*
* @author tommytony
@ -19,11 +18,45 @@ import bukkit.tommytony.war.War;
public class ZoneVolume extends Volume {
private Warzone zone;
private boolean isSaved = false;
public ZoneVolume(String name, War war, World world, Warzone zone) {
super(name, war, world);
this.zone = zone;
}
@Override
public int saveBlocks() {
// Save blocks directly to disk (i.e. don't put everything in memory)
int saved = ZoneVolumeMapper.save(this, zone.getName(), this.getWar());
isSaved = true;
return saved;
}
@Override
public boolean isSaved() {
return isSaved;
}
@Override
public int resetBlocks() {
// Load blocks directly from disk and onto the map (i.e. no more in-memory warzone blocks)
int reset = ZoneVolumeMapper.load(this, zone.getName(), this.getWar(), this.getWorld());
isSaved = true;
return reset;
}
@Override
public void setBlockTypes(int[][][] blockTypes) {
return;
}
@Override
public void setBlockDatas(byte[][][] blockData) {
return;
}
public void setNorthwest(Block block) throws NotNorthwestException, TooSmallException, TooBigException {
// northwest defaults to top block
@ -293,7 +326,7 @@ public class ZoneVolume extends Volume {
return false;
}
public int resetWallBlocks(BlockFace wall) {
/*public int resetWallBlocks(BlockFace wall) {
int noOfResetBlocks = 0;
try {
if(hasTwoCorners() && getBlockTypes() != null) {
@ -407,6 +440,7 @@ public class ZoneVolume extends Volume {
return noOfResetBlocks;
}
private boolean resetBlock(int oldBlockType, byte oldBlockData, Block currentBlock) {
if(currentBlock.getTypeId() != oldBlockType ||
(currentBlock.getTypeId() == oldBlockType && currentBlock.getData() != oldBlockData) ||
@ -421,6 +455,7 @@ public class ZoneVolume extends Volume {
}
return false;
}
*/
}

View File

@ -1,5 +1,5 @@
name: War
version: 1.5.1 (MacArthur)
version: 1.6 (de Gaulle)
description: Lets you create TDM and CTF (warzones) for a more structured PVP experience.
author: tommytony
website: war.tommytony.com

View File

@ -1,5 +1,5 @@
name: War
version: 1.5.1 (MacArthur)
version: 1.6 (de Gaulle)
description: Lets you create TDM and CTF (warzones) for a more structured PVP experience.
author: tommytony
website: war.tommytony.com