Reverting e9193565f3 (the War singleton) because it caused unpredictable behavior. For example, doubly nested scheduler calls would cause NPEs when accessing the somehow null singleton. Sorry Tim.

This commit is contained in:
taoneill 2011-07-17 20:36:44 -04:00
parent 354955c04e
commit 797ca9246b
23 changed files with 580 additions and 517 deletions

View File

@ -33,17 +33,17 @@ import com.tommytony.war.utils.*;
/** /**
* Main class of War * Main class of War
* *
* @author tommytony, Tim Düsterhus * @author tommytony, Tim Düsterhus
* @package bukkit.tommytony.war * @package bukkit.tommytony.war
*/ */
public class War extends JavaPlugin { public class War extends JavaPlugin {
public static PermissionHandler permissionHandler; public static PermissionHandler permissionHandler;
public static War war; public static War war;
// general // general
private WarPlayerListener playerListener = new WarPlayerListener(); private WarPlayerListener playerListener = new WarPlayerListener(this);
private WarEntityListener entityListener = new WarEntityListener(); private WarEntityListener entityListener = new WarEntityListener(this);
private WarBlockListener blockListener = new WarBlockListener(); private WarBlockListener blockListener = new WarBlockListener(this);
private Logger log; private Logger log;
private PluginDescriptionFile desc = null; private PluginDescriptionFile desc = null;
private boolean loaded = false; private boolean loaded = false;
@ -134,7 +134,7 @@ public class War extends JavaPlugin {
this.getDefaultLoadout().put(4, new ItemStack(Material.STONE_SPADE, 1, (byte) 8)); this.getDefaultLoadout().put(4, new ItemStack(Material.STONE_SPADE, 1, (byte) 8));
this.getDefaultReward().put(0, new ItemStack(Material.CAKE, 1)); this.getDefaultReward().put(0, new ItemStack(Material.CAKE, 1));
WarMapper.load(); WarMapper.load(this);
this.log("War v" + this.desc.getVersion() + " is on.", Level.INFO); this.log("War v" + this.desc.getVersion() + " is on.", Level.INFO);
} }
@ -308,7 +308,7 @@ public class War extends JavaPlugin {
this.getZoneMakersImpersonatingPlayers().remove(player.getName()); this.getZoneMakersImpersonatingPlayers().remove(player.getName());
this.msg(player, "You are back as a zone maker."); this.msg(player, "You are back as a zone maker.");
} }
WarMapper.save(); WarMapper.save(this);
} }
public void performZonemakerAsZonemaker(Player player, String[] arguments) { public void performZonemakerAsZonemaker(Player player, String[] arguments) {
@ -342,7 +342,7 @@ public class War extends JavaPlugin {
this.msg(player, "You are now impersonating a regular player. Type /zonemaker again to toggle back to war maker mode."); this.msg(player, "You are now impersonating a regular player. Type /zonemaker again to toggle back to war maker mode.");
} }
WarMapper.save(); WarMapper.save(this);
} }
} }
@ -351,7 +351,7 @@ public class War extends JavaPlugin {
this.badMsg(player, "Usage: /setwarconfig pvpinzonesonly:on lifepool:8 teamsize:5 maxscore:7 autoassign:on outline:off ff:on " + "Changes the server defaults for new warzones. Please give at leaset one named parameter."); this.badMsg(player, "Usage: /setwarconfig pvpinzonesonly:on lifepool:8 teamsize:5 maxscore:7 autoassign:on outline:off ff:on " + "Changes the server defaults for new warzones. Please give at leaset one named parameter.");
} else { } else {
if (this.updateFromNamedParams(player, arguments)) { if (this.updateFromNamedParams(player, arguments)) {
WarMapper.save(); WarMapper.save(this);
this.msg(player, "War config saved."); this.msg(player, "War config saved.");
} else { } else {
this.badMsg(player, "Failed to read named parameters."); this.badMsg(player, "Failed to read named parameters.");
@ -376,7 +376,7 @@ public class War extends JavaPlugin {
} else { } else {
this.badMsg(player, "No War hub to delete."); this.badMsg(player, "No War hub to delete.");
} }
WarMapper.save(); WarMapper.save(this);
} }
public void performSetWarhub(Player player) { public void performSetWarhub(Player player) {
@ -388,7 +388,7 @@ public class War extends JavaPlugin {
this.warHub.initialize(); this.warHub.initialize();
this.msg(player, "War hub moved."); this.msg(player, "War hub moved.");
} else { } else {
this.warHub = new WarHub(player.getLocation()); this.warHub = new WarHub(this, player.getLocation());
this.warHub.initialize(); this.warHub.initialize();
for (Warzone zone : this.warzones) { for (Warzone zone : this.warzones) {
if (zone.getLobby() != null) { if (zone.getLobby() != null) {
@ -398,7 +398,7 @@ public class War extends JavaPlugin {
} }
this.msg(player, "War hub created."); this.msg(player, "War hub created.");
} }
WarMapper.save(); WarMapper.save(this);
} else { } else {
this.badMsg(player, "No warzones yet."); this.badMsg(player, "No warzones yet.");
} }
@ -420,7 +420,7 @@ public class War extends JavaPlugin {
if (monument != null) { if (monument != null) {
monument.getVolume().resetBlocks(); monument.getVolume().resetBlocks();
warzone.getMonuments().remove(monument); warzone.getMonuments().remove(monument);
WarzoneMapper.save(warzone, false); WarzoneMapper.save(this, warzone, false);
this.msg(player, "Monument " + monument.getName() + " removed."); this.msg(player, "Monument " + monument.getName() + " removed.");
} else { } else {
this.badMsg(player, "No such monument."); this.badMsg(player, "No such monument.");
@ -442,11 +442,11 @@ public class War extends JavaPlugin {
this.msg(player, "Monument " + monument.getName() + " was moved."); this.msg(player, "Monument " + monument.getName() + " was moved.");
} else { } else {
// create a new monument // create a new monument
Monument monument = new Monument(arguments[0], warzone, player.getLocation()); Monument monument = new Monument(arguments[0], this, warzone, player.getLocation());
warzone.getMonuments().add(monument); warzone.getMonuments().add(monument);
this.msg(player, "Monument " + monument.getName() + " created."); this.msg(player, "Monument " + monument.getName() + " created.");
} }
WarzoneMapper.save(warzone, false); WarzoneMapper.save(this, warzone, false);
} }
} }
@ -475,7 +475,7 @@ public class War extends JavaPlugin {
// warzone.addZoneOutline(warzone.getLobby().getWall()); // warzone.addZoneOutline(warzone.getLobby().getWall());
warzone.getLobby().initialize(); warzone.getLobby().initialize();
} }
WarzoneMapper.save(warzone, false); WarzoneMapper.save(this, warzone, false);
this.msg(player, "Team " + team.getName() + " removed."); this.msg(player, "Team " + team.getName() + " removed.");
} else { } else {
this.badMsg(player, "No such team."); this.badMsg(player, "No such team.");
@ -499,7 +499,7 @@ public class War extends JavaPlugin {
Location playerLoc = player.getLocation(); Location playerLoc = player.getLocation();
player.teleport(new Location(playerLoc.getWorld(), playerLoc.getBlockX() + 1, playerLoc.getBlockY(), playerLoc.getBlockZ())); player.teleport(new Location(playerLoc.getWorld(), playerLoc.getBlockX() + 1, playerLoc.getBlockY(), playerLoc.getBlockZ()));
this.msg(player, "Team " + team.getName() + " flag added here."); this.msg(player, "Team " + team.getName() + " flag added here.");
WarzoneMapper.save(warzone, false); WarzoneMapper.save(this, warzone, false);
} else { } else {
// relocate flag // relocate flag
team.getFlagVolume().resetBlocks(); team.getFlagVolume().resetBlocks();
@ -507,7 +507,7 @@ public class War extends JavaPlugin {
Location playerLoc = player.getLocation(); Location playerLoc = player.getLocation();
player.teleport(new Location(playerLoc.getWorld(), playerLoc.getBlockX() + 1, playerLoc.getBlockY(), playerLoc.getBlockZ() + 1)); player.teleport(new Location(playerLoc.getWorld(), playerLoc.getBlockX() + 1, playerLoc.getBlockY(), playerLoc.getBlockZ() + 1));
this.msg(player, "Team " + team.getName() + " flag moved."); this.msg(player, "Team " + team.getName() + " flag moved.");
WarzoneMapper.save(warzone, false); WarzoneMapper.save(this, warzone, false);
} }
} }
} }
@ -525,7 +525,7 @@ public class War extends JavaPlugin {
this.msg(player, "Team " + existingTeam.getName() + " spawn relocated."); this.msg(player, "Team " + existingTeam.getName() + " spawn relocated.");
} else { } else {
// new team (use default TeamKind name for now) // new team (use default TeamKind name for now)
Team newTeam = new Team(teamKind.getDefaultName(), teamKind, player.getLocation(), warzone); Team newTeam = new Team(teamKind.getDefaultName(), teamKind, player.getLocation(), this, warzone);
newTeam.setRemainingLives(warzone.getLifePool()); newTeam.setRemainingLives(warzone.getLifePool());
warzone.getTeams().add(newTeam); warzone.getTeams().add(newTeam);
if (warzone.getLobby() != null) { if (warzone.getLobby() != null) {
@ -538,7 +538,7 @@ public class War extends JavaPlugin {
this.msg(player, "Team " + newTeam.getName() + " created with spawn here."); this.msg(player, "Team " + newTeam.getName() + " created with spawn here.");
} }
WarzoneMapper.save(warzone, false); WarzoneMapper.save(this, warzone, false);
} }
} }
@ -589,8 +589,8 @@ public class War extends JavaPlugin {
} }
warzone.getVolume().resetBlocks(); warzone.getVolume().resetBlocks();
this.getWarzones().remove(warzone); this.getWarzones().remove(warzone);
WarMapper.save(); WarMapper.save(this);
WarzoneMapper.delete(warzone.getName()); WarzoneMapper.delete(this, warzone.getName());
if (this.warHub != null) { // warhub has to change if (this.warHub != null) { // warhub has to change
this.warHub.getVolume().resetBlocks(); this.warHub.getVolume().resetBlocks();
this.warHub.initialize(); this.warHub.initialize();
@ -644,7 +644,7 @@ public class War extends JavaPlugin {
} }
if (this.updateZoneFromNamedParams(warzone, player, arguments)) { if (this.updateZoneFromNamedParams(warzone, player, arguments)) {
this.msg(player, "Saving config and resetting warzone " + warzone.getName() + "."); this.msg(player, "Saving config and resetting warzone " + warzone.getName() + ".");
WarzoneMapper.save(warzone, false); WarzoneMapper.save(this, warzone, false);
warzone.getVolume().resetBlocks(); warzone.getVolume().resetBlocks();
if (lobby != null) { if (lobby != null) {
lobby.getVolume().resetBlocks(); lobby.getVolume().resetBlocks();
@ -678,7 +678,7 @@ public class War extends JavaPlugin {
if (arguments.length > 0) { if (arguments.length > 0) {
// changed settings: must reinitialize with new settings // changed settings: must reinitialize with new settings
this.updateZoneFromNamedParams(warzone, player, arguments); this.updateZoneFromNamedParams(warzone, player, arguments);
WarzoneMapper.save(warzone, true); WarzoneMapper.save(this, warzone, true);
warzone.getVolume().resetBlocks(); warzone.getVolume().resetBlocks();
if (lobby != null) { if (lobby != null) {
lobby.getVolume().resetBlocks(); lobby.getVolume().resetBlocks();
@ -735,7 +735,7 @@ public class War extends JavaPlugin {
this.msg(player, "Warzone lobby moved to " + wallStr + " side of zone."); this.msg(player, "Warzone lobby moved to " + wallStr + " side of zone.");
} else { } else {
// new lobby // new lobby
lobby = new ZoneLobby(warzone, wall); lobby = new ZoneLobby(this, warzone, wall);
warzone.setLobby(lobby); warzone.setLobby(lobby);
lobby.initialize(); lobby.initialize();
if (this.warHub != null) { // warhub has to change if (this.warHub != null) { // warhub has to change
@ -744,7 +744,7 @@ public class War extends JavaPlugin {
} }
this.msg(player, "Warzone lobby created on " + wallStr + "side of zone."); this.msg(player, "Warzone lobby created on " + wallStr + "side of zone.");
} }
WarzoneMapper.save(warzone, false); WarzoneMapper.save(this, warzone, false);
} else { } else {
// Not in a warzone: set the lobby position to where the player is standing // Not in a warzone: set the lobby position to where the player is standing
Warzone warzone = this.matchWarzone(arguments[0]); Warzone warzone = this.matchWarzone(arguments[0]);
@ -761,7 +761,7 @@ public class War extends JavaPlugin {
this.msg(player, "Warzone lobby moved to your location."); this.msg(player, "Warzone lobby moved to your location.");
} else { } else {
// new lobby // new lobby
lobby = new ZoneLobby(warzone, player.getLocation()); lobby = new ZoneLobby(this, warzone, player.getLocation());
warzone.setLobby(lobby); warzone.setLobby(lobby);
lobby.initialize(); lobby.initialize();
if (this.warHub != null) { // warhub has to change if (this.warHub != null) { // warhub has to change
@ -770,7 +770,7 @@ public class War extends JavaPlugin {
} }
this.msg(player, "Warzone lobby moved to your location."); this.msg(player, "Warzone lobby moved to your location.");
} }
WarzoneMapper.save(warzone, false); WarzoneMapper.save(this, warzone, false);
} }
} }
} }
@ -784,7 +784,7 @@ public class War extends JavaPlugin {
this.badMsg(player, "Usage: =<Classic mode>= /setzone <warzone-name> <'northwest'/'southeast'/'nw'/'se'> (NW defaults to top block, SE to bottom). " + "=<Wand Cuboid mode>= /setzone <warzone-name> wand (gives you a wooden sword to right and left click, drop to disable). " + "=<Wandless Cuboid mode>= /setzone <warzone-name> <'corner1'/'corner2'/'c1'/'c2'/'pos1'/'pos2'> (block where you're standing). " + "Set one corner, then the next. Defines the outline of the warzone, which will be reset at the start of every battle. " + "Saves the zone blocks if the outline is valid."); this.badMsg(player, "Usage: =<Classic mode>= /setzone <warzone-name> <'northwest'/'southeast'/'nw'/'se'> (NW defaults to top block, SE to bottom). " + "=<Wand Cuboid mode>= /setzone <warzone-name> wand (gives you a wooden sword to right and left click, drop to disable). " + "=<Wandless Cuboid mode>= /setzone <warzone-name> <'corner1'/'corner2'/'c1'/'c2'/'pos1'/'pos2'> (block where you're standing). " + "Set one corner, then the next. Defines the outline of the warzone, which will be reset at the start of every battle. " + "Saves the zone blocks if the outline is valid.");
} }
} else { } else {
ZoneSetter setter = new ZoneSetter(player, arguments[0]); ZoneSetter setter = new ZoneSetter(this, player, arguments[0]);
if (arguments[1].equals("northwest") || arguments[1].equals("nw")) { if (arguments[1].equals("northwest") || arguments[1].equals("nw")) {
setter.placeNorthwest(); setter.placeNorthwest();
} else if (arguments[1].equals("southeast") || arguments[1].equals("se")) { } else if (arguments[1].equals("southeast") || arguments[1].equals("se")) {
@ -1155,7 +1155,7 @@ public class War extends JavaPlugin {
this.badMsg(player, "Can't set rally point. No such warzone."); this.badMsg(player, "Can't set rally point. No such warzone.");
} else { } else {
zone.setRallyPoint(player.getLocation()); zone.setRallyPoint(player.getLocation());
WarzoneMapper.save(zone, false); WarzoneMapper.save(this, zone, false);
} }
} }

View File

@ -18,20 +18,26 @@ import com.tommytony.war.Team;
import com.tommytony.war.Warzone; import com.tommytony.war.Warzone;
/** /**
* *
* @author tommytony * @author tommytony
* *
*/ */
public class WarBlockListener extends BlockListener { public class WarBlockListener extends BlockListener {
private War war;
public WarBlockListener(War war) {
this.war = war;
}
@Override @Override
public void onBlockPlace(BlockPlaceEvent event) { public void onBlockPlace(BlockPlaceEvent event) {
if (War.war.isLoaded()) { if (this.war.isLoaded()) {
Player player = event.getPlayer(); Player player = event.getPlayer();
Block block = event.getBlock(); Block block = event.getBlock();
if (player != null && block != null) { if (player != null && block != null) {
Team team = War.war.getPlayerTeam(player.getName()); Team team = this.war.getPlayerTeam(player.getName());
Warzone zone = War.war.warzone(player.getLocation()); Warzone zone = this.war.warzone(player.getLocation());
if (team != null && block != null && zone != null && zone.isMonumentCenterBlock(block) && block.getType() == team.getKind().getMaterial() && block.getData() == team.getKind().getData()) { if (team != null && block != null && zone != null && zone.isMonumentCenterBlock(block) && block.getType() == team.getKind().getMaterial() && block.getData() == team.getKind().getData()) {
Monument monument = zone.getMonumentFromCenterBlock(block); Monument monument = zone.getMonumentFromCenterBlock(block);
if (monument != null && !monument.hasOwner()) { if (monument != null && !monument.hasOwner()) {
@ -43,49 +49,49 @@ public class WarBlockListener extends BlockListener {
event.setCancelled(false); event.setCancelled(false);
return; // important otherwise cancelled down a few line by isImportantblock return; // important otherwise cancelled down a few line by isImportantblock
} else { } else {
War.war.badMsg(player, "You can't capture a monument without a block of your team's material. Get one from your team spawn."); this.war.badMsg(player, "You can't capture a monument without a block of your team's material. Get one from your team spawn.");
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
} }
boolean isZoneMaker = War.war.isZoneMaker(player); boolean isZoneMaker = this.war.isZoneMaker(player);
if (zone != null && zone.isImportantBlock(block) && (!isZoneMaker || (isZoneMaker && team != null))) { if (zone != null && zone.isImportantBlock(block) && (!isZoneMaker || (isZoneMaker && team != null))) {
War.war.badMsg(player, "Can't build here."); this.war.badMsg(player, "Can't build here.");
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
// protect warzone lobbies // protect warzone lobbies
for (Warzone wz : War.war.getWarzones()) { for (Warzone wz : this.war.getWarzones()) {
if (wz.getLobby() != null && wz.getLobby().getVolume() != null && wz.getLobby().getVolume().contains(block)) { if (wz.getLobby() != null && wz.getLobby().getVolume() != null && wz.getLobby().getVolume().contains(block)) {
War.war.badMsg(player, "Can't build here."); this.war.badMsg(player, "Can't build here.");
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
} }
// protect the hub // protect the hub
if (War.war.getWarHub() != null && War.war.getWarHub().getVolume().contains(block)) { if (this.war.getWarHub() != null && this.war.getWarHub().getVolume().contains(block)) {
War.war.badMsg(player, "Can't build here."); this.war.badMsg(player, "Can't build here.");
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
// buildInZonesOnly // buildInZonesOnly
if (zone == null && War.war.isBuildInZonesOnly() && !War.war.canBuildOutsideZone(player)) { if (zone == null && this.war.isBuildInZonesOnly() && !this.war.canBuildOutsideZone(player)) {
War.war.badMsg(player, "You can only build inside warzones. Ask for the 'war.build' permission to build outside."); this.war.badMsg(player, "You can only build inside warzones. Ask for the 'war.build' permission to build outside.");
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
// can't place a block of your team's color // can't place a block of your team's color
if (team != null && block.getType() == team.getKind().getMaterial() && block.getData() == team.getKind().getData()) { if (team != null && block.getType() == team.getKind().getMaterial() && block.getData() == team.getKind().getData()) {
War.war.badMsg(player, "You can only use your team's blocks to capture monuments."); this.war.badMsg(player, "You can only use your team's blocks to capture monuments.");
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
if (team != null && zone != null && zone.isFlagThief(player.getName())) { if (team != null && zone != null && zone.isFlagThief(player.getName())) {
// a flag thief can't drop his flag // a flag thief can't drop his flag
War.war.badMsg(player, "Can't drop the flag. What are you doing? Run!"); this.war.badMsg(player, "Can't drop the flag. What are you doing? Run!");
event.setCancelled(true); event.setCancelled(true);
} }
@ -93,7 +99,7 @@ public class WarBlockListener extends BlockListener {
// unbreakableZoneBlocks // unbreakableZoneBlocks
if (zone != null && zone.isUnbreakableZoneBlocks() && (!isZoneMaker || (isZoneMaker && team != null))) { if (zone != null && zone.isUnbreakableZoneBlocks() && (!isZoneMaker || (isZoneMaker && team != null))) {
// if the zone is unbreakable, no one but zone makers can break blocks (even then, zone makers in a team can't break blocks) // if the zone is unbreakable, no one but zone makers can break blocks (even then, zone makers in a team can't break blocks)
War.war.badMsg(player, "The blocks in this zone are unbreakable - this also means you can't build!"); this.war.badMsg(player, "The blocks in this zone are unbreakable - this also means you can't build!");
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@ -103,7 +109,7 @@ public class WarBlockListener extends BlockListener {
@Override @Override
public void onBlockBreak(BlockBreakEvent event) { public void onBlockBreak(BlockBreakEvent event) {
if (War.war.isLoaded()) { if (this.war.isLoaded()) {
Player player = event.getPlayer(); Player player = event.getPlayer();
Block block = event.getBlock(); Block block = event.getBlock();
if (player != null && block != null) { if (player != null && block != null) {
@ -113,13 +119,13 @@ public class WarBlockListener extends BlockListener {
} }
private void handleBreakOrDamage(Player player, Block block, Cancellable event) { private void handleBreakOrDamage(Player player, Block block, Cancellable event) {
Warzone warzone = War.war.warzone(player.getLocation()); Warzone warzone = this.war.warzone(player.getLocation());
Team team = War.war.getPlayerTeam(player.getName()); Team team = this.war.getPlayerTeam(player.getName());
boolean isZoneMaker = War.war.isZoneMaker(player); boolean isZoneMaker = this.war.isZoneMaker(player);
if (warzone != null && team == null && !isZoneMaker) { if (warzone != null && team == null && !isZoneMaker) {
// can't actually destroy blocks in a warzone if not part of a team // can't actually destroy blocks in a warzone if not part of a team
War.war.badMsg(player, "Can't destroy part of a warzone if you're not in a team."); this.war.badMsg(player, "Can't destroy part of a warzone if you're not in a team.");
event.setCancelled(true); event.setCancelled(true);
return; return;
} else if (team != null && block != null && warzone != null && warzone.isMonumentCenterBlock(block)) { } else if (team != null && block != null && warzone != null && warzone.isMonumentCenterBlock(block)) {
@ -139,7 +145,7 @@ public class WarBlockListener extends BlockListener {
if (team != null && team.getSpawnVolume().contains(block)) { if (team != null && team.getSpawnVolume().contains(block)) {
ItemStack teamKindBlock = new ItemStack(team.getKind().getMaterial(), team.getKind().getData()); ItemStack teamKindBlock = new ItemStack(team.getKind().getMaterial(), team.getKind().getData());
if (player.getInventory().contains(teamKindBlock)) { if (player.getInventory().contains(teamKindBlock)) {
War.war.badMsg(player, "You already have a " + team.getName() + " block."); this.war.badMsg(player, "You already have a " + team.getName() + " block.");
event.setCancelled(true); event.setCancelled(true);
return; return;
} else { } else {
@ -150,7 +156,7 @@ public class WarBlockListener extends BlockListener {
} else if (team != null && warzone.isEnemyTeamFlagBlock(team, block)) { } else if (team != null && warzone.isEnemyTeamFlagBlock(team, block)) {
if (warzone.isFlagThief(player.getName())) { if (warzone.isFlagThief(player.getName())) {
// detect audacious thieves // detect audacious thieves
War.war.badMsg(player, "You can only steal one flag at a time!"); this.war.badMsg(player, "You can only steal one flag at a time!");
} else { } else {
Team lostFlagTeam = warzone.getTeamForFlagBlock(block); Team lostFlagTeam = warzone.getTeamForFlagBlock(block);
if (lostFlagTeam.getPlayers().size() != 0) { if (lostFlagTeam.getPlayers().size() != 0) {
@ -168,15 +174,15 @@ public class WarBlockListener extends BlockListener {
+ " from reaching team " + team.getName() + "'s spawn or flag."); + " from reaching team " + team.getName() + "'s spawn or flag.");
} }
} }
War.war.msg(player, "You have team " + lostFlagTeam.getName() + "'s flag. Reach your team spawn or flag to capture it!"); this.war.msg(player, "You have team " + lostFlagTeam.getName() + "'s flag. Reach your team spawn or flag to capture it!");
} else { } else {
War.war.msg(player, "You can't steal team " + lostFlagTeam.getName() + "'s flag since no players are on that team."); this.war.msg(player, "You can't steal team " + lostFlagTeam.getName() + "'s flag since no players are on that team.");
} }
} }
event.setCancelled(true); event.setCancelled(true);
return; return;
} else if (!warzone.isMonumentCenterBlock(block)) { } else if (!warzone.isMonumentCenterBlock(block)) {
War.war.badMsg(player, "Can't destroy this."); this.war.badMsg(player, "Can't destroy this.");
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@ -184,9 +190,9 @@ public class WarBlockListener extends BlockListener {
// protect warzone lobbies // protect warzone lobbies
if (block != null) { if (block != null) {
for (Warzone zone : War.war.getWarzones()) { for (Warzone zone : this.war.getWarzones()) {
if (zone.getLobby() != null && zone.getLobby().getVolume() != null && zone.getLobby().getVolume().contains(block)) { if (zone.getLobby() != null && zone.getLobby().getVolume() != null && zone.getLobby().getVolume().contains(block)) {
War.war.badMsg(player, "Can't destroy this."); this.war.badMsg(player, "Can't destroy this.");
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@ -194,16 +200,16 @@ public class WarBlockListener extends BlockListener {
} }
// protect the hub // protect the hub
if (War.war.getWarHub() != null && War.war.getWarHub().getVolume().contains(block)) { if (this.war.getWarHub() != null && this.war.getWarHub().getVolume().contains(block)) {
War.war.badMsg(player, "Can't destroy this."); this.war.badMsg(player, "Can't destroy this.");
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
// buildInZonesOnly // buildInZonesOnly
Warzone blockZone = War.war.warzone(new Location(block.getWorld(), block.getX(), block.getY(), block.getZ())); Warzone blockZone = this.war.warzone(new Location(block.getWorld(), block.getX(), block.getY(), block.getZ()));
if (blockZone == null && War.war.isBuildInZonesOnly() && !War.war.canBuildOutsideZone(player)) { if (blockZone == null && this.war.isBuildInZonesOnly() && !this.war.canBuildOutsideZone(player)) {
War.war.badMsg(player, "You can only build inside warzones. Ask for the 'war.build' permission to build outside."); this.war.badMsg(player, "You can only build inside warzones. Ask for the 'war.build' permission to build outside.");
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@ -211,7 +217,7 @@ public class WarBlockListener extends BlockListener {
// unbreakableZoneBlocks // unbreakableZoneBlocks
if (blockZone != null && blockZone.isUnbreakableZoneBlocks() && (!isZoneMaker || (isZoneMaker && team != null))) { if (blockZone != null && blockZone.isUnbreakableZoneBlocks() && (!isZoneMaker || (isZoneMaker && team != null))) {
// if the zone is unbreakable, no one but zone makers can break blocks (even then, zone makers in a team can't break blocks // if the zone is unbreakable, no one but zone makers can break blocks (even then, zone makers in a team can't break blocks
War.war.badMsg(player, "The blocks in this zone are unbreakable!"); this.war.badMsg(player, "The blocks in this zone are unbreakable!");
event.setCancelled(true); event.setCancelled(true);
return; return;
} }

View File

@ -15,6 +15,7 @@ import org.bukkit.event.entity.EntityCombustEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageByProjectileEvent; import org.bukkit.event.entity.EntityDamageByProjectileEvent;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntityListener; import org.bukkit.event.entity.EntityListener;
import org.bukkit.event.entity.EntityRegainHealthEvent; import org.bukkit.event.entity.EntityRegainHealthEvent;
@ -31,6 +32,17 @@ import com.tommytony.war.Warzone;
*/ */
public class WarEntityListener extends EntityListener { public class WarEntityListener extends EntityListener {
/**
* Instance of war
*
* @var War
*/
private final War war;
public WarEntityListener(War war) {
this.war = war;
}
/** /**
* Handles PVP-Damage * Handles PVP-Damage
* *
@ -44,21 +56,21 @@ public class WarEntityListener extends EntityListener {
// only let adversaries (same warzone, different team) attack each other // only let adversaries (same warzone, different team) attack each other
Player a = (Player) attacker; Player a = (Player) attacker;
Player d = (Player) defender; Player d = (Player) defender;
Warzone attackerWarzone = War.war.getPlayerTeamWarzone(a.getName()); Warzone attackerWarzone = this.war.getPlayerTeamWarzone(a.getName());
Team attackerTeam = War.war.getPlayerTeam(a.getName()); Team attackerTeam = this.war.getPlayerTeam(a.getName());
Warzone defenderWarzone = War.war.getPlayerTeamWarzone(d.getName()); Warzone defenderWarzone = this.war.getPlayerTeamWarzone(d.getName());
Team defenderTeam = War.war.getPlayerTeam(d.getName()); Team defenderTeam = this.war.getPlayerTeam(d.getName());
if (attackerTeam != null && defenderTeam != null && attackerTeam != defenderTeam && attackerWarzone == defenderWarzone) { if (attackerTeam != null && defenderTeam != null && attackerTeam != defenderTeam && attackerWarzone == defenderWarzone) {
// Make sure one of the players isn't in the spawn // Make sure one of the players isn't in the spawn
if (defenderTeam.getSpawnVolume().contains(d.getLocation())) { // attacking person in spawn if (defenderTeam.getSpawnVolume().contains(d.getLocation())) { // attacking person in spawn
if (!defenderWarzone.isFlagThief(d.getName())) { // thiefs can always be attacked if (!defenderWarzone.isFlagThief(d.getName())) { // thiefs can always be attacked
War.war.badMsg(a, "Can't attack a player that's inside his team's spawn."); this.war.badMsg(a, "Can't attack a player that's inside his team's spawn.");
event.setCancelled(true); event.setCancelled(true);
} }
} else if (attackerTeam.getSpawnVolume().contains(a.getLocation()) && !attackerTeam.getSpawnVolume().contains(d.getLocation())) { } else if (attackerTeam.getSpawnVolume().contains(a.getLocation()) && !attackerTeam.getSpawnVolume().contains(d.getLocation())) {
// only let a player inside spawn attack an enemy player if that player enters the spawn // only let a player inside spawn attack an enemy player if that player enters the spawn
if (!attackerWarzone.isFlagThief(a.getName())) { // thiefs can always attack if (!attackerWarzone.isFlagThief(a.getName())) { // thiefs can always attack
War.war.badMsg(a, "Can't attack a player from inside your spawn."); this.war.badMsg(a, "Can't attack a player from inside your spawn.");
event.setCancelled(true); event.setCancelled(true);
} }
} }
@ -77,30 +89,30 @@ public class WarEntityListener extends EntityListener {
} else if (attackerTeam != null && defenderTeam != null && attackerTeam == defenderTeam && attackerWarzone == defenderWarzone && attacker.getEntityId() != defender.getEntityId()) { } else if (attackerTeam != null && defenderTeam != null && attackerTeam == defenderTeam && attackerWarzone == defenderWarzone && attacker.getEntityId() != defender.getEntityId()) {
// same team, but not same person // same team, but not same person
if (attackerWarzone.getFriendlyFire()) { if (attackerWarzone.getFriendlyFire()) {
War.war.badMsg(a, "Friendly fire is on! Please, don't hurt your teammates."); // if ff is on, let the attack go through this.war.badMsg(a, "Friendly fire is on! Please, don't hurt your teammates."); // if ff is on, let the attack go through
} else { } else {
War.war.badMsg(a, "Your attack missed! Your target is on your team."); this.war.badMsg(a, "Your attack missed! Your target is on your team.");
event.setCancelled(true); // ff is off event.setCancelled(true); // ff is off
} }
} else if (attackerTeam == null && defenderTeam == null && War.war.canPvpOutsideZones(a)) { } else if (attackerTeam == null && defenderTeam == null && this.war.canPvpOutsideZones(a)) {
// let normal PVP through is its not turned off or if you have perms // let normal PVP through is its not turned off or if you have perms
} else if (attackerTeam == null && defenderTeam == null && !War.war.canPvpOutsideZones(a)) { } else if (attackerTeam == null && defenderTeam == null && !this.war.canPvpOutsideZones(a)) {
if (!War.war.isDisablePvpMessage()) { if (!this.war.isDisablePvpMessage()) {
War.war.badMsg(a, "You need the 'war.pvp' permission to attack players outside warzones."); this.war.badMsg(a, "You need the 'war.pvp' permission to attack players outside warzones.");
} }
event.setCancelled(true); // global pvp is off event.setCancelled(true); // global pvp is off
} else { } else {
War.war.badMsg(a, "Your attack missed!"); this.war.badMsg(a, "Your attack missed!");
if (attackerTeam == null) { if (attackerTeam == null) {
War.war.badMsg(a, "You must join a team " + ", then you'll be able to damage people " + "in the other teams in that warzone."); this.war.badMsg(a, "You must join a team " + ", then you'll be able to damage people " + "in the other teams in that warzone.");
} else if (defenderTeam == null) { } else if (defenderTeam == null) {
War.war.badMsg(a, "Your target is not in a team."); this.war.badMsg(a, "Your target is not in a team.");
} else if (attacker != null && defender != null && attacker.getEntityId() == defender.getEntityId()) { } else if (attacker != null && defender != null && attacker.getEntityId() == defender.getEntityId()) {
// You just hit yourself, probably with a bouncing arrow // You just hit yourself, probably with a bouncing arrow
} else if (attackerTeam == defenderTeam) { } else if (attackerTeam == defenderTeam) {
War.war.badMsg(a, "Your target is on your team."); this.war.badMsg(a, "Your target is on your team.");
} else if (attackerWarzone != defenderWarzone) { } else if (attackerWarzone != defenderWarzone) {
War.war.badMsg(a, "Your target is playing in another warzone."); this.war.badMsg(a, "Your target is playing in another warzone.");
} }
event.setCancelled(true); // can't attack someone inside a warzone if you're not in a team event.setCancelled(true); // can't attack someone inside a warzone if you're not in a team
} }
@ -109,15 +121,15 @@ public class WarEntityListener extends EntityListener {
// attacked by dispenser arrow most probably // attacked by dispenser arrow most probably
// Detect death, prevent it and respawn the player // Detect death, prevent it and respawn the player
Player d = (Player) defender; Player d = (Player) defender;
Warzone defenderWarzone = War.war.getPlayerTeamWarzone(d.getName()); Warzone defenderWarzone = this.war.getPlayerTeamWarzone(d.getName());
if (d != null && defenderWarzone != null && event.getDamage() >= d.getHealth()) { if (d != null && defenderWarzone != null && event.getDamage() >= d.getHealth()) {
String deathMessage = ""; String deathMessage = "";
if (event instanceof EntityDamageByProjectileEvent) if (event instanceof EntityDamageByProjectileEvent)
deathMessage = "A dispenser killed " + War.war.getPlayerTeam(d.getName()).getKind().getColor() + d.getDisplayName(); deathMessage = "A dispenser killed " + this.war.getPlayerTeam(d.getName()).getKind().getColor() + d.getDisplayName();
else if (event.getDamager() instanceof CraftTNTPrimed) else if (event.getDamager() instanceof CraftTNTPrimed)
deathMessage = War.war.getPlayerTeam(d.getName()).getKind().getColor() + d.getDisplayName() + ChatColor.WHITE + " exploded"; deathMessage = this.war.getPlayerTeam(d.getName()).getKind().getColor() + d.getDisplayName() + ChatColor.WHITE + " exploded";
else else
deathMessage = War.war.getPlayerTeam(d.getName()).getKind().getColor() + d.getDisplayName() + ChatColor.WHITE + " died"; deathMessage = this.war.getPlayerTeam(d.getName()).getKind().getColor() + d.getDisplayName() + ChatColor.WHITE + " died";
for (Team team : defenderWarzone.getTeams()) { for (Team team : defenderWarzone.getTeams()) {
team.teamcast(deathMessage); team.teamcast(deathMessage);
} }
@ -132,23 +144,23 @@ public class WarEntityListener extends EntityListener {
*/ */
@Override @Override
public void onEntityExplode(EntityExplodeEvent event) { public void onEntityExplode(EntityExplodeEvent event) {
if (War.war.isLoaded()) { if (this.war.isLoaded()) {
// protect zones elements, lobbies and warhub from creepers // protect zones elements, lobbies and warhub from creepers
List<Block> explodedBlocks = event.blockList(); List<Block> explodedBlocks = event.blockList();
for (Block block : explodedBlocks) { for (Block block : explodedBlocks) {
if (War.war.getWarHub() != null && War.war.getWarHub().getVolume().contains(block)) { if (this.war.getWarHub() != null && this.war.getWarHub().getVolume().contains(block)) {
event.setCancelled(true); event.setCancelled(true);
War.war.log("Explosion prevented at warhub.", Level.INFO); this.war.log("Explosion prevented at warhub.", Level.INFO);
return; return;
} }
for (Warzone zone : War.war.getWarzones()) { for (Warzone zone : this.war.getWarzones()) {
if (zone.isImportantBlock(block)) { if (zone.isImportantBlock(block)) {
event.setCancelled(true); event.setCancelled(true);
War.war.log("Explosion prevented in zone " + zone.getName() + ".", Level.INFO); this.war.log("Explosion prevented in zone " + zone.getName() + ".", Level.INFO);
return; return;
} else if (zone.getLobby() != null && zone.getLobby().getVolume().contains(block)) { } else if (zone.getLobby() != null && zone.getLobby().getVolume().contains(block)) {
event.setCancelled(true); event.setCancelled(true);
War.war.log("Explosion prevented at zone " + zone.getName() + " lobby.", Level.INFO); this.war.log("Explosion prevented at zone " + zone.getName() + " lobby.", Level.INFO);
return; return;
} }
} }
@ -161,10 +173,10 @@ public class WarEntityListener extends EntityListener {
*/ */
@Override @Override
public void onEntityDamage(EntityDamageEvent event) { public void onEntityDamage(EntityDamageEvent event) {
if (War.war.isLoaded()) { if (this.war.isLoaded()) {
Entity entity = event.getEntity(); Entity entity = event.getEntity();
// prevent godmode // prevent godmode
if (entity instanceof Player && War.war.getPlayerTeamWarzone(((Player) entity).getName()) != null) { if (entity instanceof Player && this.war.getPlayerTeamWarzone(((Player) entity).getName()) != null) {
event.setCancelled(false); event.setCancelled(false);
} }
@ -175,10 +187,10 @@ public class WarEntityListener extends EntityListener {
// Detect death, prevent it and respawn the player // Detect death, prevent it and respawn the player
if (entity instanceof Player) { if (entity instanceof Player) {
Player player = (Player) entity; Player player = (Player) entity;
Warzone zone = War.war.getPlayerTeamWarzone(player.getName()); Warzone zone = this.war.getPlayerTeamWarzone(player.getName());
if (zone != null && event.getDamage() >= player.getHealth()) { if (zone != null && event.getDamage() >= player.getHealth()) {
String deathMessage = ""; String deathMessage = "";
deathMessage = War.war.getPlayerTeam(player.getName()).getKind().getColor() + player.getDisplayName() + ChatColor.WHITE + " died"; deathMessage = this.war.getPlayerTeam(player.getName()).getKind().getColor() + player.getDisplayName() + ChatColor.WHITE + " died";
for (Team team : zone.getTeams()) { for (Team team : zone.getTeams()) {
team.teamcast(deathMessage); team.teamcast(deathMessage);
} }
@ -192,11 +204,11 @@ public class WarEntityListener extends EntityListener {
@Override @Override
public void onEntityCombust(EntityCombustEvent event) { public void onEntityCombust(EntityCombustEvent event) {
if (War.war.isLoaded()) { if (this.war.isLoaded()) {
Entity entity = event.getEntity(); Entity entity = event.getEntity();
if (entity instanceof Player) { if (entity instanceof Player) {
Player player = (Player) entity; Player player = (Player) entity;
Team team = War.war.getPlayerTeam(player.getName()); Team team = this.war.getPlayerTeam(player.getName());
if (team != null && team.getSpawnVolume().contains(player.getLocation())) { if (team != null && team.getSpawnVolume().contains(player.getLocation())) {
// smother out the fire that didn't burn out when you respawned // smother out the fire that didn't burn out when you respawned
// Stop fire (upcast, watch out!) // Stop fire (upcast, watch out!)
@ -215,9 +227,9 @@ public class WarEntityListener extends EntityListener {
*/ */
@Override @Override
public void onCreatureSpawn(CreatureSpawnEvent event) { public void onCreatureSpawn(CreatureSpawnEvent event) {
if (War.war.isLoaded()) { if (this.war.isLoaded()) {
Location location = event.getLocation(); Location location = event.getLocation();
Warzone zone = War.war.warzone(location); Warzone zone = this.war.warzone(location);
if (zone != null && zone.isNoCreatures()) { if (zone != null && zone.isNoCreatures()) {
event.setCancelled(true); event.setCancelled(true);
// war.logInfo("Prevented " + event.getMobType().getName() + " from spawning in zone " + zone.getName()); // war.logInfo("Prevented " + event.getMobType().getName() + " from spawning in zone " + zone.getName());
@ -230,12 +242,12 @@ public class WarEntityListener extends EntityListener {
*/ */
@Override @Override
public void onEntityRegainHealth(EntityRegainHealthEvent event) { public void onEntityRegainHealth(EntityRegainHealthEvent event) {
if (War.war.isLoaded() && event.getRegainReason() == RegainReason.REGEN) { if (this.war.isLoaded() && event.getRegainReason() == RegainReason.REGEN) {
Entity entity = event.getEntity(); Entity entity = event.getEntity();
if (entity instanceof Player) { if (entity instanceof Player) {
Player player = (Player) entity; Player player = (Player) entity;
Location location = player.getLocation(); Location location = player.getLocation();
Warzone zone = War.war.warzone(location); Warzone zone = this.war.warzone(location);
if (zone != null) { if (zone != null) {
event.setCancelled(true); event.setCancelled(true);
} }

View File

@ -1,5 +1,7 @@
package bukkit.tommytony.war; package bukkit.tommytony.war;
import java.util.Random;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
@ -28,41 +30,48 @@ import com.tommytony.war.ZoneLobby;
import com.tommytony.war.ZoneSetter; import com.tommytony.war.ZoneSetter;
/** /**
* @author tommytony, Tim Düsterhus *
* @package bukkit.tommytony.war * @author tommytony
*
*/ */
public class WarPlayerListener extends PlayerListener { public class WarPlayerListener extends PlayerListener {
private java.util.Random random = new java.util.Random(); private final War war;
private Random random = null;
public WarPlayerListener(War war) {
this.war = war;
this.random = new Random();
}
@Override @Override
public void onPlayerQuit(PlayerQuitEvent event) { public void onPlayerQuit(PlayerQuitEvent event) {
if (War.war.isLoaded()) { if (this.war.isLoaded()) {
Player player = event.getPlayer(); Player player = event.getPlayer();
Team team = War.war.getPlayerTeam(player.getName()); Team team = this.war.getPlayerTeam(player.getName());
if (team != null) { if (team != null) {
Warzone zone = War.war.getPlayerTeamWarzone(player.getName()); Warzone zone = this.war.getPlayerTeamWarzone(player.getName());
if (zone != null) { if (zone != null) {
zone.handlePlayerLeave(player, zone.getTeleport(), true); zone.handlePlayerLeave(player, zone.getTeleport(), true);
} }
} }
if (War.war.isWandBearer(player)) { if (this.war.isWandBearer(player)) {
War.war.removeWandBearer(player); this.war.removeWandBearer(player);
} }
} }
} }
@Override @Override
public void onPlayerDropItem(PlayerDropItemEvent event) { public void onPlayerDropItem(PlayerDropItemEvent event) {
if (War.war.isLoaded()) { if (this.war.isLoaded()) {
Player player = event.getPlayer(); Player player = event.getPlayer();
Team team = War.war.getPlayerTeam(player.getName()); Team team = this.war.getPlayerTeam(player.getName());
if (team != null) { if (team != null) {
Warzone zone = War.war.getPlayerTeamWarzone(player.getName()); Warzone zone = this.war.getPlayerTeamWarzone(player.getName());
if (zone.isFlagThief(player.getName())) { if (zone.isFlagThief(player.getName())) {
// a flag thief can't drop his flag // a flag thief can't drop his flag
War.war.badMsg(player, "Can't drop items while stealing flag. What are you doing?! Run!"); this.war.badMsg(player, "Can't drop items while stealing flag. What are you doing?! Run!");
event.setCancelled(true); event.setCancelled(true);
} else { } else {
@ -71,25 +80,25 @@ public class WarPlayerListener extends PlayerListener {
ItemStack itemStack = item.getItemStack(); ItemStack itemStack = item.getItemStack();
if (itemStack != null && itemStack.getType() == team.getKind().getMaterial() && itemStack.getData().getData() == team.getKind().getData()) { if (itemStack != null && itemStack.getType() == team.getKind().getMaterial() && itemStack.getData().getData() == team.getKind().getData()) {
// Can't drop your team's kind block // Can't drop your team's kind block
War.war.badMsg(player, "Can't drop " + team.getName() + " block blocks."); this.war.badMsg(player, "Can't drop " + team.getName() + " block blocks.");
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
if (zone.isNearWall(player.getLocation()) && itemStack != null) { if (zone.isNearWall(player.getLocation()) && itemStack != null) {
War.war.badMsg(player, "Can't drop items near the zone border!"); this.war.badMsg(player, "Can't drop items near the zone border!");
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
} }
} }
} }
if (War.war.isWandBearer(player)) { if (this.war.isWandBearer(player)) {
Item item = event.getItemDrop(); Item item = event.getItemDrop();
if (item.getItemStack().getType() == Material.WOOD_SWORD) { if (item.getItemStack().getType() == Material.WOOD_SWORD) {
String zoneName = War.war.getWandBearerZone(player); String zoneName = this.war.getWandBearerZone(player);
War.war.removeWandBearer(player); this.war.removeWandBearer(player);
War.war.msg(player, "You dropped the zone " + zoneName + " wand."); this.war.msg(player, "You dropped the zone " + zoneName + " wand.");
} }
} }
} }
@ -97,11 +106,11 @@ public class WarPlayerListener extends PlayerListener {
@Override @Override
public void onPlayerPickupItem(PlayerPickupItemEvent event) { public void onPlayerPickupItem(PlayerPickupItemEvent event) {
if (War.war.isLoaded()) { if (this.war.isLoaded()) {
Player player = event.getPlayer(); Player player = event.getPlayer();
Team team = War.war.getPlayerTeam(player.getName()); Team team = this.war.getPlayerTeam(player.getName());
if (team != null) { if (team != null) {
Warzone zone = War.war.getPlayerTeamWarzone(player.getName()); Warzone zone = this.war.getPlayerTeamWarzone(player.getName());
if (zone.isFlagThief(player.getName())) { if (zone.isFlagThief(player.getName())) {
// a flag thief can't pick up anything // a flag thief can't pick up anything
@ -127,10 +136,10 @@ public class WarPlayerListener extends PlayerListener {
@Override @Override
public void onInventoryOpen(PlayerInventoryEvent event) { public void onInventoryOpen(PlayerInventoryEvent event) {
if (War.war.isLoaded()) { if (this.war.isLoaded()) {
Player player = event.getPlayer(); Player player = event.getPlayer();
Inventory inventory = event.getInventory(); Inventory inventory = event.getInventory();
Team team = War.war.getPlayerTeam(player.getName()); Team team = this.war.getPlayerTeam(player.getName());
if (team != null && inventory instanceof PlayerInventory) { if (team != null && inventory instanceof PlayerInventory) {
// make sure the player doesn't have too many precious blocks // make sure the player doesn't have too many precious blocks
// or illegal armor (i.e. armor not found in loadout) // or illegal armor (i.e. armor not found in loadout)
@ -139,7 +148,7 @@ public class WarPlayerListener extends PlayerListener {
if (playerInv.contains(teamKindBlock, 2)) { if (playerInv.contains(teamKindBlock, 2)) {
playerInv.remove(teamKindBlock); playerInv.remove(teamKindBlock);
playerInv.addItem(teamKindBlock); playerInv.addItem(teamKindBlock);
War.war.badMsg(player, "All that " + team.getName() + " must have been heavy!"); this.war.badMsg(player, "All that " + team.getName() + " must have been heavy!");
} }
} }
} }
@ -147,21 +156,21 @@ public class WarPlayerListener extends PlayerListener {
@Override @Override
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
if (War.war.isLoaded()) { if (this.war.isLoaded()) {
Player player = event.getPlayer(); Player player = event.getPlayer();
Team talkingPlayerTeam = War.war.getPlayerTeam(player.getName()); Team talkingPlayerTeam = this.war.getPlayerTeam(player.getName());
if (talkingPlayerTeam != null) { if (talkingPlayerTeam != null) {
String msg = event.getMessage(); String msg = event.getMessage();
String[] split = msg.split(" "); String[] split = msg.split(" ");
if (!War.war.isZoneMaker(player) && split.length > 0 && split[0].startsWith("/")) { if (!this.war.isZoneMaker(player) && split.length > 0 && split[0].startsWith("/")) {
String command = split[0].substring(1); String command = split[0].substring(1);
if (!command.equals("war") && !command.equals("zones") && !command.equals("warzones") && !command.equals("zone") && !command.equals("warzone") && !command.equals("teams") && !command.equals("join") && !command.equals("leave") && !command.equals("team") && !command.equals("warhub") && !command.equals("zonemaker")) { if (!command.equals("war") && !command.equals("zones") && !command.equals("warzones") && !command.equals("zone") && !command.equals("warzone") && !command.equals("teams") && !command.equals("join") && !command.equals("leave") && !command.equals("team") && !command.equals("warhub") && !command.equals("zonemaker")) {
for (String whiteCommand : War.war.getCommandWhitelist()) { for (String whiteCommand : this.war.getCommandWhitelist()) {
if (whiteCommand.equals(command)) { if (whiteCommand.equals(command)) {
return; return;
} }
} }
War.war.badMsg(player, "Can't use anything but War commands (e.g. /leave, /warhub) while you're playing in a warzone."); this.war.badMsg(player, "Can't use anything but War commands (e.g. /leave, /warhub) while you're playing in a warzone.");
event.setCancelled(true); event.setCancelled(true);
} }
} }
@ -171,19 +180,19 @@ public class WarPlayerListener extends PlayerListener {
@Override @Override
public void onPlayerKick(PlayerKickEvent event) { public void onPlayerKick(PlayerKickEvent event) {
if (War.war.isLoaded()) { if (this.war.isLoaded()) {
Player player = event.getPlayer(); Player player = event.getPlayer();
String reason = event.getReason(); String reason = event.getReason();
if (reason.contains("moved") || reason.contains("too quickly") || reason.contains("Hacking")) { if (reason.contains("moved") || reason.contains("too quickly") || reason.contains("Hacking")) {
boolean inWarzone = War.war.inAnyWarzone(player.getLocation()); boolean inWarzone = this.war.inAnyWarzone(player.getLocation());
boolean inLobby = War.war.inAnyWarzone(player.getLocation()); boolean inLobby = this.war.inAnyWarzone(player.getLocation());
boolean inWarhub = false; boolean inWarhub = false;
if (War.war.getWarHub() != null && War.war.getWarHub().getVolume().contains(player.getLocation())) { if (this.war.getWarHub() != null && this.war.getWarHub().getVolume().contains(player.getLocation())) {
inWarhub = true; inWarhub = true;
} }
if (inWarzone || inLobby || inWarhub) { if (inWarzone || inLobby || inWarhub) {
event.setCancelled(true); event.setCancelled(true);
War.war.log("Prevented " + player.getName() + " from getting kicked.", java.util.logging.Level.WARNING); this.war.log("Prevented " + player.getName() + " from getting kicked.", java.util.logging.Level.WARNING);
} }
} }
} }
@ -191,13 +200,13 @@ public class WarPlayerListener extends PlayerListener {
@Override @Override
public void onPlayerInteract(PlayerInteractEvent event) { public void onPlayerInteract(PlayerInteractEvent event) {
if (War.war.isLoaded()) { if (this.war.isLoaded()) {
Player player = event.getPlayer(); Player player = event.getPlayer();
if (player.getItemInHand().getType() == Material.WOOD_SWORD && War.war.isWandBearer(player)) { if (player.getItemInHand().getType() == Material.WOOD_SWORD && this.war.isWandBearer(player)) {
String zoneName = War.war.getWandBearerZone(player); String zoneName = this.war.getWandBearerZone(player);
ZoneSetter setter = new ZoneSetter(player, zoneName); ZoneSetter setter = new ZoneSetter(this.war, player, zoneName);
if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_AIR) { if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_AIR) {
War.war.badMsg(player, "Too far."); this.war.badMsg(player, "Too far.");
} else if (event.getAction() == Action.LEFT_CLICK_BLOCK) { } else if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
setter.placeCorner1(event.getClickedBlock()); setter.placeCorner1(event.getClickedBlock());
event.setUseItemInHand(Result.ALLOW); event.setUseItemInHand(Result.ALLOW);
@ -211,25 +220,25 @@ public class WarPlayerListener extends PlayerListener {
@Override @Override
public void onPlayerMove(PlayerMoveEvent event) { public void onPlayerMove(PlayerMoveEvent event) {
if (War.war.isLoaded()) { if (this.war.isLoaded()) {
Player player = event.getPlayer(); Player player = event.getPlayer();
Location playerLoc = event.getFrom(); // same as player.getLoc. Don't call again we need same result. Location playerLoc = event.getFrom(); // same as player.getLoc. Don't call again we need same result.
Warzone locZone = null; Warzone locZone = null;
ZoneLobby locLobby = null; ZoneLobby locLobby = null;
locZone = War.war.warzone(playerLoc); locZone = this.war.warzone(playerLoc);
locLobby = War.war.lobby(playerLoc); locLobby = this.war.lobby(playerLoc);
boolean canPlay = War.war.canPlayWar(player); boolean canPlay = this.war.canPlayWar(player);
boolean isMaker = War.war.isZoneMaker(player); boolean isMaker = this.war.isZoneMaker(player);
// Zone walls // Zone walls
Team currentTeam = War.war.getPlayerTeam(player.getName()); Team currentTeam = this.war.getPlayerTeam(player.getName());
Warzone playerWarzone = War.war.getPlayerTeamWarzone(player.getName()); // this uses the teams, so it asks: get the player's team's warzone Warzone playerWarzone = this.war.getPlayerTeamWarzone(player.getName()); // this uses the teams, so it asks: get the player's team's warzone
boolean protecting = false; boolean protecting = false;
if (currentTeam != null) { if (currentTeam != null) {
// Warzone nearbyZone = war.zoneOfZoneWallAtProximity(playerLoc); // Warzone nearbyZone = war.zoneOfZoneWallAtProximity(playerLoc);
protecting = playerWarzone.protectZoneWallAgainstPlayer(player); protecting = playerWarzone.protectZoneWallAgainstPlayer(player);
} else { } else {
Warzone nearbyZone = War.war.zoneOfZoneWallAtProximity(playerLoc); Warzone nearbyZone = this.war.zoneOfZoneWallAtProximity(playerLoc);
if (nearbyZone != null && !isMaker) { if (nearbyZone != null && !isMaker) {
protecting = nearbyZone.protectZoneWallAgainstPlayer(player); protecting = nearbyZone.protectZoneWallAgainstPlayer(player);
} }
@ -238,7 +247,7 @@ public class WarPlayerListener extends PlayerListener {
if (!protecting) { if (!protecting) {
// zone makers still need to delete their walls // zone makers still need to delete their walls
// make sure to delete any wall guards as you leave // make sure to delete any wall guards as you leave
for (Warzone zone : War.war.getWarzones()) { for (Warzone zone : this.war.getWarzones()) {
zone.dropZoneWallGuardIfAny(player); zone.dropZoneWallGuardIfAny(player);
} }
} }
@ -246,7 +255,7 @@ public class WarPlayerListener extends PlayerListener {
// Warzone lobby gates // Warzone lobby gates
if (locLobby != null) { if (locLobby != null) {
Warzone zone = locLobby.getZone(); Warzone zone = locLobby.getZone();
Team oldTeam = War.war.getPlayerTeam(player.getName()); Team oldTeam = this.war.getPlayerTeam(player.getName());
boolean isAutoAssignGate = false; boolean isAutoAssignGate = false;
if (oldTeam == null && canPlay) { // trying to counter spammy player move if (oldTeam == null && canPlay) { // trying to counter spammy player move
isAutoAssignGate = zone.getLobby().isAutoAssignGate(playerLoc); isAutoAssignGate = zone.getLobby().isAutoAssignGate(playerLoc);
@ -262,13 +271,13 @@ public class WarPlayerListener extends PlayerListener {
if (noOfPlayers < zone.getTeams().size() * zone.getTeamCap()) { if (noOfPlayers < zone.getTeams().size() * zone.getTeamCap()) {
zone.autoAssign(player); zone.autoAssign(player);
if (War.war.getWarHub() != null) { if (this.war.getWarHub() != null) {
War.war.getWarHub().resetZoneSign(zone); this.war.getWarHub().resetZoneSign(zone);
} }
} else { } else {
event.setTo(zone.getTeleport()); event.setTo(zone.getTeleport());
// player.teleport(zone.getTeleport()); // player.teleport(zone.getTeleport());
War.war.badMsg(player, "All teams are full."); this.war.badMsg(player, "All teams are full.");
} }
} }
return; return;
@ -283,28 +292,28 @@ public class WarPlayerListener extends PlayerListener {
} else if (team.getPlayers().size() < zone.getTeamCap()) { } else if (team.getPlayers().size() < zone.getTeamCap()) {
team.addPlayer(player); team.addPlayer(player);
team.resetSign(); team.resetSign();
if (War.war.getWarHub() != null) { if (this.war.getWarHub() != null) {
War.war.getWarHub().resetZoneSign(zone); this.war.getWarHub().resetZoneSign(zone);
} }
zone.keepPlayerInventory(player); zone.keepPlayerInventory(player);
War.war.msg(player, "Your inventory is in storage until you /leave."); this.war.msg(player, "Your inventory is in storage until you /leave.");
zone.respawnPlayer(event, team, player); zone.respawnPlayer(event, team, player);
for (Team t : zone.getTeams()) { for (Team t : zone.getTeams()) {
t.teamcast("" + player.getName() + " joined team " + team.getName() + "."); t.teamcast("" + player.getName() + " joined team " + team.getName() + ".");
} }
} else { } else {
event.setTo(zone.getTeleport()); event.setTo(zone.getTeleport());
War.war.badMsg(player, "Team " + team.getName() + " is full."); this.war.badMsg(player, "Team " + team.getName() + " is full.");
} }
return; return;
} }
} }
if (War.war.getWarHub() != null && zone.getLobby().isInWarHubLinkGate(playerLoc) && !War.war.getWarHub().getVolume().contains(player.getLocation())) { if (this.war.getWarHub() != null && zone.getLobby().isInWarHubLinkGate(playerLoc) && !this.war.getWarHub().getVolume().contains(player.getLocation())) {
this.dropFromOldTeamIfAny(player); this.dropFromOldTeamIfAny(player);
event.setTo(War.war.getWarHub().getLocation()); event.setTo(this.war.getWarHub().getLocation());
// player.teleport(war.getWarHub().getLocation()); // player.teleport(war.getWarHub().getLocation());
War.war.msg(player, "Welcome to the War hub."); this.war.msg(player, "Welcome to the War hub.");
return; return;
} }
} }
@ -312,19 +321,19 @@ public class WarPlayerListener extends PlayerListener {
} }
// Warhub zone gates // Warhub zone gates
WarHub hub = War.war.getWarHub(); WarHub hub = this.war.getWarHub();
if (hub != null && hub.getVolume().contains(player.getLocation())) { if (hub != null && hub.getVolume().contains(player.getLocation())) {
Warzone zone = hub.getDestinationWarzoneForLocation(playerLoc); Warzone zone = hub.getDestinationWarzoneForLocation(playerLoc);
if (zone != null && zone.getTeleport() != null) { if (zone != null && zone.getTeleport() != null) {
event.setTo(zone.getTeleport()); event.setTo(zone.getTeleport());
// player.teleport(zone.getTeleport()); // player.teleport(zone.getTeleport());
War.war.msg(player, "Welcome to warzone " + zone.getName() + "."); this.war.msg(player, "Welcome to warzone " + zone.getName() + ".");
return; return;
} }
} }
boolean isLeaving = playerWarzone != null && playerWarzone.getLobby().isLeavingZone(playerLoc); boolean isLeaving = playerWarzone != null && playerWarzone.getLobby().isLeavingZone(playerLoc);
Team playerTeam = War.war.getPlayerTeam(player.getName()); Team playerTeam = this.war.getPlayerTeam(player.getName());
if (isLeaving) { // already in a team and in warzone, leaving if (isLeaving) { // already in a team and in warzone, leaving
// same as leave // same as leave
if (playerTeam != null) { if (playerTeam != null) {
@ -339,7 +348,7 @@ public class WarPlayerListener extends PlayerListener {
if (playerWarzone != null) { if (playerWarzone != null) {
// Player belongs to a warzone team but is outside: he snuck out or is at spawn and died // Player belongs to a warzone team but is outside: he snuck out or is at spawn and died
if (locZone == null && playerTeam != null && playerWarzone.getLobby() != null && !playerWarzone.getLobby().getVolume().contains(playerLoc) && !isLeaving) { if (locZone == null && playerTeam != null && playerWarzone.getLobby() != null && !playerWarzone.getLobby().getVolume().contains(playerLoc) && !isLeaving) {
War.war.badMsg(player, "Use /leave to exit the zone."); this.war.badMsg(player, "Use /leave to exit the zone.");
event.setTo(playerTeam.getTeamSpawn()); event.setTo(playerTeam.getTeamSpawn());
return; return;
} }
@ -365,14 +374,14 @@ public class WarPlayerListener extends PlayerListener {
} else { } else {
heartNum = ((newHp - currentHp - 1) / 2) + ".5 "; heartNum = ((newHp - currentHp - 1) / 2) + ".5 ";
} }
War.war.msg(player, "Your dance pleases the monument's voodoo. You gain " + heartNum + "heart" + isS + "!"); this.war.msg(player, "Your dance pleases the monument's voodoo. You gain " + heartNum + "heart" + isS + "!");
return; return;
} }
// Flag capture // Flag capture
if (playerWarzone.isFlagThief(player.getName()) && (playerTeam.getSpawnVolume().contains(player.getLocation()) || (playerTeam.getFlagVolume() != null && playerTeam.getFlagVolume().contains(player.getLocation())))) { if (playerWarzone.isFlagThief(player.getName()) && (playerTeam.getSpawnVolume().contains(player.getLocation()) || (playerTeam.getFlagVolume() != null && playerTeam.getFlagVolume().contains(player.getLocation())))) {
if (playerWarzone.isTeamFlagStolen(playerTeam)) { if (playerWarzone.isTeamFlagStolen(playerTeam)) {
War.war.badMsg(player, "You can't capture the enemy flag until your team's flag is returned."); this.war.badMsg(player, "You can't capture the enemy flag until your team's flag is returned.");
} else { } else {
synchronized (playerWarzone) { synchronized (playerWarzone) {
// flags can be captured at own spawn or own flag pole // flags can be captured at own spawn or own flag pole
@ -390,7 +399,7 @@ public class WarPlayerListener extends PlayerListener {
victim.getFlagVolume().resetBlocks(); // bring back flag to team that lost it victim.getFlagVolume().resetBlocks(); // bring back flag to team that lost it
victim.initializeTeamFlag(); victim.initializeTeamFlag();
for (Team t : playerWarzone.getTeams()) { for (Team t : playerWarzone.getTeams()) {
t.teamcast(playerTeam.getKind().getColor() + player.getName() + ChatColor.WHITE t.teamcast(playerTeam.getKind().getColor() + player.getName() + ChatColor.WHITE
+ " captured team " + victim.getName() + "'s flag. Team " + playerTeam.getName() + " scores one point."); + " captured team " + victim.getName() + "'s flag. Team " + playerTeam.getName() + " scores one point.");
} }
playerWarzone.respawnPlayer(event, playerTeam, player); playerWarzone.respawnPlayer(event, playerTeam, player);
@ -404,10 +413,10 @@ public class WarPlayerListener extends PlayerListener {
} }
} else if (locZone != null && locZone.getLobby() != null && !locZone.getLobby().isLeavingZone(playerLoc) && !isMaker) { } else if (locZone != null && locZone.getLobby() != null && !locZone.getLobby().isLeavingZone(playerLoc) && !isMaker) {
// player is not in any team, but inside warzone boundaries, get him out // player is not in any team, but inside warzone boundaries, get him out
Warzone zone = War.war.warzone(playerLoc); Warzone zone = this.war.warzone(playerLoc);
event.setTo(zone.getTeleport()); event.setTo(zone.getTeleport());
// player.teleport(zone.getTeleport()); // player.teleport(zone.getTeleport());
War.war.badMsg(player, "You can't be inside a warzone without a team."); this.war.badMsg(player, "You can't be inside a warzone without a team.");
return; return;
} }
} }
@ -415,25 +424,25 @@ public class WarPlayerListener extends PlayerListener {
private void handleDisabledZone(PlayerMoveEvent event, Player player, Warzone zone) { private void handleDisabledZone(PlayerMoveEvent event, Player player, Warzone zone) {
if (zone.getLobby() != null) { if (zone.getLobby() != null) {
War.war.badMsg(player, "This warzone is disabled."); this.war.badMsg(player, "This warzone is disabled.");
event.setTo(zone.getTeleport()); event.setTo(zone.getTeleport());
} }
} }
private void dropFromOldTeamIfAny(Player player) { private void dropFromOldTeamIfAny(Player player) {
// drop from old team if any // drop from old team if any
Team previousTeam = War.war.getPlayerTeam(player.getName()); Team previousTeam = this.war.getPlayerTeam(player.getName());
if (previousTeam != null) { if (previousTeam != null) {
if (!previousTeam.removePlayer(player.getName())) { if (!previousTeam.removePlayer(player.getName())) {
War.war.log("Could not remove player " + player.getName() + " from team " + previousTeam.getName(), java.util.logging.Level.WARNING); this.war.log("Could not remove player " + player.getName() + " from team " + previousTeam.getName(), java.util.logging.Level.WARNING);
} }
} }
} }
public String getAllTeamsMsg(Player player) { public String getAllTeamsMsg(Player player) {
String teamsMessage = "Teams: "; String teamsMessage = "Teams: ";
Warzone warzone = War.war.warzone(player.getLocation()); Warzone warzone = this.war.warzone(player.getLocation());
ZoneLobby lobby = War.war.lobby(player.getLocation()); ZoneLobby lobby = this.war.lobby(player.getLocation());
if (warzone == null && lobby != null) { if (warzone == null && lobby != null) {
warzone = lobby.getZone(); warzone = lobby.getZone();
} else { } else {

View File

@ -5,12 +5,14 @@ import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import bukkit.tommytony.war.War;
import com.tommytony.war.volumes.Volume; import com.tommytony.war.volumes.Volume;
/** /**
* *
* @author tommytony * @author tommytony
* *
*/ */
public class Monument { public class Monument {
private Location location; private Location location;
@ -20,11 +22,11 @@ public class Monument {
private final String name; private final String name;
private Warzone warzone; private Warzone warzone;
public Monument(String name, Warzone warzone, Location location) { public Monument(String name, War war, Warzone warzone, Location location) {
this.name = name; this.name = name;
this.location = location; this.location = location;
this.warzone = warzone; this.warzone = warzone;
this.volume = new Volume(name, warzone.getWorld()); this.volume = new Volume(name, war, warzone.getWorld());
this.setLocation(location); this.setLocation(location);
this.addMonumentBlocks(); this.addMonumentBlocks();

View File

@ -30,12 +30,14 @@ public class Team {
private Volume flagVolume; private Volume flagVolume;
private final Warzone warzone; private final Warzone warzone;
private TeamKind kind; private TeamKind kind;
private War war;
public Team(String name, TeamKind kind, Location teamSpawn, Warzone warzone) { public Team(String name, TeamKind kind, Location teamSpawn, War war, Warzone warzone) {
this.warzone = warzone; this.warzone = warzone;
this.setName(name); this.setName(name);
this.teamSpawn = teamSpawn; this.teamSpawn = teamSpawn;
this.setSpawnVolume(new Volume(name, warzone.getWorld())); this.war = war;
this.setSpawnVolume(new Volume(name, war, warzone.getWorld()));
this.kind = kind; this.kind = kind;
this.setFlagVolume(null); // no flag at the start this.setFlagVolume(null); // no flag at the start
} }
@ -296,7 +298,7 @@ public class Team {
lines[3] = this.remainingLives + "/" + this.warzone.getLifePool() + " lives left"; lines[3] = this.remainingLives + "/" + this.warzone.getLifePool() + " lives left";
} }
SignHelper.setToSign(War.war, signBlock, (byte) signData, lines); SignHelper.setToSign(this.war, signBlock, (byte) signData, lines);
} }
} }
@ -331,7 +333,7 @@ public class Team {
public void teamcast(String message) { public void teamcast(String message) {
for (Player player : this.players) { for (Player player : this.players) {
War.war.msg(player, message); this.war.msg(player, message);
} }
} }
@ -416,7 +418,7 @@ public class Team {
private void setFlagVolume() { private void setFlagVolume() {
if (this.flagVolume == null) { if (this.flagVolume == null) {
this.flagVolume = new Volume(this.getName() + "flag", this.warzone.getWorld()); this.flagVolume = new Volume(this.getName() + "flag", this.war, this.warzone.getWorld());
} }
if (this.flagVolume.isSaved()) { if (this.flagVolume.isSaved()) {
this.flagVolume.resetBlocks(); this.flagVolume.resetBlocks();

View File

@ -20,13 +20,17 @@ import com.tommytony.war.volumes.Volume;
* @package com.tommytony.war * @package com.tommytony.war
*/ */
public class WarHub { public class WarHub {
private final War war;
private Location location; private Location location;
private Volume volume; private Volume volume;
private Map<String, Block> zoneGateBlocks = new HashMap<String, Block>(); private Map<String, Block> zoneGateBlocks = new HashMap<String, Block>();
private BlockFace orientation; private BlockFace orientation;
public WarHub(Location location, String hubOrientation) { public WarHub(War war, Location location, String hubOrientation) {
this.war = war;
this.location = location;
int yaw = 0; int yaw = 0;
if (hubOrientation.equals("south")) { if (hubOrientation.equals("south")) {
yaw = 270; yaw = 270;
this.setOrientation(BlockFace.SOUTH); this.setOrientation(BlockFace.SOUTH);
@ -46,13 +50,14 @@ public class WarHub {
location.getY(), location.getY(),
location.getZ(), location.getZ(),
yaw, 0); yaw, 0);
this.volume = new Volume("warhub", location.getWorld()); this.volume = new Volume("warhub", war, location.getWorld());
} }
// Use when creating from player location (with yaw) // Use when creating from player location (with yaw)
public WarHub(Location location) { public WarHub(War war, Location location) {
this.war = war;
this.location = location; this.location = location;
this.volume = new Volume("warhub", location.getWorld()); this.volume = new Volume("warhub", war, location.getWorld());
setLocation(location); setLocation(location);
} }
@ -93,7 +98,7 @@ public class WarHub {
for (String zoneName : this.zoneGateBlocks.keySet()) { for (String zoneName : this.zoneGateBlocks.keySet()) {
Block gate = this.zoneGateBlocks.get(zoneName); Block gate = this.zoneGateBlocks.get(zoneName);
if (gate.getX() == playerLocation.getBlockX() && gate.getY() == playerLocation.getBlockY() && gate.getZ() == playerLocation.getBlockZ()) { if (gate.getX() == playerLocation.getBlockX() && gate.getY() == playerLocation.getBlockY() && gate.getZ() == playerLocation.getBlockZ()) {
zone = War.war.findWarzone(zoneName); zone = this.war.findWarzone(zoneName);
} }
} }
return zone; return zone;
@ -103,12 +108,12 @@ public class WarHub {
// for now, draw the wall of gates to the west // for now, draw the wall of gates to the west
this.zoneGateBlocks.clear(); this.zoneGateBlocks.clear();
int disabled = 0; int disabled = 0;
for (Warzone zone : War.war.getWarzones()) { for (Warzone zone : this.war.getWarzones()) {
if (zone.isDisabled()) { if (zone.isDisabled()) {
disabled++; disabled++;
} }
} }
int noOfWarzones = War.war.getWarzones().size() - disabled; int noOfWarzones = this.war.getWarzones().size() - disabled;
if (noOfWarzones > 0) { if (noOfWarzones > 0) {
int hubWidth = noOfWarzones * 4 + 2; int hubWidth = noOfWarzones * 4 + 2;
int halfHubWidth = hubWidth / 2; int halfHubWidth = hubWidth / 2;
@ -155,7 +160,7 @@ public class WarHub {
// draw gates // draw gates
Block currentGateBlock = BlockInfo.getBlock(this.location.getWorld(), this.volume.getCornerOne()).getFace(BlockFace.UP).getFace(front, hubDepth).getFace(right, 2); Block currentGateBlock = BlockInfo.getBlock(this.location.getWorld(), this.volume.getCornerOne()).getFace(BlockFace.UP).getFace(front, hubDepth).getFace(right, 2);
for (Warzone zone : War.war.getWarzones()) { // gonna use the index to find it again for (Warzone zone : this.war.getWarzones()) { // gonna use the index to find it again
if (!zone.isDisabled()) { if (!zone.isDisabled()) {
this.zoneGateBlocks.put(zone.getName(), currentGateBlock); this.zoneGateBlocks.put(zone.getName(), currentGateBlock);
currentGateBlock.getFace(BlockFace.DOWN).setType(Material.GLOWSTONE); currentGateBlock.getFace(BlockFace.DOWN).setType(Material.GLOWSTONE);
@ -179,10 +184,10 @@ public class WarHub {
lines[1] = "(/warhub)"; lines[1] = "(/warhub)";
lines[2] = "Pick your"; lines[2] = "Pick your";
lines[3] = "battle!"; lines[3] = "battle!";
SignHelper.setToSign(War.war, signBlock, data, lines); SignHelper.setToSign(this.war, signBlock, data, lines);
// Warzone signs // Warzone signs
for (Warzone zone : War.war.getWarzones()) { for (Warzone zone : this.war.getWarzones()) {
if (!zone.isDisabled() && zone.ready()) { if (!zone.isDisabled() && zone.ready()) {
this.resetZoneSign(zone); this.resetZoneSign(zone);
} }
@ -235,7 +240,7 @@ public class WarHub {
lines[1] = zone.getName(); lines[1] = zone.getName();
lines[2] = zonePlayers + "/" + zoneCap + " players"; lines[2] = zonePlayers + "/" + zoneCap + " players";
lines[3] = zone.getTeams().size() + " teams"; lines[3] = zone.getTeams().size() + " teams";
SignHelper.setToSign(War.war, block, data, lines); SignHelper.setToSign(this.war, block, data, lines);
} }
public void setVolume(Volume vol) { public void setVolume(Volume vol) {

View File

@ -27,8 +27,8 @@ import com.tommytony.war.volumes.ZoneVolume;
/** /**
* *
* @author tommytony * @author tommytony
* @package com.tommytony.war *
*/ */
public class Warzone { public class Warzone {
private String name; private String name;
@ -51,6 +51,7 @@ public class Warzone {
private World world; private World world;
private final int minSafeDistanceFromWall = 6; private final int minSafeDistanceFromWall = 6;
private List<ZoneWallGuard> zoneWallGuards = new ArrayList<ZoneWallGuard>(); private List<ZoneWallGuard> zoneWallGuards = new ArrayList<ZoneWallGuard>();
private War war;
private ZoneLobby lobby; private ZoneLobby lobby;
private boolean autoAssignOnly; private boolean autoAssignOnly;
private boolean blockHeads; private boolean blockHeads;
@ -66,24 +67,25 @@ public class Warzone {
private HashMap<String, InventoryStash> deadMenInventories = new HashMap<String, InventoryStash>(); private HashMap<String, InventoryStash> deadMenInventories = new HashMap<String, InventoryStash>();
private Location rallyPoint; private Location rallyPoint;
public Warzone(World world, String name) { public Warzone(War war, World world, String name) {
this.world = world; this.world = world;
this.war = war;
this.name = name; this.name = name;
this.friendlyFire = War.war.getDefaultFriendlyFire(); this.friendlyFire = war.getDefaultFriendlyFire();
this.setLifePool(War.war.getDefaultLifepool()); this.setLifePool(war.getDefaultLifepool());
this.setLoadout(War.war.getDefaultLoadout()); this.setLoadout(war.getDefaultLoadout());
this.setAutoAssignOnly(War.war.getDefaultAutoAssignOnly()); this.setAutoAssignOnly(war.getDefaultAutoAssignOnly());
this.teamCap = War.war.getDefaultTeamCap(); this.teamCap = war.getDefaultTeamCap();
this.scoreCap = War.war.getDefaultScoreCap(); this.scoreCap = war.getDefaultScoreCap();
this.monumentHeal = War.war.getDefaultMonumentHeal(); this.monumentHeal = war.getDefaultMonumentHeal();
this.setBlockHeads(War.war.isDefaultBlockHeads()); this.setBlockHeads(war.isDefaultBlockHeads());
this.setDropLootOnDeath(War.war.isDefaultDropLootOnDeath()); this.setDropLootOnDeath(war.isDefaultDropLootOnDeath());
this.setUnbreakableZoneBlocks(War.war.isDefaultUnbreakableZoneBlocks()); this.setUnbreakableZoneBlocks(war.isDefaultUnbreakableZoneBlocks());
this.setNoCreatures(War.war.getDefaultNoCreatures()); this.setNoCreatures(war.getDefaultNoCreatures());
this.setResetOnEmpty(War.war.isDefaultResetOnEmpty()); this.setResetOnEmpty(war.isDefaultResetOnEmpty());
this.setResetOnLoad(War.war.isDefaultResetOnLoad()); this.setResetOnLoad(war.isDefaultResetOnLoad());
this.setResetOnUnload(War.war.isDefaultResetOnUnload()); this.setResetOnUnload(war.isDefaultResetOnUnload());
this.volume = new ZoneVolume(name, this.getWorld(), this); this.volume = new ZoneVolume(name, war, this.getWorld(), this);
} }
public boolean ready() { public boolean ready() {
@ -186,12 +188,12 @@ public class Warzone {
public void initializeZoneAsJob(Player respawnExempted) { public void initializeZoneAsJob(Player respawnExempted) {
InitZoneJob job = new InitZoneJob(this, respawnExempted); InitZoneJob job = new InitZoneJob(this, respawnExempted);
War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, job); this.war.getServer().getScheduler().scheduleSyncDelayedTask(this.war, job);
} }
public void initializeZoneAsJob() { public void initializeZoneAsJob() {
InitZoneJob job = new InitZoneJob(this); InitZoneJob job = new InitZoneJob(this);
War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, job); this.war.getServer().getScheduler().scheduleSyncDelayedTask(this.war, job);
} }
private void initZone() { private void initZone() {
@ -233,7 +235,7 @@ public class Warzone {
player.setHealth(20); player.setHealth(20);
LoadoutResetJob job = new LoadoutResetJob(this, team, player); LoadoutResetJob job = new LoadoutResetJob(this, team, player);
War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, job); this.war.getServer().getScheduler().scheduleSyncDelayedTask(this.war, job);
} }
public void resetInventory(Team team, Player player) { public void resetInventory(Team team, Player player) {
@ -579,7 +581,7 @@ public class Warzone {
guard.updatePlayerPosition(player.getLocation()); guard.updatePlayerPosition(player.getLocation());
} else { } else {
// new guard // new guard
guard = new ZoneWallGuard(player, War.war, this, wall); guard = new ZoneWallGuard(player, this.war, this, wall);
this.zoneWallGuards.add(guard); this.zoneWallGuards.add(guard);
} }
protecting = true; protecting = true;
@ -637,7 +639,7 @@ public class Warzone {
if (!this.hasPlayerInventory(player.getName())) { if (!this.hasPlayerInventory(player.getName())) {
this.keepPlayerInventory(player); this.keepPlayerInventory(player);
} }
War.war.msg(player, "Your inventory is in storage until you /leave."); this.war.msg(player, "Your inventory is in storage until you /leave.");
this.respawnPlayer(lowestNoOfPlayers, player); this.respawnPlayer(lowestNoOfPlayers, player);
for (Team team : this.teams) { for (Team team : this.teams) {
team.teamcast("" + player.getName() + " joined team " + lowestNoOfPlayers.getName() + "."); team.teamcast("" + player.getName() + " joined team " + lowestNoOfPlayers.getName() + ".");
@ -674,11 +676,10 @@ public class Warzone {
} }
public void handleDeath(Player player) { public void handleDeath(Player player) {
Team playerTeam = War.war.getPlayerTeam(player.getName()); Team playerTeam = this.war.getPlayerTeam(player.getName());
Warzone playerWarzone = War.war.getPlayerTeamWarzone(player.getName()); Warzone playerWarzone = this.war.getPlayerTeamWarzone(player.getName());
if (playerTeam != null && playerWarzone != null) { if (playerTeam != null && playerWarzone != null) {
// teleport to team spawn upon death // teleport to team spawn upon death
playerWarzone.respawnPlayer(playerTeam, player); playerWarzone.respawnPlayer(playerTeam, player);
int remaining = playerTeam.getRemainingLifes(); int remaining = playerTeam.getRemainingLifes();
if (remaining == 0) { // your death caused your team to lose if (remaining == 0) { // your death caused your team to lose
@ -750,7 +751,7 @@ public class Warzone {
} }
} }
playerTeam.resetSign(); playerTeam.resetSign();
Plugin heroicDeath = War.war.getServer().getPluginManager().getPlugin("HeroicDeath"); Plugin heroicDeath = this.war.getServer().getPluginManager().getPlugin("HeroicDeath");
if (heroicDeath != null) { if (heroicDeath != null) {
} }
@ -768,7 +769,7 @@ public class Warzone {
} }
private void handlePlayerLeave(Player player, boolean removeFromTeam) { private void handlePlayerLeave(Player player, boolean removeFromTeam) {
Team playerTeam = War.war.getPlayerTeam(player.getName()); Team playerTeam = this.war.getPlayerTeam(player.getName());
if (playerTeam != null) { if (playerTeam != null) {
if (removeFromTeam) { if (removeFromTeam) {
playerTeam.removePlayer(player.getName()); playerTeam.removePlayer(player.getName());
@ -796,9 +797,9 @@ public class Warzone {
player.setFireTicks(0); player.setFireTicks(0);
player.setRemainingAir(300); player.setRemainingAir(300);
War.war.msg(player, "Left the zone. Your inventory has been restored."); this.war.msg(player, "Left the zone. Your inventory has been restored.");
if (War.war.getWarHub() != null) { if (this.war.getWarHub() != null) {
War.war.getWarHub().resetZoneSign(this); this.war.getWarHub().resetZoneSign(this);
} }
boolean zoneEmpty = true; boolean zoneEmpty = true;
@ -816,7 +817,7 @@ public class Warzone {
} }
this.getVolume().resetBlocksAsJob(); this.getVolume().resetBlocksAsJob();
this.initializeZoneAsJob(); this.initializeZoneAsJob();
War.war.log("Last player left warzone " + this.getName() + ". Warzone blocks resetting automatically...", Level.INFO); this.war.log("Last player left warzone " + this.getName() + ". Warzone blocks resetting automatically...", Level.INFO);
} }
} }
} }
@ -876,15 +877,15 @@ public class Warzone {
winnersStr += ". Resetting warzone and your inventory..."; winnersStr += ". Resetting warzone and your inventory...";
// Score cap reached. Reset everything. // Score cap reached. Reset everything.
ScoreCapReachedJob job = new ScoreCapReachedJob(this, winnersStr); ScoreCapReachedJob job = new ScoreCapReachedJob(this, winnersStr);
War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, job); this.war.getServer().getScheduler().scheduleSyncDelayedTask(this.war, job);
if (this.getLobby() != null) { if (this.getLobby() != null) {
this.getLobby().getVolume().resetBlocksAsJob(); this.getLobby().getVolume().resetBlocksAsJob();
} }
this.getVolume().resetBlocksAsJob(); this.getVolume().resetBlocksAsJob();
this.initializeZoneAsJob(player); this.initializeZoneAsJob(player);
if (War.war.getWarHub() != null) { if (this.war.getWarHub() != null) {
// TODO: test if warhub sign give the correct info despite the jobs // TODO: test if warhub sign give the correct info despite the jobs
War.war.getWarHub().resetZoneSign(this); this.war.getWarHub().resetZoneSign(this);
} }
} }
@ -971,7 +972,7 @@ public class Warzone {
} }
public void unload() { public void unload() {
War.war.log("Unloading zone " + this.getName() + "...", Level.INFO); this.war.log("Unloading zone " + this.getName() + "...", Level.INFO);
for (Team team : this.getTeams()) { for (Team team : this.getTeams()) {
for (Player player : team.getPlayers()) { for (Player player : team.getPlayers()) {
this.handlePlayerLeave(player, this.getTeleport(), false); this.handlePlayerLeave(player, this.getTeleport(), false);

View File

@ -22,6 +22,7 @@ import com.tommytony.war.volumes.ZoneVolume;
* *
*/ */
public class ZoneLobby { public class ZoneLobby {
private final War war;
private final Warzone warzone; private final Warzone warzone;
private BlockFace wall; private BlockFace wall;
private Volume volume; private Volume volume;
@ -46,7 +47,8 @@ public class ZoneLobby {
* @param wall * @param wall
* On which wall of the warzone will the lobby be stuck to at mid-weight * On which wall of the warzone will the lobby be stuck to at mid-weight
*/ */
public ZoneLobby(Warzone warzone, BlockFace wall) { public ZoneLobby(War war, Warzone warzone, BlockFace wall) {
this.war = war;
this.warzone = warzone; this.warzone = warzone;
int lobbyWidth = warzone.getTeams().size() * 4 + 5; int lobbyWidth = warzone.getTeams().size() * 4 + 5;
this.lobbyHalfSide = lobbyWidth / 2; this.lobbyHalfSide = lobbyWidth / 2;
@ -64,7 +66,8 @@ public class ZoneLobby {
* @param wall * @param wall
* On which wall of the warzone will the lobby be stuck to at mid-weight * On which wall of the warzone will the lobby be stuck to at mid-weight
*/ */
public ZoneLobby(Warzone warzone, Location playerLocation) { public ZoneLobby(War war, Warzone warzone, Location playerLocation) {
this.war = war;
this.warzone = warzone; this.warzone = warzone;
int lobbyWidth = warzone.getTeams().size() * 4 + 5; int lobbyWidth = warzone.getTeams().size() * 4 + 5;
this.lobbyHalfSide = lobbyWidth / 2; this.lobbyHalfSide = lobbyWidth / 2;
@ -77,7 +80,8 @@ public class ZoneLobby {
/** /**
* Convenience ctor when loading form disk. This figures out the middle wall block of the lobby from the volume instead of the other way around. * Convenience ctor when loading form disk. This figures out the middle wall block of the lobby from the volume instead of the other way around.
*/ */
public ZoneLobby(Warzone warzone, BlockFace wall, Volume volume) { public ZoneLobby(War war, Warzone warzone, BlockFace wall, Volume volume) {
this.war = war;
this.warzone = warzone; this.warzone = warzone;
int lobbyWidth = warzone.getTeams().size() * 4 + 5; int lobbyWidth = warzone.getTeams().size() * 4 + 5;
this.lobbyHalfSide = lobbyWidth / 2; this.lobbyHalfSide = lobbyWidth / 2;
@ -221,7 +225,7 @@ public class ZoneLobby {
private void createVolumeOrReset() { private void createVolumeOrReset() {
if (this.volume == null) { if (this.volume == null) {
// no previous wall // no previous wall
this.volume = new Volume("lobby", this.warzone.getWorld()); this.volume = new Volume("lobby", this.war, this.warzone.getWorld());
} else if (this.volume.isSaved()) { } else if (this.volume.isSaved()) {
this.volume.resetBlocks(); this.volume.resetBlocks();
} }
@ -257,7 +261,7 @@ public class ZoneLobby {
this.volume.setFaceMaterial(BlockFace.DOWN, Material.GLASS); // beautiful this.volume.setFaceMaterial(BlockFace.DOWN, Material.GLASS); // beautiful
// add war hub link gate // add war hub link gate
if (War.war.getWarHub() != null) { if (this.war.getWarHub() != null) {
Block linkGateBlock = BlockInfo.getBlock(this.warzone.getWorld(), this.warHubLinkGate); Block linkGateBlock = BlockInfo.getBlock(this.warzone.getWorld(), this.warHubLinkGate);
this.placeGate(linkGateBlock, Material.OBSIDIAN); this.placeGate(linkGateBlock, Material.OBSIDIAN);
// add warhub sign // add warhub sign
@ -315,7 +319,7 @@ public class ZoneLobby {
lines[2] = ""; lines[2] = "";
lines[3] = "Pick your team."; lines[3] = "Pick your team.";
} }
SignHelper.setToSign(War.war, zoneSignBlock, data, lines); SignHelper.setToSign(this.war, zoneSignBlock, data, lines);
// lets get some light in here // lets get some light in here
if (this.wall == BlockFace.NORTH || this.wall == BlockFace.SOUTH) { if (this.wall == BlockFace.NORTH || this.wall == BlockFace.SOUTH) {
@ -326,7 +330,7 @@ public class ZoneLobby {
BlockInfo.getBlock(this.warzone.getWorld(), this.lobbyMiddleWallBlock).getFace(BlockFace.DOWN).getFace(BlockFace.SOUTH, this.lobbyHalfSide - 1).getFace(this.wall, 9).setType(Material.GLOWSTONE); BlockInfo.getBlock(this.warzone.getWorld(), this.lobbyMiddleWallBlock).getFace(BlockFace.DOWN).getFace(BlockFace.SOUTH, this.lobbyHalfSide - 1).getFace(this.wall, 9).setType(Material.GLOWSTONE);
} }
} else { } else {
War.war.log("Failed to initalize zone lobby for zone " + this.warzone.getName(), java.util.logging.Level.WARNING); this.war.log("Failed to initalize zone lobby for zone " + this.warzone.getName(), java.util.logging.Level.WARNING);
} }
} }
@ -623,7 +627,7 @@ public class ZoneLobby {
} }
} }
SignHelper.setToSign(War.war, block, data, lines); SignHelper.setToSign(this.war, block, data, lines);
} }
public boolean isLeavingZone(Location location) { public boolean isLeavingZone(Location location) {
@ -664,7 +668,7 @@ public class ZoneLobby {
private boolean leaving(Location location, Block gate, BlockFace inside, BlockFace left, BlockFace right) { private boolean leaving(Location location, Block gate, BlockFace inside, BlockFace left, BlockFace right) {
// 3x4x1 deep // 3x4x1 deep
Volume gateExitVolume = new Volume("tempGateExit", location.getWorld()); Volume gateExitVolume = new Volume("tempGateExit", this.war, location.getWorld());
Block out = gate.getFace(inside); Block out = gate.getFace(inside);
gateExitVolume.setCornerOne(out.getFace(left).getFace(BlockFace.DOWN)); gateExitVolume.setCornerOne(out.getFace(left).getFace(BlockFace.DOWN));
gateExitVolume.setCornerTwo(gate.getFace(right, 1).getFace(BlockFace.UP, 3)); gateExitVolume.setCornerTwo(gate.getFace(right, 1).getFace(BlockFace.UP, 3));

View File

@ -15,25 +15,27 @@ import bukkit.tommytony.war.War;
public class ZoneSetter { public class ZoneSetter {
private final War war;
private final Player player; private final Player player;
private final String zoneName; private final String zoneName;
public ZoneSetter(Player player, String zoneName) { public ZoneSetter(War war, Player player, String zoneName) {
this.war = war;
this.player = player; this.player = player;
this.zoneName = zoneName; this.zoneName = zoneName;
} }
public void placeNorthwest() { public void placeNorthwest() {
Warzone warzone = War.war.findWarzone(this.zoneName); Warzone warzone = this.war.findWarzone(this.zoneName);
Block northwestBlock = this.player.getLocation().getWorld().getBlockAt(this.player.getLocation()); Block northwestBlock = this.player.getLocation().getWorld().getBlockAt(this.player.getLocation());
StringBuilder msgString = new StringBuilder(); StringBuilder msgString = new StringBuilder();
try { try {
if (warzone == null) { if (warzone == null) {
// create the warzone // create the warzone
warzone = new Warzone(this.player.getLocation().getWorld(), this.zoneName); warzone = new Warzone(this.war, this.player.getLocation().getWorld(), this.zoneName);
War.war.getIncompleteZones().add(warzone); this.war.getIncompleteZones().add(warzone);
warzone.getVolume().setNorthwest(northwestBlock); warzone.getVolume().setNorthwest(northwestBlock);
War.war.msg(this.player, "Warzone " + warzone.getName() + " created. Northwesternmost point set to x:" + warzone.getVolume().getNorthwestX() + " z:" + warzone.getVolume().getNorthwestZ() + ". "); this.war.msg(this.player, "Warzone " + warzone.getName() + " created. Northwesternmost point set to x:" + warzone.getVolume().getNorthwestX() + " z:" + warzone.getVolume().getNorthwestZ() + ". ");
} else { } else {
// change existing warzone // change existing warzone
this.resetWarzone(warzone, msgString); this.resetWarzone(warzone, msgString);
@ -42,7 +44,7 @@ public class ZoneSetter {
} }
this.saveIfReady(warzone, msgString); this.saveIfReady(warzone, msgString);
} catch (NotNorthwestException e) { } catch (NotNorthwestException e) {
War.war.badMsg(this.player, "The block you selected is not to the northwest of the existing southeasternmost block."); this.war.badMsg(this.player, "The block you selected is not to the northwest of the existing southeasternmost block.");
if (warzone.getVolume().isSaved()) { if (warzone.getVolume().isSaved()) {
warzone.initializeZone(); // was reset before changing warzone.initializeZone(); // was reset before changing
} }
@ -60,16 +62,16 @@ public class ZoneSetter {
} }
public void placeSoutheast() { public void placeSoutheast() {
Warzone warzone = War.war.findWarzone(this.zoneName); Warzone warzone = this.war.findWarzone(this.zoneName);
Block southeastBlock = this.player.getLocation().getWorld().getBlockAt(this.player.getLocation()); Block southeastBlock = this.player.getLocation().getWorld().getBlockAt(this.player.getLocation());
StringBuilder msgString = new StringBuilder(); StringBuilder msgString = new StringBuilder();
try { try {
if (warzone == null) { if (warzone == null) {
// create the warzone // create the warzone
warzone = new Warzone(this.player.getLocation().getWorld(), this.zoneName); warzone = new Warzone(this.war, this.player.getLocation().getWorld(), this.zoneName);
War.war.getIncompleteZones().add(warzone); this.war.getIncompleteZones().add(warzone);
warzone.getVolume().setSoutheast(southeastBlock); warzone.getVolume().setSoutheast(southeastBlock);
War.war.msg(this.player, "Warzone " + warzone.getName() + " created. Southeasternmost point set to x:" + warzone.getVolume().getSoutheastX() + " z:" + warzone.getVolume().getSoutheastZ() + ". "); this.war.msg(this.player, "Warzone " + warzone.getName() + " created. Southeasternmost point set to x:" + warzone.getVolume().getSoutheastX() + " z:" + warzone.getVolume().getSoutheastZ() + ". ");
} else { } else {
// change existing warzone // change existing warzone
this.resetWarzone(warzone, msgString); this.resetWarzone(warzone, msgString);
@ -78,7 +80,7 @@ public class ZoneSetter {
} }
this.saveIfReady(warzone, msgString); this.saveIfReady(warzone, msgString);
} catch (NotSoutheastException e) { } catch (NotSoutheastException e) {
War.war.badMsg(this.player, "The block you selected is not to the southeast of the existing northwestnmost block."); this.war.badMsg(this.player, "The block you selected is not to the southeast of the existing northwestnmost block.");
if (warzone.getVolume().isSaved()) { if (warzone.getVolume().isSaved()) {
warzone.initializeZone(); // was reset before changing warzone.initializeZone(); // was reset before changing
} }
@ -101,15 +103,15 @@ public class ZoneSetter {
} }
public void placeCorner1(Block corner1Block) { public void placeCorner1(Block corner1Block) {
Warzone warzone = War.war.findWarzone(this.zoneName); Warzone warzone = this.war.findWarzone(this.zoneName);
StringBuilder msgString = new StringBuilder(); StringBuilder msgString = new StringBuilder();
try { try {
if (warzone == null) { if (warzone == null) {
// create the warzone // create the warzone
warzone = new Warzone(this.player.getLocation().getWorld(), this.zoneName); warzone = new Warzone(this.war, this.player.getLocation().getWorld(), this.zoneName);
War.war.getIncompleteZones().add(warzone); this.war.getIncompleteZones().add(warzone);
warzone.getVolume().setZoneCornerOne(corner1Block); warzone.getVolume().setZoneCornerOne(corner1Block);
War.war.msg(this.player, "Warzone " + warzone.getName() + " created. Corner 1 set to x:" + corner1Block.getX() + " y:" + corner1Block.getY() + " z:" + corner1Block.getZ() + ". "); this.war.msg(this.player, "Warzone " + warzone.getName() + " created. Corner 1 set to x:" + corner1Block.getX() + " y:" + corner1Block.getY() + " z:" + corner1Block.getZ() + ". ");
} else { } else {
// change existing warzone // change existing warzone
this.resetWarzone(warzone, msgString); this.resetWarzone(warzone, msgString);
@ -136,15 +138,15 @@ public class ZoneSetter {
} }
public void placeCorner2(Block corner2Block) { public void placeCorner2(Block corner2Block) {
Warzone warzone = War.war.findWarzone(this.zoneName); Warzone warzone = this.war.findWarzone(this.zoneName);
StringBuilder msgString = new StringBuilder(); StringBuilder msgString = new StringBuilder();
try { try {
if (warzone == null) { if (warzone == null) {
// create the warzone // create the warzone
warzone = new Warzone(this.player.getLocation().getWorld(), this.zoneName); warzone = new Warzone(this.war, this.player.getLocation().getWorld(), this.zoneName);
War.war.getIncompleteZones().add(warzone); this.war.getIncompleteZones().add(warzone);
warzone.getVolume().setZoneCornerTwo(corner2Block); warzone.getVolume().setZoneCornerTwo(corner2Block);
War.war.msg(this.player, "Warzone " + warzone.getName() + " created. Corner 2 set to x:" + corner2Block.getX() + " y:" + corner2Block.getY() + " z:" + corner2Block.getZ() + ". "); this.war.msg(this.player, "Warzone " + warzone.getName() + " created. Corner 2 set to x:" + corner2Block.getX() + " y:" + corner2Block.getY() + " z:" + corner2Block.getZ() + ". ");
} else { } else {
// change existing warzone // change existing warzone
this.resetWarzone(warzone, msgString); this.resetWarzone(warzone, msgString);
@ -167,7 +169,7 @@ public class ZoneSetter {
private void resetWarzone(Warzone warzone, StringBuilder msgString) { private void resetWarzone(Warzone warzone, StringBuilder msgString) {
if (warzone.getVolume().isSaved()) { if (warzone.getVolume().isSaved()) {
War.war.msg(this.player, "Resetting " + warzone.getName() + " blocks."); this.war.msg(this.player, "Resetting " + warzone.getName() + " blocks.");
if (warzone.getLobby() != null && warzone.getLobby().getVolume() != null) { if (warzone.getLobby() != null && warzone.getLobby().getVolume() != null) {
warzone.getLobby().getVolume().resetBlocks(); warzone.getLobby().getVolume().resetBlocks();
} }
@ -177,48 +179,48 @@ public class ZoneSetter {
} }
private void handleTooSmall() { private void handleTooSmall() {
War.war.badMsg(this.player, "That would make the " + this.zoneName + " warzone too small. Sides must be at least 10 blocks and all existing structures (spawns, flags, etc) must fit inside."); this.war.badMsg(this.player, "That would make the " + this.zoneName + " warzone too small. Sides must be at least 10 blocks and all existing structures (spawns, flags, etc) must fit inside.");
} }
private void handleTooBig() { private void handleTooBig() {
War.war.badMsg(this.player, "That would make the " + this.zoneName + " warzone too big. Sides must be less than 750 blocks."); this.war.badMsg(this.player, "That would make the " + this.zoneName + " warzone too big. Sides must be less than 750 blocks.");
} }
private void saveIfReady(Warzone warzone, StringBuilder msgString) { private void saveIfReady(Warzone warzone, StringBuilder msgString) {
if (warzone.ready()) { if (warzone.ready()) {
if (!War.war.getWarzones().contains(warzone)) { if (!this.war.getWarzones().contains(warzone)) {
War.war.addWarzone(warzone); this.war.addWarzone(warzone);
} }
if (War.war.getIncompleteZones().contains(warzone)) { if (this.war.getIncompleteZones().contains(warzone)) {
War.war.getIncompleteZones().remove(warzone); this.war.getIncompleteZones().remove(warzone);
} }
WarMapper.save(); WarMapper.save(this.war);
msgString.append("Saving new warzone blocks..."); msgString.append("Saving new warzone blocks...");
War.war.msg(this.player, msgString.toString()); this.war.msg(this.player, msgString.toString());
warzone.saveState(false); // we just changed the volume, cant reset walls warzone.saveState(false); // we just changed the volume, cant reset walls
if (warzone.getLobby() == null) { if (warzone.getLobby() == null) {
// Set default lobby on south side // Set default lobby on south side
ZoneLobby lobby = new ZoneLobby(warzone, BlockFace.SOUTH); ZoneLobby lobby = new ZoneLobby(this.war, warzone, BlockFace.SOUTH);
warzone.setLobby(lobby); warzone.setLobby(lobby);
if (War.war.getWarHub() != null) { // warhub has to change if (this.war.getWarHub() != null) { // warhub has to change
War.war.getWarHub().getVolume().resetBlocks(); this.war.getWarHub().getVolume().resetBlocks();
War.war.getWarHub().initialize(); this.war.getWarHub().initialize();
} }
War.war.msg(this.player, "Default lobby created on south side of zone. Use /setzonelobby <n/s/e/w> to change its position."); this.war.msg(this.player, "Default lobby created on south side of zone. Use /setzonelobby <n/s/e/w> to change its position.");
} // else { } // else {
// gotta move the lobby (or dont because zone.initzon does it for you) // gotta move the lobby (or dont because zone.initzon does it for you)
// warzone.getLobby().changeWall(warzone.getLobby().getWall()); // warzone.getLobby().changeWall(warzone.getLobby().getWall());
// } // }
warzone.initializeZone(); warzone.initializeZone();
WarzoneMapper.save(warzone, true); WarzoneMapper.save(this.war, warzone, true);
War.war.msg(this.player, "Warzone saved."); this.war.msg(this.player, "Warzone saved.");
} else { } else {
if (warzone.getVolume().getCornerOne() == null) { if (warzone.getVolume().getCornerOne() == null) {
msgString.append("Still missing corner 1."); msgString.append("Still missing corner 1.");
} else if (warzone.getVolume().getCornerTwo() == null) { } else if (warzone.getVolume().getCornerTwo() == null) {
msgString.append("Still missing corner 2."); msgString.append("Still missing corner 2.");
} }
War.war.msg(this.player, msgString.toString()); this.war.msg(this.player, msgString.toString());
} }
} }

View File

@ -14,9 +14,11 @@ import com.tommytony.war.volumes.Volume;
public class RestoreWarhubJob implements Runnable { public class RestoreWarhubJob implements Runnable {
private final War war;
private final String hubStr; private final String hubStr;
public RestoreWarhubJob(String hubStr) { public RestoreWarhubJob(War war, String hubStr) {
this.war = war;
this.hubStr = hubStr; this.hubStr = hubStr;
} }
@ -31,33 +33,33 @@ public class RestoreWarhubJob implements Runnable {
String hubOrientation = "west"; String hubOrientation = "west";
if (hubStrSplit.length > 3) { if (hubStrSplit.length > 3) {
worldName = hubStrSplit[3]; worldName = hubStrSplit[3];
world = War.war.getServer().getWorld(worldName); world = this.war.getServer().getWorld(worldName);
if(hubStrSplit.length > 4) { if(hubStrSplit.length > 4) {
hubOrientation = hubStrSplit[4]; hubOrientation = hubStrSplit[4];
} }
} else { } else {
worldName = "DEFAULT"; worldName = "DEFAULT";
world = War.war.getServer().getWorlds().get(0); // default to first world world = this.war.getServer().getWorlds().get(0); // default to first world
} }
if (world != null) { if (world != null) {
Location hubLocation = new Location(world, hubX, hubY, hubZ); Location hubLocation = new Location(world, hubX, hubY, hubZ);
WarHub hub = new WarHub(hubLocation, hubOrientation); WarHub hub = new WarHub(this.war, hubLocation, hubOrientation);
War.war.setWarHub(hub); this.war.setWarHub(hub);
Volume vol = VolumeMapper.loadVolume("warhub", "", world); Volume vol = VolumeMapper.loadVolume("warhub", "", this.war, world);
hub.setVolume(vol); hub.setVolume(vol);
hub.getVolume().resetBlocks(); hub.getVolume().resetBlocks();
hub.initialize(); hub.initialize();
// In the previous job started by the mapper, warzones were created, but their lobbies are missing the war hub gate (because it didn't exist yet) // In the previous job started by the mapper, warzones were created, but their lobbies are missing the war hub gate (because it didn't exist yet)
for (Warzone zone : War.war.getWarzones()) { for (Warzone zone : this.war.getWarzones()) {
if (zone.getLobby() != null) { if (zone.getLobby() != null) {
zone.getLobby().getVolume().resetBlocks(); zone.getLobby().getVolume().resetBlocks();
zone.getLobby().initialize(); zone.getLobby().initialize();
} }
} }
War.war.log("Warhub ready.", Level.INFO); this.war.log("Warhub ready.", Level.INFO);
} else { } else {
War.war.log("Failed to restore warhub. The specified world (name: " + worldName + ") does not exist!", Level.WARNING); this.war.log("Failed to restore warhub. The specified world (name: " + worldName + ") does not exist!", Level.WARNING);
} }
} }
} }

View File

@ -9,23 +9,25 @@ import com.tommytony.war.mappers.WarzoneMapper;
public class RestoreWarzonesJob implements Runnable { public class RestoreWarzonesJob implements Runnable {
private final War war;
private final String warzonesStr; private final String warzonesStr;
private final boolean newWarInstall; private final boolean newWarInstall;
public RestoreWarzonesJob(String warzonesStr, boolean newWarInstall) { public RestoreWarzonesJob(War war, String warzonesStr, boolean newWarInstall) {
this.war = war;
this.warzonesStr = warzonesStr; this.warzonesStr = warzonesStr;
this.newWarInstall = newWarInstall; this.newWarInstall = newWarInstall;
} }
public void run() { public void run() {
String[] warzoneSplit = this.warzonesStr.split(","); String[] warzoneSplit = this.warzonesStr.split(",");
War.war.getWarzones().clear(); this.war.getWarzones().clear();
for (String warzoneName : warzoneSplit) { for (String warzoneName : warzoneSplit) {
if (warzoneName != null && !warzoneName.equals("")) { if (warzoneName != null && !warzoneName.equals("")) {
War.war.log("Loading zone " + warzoneName + "...", Level.INFO); this.war.log("Loading zone " + warzoneName + "...", Level.INFO);
Warzone zone = WarzoneMapper.load(warzoneName, !this.newWarInstall); Warzone zone = WarzoneMapper.load(this.war, warzoneName, !this.newWarInstall);
if (zone != null) { // could have failed, would've been logged already if (zone != null) { // could have failed, would've been logged already
War.war.getWarzones().add(zone); this.war.getWarzones().add(zone);
// zone.getVolume().loadCorners(); // zone.getVolume().loadCorners();
zone.getVolume().loadCorners(); zone.getVolume().loadCorners();
if (zone.getLobby() != null) { if (zone.getLobby() != null) {
@ -38,8 +40,8 @@ public class RestoreWarzonesJob implements Runnable {
} }
} }
} }
if (War.war.getWarzones().size() > 0) { if (this.war.getWarzones().size() > 0) {
War.war.log("Warzones ready.", Level.INFO); this.war.log("Warzones ready.", Level.INFO);
} }
} }

View File

@ -1,19 +1,23 @@
package com.tommytony.war.jobs; package com.tommytony.war.jobs;
import bukkit.tommytony.war.War;
import com.tommytony.war.mappers.ZoneVolumeMapper; import com.tommytony.war.mappers.ZoneVolumeMapper;
import com.tommytony.war.volumes.Volume; import com.tommytony.war.volumes.Volume;
public class ZoneVolumeSaveJob extends Thread { public class ZoneVolumeSaveJob extends Thread {
private final Volume volume; private final Volume volume;
private final String zoneName; private final String zoneName;
private final War war;
public ZoneVolumeSaveJob(Volume volume, String zoneName) { public ZoneVolumeSaveJob(Volume volume, String zoneName, War war) {
this.volume = volume; this.volume = volume;
this.zoneName = zoneName; this.zoneName = zoneName;
this.war = war;
} }
@Override @Override
public void run() { public void run() {
ZoneVolumeMapper.save(this.volume, this.zoneName); ZoneVolumeMapper.save(this.volume, this.zoneName, this.war);
} }
} }

View File

@ -59,11 +59,11 @@ public class PreDeGaulleZoneVolumeMapper {
return items; return items;
} }
public static int load(ZoneVolume volume, String zoneName, World world, boolean onlyLoadCorners) { public static int load(ZoneVolume volume, String zoneName, War war, World world, boolean onlyLoadCorners) {
BufferedReader in = null; BufferedReader in = null;
int noOfResetBlocks = 0; int noOfResetBlocks = 0;
try { try {
in = new BufferedReader(new FileReader(new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".dat"))); in = new BufferedReader(new FileReader(new File(war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".dat")));
String firstLine = in.readLine(); String firstLine = in.readLine();
if (firstLine != null && !firstLine.equals("")) { if (firstLine != null && !firstLine.equals("")) {
@ -240,7 +240,7 @@ public class PreDeGaulleZoneVolumeMapper {
} }
} catch (Exception e) { } catch (Exception e) {
War.war.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()); 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(); e.printStackTrace();
} finally { } finally {
z++; z++;
@ -257,15 +257,15 @@ public class PreDeGaulleZoneVolumeMapper {
x++; x++;
} }
if (!deferred.isEmpty()) { if (!deferred.isEmpty()) {
War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, deferred, 1); war.getServer().getScheduler().scheduleSyncDelayedTask(war, deferred, 1);
} }
} }
} }
} catch (IOException e) { } catch (IOException e) {
War.war.log("Failed to read volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING); war.log("Failed to read volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
e.printStackTrace(); e.printStackTrace();
} catch (Exception e) { } catch (Exception e) {
War.war.log("Unexpected error caused failure to read volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING); war.log("Unexpected error caused failure to read volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
if (in != null) { if (in != null) {
@ -276,7 +276,7 @@ public class PreDeGaulleZoneVolumeMapper {
// scanner.close(); // scanner.close();
// scanner = null; // scanner = null;
} catch (IOException e) { } catch (IOException e) {
War.war.log("Failed to close file reader for volume " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING); war.log("Failed to close file reader for volume " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
e.printStackTrace(); e.printStackTrace();
} }
} }

View File

@ -26,9 +26,9 @@ import com.tommytony.war.volumes.Volume;
*/ */
public class VolumeMapper { public class VolumeMapper {
public static Volume loadVolume(String volumeName, String zoneName, World world) { public static Volume loadVolume(String volumeName, String zoneName, War war, World world) {
Volume volume = new Volume(volumeName, world); Volume volume = new Volume(volumeName, war, world);
VolumeMapper.load(volume, zoneName, world); VolumeMapper.load(volume, zoneName, war, world);
return volume; return volume;
} }
@ -39,13 +39,13 @@ public class VolumeMapper {
// return volume; // return volume;
// } // }
public static void load(Volume volume, String zoneName, World world) { public static void load(Volume volume, String zoneName, War war, World world) {
BufferedReader in = null; BufferedReader in = null;
try { try {
if (zoneName.equals("")) { if (zoneName.equals("")) {
in = new BufferedReader(new FileReader(new File(War.war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".dat"))); // for the warhub in = new BufferedReader(new FileReader(new File(war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".dat"))); // for the warhub
} else { } else {
in = new BufferedReader(new FileReader(new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".dat"))); in = new BufferedReader(new FileReader(new File(war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".dat")));
} }
String firstLine = in.readLine(); String firstLine = in.readLine();
if (firstLine != null && !firstLine.equals("")) { if (firstLine != null && !firstLine.equals("")) {
@ -151,7 +151,7 @@ public class VolumeMapper {
blockReads++; blockReads++;
} }
} catch (Exception e) { } catch (Exception e) {
War.war.log("Unexpected error while reading block from volume " + volume.getName() + " file for zone " + zoneName + ". Blocks read so far: " + blockReads + "Position: x:" + i + " y:" + j + " z:" + k + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING); war.log("Unexpected error while reading block from volume " + volume.getName() + " file for zone " + zoneName + ". Blocks read so far: " + blockReads + "Position: x:" + i + " y:" + j + " z:" + k + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -164,31 +164,31 @@ public class VolumeMapper {
} }
} }
} catch (IOException e) { } catch (IOException e) {
War.war.log("Failed to read volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING); war.log("Failed to read volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
e.printStackTrace(); e.printStackTrace();
} catch (Exception e) { } catch (Exception e) {
War.war.log("Unexpected error caused failure to read volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING); war.log("Unexpected error caused failure to read volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
if (in != null) { if (in != null) {
try { try {
in.close(); in.close();
} catch (IOException e) { } catch (IOException e) {
War.war.log("Failed to close file reader for volume " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING); war.log("Failed to close file reader for volume " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
e.printStackTrace(); e.printStackTrace();
} }
} }
} }
} }
public static void save(Volume volume, String zoneName) { public static void save(Volume volume, String zoneName, War war) {
if (volume.hasTwoCorners()) { if (volume.hasTwoCorners()) {
BufferedWriter out = null; BufferedWriter out = null;
try { try {
if (zoneName.equals("")) { if (zoneName.equals("")) {
out = new BufferedWriter(new FileWriter(new File(War.war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".dat"))); out = new BufferedWriter(new FileWriter(new File(war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".dat")));
} else { } else {
out = new BufferedWriter(new FileWriter(new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".dat"))); out = new BufferedWriter(new FileWriter(new File(war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".dat")));
} }
out.write("corner1"); out.write("corner1");
@ -260,24 +260,24 @@ public class VolumeMapper {
} }
out.newLine(); out.newLine();
} catch (Exception e) { } catch (Exception e) {
War.war.log("Unexpected error while writing block into volume " + volume.getName() + " file for zone " + zoneName + ". Blocks written so far: " + blockWrites + "Position: x:" + i + " y:" + j + " z:" + k + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING); war.log("Unexpected error while writing block into volume " + volume.getName() + " file for zone " + zoneName + ". Blocks written so far: " + blockWrites + "Position: x:" + i + " y:" + j + " z:" + k + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
e.printStackTrace(); e.printStackTrace();
} }
} }
} }
} }
} catch (IOException e) { } catch (IOException e) {
War.war.log("Failed to write volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING); war.log("Failed to write volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
e.printStackTrace(); e.printStackTrace();
} catch (Exception e) { } catch (Exception e) {
War.war.log("Unexpected error caused failure to write volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING); war.log("Unexpected error caused failure to write volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
if (out != null) { if (out != null) {
try { try {
out.close(); out.close();
} catch (IOException e) { } catch (IOException e) {
War.war.log("Failed to close file writer for volume " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING); war.log("Failed to close file writer for volume " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
e.printStackTrace(); e.printStackTrace();
} }
} }

View File

@ -23,15 +23,15 @@ import com.tommytony.war.jobs.RestoreWarzonesJob;
*/ */
public class WarMapper { public class WarMapper {
public static void load() { public static void load(War war) {
// war.getLogger().info("Loading war config..."); // war.getLogger().info("Loading war config...");
(War.war.getDataFolder()).mkdir(); (war.getDataFolder()).mkdir();
(new File(War.war.getDataFolder().getPath() + "/dat")).mkdir(); (new File(war.getDataFolder().getPath() + "/dat")).mkdir();
PropertiesFile warConfig = new PropertiesFile(War.war.getDataFolder().getPath() + "/war.txt"); PropertiesFile warConfig = new PropertiesFile(war.getDataFolder().getPath() + "/war.txt");
try { try {
warConfig.load(); warConfig.load();
} catch (IOException e) { } catch (IOException e) {
War.war.log("Failed to load war.txt file.", Level.WARNING); war.log("Failed to load war.txt file.", Level.WARNING);
e.printStackTrace(); e.printStackTrace();
} }
@ -39,93 +39,93 @@ public class WarMapper {
boolean newWar = false; boolean newWar = false;
if (!warConfig.containsKey("warzones")) { if (!warConfig.containsKey("warzones")) {
newWar = true; newWar = true;
WarMapper.save(); WarMapper.save(war);
War.war.log("war.txt settings file created.", Level.INFO); war.log("war.txt settings file created.", Level.INFO);
try { try {
warConfig.load(); warConfig.load();
} catch (IOException e) { } catch (IOException e) {
War.war.log("Failed to reload war.txt file after creating it.", Level.WARNING); war.log("Failed to reload war.txt file after creating it.", Level.WARNING);
e.printStackTrace(); e.printStackTrace();
} }
} }
// warzones // warzones
String warzonesStr = warConfig.getString("warzones"); String warzonesStr = warConfig.getString("warzones");
RestoreWarzonesJob restoreWarzones = new RestoreWarzonesJob(warzonesStr, newWar); RestoreWarzonesJob restoreWarzones = new RestoreWarzonesJob(war, warzonesStr, newWar);
if (War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, restoreWarzones) == -1) { if (war.getServer().getScheduler().scheduleSyncDelayedTask(war, restoreWarzones) == -1) {
War.war.log("Failed to schedule warzone-restore job. No warzone was loaded.", Level.WARNING); war.log("Failed to schedule warzone-restore job. No warzone was loaded.", Level.WARNING);
} }
// zone makers // zone makers
String[] makers = warConfig.getString("zoneMakers").split(","); String[] makers = warConfig.getString("zoneMakers").split(",");
War.war.getZoneMakerNames().clear(); war.getZoneMakerNames().clear();
for (String makerName : makers) { for (String makerName : makers) {
if (makerName != null && !makerName.equals("")) { if (makerName != null && !makerName.equals("")) {
War.war.getZoneMakerNames().add(makerName); war.getZoneMakerNames().add(makerName);
} }
} }
// command whitelist // command whitelist
String[] whitelist = warConfig.getString("commandWhitelist").split(","); String[] whitelist = warConfig.getString("commandWhitelist").split(",");
War.war.getCommandWhitelist().clear(); war.getCommandWhitelist().clear();
for (String command : whitelist) { for (String command : whitelist) {
if (command != null && !command.equals("")) { if (command != null && !command.equals("")) {
War.war.getCommandWhitelist().add(command); war.getCommandWhitelist().add(command);
} }
} }
// defaultLoadout // defaultLoadout
String defaultLoadoutStr = warConfig.getString("defaultLoadout"); String defaultLoadoutStr = warConfig.getString("defaultLoadout");
String[] defaultLoadoutSplit = defaultLoadoutStr.split(";"); String[] defaultLoadoutSplit = defaultLoadoutStr.split(";");
War.war.getDefaultLoadout().clear(); war.getDefaultLoadout().clear();
for (String itemStr : defaultLoadoutSplit) { for (String itemStr : defaultLoadoutSplit) {
if (itemStr != null && !itemStr.equals("")) { if (itemStr != null && !itemStr.equals("")) {
String[] itemStrSplit = itemStr.split(","); String[] itemStrSplit = itemStr.split(",");
ItemStack item = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1])); ItemStack item = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1]));
War.war.getDefaultLoadout().put(Integer.parseInt(itemStrSplit[2]), item); war.getDefaultLoadout().put(Integer.parseInt(itemStrSplit[2]), item);
} }
} }
// defaultLifePool // defaultLifePool
War.war.setDefaultLifepool(warConfig.getInt("defaultLifePool")); war.setDefaultLifepool(warConfig.getInt("defaultLifePool"));
// defaultMonumentHeal // defaultMonumentHeal
War.war.setDefaultMonumentHeal(warConfig.getInt("defaultMonumentHeal")); war.setDefaultMonumentHeal(warConfig.getInt("defaultMonumentHeal"));
// defaultFriendlyFire // defaultFriendlyFire
War.war.setDefaultFriendlyFire(warConfig.getBoolean("defaultFriendlyFire")); war.setDefaultFriendlyFire(warConfig.getBoolean("defaultFriendlyFire"));
// defaultAutoAssignOnly // defaultAutoAssignOnly
War.war.setDefaultAutoAssignOnly(warConfig.getBoolean("defaultAutoAssignOnly")); war.setDefaultAutoAssignOnly(warConfig.getBoolean("defaultAutoAssignOnly"));
// defaultTeamCap // defaultTeamCap
War.war.setDefaultTeamCap(warConfig.getInt("defaultTeamCap")); war.setDefaultTeamCap(warConfig.getInt("defaultTeamCap"));
// defaultScoreCap // defaultScoreCap
War.war.setDefaultScoreCap(warConfig.getInt("defaultScoreCap")); war.setDefaultScoreCap(warConfig.getInt("defaultScoreCap"));
// pvpInZonesOnly // pvpInZonesOnly
War.war.setPvpInZonesOnly(warConfig.getBoolean("pvpInZonesOnly")); war.setPvpInZonesOnly(warConfig.getBoolean("pvpInZonesOnly"));
// defaultBlockHeads // defaultBlockHeads
War.war.setDefaultBlockHeads(warConfig.getBoolean("defaultBlockHeads")); war.setDefaultBlockHeads(warConfig.getBoolean("defaultBlockHeads"));
// buildInZonesOnly // buildInZonesOnly
War.war.setBuildInZonesOnly(warConfig.getBoolean("buildInZonesOnly")); war.setBuildInZonesOnly(warConfig.getBoolean("buildInZonesOnly"));
// disablePVPMessage // disablePVPMessage
War.war.setDisablePvpMessage(warConfig.getBoolean("disablePvpMessage")); war.setDisablePvpMessage(warConfig.getBoolean("disablePvpMessage"));
// defaultSpawnStyle // defaultSpawnStyle
String spawnStyle = warConfig.getString("defaultspawnStyle"); String spawnStyle = warConfig.getString("defaultspawnStyle");
if (spawnStyle != null && !spawnStyle.equals("")) { if (spawnStyle != null && !spawnStyle.equals("")) {
spawnStyle = spawnStyle.toLowerCase(); spawnStyle = spawnStyle.toLowerCase();
if (spawnStyle.equals(TeamSpawnStyles.SMALL)) { if (spawnStyle.equals(TeamSpawnStyles.SMALL)) {
War.war.setDefaultSpawnStyle(spawnStyle); war.setDefaultSpawnStyle(spawnStyle);
} else if (spawnStyle.equals(TeamSpawnStyles.FLAT)) { } else if (spawnStyle.equals(TeamSpawnStyles.FLAT)) {
War.war.setDefaultSpawnStyle(spawnStyle); war.setDefaultSpawnStyle(spawnStyle);
} else if (spawnStyle.equals(TeamSpawnStyles.INVISIBLE)) { } else if (spawnStyle.equals(TeamSpawnStyles.INVISIBLE)) {
War.war.setDefaultSpawnStyle(spawnStyle); war.setDefaultSpawnStyle(spawnStyle);
} }
// default is already initialized to BIG (see Warzone) // default is already initialized to BIG (see Warzone)
} }
@ -134,73 +134,73 @@ public class WarMapper {
String defaultRewardStr = warConfig.getString("defaultReward"); String defaultRewardStr = warConfig.getString("defaultReward");
if (defaultRewardStr != null && !defaultRewardStr.equals("")) { if (defaultRewardStr != null && !defaultRewardStr.equals("")) {
String[] defaultRewardStrSplit = defaultRewardStr.split(";"); String[] defaultRewardStrSplit = defaultRewardStr.split(";");
War.war.getDefaultReward().clear(); war.getDefaultReward().clear();
for (String itemStr : defaultRewardStrSplit) { for (String itemStr : defaultRewardStrSplit) {
if (itemStr != null && !itemStr.equals("")) { if (itemStr != null && !itemStr.equals("")) {
String[] itemStrSplit = itemStr.split(","); String[] itemStrSplit = itemStr.split(",");
ItemStack item = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1])); ItemStack item = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1]));
War.war.getDefaultReward().put(Integer.parseInt(itemStrSplit[2]), item); war.getDefaultReward().put(Integer.parseInt(itemStrSplit[2]), item);
} }
} }
} }
// defaultUnbreakableZoneBlocks // defaultUnbreakableZoneBlocks
War.war.setDefaultUnbreakableZoneBlocks(warConfig.getBoolean("defaultUnbreakableZoneBlocks")); war.setDefaultUnbreakableZoneBlocks(warConfig.getBoolean("defaultUnbreakableZoneBlocks"));
// defaultNoCreatures // defaultNoCreatures
War.war.setDefaultNoCreatures(warConfig.getBoolean("defaultNoCreatures")); war.setDefaultNoCreatures(warConfig.getBoolean("defaultNoCreatures"));
// defaultDropLootOnDeath // defaultDropLootOnDeath
// war.setDefaultDropLootOnDeath(warConfig.getBoolean("defaultDropLootOnDeath")); // war.setDefaultDropLootOnDeath(warConfig.getBoolean("defaultDropLootOnDeath"));
// defaultResetOnEmpty // defaultResetOnEmpty
War.war.setDefaultResetOnEmpty(warConfig.getBoolean("defaultResetOnEmpty")); war.setDefaultResetOnEmpty(warConfig.getBoolean("defaultResetOnEmpty"));
// defaultResetOnLoad // defaultResetOnLoad
War.war.setDefaultResetOnLoad(warConfig.getBoolean("defaultResetOnLoad")); war.setDefaultResetOnLoad(warConfig.getBoolean("defaultResetOnLoad"));
// defaultResetOnUnload // defaultResetOnUnload
War.war.setDefaultResetOnUnload(warConfig.getBoolean("defaultResetOnUnload")); war.setDefaultResetOnUnload(warConfig.getBoolean("defaultResetOnUnload"));
// warhub // warhub
String hubStr = warConfig.getString("warhub"); String hubStr = warConfig.getString("warhub");
if (hubStr != null && !hubStr.equals("")) { if (hubStr != null && !hubStr.equals("")) {
RestoreWarhubJob restoreWarhub = new RestoreWarhubJob(hubStr); RestoreWarhubJob restoreWarhub = new RestoreWarhubJob(war, hubStr);
if (War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, restoreWarhub) == -1) { if (war.getServer().getScheduler().scheduleSyncDelayedTask(war, restoreWarhub) == -1) {
War.war.log("Failed to schedule warhub-restore job. War hub was not loaded.", Level.WARNING); war.log("Failed to schedule warhub-restore job. War hub was not loaded.", Level.WARNING);
} }
} }
warConfig.close(); warConfig.close();
} }
public static void save() { public static void save(War war) {
PropertiesFile warConfig = new PropertiesFile(War.war.getDataFolder().getPath() + "/war.txt"); PropertiesFile warConfig = new PropertiesFile(war.getDataFolder().getPath() + "/war.txt");
String warzonesStr = ""; String warzonesStr = "";
// warzones // warzones
for (Warzone zone : War.war.getWarzones()) { for (Warzone zone : war.getWarzones()) {
warzonesStr += zone.getName() + ","; warzonesStr += zone.getName() + ",";
} }
warConfig.setString("warzones", warzonesStr); warConfig.setString("warzones", warzonesStr);
// zone makers: default is none and it means everyone can use /setzone // zone makers: default is none and it means everyone can use /setzone
String makersStr = ""; // everyone String makersStr = ""; // everyone
for (String name : War.war.getZoneMakerNames()) { for (String name : war.getZoneMakerNames()) {
makersStr += name + ","; makersStr += name + ",";
} }
warConfig.setString("zoneMakers", makersStr); warConfig.setString("zoneMakers", makersStr);
// whitelisted commands during a game // whitelisted commands during a game
String commandWhitelistStr = ""; // everyone String commandWhitelistStr = ""; // everyone
for (String command : War.war.getCommandWhitelist()) { for (String command : war.getCommandWhitelist()) {
commandWhitelistStr += command + ","; commandWhitelistStr += command + ",";
} }
warConfig.setString("commandWhitelist", makersStr); warConfig.setString("commandWhitelist", makersStr);
// defaultLoadout // defaultLoadout
String defaultLoadoutStr = ""; String defaultLoadoutStr = "";
HashMap<Integer, ItemStack> items = War.war.getDefaultLoadout(); HashMap<Integer, ItemStack> items = war.getDefaultLoadout();
for (Integer slot : items.keySet()) { for (Integer slot : items.keySet()) {
ItemStack item = items.get(slot); ItemStack item = items.get(slot);
if (item != null) { if (item != null) {
@ -210,41 +210,41 @@ public class WarMapper {
warConfig.setString("defaultLoadout", defaultLoadoutStr); warConfig.setString("defaultLoadout", defaultLoadoutStr);
// defaultLifepool // defaultLifepool
warConfig.setInt("defaultLifePool", War.war.getDefaultLifepool()); warConfig.setInt("defaultLifePool", war.getDefaultLifepool());
// defaultMonumentHeal // defaultMonumentHeal
warConfig.setInt("defaultMonumentHeal", War.war.getDefaultMonumentHeal()); warConfig.setInt("defaultMonumentHeal", war.getDefaultMonumentHeal());
// defaultFriendlyFire // defaultFriendlyFire
warConfig.setBoolean("defaultFriendlyFire", War.war.getDefaultFriendlyFire()); warConfig.setBoolean("defaultFriendlyFire", war.getDefaultFriendlyFire());
// defaultAutoAssignOnly // defaultAutoAssignOnly
warConfig.setBoolean("defaultAutoAssignOnly", War.war.getDefaultAutoAssignOnly()); warConfig.setBoolean("defaultAutoAssignOnly", war.getDefaultAutoAssignOnly());
// defaultTeamCap // defaultTeamCap
warConfig.setInt("defaultTeamCap", War.war.getDefaultTeamCap()); warConfig.setInt("defaultTeamCap", war.getDefaultTeamCap());
// defaultScoreCap // defaultScoreCap
warConfig.setInt("defaultScoreCap", War.war.getDefaultScoreCap()); warConfig.setInt("defaultScoreCap", war.getDefaultScoreCap());
// pvpInZonesOnly // pvpInZonesOnly
warConfig.setBoolean("pvpInZonesOnly", War.war.isPvpInZonesOnly()); warConfig.setBoolean("pvpInZonesOnly", war.isPvpInZonesOnly());
// defaultBlockHeads // defaultBlockHeads
warConfig.setBoolean("defaultBlockHeads", War.war.isDefaultBlockHeads()); warConfig.setBoolean("defaultBlockHeads", war.isDefaultBlockHeads());
// buildInZonesOnly // buildInZonesOnly
warConfig.setBoolean("buildInZonesOnly", War.war.isBuildInZonesOnly()); warConfig.setBoolean("buildInZonesOnly", war.isBuildInZonesOnly());
// disablePVPMessage // disablePVPMessage
warConfig.setBoolean("disablePvpMessage", War.war.isDisablePvpMessage()); warConfig.setBoolean("disablePvpMessage", war.isDisablePvpMessage());
// spawnStyle // spawnStyle
warConfig.setString("spawnStyle", War.war.getDefaultSpawnStyle()); warConfig.setString("spawnStyle", war.getDefaultSpawnStyle());
// defaultReward // defaultReward
String defaultRewardStr = ""; String defaultRewardStr = "";
HashMap<Integer, ItemStack> rewardItems = War.war.getDefaultReward(); HashMap<Integer, ItemStack> rewardItems = war.getDefaultReward();
for (Integer slot : rewardItems.keySet()) { for (Integer slot : rewardItems.keySet()) {
ItemStack item = items.get(slot); ItemStack item = items.get(slot);
if (item != null) { if (item != null) {
@ -254,26 +254,26 @@ public class WarMapper {
warConfig.setString("defaultReward", defaultRewardStr); warConfig.setString("defaultReward", defaultRewardStr);
// defaultUnbreakableZoneBlocks // defaultUnbreakableZoneBlocks
warConfig.setBoolean("defaultUnbreakableZoneBlocks", War.war.isDefaultUnbreakableZoneBlocks()); warConfig.setBoolean("defaultUnbreakableZoneBlocks", war.isDefaultUnbreakableZoneBlocks());
// defaultNoCreatures // defaultNoCreatures
warConfig.setBoolean("defaultNoCreatures", War.war.isDefaultNoCreatures()); warConfig.setBoolean("defaultNoCreatures", war.isDefaultNoCreatures());
// defaultResetOnEmpty // defaultResetOnEmpty
warConfig.setBoolean("defaultResetOnEmpty", War.war.isDefaultResetOnEmpty()); warConfig.setBoolean("defaultResetOnEmpty", war.isDefaultResetOnEmpty());
// defaultResetOnLoad // defaultResetOnLoad
warConfig.setBoolean("defaultResetOnLoad", War.war.isDefaultResetOnLoad()); warConfig.setBoolean("defaultResetOnLoad", war.isDefaultResetOnLoad());
// defaultResetOnUnload // defaultResetOnUnload
warConfig.setBoolean("defaultResetOnUnload", War.war.isDefaultResetOnUnload()); warConfig.setBoolean("defaultResetOnUnload", war.isDefaultResetOnUnload());
// defaultDropLootOnDeath // defaultDropLootOnDeath
// warConfig.setBoolean("defaultDropLootOnDeath", war.isDefaultDropLootOnDeath()); // warConfig.setBoolean("defaultDropLootOnDeath", war.isDefaultDropLootOnDeath());
// warhub // warhub
String hubStr = ""; String hubStr = "";
WarHub hub = War.war.getWarHub(); WarHub hub = war.getWarHub();
if (hub != null) { if (hub != null) {
String orientationStr = ""; String orientationStr = "";
if (BlockFace.SOUTH == hub.getOrientation()) { if (BlockFace.SOUTH == hub.getOrientation()) {
@ -287,7 +287,7 @@ public class WarMapper {
} }
hubStr = hub.getLocation().getBlockX() + "," + hub.getLocation().getBlockY() + "," + hub.getLocation().getBlockZ() + "," hubStr = hub.getLocation().getBlockX() + "," + hub.getLocation().getBlockY() + "," + hub.getLocation().getBlockZ() + ","
+ hub.getLocation().getWorld().getName() + "," + orientationStr; + hub.getLocation().getWorld().getName() + "," + orientationStr;
VolumeMapper.save(hub.getVolume(), ""); VolumeMapper.save(hub.getVolume(), "", war);
} }
warConfig.setString("warhub", hubStr); warConfig.setString("warhub", hubStr);

View File

@ -29,13 +29,13 @@ import com.tommytony.war.volumes.ZoneVolume;
*/ */
public class WarzoneMapper { public class WarzoneMapper {
public static Warzone load(String name, boolean createNewVolume) { public static Warzone load(War war, String name, boolean createNewVolume) {
// war.getLogger().info("Loading warzone " + name + " config and blocks..."); // war.getLogger().info("Loading warzone " + name + " config and blocks...");
PropertiesFile warzoneConfig = new PropertiesFile(War.war.getDataFolder().getPath() + "/warzone-" + name + ".txt"); PropertiesFile warzoneConfig = new PropertiesFile(war.getDataFolder().getPath() + "/warzone-" + name + ".txt");
try { try {
warzoneConfig.load(); warzoneConfig.load();
} catch (IOException e) { } catch (IOException e) {
War.war.getLogger().info("Failed to load warzone-" + name + ".txt file."); war.getLogger().info("Failed to load warzone-" + name + ".txt file.");
e.printStackTrace(); e.printStackTrace();
} }
@ -43,21 +43,21 @@ public class WarzoneMapper {
String worldStr = warzoneConfig.getProperty("world"); String worldStr = warzoneConfig.getProperty("world");
World world = null; World world = null;
if (worldStr == null || worldStr.equals("")) { if (worldStr == null || worldStr.equals("")) {
world = War.war.getServer().getWorlds().get(0); // default to first world world = war.getServer().getWorlds().get(0); // default to first world
} else { } else {
world = War.war.getServer().getWorld(worldStr); world = war.getServer().getWorld(worldStr);
} }
if (world == null) { if (world == null) {
War.war.log("Failed to restore warzone " + name + ". The specified world (name: " + worldStr + ") does not exist!", Level.WARNING); war.log("Failed to restore warzone " + name + ". The specified world (name: " + worldStr + ") does not exist!", Level.WARNING);
} else { } else {
// Create the zone // Create the zone
Warzone warzone = new Warzone(world, name); Warzone warzone = new Warzone(war, world, name);
// Create file if needed // Create file if needed
if (!warzoneConfig.containsKey("name")) { if (!warzoneConfig.containsKey("name")) {
WarzoneMapper.save(warzone, false); WarzoneMapper.save(war, warzone, false);
War.war.getLogger().info("Warzone " + name + " config file created."); war.getLogger().info("Warzone " + name + " config file created.");
try { try {
warzoneConfig.load(); warzoneConfig.load();
} catch (IOException e) { } catch (IOException e) {
@ -93,7 +93,7 @@ public class WarzoneMapper {
int yaw = Integer.parseInt(teamStrSplit[4]); int yaw = Integer.parseInt(teamStrSplit[4]);
teamLocation.setYaw(yaw); teamLocation.setYaw(yaw);
} }
Team team = new Team(teamStrSplit[0], TeamKinds.teamKindFromString(teamStrSplit[0]), teamLocation, warzone); Team team = new Team(teamStrSplit[0], TeamKinds.teamKindFromString(teamStrSplit[0]), teamLocation, war, warzone);
team.setRemainingLives(warzone.getLifePool()); team.setRemainingLives(warzone.getLifePool());
warzone.getTeams().add(team); warzone.getTeams().add(team);
} }
@ -230,7 +230,7 @@ public class WarzoneMapper {
int monumentX = Integer.parseInt(monumentStrSplit[1]); int monumentX = Integer.parseInt(monumentStrSplit[1]);
int monumentY = Integer.parseInt(monumentStrSplit[2]); int monumentY = Integer.parseInt(monumentStrSplit[2]);
int monumentZ = Integer.parseInt(monumentStrSplit[3]); int monumentZ = Integer.parseInt(monumentStrSplit[3]);
Monument monument = new Monument(monumentStrSplit[0], warzone, new Location(world, monumentX, monumentY, monumentZ)); Monument monument = new Monument(monumentStrSplit[0], war, warzone, new Location(world, monumentX, monumentY, monumentZ));
warzone.getMonuments().add(monument); warzone.getMonuments().add(monument);
} }
} }
@ -242,20 +242,20 @@ public class WarzoneMapper {
warzoneConfig.close(); warzoneConfig.close();
if (createNewVolume) { if (createNewVolume) {
ZoneVolume zoneVolume = new ZoneVolume(warzone.getName(), world, warzone); // VolumeMapper.loadZoneVolume(warzone.getName(), warzone.getName(), war, warzone.getWorld(), warzone); ZoneVolume zoneVolume = new ZoneVolume(warzone.getName(), war, world, warzone); // VolumeMapper.loadZoneVolume(warzone.getName(), warzone.getName(), war, warzone.getWorld(), warzone);
warzone.setVolume(zoneVolume); warzone.setVolume(zoneVolume);
} }
// monument blocks // monument blocks
for (Monument monument : warzone.getMonuments()) { for (Monument monument : warzone.getMonuments()) {
monument.setVolume(VolumeMapper.loadVolume(monument.getName(), warzone.getName(), world)); monument.setVolume(VolumeMapper.loadVolume(monument.getName(), warzone.getName(), war, world));
} }
// team spawn blocks // team spawn blocks
for (Team team : warzone.getTeams()) { for (Team team : warzone.getTeams()) {
team.setSpawnVolume(VolumeMapper.loadVolume(team.getName(), warzone.getName(), world)); team.setSpawnVolume(VolumeMapper.loadVolume(team.getName(), warzone.getName(), war, world));
if (team.getTeamFlag() != null) { if (team.getTeamFlag() != null) {
team.setFlagVolume(VolumeMapper.loadVolume(team.getName() + "flag", warzone.getName(), world)); team.setFlagVolume(VolumeMapper.loadVolume(team.getName() + "flag", warzone.getName(), war, world));
} }
} }
@ -271,8 +271,8 @@ public class WarzoneMapper {
} else if (lobbyStr.equals("west")) { } else if (lobbyStr.equals("west")) {
lobbyFace = BlockFace.WEST; lobbyFace = BlockFace.WEST;
} }
Volume lobbyVolume = VolumeMapper.loadVolume("lobby", warzone.getName(), world); Volume lobbyVolume = VolumeMapper.loadVolume("lobby", warzone.getName(), war, world);
ZoneLobby lobby = new ZoneLobby(warzone, lobbyFace, lobbyVolume); ZoneLobby lobby = new ZoneLobby(war, warzone, lobbyFace, lobbyVolume);
warzone.setLobby(lobby); warzone.setLobby(lobby);
} }
@ -281,9 +281,9 @@ public class WarzoneMapper {
return null; return null;
} }
public static void save(Warzone warzone, boolean saveAllBlocks) { public static void save(War war, Warzone warzone, boolean saveAllBlocks) {
(new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + warzone.getName())).mkdir(); (new File(war.getDataFolder().getPath() + "/dat/warzone-" + warzone.getName())).mkdir();
PropertiesFile warzoneConfig = new PropertiesFile(War.war.getDataFolder().getPath() + "/warzone-" + warzone.getName() + ".txt"); PropertiesFile warzoneConfig = new PropertiesFile(war.getDataFolder().getPath() + "/warzone-" + warzone.getName() + ".txt");
// war.getLogger().info("Saving warzone " + warzone.getName() + "..."); // war.getLogger().info("Saving warzone " + warzone.getName() + "...");
// name // name
@ -446,19 +446,19 @@ public class WarzoneMapper {
// monument blocks // monument blocks
for (Monument monument : monuments) { for (Monument monument : monuments) {
VolumeMapper.save(monument.getVolume(), warzone.getName()); VolumeMapper.save(monument.getVolume(), warzone.getName(), war);
} }
// team spawn & flag blocks // team spawn & flag blocks
for (Team team : teams) { for (Team team : teams) {
VolumeMapper.save(team.getSpawnVolume(), warzone.getName()); VolumeMapper.save(team.getSpawnVolume(), warzone.getName(), war);
if (team.getFlagVolume() != null) { if (team.getFlagVolume() != null) {
VolumeMapper.save(team.getFlagVolume(), warzone.getName()); VolumeMapper.save(team.getFlagVolume(), warzone.getName(), war);
} }
} }
if (warzone.getLobby() != null) { if (warzone.getLobby() != null) {
VolumeMapper.save(warzone.getLobby().getVolume(), warzone.getName()); VolumeMapper.save(warzone.getLobby().getVolume(), warzone.getName(), war);
} }
// if (saveBlocks) { // if (saveBlocks) {
@ -468,23 +468,23 @@ public class WarzoneMapper {
// } // }
} }
public static void delete(String name) { public static void delete(War war, String name) {
File zoneFolder = new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + name); File zoneFolder = new File(war.getDataFolder().getPath() + "/dat/warzone-" + name);
File[] files = zoneFolder.listFiles(); File[] files = zoneFolder.listFiles();
for (File file : files) { for (File file : files) {
boolean deletedData = file.delete(); boolean deletedData = file.delete();
if (!deletedData) { if (!deletedData) {
War.war.log("Failed to delete file " + file.getName(), Level.WARNING); war.log("Failed to delete file " + file.getName(), Level.WARNING);
} }
} }
boolean deletedData = zoneFolder.delete(); boolean deletedData = zoneFolder.delete();
if (!deletedData) { if (!deletedData) {
War.war.log("Failed to delete folder " + zoneFolder.getName(), Level.WARNING); war.log("Failed to delete folder " + zoneFolder.getName(), Level.WARNING);
} }
File zoneFile = new File(War.war.getDataFolder().getPath() + "/warzone-" + name + ".txt"); File zoneFile = new File(war.getDataFolder().getPath() + "/warzone-" + name + ".txt");
deletedData = zoneFile.delete(); deletedData = zoneFile.delete();
if (!deletedData) { if (!deletedData) {
War.war.log("Failed to delete file " + zoneFile.getName(), Level.WARNING); war.log("Failed to delete file " + zoneFile.getName(), Level.WARNING);
} }
} }

View File

@ -45,25 +45,26 @@ public class ZoneVolumeMapper {
* *
* @param ZoneVolume volume Volume to load * @param ZoneVolume volume Volume to load
* @param String zoneName Zone to load the volume from * @param String zoneName Zone to load the volume from
* @param War war Instance of War
* @param World world The world the zone is located * @param World world The world the zone is located
* @param boolean onlyLoadCorners Should only the corners be loaded * @param boolean onlyLoadCorners Should only the corners be loaded
* @return integer Changed blocks * @return integer Changed blocks
*/ */
public static int load(ZoneVolume volume, String zoneName, World world, boolean onlyLoadCorners) { public static int load(ZoneVolume volume, String zoneName, War war, World world, boolean onlyLoadCorners) {
File cornersFile = new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".corners"); File cornersFile = new File(war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".corners");
File blocksFile = new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".blocks"); File blocksFile = new File(war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".blocks");
File signsFile = new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".signs"); File signsFile = new File(war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".signs");
File invsFile = new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".invs"); File invsFile = new File(war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".invs");
int noOfResetBlocks = 0; int noOfResetBlocks = 0;
if (!blocksFile.exists()) { if (!blocksFile.exists()) {
// The post 1.6 formatted files haven't been created yet so // The post 1.6 formatted files haven't been created yet so
// we need to use the old load. // we need to use the old load.
noOfResetBlocks = PreDeGaulleZoneVolumeMapper.load(volume, zoneName, world, onlyLoadCorners); noOfResetBlocks = PreDeGaulleZoneVolumeMapper.load(volume, zoneName, war, world, onlyLoadCorners);
// The new 1.6 files aren't created yet. We just reset the zone (except deferred blocks which will soon execute on main thread ), // The new 1.6 files aren't created yet. We just reset the zone (except deferred blocks which will soon execute on main thread ),
// so let's save to the new format as soon as the zone is fully reset. // so let's save to the new format as soon as the zone is fully reset.
ZoneVolumeMapper.saveAsJob(volume, zoneName, 2); ZoneVolumeMapper.saveAsJob(volume, zoneName, war, 2);
War.war.log("Warzone " + zoneName + " file converted!", Level.INFO); war.log("Warzone " + zoneName + " file converted!", Level.INFO);
return noOfResetBlocks; return noOfResetBlocks;
} else { } else {
@ -229,7 +230,7 @@ public class ZoneVolumeMapper {
blockReads++; blockReads++;
} catch (Exception e) { } catch (Exception e) {
War.war.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()); 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(); e.printStackTrace();
} finally { } finally {
z++; z++;
@ -240,14 +241,14 @@ public class ZoneVolumeMapper {
x++; x++;
} }
if (!deferred.isEmpty()) { if (!deferred.isEmpty()) {
War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, deferred, 1); war.getServer().getScheduler().scheduleSyncDelayedTask(war, deferred, 1);
} }
} }
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
War.war.log("Failed to find volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING); war.log("Failed to find volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
e.printStackTrace(); e.printStackTrace();
} catch (IOException e) { } catch (IOException e) {
War.war.log("Failed to read volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING); war.log("Failed to read volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
try { try {
@ -264,7 +265,7 @@ public class ZoneVolumeMapper {
invsReader.close(); invsReader.close();
} }
} catch (IOException e) { } catch (IOException e) {
War.war.log("Failed to close volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING); war.log("Failed to close volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -308,9 +309,10 @@ public class ZoneVolumeMapper {
* *
* @param Volume volume Volume to save * @param Volume volume Volume to save
* @param String zoneName The warzone the volume is located * @param String zoneName The warzone the volume is located
* @param War war Instance of war
* @return integer Number of written blocks * @return integer Number of written blocks
*/ */
public static int save(Volume volume, String zoneName) { public static int save(Volume volume, String zoneName, War war) {
int noOfSavedBlocks = 0; int noOfSavedBlocks = 0;
if (volume.hasTwoCorners()) { if (volume.hasTwoCorners()) {
BufferedWriter cornersWriter = null; BufferedWriter cornersWriter = null;
@ -318,8 +320,8 @@ public class ZoneVolumeMapper {
BufferedWriter signsWriter = null; BufferedWriter signsWriter = null;
BufferedWriter invsWriter = null; BufferedWriter invsWriter = null;
try { try {
(new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName)).mkdir(); (new File(war.getDataFolder().getPath() + "/dat/warzone-" + zoneName)).mkdir();
String path = War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName(); String path = war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName();
cornersWriter = new BufferedWriter(new FileWriter(new File(path + ".corners"))); cornersWriter = new BufferedWriter(new FileWriter(new File(path + ".corners")));
blocksOutput = new FileOutputStream(new File(path + ".blocks")); blocksOutput = new FileOutputStream(new File(path + ".blocks"));
signsWriter = new BufferedWriter(new FileWriter(new File(path + ".signs"))); signsWriter = new BufferedWriter(new FileWriter(new File(path + ".signs")));
@ -431,7 +433,7 @@ public class ZoneVolumeMapper {
} }
noOfSavedBlocks++; noOfSavedBlocks++;
} catch (Exception e) { } catch (Exception e) {
War.war.log("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(), Level.WARNING); war.log("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(), Level.WARNING);
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
z++; z++;
@ -442,10 +444,10 @@ public class ZoneVolumeMapper {
x++; x++;
} }
} catch (IOException e) { } catch (IOException e) {
War.war.log("Failed to write volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING); war.log("Failed to write volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
e.printStackTrace(); e.printStackTrace();
} catch (Exception e) { } catch (Exception e) {
War.war.log("Unexpected error caused failure to write volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING); war.log("Unexpected error caused failure to write volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
try { try {
@ -462,7 +464,7 @@ public class ZoneVolumeMapper {
invsWriter.close(); invsWriter.close();
} }
} catch (IOException e) { } catch (IOException e) {
War.war.log("Failed to close volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING); war.log("Failed to close volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -478,9 +480,9 @@ public class ZoneVolumeMapper {
* @param War war Instance of war * @param War war Instance of war
* @param long tickDelay delay before beginning the task * @param long tickDelay delay before beginning the task
*/ */
private static void saveAsJob(ZoneVolume volume, String zoneName, long tickDelay) { private static void saveAsJob(ZoneVolume volume, String zoneName, War war, long tickDelay) {
ZoneVolumeSaveJob job = new ZoneVolumeSaveJob(volume, zoneName); ZoneVolumeSaveJob job = new ZoneVolumeSaveJob(volume, zoneName, war);
War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, job, tickDelay); war.getServer().getScheduler().scheduleSyncDelayedTask(war, job, tickDelay);
} }
/** /**
@ -489,12 +491,12 @@ public class ZoneVolumeMapper {
* @param Volume volume volume to delete * @param Volume volume volume to delete
* @param War war Instance of war * @param War war Instance of war
*/ */
public static void delete(Volume volume) { public static void delete(Volume volume, War war) {
ZoneVolumeMapper.deleteFile("War/dat/volume-" + volume.getName() + ".dat"); ZoneVolumeMapper.deleteFile("War/dat/volume-" + volume.getName() + ".dat", war);
ZoneVolumeMapper.deleteFile("War/dat/volume-" + volume.getName() + ".corners"); ZoneVolumeMapper.deleteFile("War/dat/volume-" + volume.getName() + ".corners", war);
ZoneVolumeMapper.deleteFile("War/dat/volume-" + volume.getName() + ".blocks"); ZoneVolumeMapper.deleteFile("War/dat/volume-" + volume.getName() + ".blocks", war);
ZoneVolumeMapper.deleteFile("War/dat/volume-" + volume.getName() + ".signs"); ZoneVolumeMapper.deleteFile("War/dat/volume-" + volume.getName() + ".signs", war);
ZoneVolumeMapper.deleteFile("War/dat/volume-" + volume.getName() + ".invs"); ZoneVolumeMapper.deleteFile("War/dat/volume-" + volume.getName() + ".invs", war);
} }
/** /**
@ -503,12 +505,12 @@ public class ZoneVolumeMapper {
* @param String path path of file * @param String path path of file
* @param War war Instance of war * @param War war Instance of war
*/ */
private static void deleteFile(String path) { private static void deleteFile(String path, War war) {
File volFile = new File(path); File volFile = new File(path);
if (volFile.exists()) { if (volFile.exists()) {
boolean deletedData = volFile.delete(); boolean deletedData = volFile.delete();
if (!deletedData) { if (!deletedData) {
War.war.log("Failed to delete file " + volFile.getName(), Level.WARNING); war.log("Failed to delete file " + volFile.getName(), Level.WARNING);
} }
} }
} }

View File

@ -4,10 +4,14 @@ import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import bukkit.tommytony.war.War;
/** /**
* *
* @author tommytony * @author tommytony
* @deprecated Broken, don't use. *
* Broken, don't use.
*
*/ */
@Deprecated @Deprecated
public class CenteredVolume extends Volume { public class CenteredVolume extends Volume {
@ -16,8 +20,8 @@ public class CenteredVolume extends Volume {
private int sideSize = -1; private int sideSize = -1;
private final World world; private final World world;
public CenteredVolume(String name, Block center, int sideSize, World world) { public CenteredVolume(String name, Block center, int sideSize, War war, World world) {
super(name, world); super(name, war, world);
this.world = world; this.world = world;
this.setCenter(center); this.setCenter(center);
this.setSideSize(sideSize); this.setSideSize(sideSize);

View File

@ -1,7 +1,5 @@
package com.tommytony.war.volumes; package com.tommytony.war.volumes;
import java.util.logging.Level;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
@ -10,15 +8,15 @@ import org.bukkit.block.BlockFace;
import bukkit.tommytony.war.War; import bukkit.tommytony.war.War;
/** /**
* *
* @author tommytony * @author tommytony
* *
*/ */
@Deprecated @Deprecated
public class VerticalVolume extends Volume { public class VerticalVolume extends Volume {
public VerticalVolume(String name, World world) { public VerticalVolume(String name, War war, World world) {
super(name, world); super(name, war, world);
} }
@ -143,7 +141,7 @@ public class VerticalVolume extends Volume {
} }
} }
} catch (Exception e) { } catch (Exception e) {
War.war.log("Failed to reset wall " + wall + " in volume " + this.getName() + ". " + e.getClass().toString() + " " + e.getMessage(), Level.WARNING); this.getWar().logWarn("Failed to reset wall " + wall + " in volume " + this.getName() + ". " + e.getClass().toString() + " " + e.getMessage());
} }
return noOfResetBlocks; return noOfResetBlocks;
} }

View File

@ -36,9 +36,11 @@ public class Volume {
private byte[][][] blockDatas = null; private byte[][][] blockDatas = null;
private HashMap<String, String[]> signLines = new HashMap<String, String[]>(); private HashMap<String, String[]> signLines = new HashMap<String, String[]>();
private HashMap<String, List<ItemStack>> invBlockContents = new HashMap<String, List<ItemStack>>(); private HashMap<String, List<ItemStack>> invBlockContents = new HashMap<String, List<ItemStack>>();
private War war;
public Volume(String name, World world) { public Volume(String name, War war, World world) {
this.name = name; this.name = name;
this.war = war;
this.world = world; this.world = world;
} }
@ -120,7 +122,7 @@ public class Volume {
noOfSavedBlocks++; noOfSavedBlocks++;
} catch (Exception e) { } catch (Exception e) {
War.war.getLogger().warning("Failed to save block in volume " + this.getName() + ". Saved blocks so far:" + noOfSavedBlocks + ". Error at x:" + x + " y:" + y + " z:" + z + ". Exception:" + e.getClass().toString() + e.getMessage()); this.getWar().getLogger().warning("Failed to save block in volume " + this.getName() + ". Saved blocks so far:" + noOfSavedBlocks + ". Error at x:" + x + " y:" + y + " z:" + z + ". Exception:" + e.getClass().toString() + e.getMessage());
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
z++; z++;
@ -132,7 +134,7 @@ public class Volume {
} }
} }
} catch (Exception e) { } catch (Exception e) {
War.war.getLogger().warning("Failed to save volume " + this.getName() + " blocks. Saved blocks:" + noOfSavedBlocks + ". Error at x:" + x + " y:" + y + " z:" + z + ". Exception:" + e.getClass().toString() + " " + e.getMessage()); this.getWar().getLogger().warning("Failed to save volume " + this.getName() + " blocks. Saved blocks:" + noOfSavedBlocks + ". Error at x:" + x + " y:" + y + " z:" + z + ". Exception:" + e.getClass().toString() + " " + e.getMessage());
e.printStackTrace(); e.printStackTrace();
} }
return noOfSavedBlocks; return noOfSavedBlocks;
@ -140,7 +142,7 @@ public class Volume {
public void resetBlocksAsJob() { public void resetBlocksAsJob() {
BlockResetJob job = new BlockResetJob(this); BlockResetJob job = new BlockResetJob(this);
War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, job); this.war.getServer().getScheduler().scheduleSyncDelayedTask(this.war, job);
} }
public int resetBlocks() { public int resetBlocks() {
@ -268,7 +270,7 @@ public class Volume {
} }
visitedBlocks++; visitedBlocks++;
} catch (Exception e) { } catch (Exception e) {
War.war.getLogger().warning("Failed to reset block in volume " + this.getName() + ". Visited blocks so far:" + visitedBlocks + ". Blocks reset: " + noOfResetBlocks + ". Error at x:" + x + " y:" + y + " z:" + z + ". Exception:" + e.getClass().toString() + " " + e.getMessage()); this.getWar().getLogger().warning("Failed to reset block in volume " + this.getName() + ". Visited blocks so far:" + visitedBlocks + ". Blocks reset: " + noOfResetBlocks + ". Error at x:" + x + " y:" + y + " z:" + z + ". Exception:" + e.getClass().toString() + " " + e.getMessage());
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
z++; z++;
@ -280,7 +282,7 @@ public class Volume {
} }
} }
} catch (Exception e) { } catch (Exception e) {
War.war.log("Failed to reset volume " + this.getName() + " blocks. Blocks visited: " + visitedBlocks + ". Blocks reset: " + noOfResetBlocks + ". Error at x:" + x + " y:" + y + " z:" + z + ". Current block: " + currentBlockId + ". Old block: " + oldBlockType + ". Exception: " + e.getClass().toString() + " " + e.getMessage(), Level.WARNING); this.getWar().log("Failed to reset volume " + this.getName() + " blocks. Blocks visited: " + visitedBlocks + ". Blocks reset: " + noOfResetBlocks + ". Error at x:" + x + " y:" + y + " z:" + z + ". Current block: " + currentBlockId + ". Old block: " + oldBlockType + ". Exception: " + e.getClass().toString() + " " + e.getMessage(), Level.WARNING);
e.printStackTrace(); e.printStackTrace();
} }
return noOfResetBlocks; return noOfResetBlocks;
@ -415,6 +417,10 @@ public class Volume {
this.blockTypes = blockTypes; this.blockTypes = blockTypes;
} }
public War getWar() {
return this.war;
}
public String getName() { public String getName() {
return this.name; return this.name;
} }
@ -438,7 +444,7 @@ public class Volume {
} }
} }
} catch (Exception e) { } catch (Exception e) {
War.war.log("Failed to set block to " + material + "in volume " + this.name + "." + e.getClass().toString() + " " + e.getMessage(), Level.WARNING); this.getWar().log("Failed to set block to " + material + "in volume " + this.name + "." + e.getClass().toString() + " " + e.getMessage(), Level.WARNING);
} }
} }
@ -463,7 +469,7 @@ public class Volume {
} }
} }
} catch (Exception e) { } catch (Exception e) {
War.war.log("Failed to set block to " + material + "in volume " + this.name + "." + e.getClass().toString() + " " + e.getMessage(), Level.WARNING); this.getWar().log("Failed to set block to " + material + "in volume " + this.name + "." + e.getClass().toString() + " " + e.getMessage(), Level.WARNING);
} }
} }
@ -498,7 +504,7 @@ public class Volume {
} }
} }
} catch (Exception e) { } catch (Exception e) {
War.war.log("Failed to switch block to " + newType + "in volume " + this.name + "." + e.getClass().toString() + " " + e.getMessage(), Level.WARNING); this.getWar().log("Failed to switch block to " + newType + "in volume " + this.name + "." + e.getClass().toString() + " " + e.getMessage(), Level.WARNING);
} }
} }
@ -553,6 +559,6 @@ public class Volume {
this.signLines = null; this.signLines = null;
this.invBlockContents.clear(); this.invBlockContents.clear();
this.invBlockContents = null; this.invBlockContents = null;
War.war = null; this.war = null;
} }
} }

View File

@ -20,16 +20,16 @@ public class ZoneVolume extends Volume {
private Warzone zone; private Warzone zone;
private boolean isSaved = false; private boolean isSaved = false;
public ZoneVolume(String name, World world, Warzone zone) { public ZoneVolume(String name, War war, World world, Warzone zone) {
super(name, world); super(name, war, world);
this.zone = zone; this.zone = zone;
} }
@Override @Override
public int saveBlocks() { public int saveBlocks() {
// Save blocks directly to disk (i.e. don't put everything in memory) // Save blocks directly to disk (i.e. don't put everything in memory)
int saved = ZoneVolumeMapper.save(this, this.zone.getName()); int saved = ZoneVolumeMapper.save(this, this.zone.getName(), this.getWar());
War.war.log("Saved " + saved + " blocks in warzone " + this.zone.getName() + ".", java.util.logging.Level.INFO); this.getWar().log("Saved " + saved + " blocks in warzone " + this.zone.getName() + ".", java.util.logging.Level.INFO);
this.isSaved = true; this.isSaved = true;
return saved; return saved;
} }
@ -40,15 +40,15 @@ public class ZoneVolume extends Volume {
} }
public void loadCorners() { public void loadCorners() {
ZoneVolumeMapper.load(this, this.zone.getName(), this.getWorld(), true); ZoneVolumeMapper.load(this, this.zone.getName(), this.getWar(), this.getWorld(), true);
this.isSaved = true; this.isSaved = true;
} }
@Override @Override
public int resetBlocks() { public int resetBlocks() {
// Load blocks directly from disk and onto the map (i.e. no more in-memory warzone blocks) // Load blocks directly from disk and onto the map (i.e. no more in-memory warzone blocks)
int reset = ZoneVolumeMapper.load(this, this.zone.getName(), this.getWorld(), false); int reset = ZoneVolumeMapper.load(this, this.zone.getName(), this.getWar(), this.getWorld(), false);
War.war.log("Reset " + reset + " blocks in warzone " + this.zone.getName() + ".", java.util.logging.Level.INFO); this.getWar().log("Reset " + reset + " blocks in warzone " + this.zone.getName() + ".", java.util.logging.Level.INFO);
this.isSaved = true; this.isSaved = true;
return reset; return reset;
} }

View File

@ -9,6 +9,8 @@ import org.junit.Test;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
import bukkit.tommytony.war.War;
import com.tommytony.war.*; import com.tommytony.war.*;
import com.tommytony.war.volumes.*; import com.tommytony.war.volumes.*;
@ -19,12 +21,12 @@ public class ZoneVolumeSpecTest {
@Test @Test
public void setNorthwest_whenCreatingAndNoCornersAreSet_shouldSetCorner1AtTop() throws NotNorthwestException, TooSmallException, TooBigException{ public void setNorthwest_whenCreatingAndNoCornersAreSet_shouldSetCorner1AtTop() throws NotNorthwestException, TooSmallException, TooBigException{
// Arrange // Arrange
War warMock = mock(War.class);
World worldMock = mock(World.class); World worldMock = mock(World.class);
Warzone zoneMock = mock(Warzone.class); Warzone zoneMock = mock(Warzone.class);
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>()); when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>()); when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock); ZoneVolume volume = new ZoneVolume("test", warMock, worldMock, zoneMock);
Block blockMock = mock(Block.class); Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(0); when(blockMock.getX()).thenReturn(0);
when(blockMock.getY()).thenReturn(64); // at sea level when(blockMock.getY()).thenReturn(64); // at sea level
@ -47,12 +49,12 @@ public class ZoneVolumeSpecTest {
@Test @Test
public void setNorthwest_whenCreating_AndNoCorner1IsSet_ButCorner2Set_AndNewCornerBlockIsToEastOfCorner2_shouldThrowNotNorthwestException() throws TooSmallException, TooBigException{ public void setNorthwest_whenCreating_AndNoCorner1IsSet_ButCorner2Set_AndNewCornerBlockIsToEastOfCorner2_shouldThrowNotNorthwestException() throws TooSmallException, TooBigException{
// Arrange // Arrange
War warMock = mock(War.class);
World worldMock = mock(World.class); World worldMock = mock(World.class);
Warzone zoneMock = mock(Warzone.class); Warzone zoneMock = mock(Warzone.class);
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>()); when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>()); when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock); ZoneVolume volume = new ZoneVolume("test", warMock, worldMock, zoneMock);
Block blockMock = mock(Block.class); Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(-64); // further north when(blockMock.getX()).thenReturn(-64); // further north
when(blockMock.getY()).thenReturn(64); // at sea level when(blockMock.getY()).thenReturn(64); // at sea level
@ -81,12 +83,12 @@ public class ZoneVolumeSpecTest {
@Test @Test
public void setNorthwest_whenCreating_AndNoCorner1IsSet_ButCorner2Set_AndNewCornerBlockIsToSouthOfCorner2_shouldThrowNotNorthwestException() throws TooSmallException, TooBigException{ public void setNorthwest_whenCreating_AndNoCorner1IsSet_ButCorner2Set_AndNewCornerBlockIsToSouthOfCorner2_shouldThrowNotNorthwestException() throws TooSmallException, TooBigException{
// Arrange // Arrange
War warMock = mock(War.class);
World worldMock = mock(World.class); World worldMock = mock(World.class);
Warzone zoneMock = mock(Warzone.class); Warzone zoneMock = mock(Warzone.class);
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>()); when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>()); when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock); ZoneVolume volume = new ZoneVolume("test", warMock, worldMock, zoneMock);
Block blockMock = mock(Block.class); Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(64); // further south when(blockMock.getX()).thenReturn(64); // further south
when(blockMock.getY()).thenReturn(64); // at sea level when(blockMock.getY()).thenReturn(64); // at sea level
@ -115,12 +117,12 @@ public class ZoneVolumeSpecTest {
@Test @Test
public void setNorthwest_whenCreating_AndNoCorner1IsSet_ButCorner2Set_AndNewCornerBlockIsTooCloseToCorner2_shouldThrowTooSmallException() throws NotNorthwestException, TooBigException{ public void setNorthwest_whenCreating_AndNoCorner1IsSet_ButCorner2Set_AndNewCornerBlockIsTooCloseToCorner2_shouldThrowTooSmallException() throws NotNorthwestException, TooBigException{
// Arrange // Arrange
War warMock = mock(War.class);
World worldMock = mock(World.class); World worldMock = mock(World.class);
Warzone zoneMock = mock(Warzone.class); Warzone zoneMock = mock(Warzone.class);
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>()); when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>()); when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock); ZoneVolume volume = new ZoneVolume("test", warMock, worldMock, zoneMock);
Block blockMock = mock(Block.class); Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(-5); // further south when(blockMock.getX()).thenReturn(-5); // further south
when(blockMock.getY()).thenReturn(64); // at sea level when(blockMock.getY()).thenReturn(64); // at sea level
@ -149,12 +151,12 @@ public class ZoneVolumeSpecTest {
@Test @Test
public void setNorthwest_whenCreating_AndNoCorner1IsSet_ButCorner2Set_AndNewCornerBlockIsTooFarFromCorner2_shouldThrowTooBigException() throws NotNorthwestException, TooSmallException{ public void setNorthwest_whenCreating_AndNoCorner1IsSet_ButCorner2Set_AndNewCornerBlockIsTooFarFromCorner2_shouldThrowTooBigException() throws NotNorthwestException, TooSmallException{
// Arrange // Arrange
War warMock = mock(War.class);
World worldMock = mock(World.class); World worldMock = mock(World.class);
Warzone zoneMock = mock(Warzone.class); Warzone zoneMock = mock(Warzone.class);
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>()); when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>()); when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock); ZoneVolume volume = new ZoneVolume("test", warMock, worldMock, zoneMock);
Block blockMock = mock(Block.class); Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(-1000); // further south when(blockMock.getX()).thenReturn(-1000); // further south
when(blockMock.getY()).thenReturn(64); // at sea level when(blockMock.getY()).thenReturn(64); // at sea level
@ -183,12 +185,12 @@ public class ZoneVolumeSpecTest {
@Test @Test
public void setNorthwest_whenCreatingAndCorner1AlreadySet_shouldSetCorner2AtTop() throws NotNorthwestException, TooSmallException, TooBigException{ // nw always goes to top public void setNorthwest_whenCreatingAndCorner1AlreadySet_shouldSetCorner2AtTop() throws NotNorthwestException, TooSmallException, TooBigException{ // nw always goes to top
// Arrange // Arrange
War warMock = mock(War.class);
World worldMock = mock(World.class); World worldMock = mock(World.class);
Warzone zoneMock = mock(Warzone.class); Warzone zoneMock = mock(Warzone.class);
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>()); when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>()); when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock); ZoneVolume volume = new ZoneVolume("test", warMock, worldMock, zoneMock);
Block blockMock = mock(Block.class); Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(-64); // further north when(blockMock.getX()).thenReturn(-64); // further north
when(blockMock.getY()).thenReturn(64); // at sea level when(blockMock.getY()).thenReturn(64); // at sea level
@ -219,12 +221,12 @@ public class ZoneVolumeSpecTest {
@Test @Test
public void setNorthwest_whenCreating_AndCorner1AlreadySet_ButNewCornerBlockIsEastOfCorner1_shouldThrowNotNorthwestException() throws TooSmallException, TooBigException{ public void setNorthwest_whenCreating_AndCorner1AlreadySet_ButNewCornerBlockIsEastOfCorner1_shouldThrowNotNorthwestException() throws TooSmallException, TooBigException{
// Arrange // Arrange
War warMock = mock(War.class);
World worldMock = mock(World.class); World worldMock = mock(World.class);
Warzone zoneMock = mock(Warzone.class); Warzone zoneMock = mock(Warzone.class);
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>()); when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>()); when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock); ZoneVolume volume = new ZoneVolume("test", warMock, worldMock, zoneMock);
Block blockMock = mock(Block.class); Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(-64); // further north when(blockMock.getX()).thenReturn(-64); // further north
when(blockMock.getY()).thenReturn(64); // at sea level when(blockMock.getY()).thenReturn(64); // at sea level
@ -253,12 +255,12 @@ public class ZoneVolumeSpecTest {
@Test @Test
public void setNorthwest_whenCreating_AndCorner1AlreadySet_ButNewCornerBlockIsSouthOfCorner1_shouldThrowNotNorthwestException() throws TooSmallException, TooBigException{ public void setNorthwest_whenCreating_AndCorner1AlreadySet_ButNewCornerBlockIsSouthOfCorner1_shouldThrowNotNorthwestException() throws TooSmallException, TooBigException{
// Arrange // Arrange
War warMock = mock(War.class);
World worldMock = mock(World.class); World worldMock = mock(World.class);
Warzone zoneMock = mock(Warzone.class); Warzone zoneMock = mock(Warzone.class);
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>()); when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>()); when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock); ZoneVolume volume = new ZoneVolume("test", warMock, worldMock, zoneMock);
Block blockMock = mock(Block.class); Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(64); // further south when(blockMock.getX()).thenReturn(64); // further south
when(blockMock.getY()).thenReturn(64); // at sea level when(blockMock.getY()).thenReturn(64); // at sea level
@ -287,12 +289,12 @@ public class ZoneVolumeSpecTest {
@Test @Test
public void setNorthwest_whenChangingVolumeWithCorner1NwCorner2Se_shouldMoveCorner1() throws NotNorthwestException, TooSmallException, TooBigException{ public void setNorthwest_whenChangingVolumeWithCorner1NwCorner2Se_shouldMoveCorner1() throws NotNorthwestException, TooSmallException, TooBigException{
// Arrange // Arrange
War warMock = mock(War.class);
World worldMock = mock(World.class); World worldMock = mock(World.class);
Warzone zoneMock = mock(Warzone.class); Warzone zoneMock = mock(Warzone.class);
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>()); when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>()); when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock); ZoneVolume volume = new ZoneVolume("test", warMock, worldMock, zoneMock);
Block blockMock = mock(Block.class); Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(-64); // further north when(blockMock.getX()).thenReturn(-64); // further north
when(blockMock.getY()).thenReturn(64); // at sea level when(blockMock.getY()).thenReturn(64); // at sea level
@ -326,12 +328,12 @@ public class ZoneVolumeSpecTest {
@Test @Test
public void setNorthwest_whenChangingVolumeWithCorner1SeCorner2Nw_shouldMoveCorner2() throws NotNorthwestException, TooSmallException, TooBigException{ public void setNorthwest_whenChangingVolumeWithCorner1SeCorner2Nw_shouldMoveCorner2() throws NotNorthwestException, TooSmallException, TooBigException{
// Arrange // Arrange
War warMock = mock(War.class);
World worldMock = mock(World.class); World worldMock = mock(World.class);
Warzone zoneMock = mock(Warzone.class); Warzone zoneMock = mock(Warzone.class);
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>()); when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>()); when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock); ZoneVolume volume = new ZoneVolume("test", warMock, worldMock, zoneMock);
Block blockMock = mock(Block.class); Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(-64); // further north when(blockMock.getX()).thenReturn(-64); // further north
when(blockMock.getY()).thenReturn(64); // at sea level when(blockMock.getY()).thenReturn(64); // at sea level
@ -365,12 +367,12 @@ public class ZoneVolumeSpecTest {
@Test @Test
public void setNorthwest_whenChangingVolumeWithCorner1NeCorner2Sw_shouldMoveCorner1XAndCorner2Z() throws NotNorthwestException, TooSmallException, TooBigException{ public void setNorthwest_whenChangingVolumeWithCorner1NeCorner2Sw_shouldMoveCorner1XAndCorner2Z() throws NotNorthwestException, TooSmallException, TooBigException{
// Arrange // Arrange
War warMock = mock(War.class);
World worldMock = mock(World.class); World worldMock = mock(World.class);
Warzone zoneMock = mock(Warzone.class); Warzone zoneMock = mock(Warzone.class);
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>()); when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>()); when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock); ZoneVolume volume = new ZoneVolume("test", warMock, worldMock, zoneMock);
Block blockMock = mock(Block.class); Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(-64); // further north when(blockMock.getX()).thenReturn(-64); // further north
when(blockMock.getY()).thenReturn(64); // at sea level when(blockMock.getY()).thenReturn(64); // at sea level
@ -404,12 +406,12 @@ public class ZoneVolumeSpecTest {
@Test @Test
public void setNorthwest_whenChangingVolumeWithCorner1SwCorner2Ne_shouldMoveCorner1ZAndCorner2X() throws NotNorthwestException, TooSmallException, TooBigException{ public void setNorthwest_whenChangingVolumeWithCorner1SwCorner2Ne_shouldMoveCorner1ZAndCorner2X() throws NotNorthwestException, TooSmallException, TooBigException{
// Arrange // Arrange
War warMock = mock(War.class);
World worldMock = mock(World.class); World worldMock = mock(World.class);
Warzone zoneMock = mock(Warzone.class); Warzone zoneMock = mock(Warzone.class);
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>()); when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>()); when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock); ZoneVolume volume = new ZoneVolume("test", warMock, worldMock, zoneMock);
Block blockMock = mock(Block.class); Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(-64); // further north when(blockMock.getX()).thenReturn(-64); // further north
when(blockMock.getY()).thenReturn(64); // at sea level when(blockMock.getY()).thenReturn(64); // at sea level
@ -449,12 +451,12 @@ public class ZoneVolumeSpecTest {
@Test @Test
public void setSoutheast_whenCreatingAndNoCornersAreSet_shouldSetCorner2AtBottom() throws NotSoutheastException, TooSmallException, TooBigException{ public void setSoutheast_whenCreatingAndNoCornersAreSet_shouldSetCorner2AtBottom() throws NotSoutheastException, TooSmallException, TooBigException{
// Arrange // Arrange
War warMock = mock(War.class);
World worldMock = mock(World.class); World worldMock = mock(World.class);
Warzone zoneMock = mock(Warzone.class); Warzone zoneMock = mock(Warzone.class);
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>()); when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>()); when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock); ZoneVolume volume = new ZoneVolume("test", warMock, worldMock, zoneMock);
Block blockMock = mock(Block.class); Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(0); when(blockMock.getX()).thenReturn(0);
when(blockMock.getY()).thenReturn(64); // at sea level when(blockMock.getY()).thenReturn(64); // at sea level
@ -477,12 +479,12 @@ public class ZoneVolumeSpecTest {
@Test @Test
public void setSoutheast_whenCreatingAndNoCorner2IsSet_ButCorner1IsAlreadySet_AndNewCornerBlockIsToWestOfCorner1_shouldThrowNotSoutheastException() throws TooSmallException, TooBigException{ public void setSoutheast_whenCreatingAndNoCorner2IsSet_ButCorner1IsAlreadySet_AndNewCornerBlockIsToWestOfCorner1_shouldThrowNotSoutheastException() throws TooSmallException, TooBigException{
// Arrange // Arrange
War warMock = mock(War.class);
World worldMock = mock(World.class); World worldMock = mock(World.class);
Warzone zoneMock = mock(Warzone.class); Warzone zoneMock = mock(Warzone.class);
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>()); when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>()); when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock); ZoneVolume volume = new ZoneVolume("test", warMock, worldMock, zoneMock);
Block blockMock = mock(Block.class); Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(64); // further south when(blockMock.getX()).thenReturn(64); // further south
when(blockMock.getY()).thenReturn(64); // at sea level when(blockMock.getY()).thenReturn(64); // at sea level
@ -511,12 +513,12 @@ public class ZoneVolumeSpecTest {
@Test @Test
public void setSoutheast_whenCreatingAndNoCorner2IsSet_ButCorner1IsAlreadySet_AndNewCornerBlockIsToNorthOfCorner1_shouldThrowNotSoutheastException() throws TooSmallException, TooBigException{ public void setSoutheast_whenCreatingAndNoCorner2IsSet_ButCorner1IsAlreadySet_AndNewCornerBlockIsToNorthOfCorner1_shouldThrowNotSoutheastException() throws TooSmallException, TooBigException{
// Arrange // Arrange
War warMock = mock(War.class);
World worldMock = mock(World.class); World worldMock = mock(World.class);
Warzone zoneMock = mock(Warzone.class); Warzone zoneMock = mock(Warzone.class);
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>()); when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>()); when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock); ZoneVolume volume = new ZoneVolume("test", warMock, worldMock, zoneMock);
Block blockMock = mock(Block.class); Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(-64); // further north when(blockMock.getX()).thenReturn(-64); // further north
when(blockMock.getY()).thenReturn(64); // at sea level when(blockMock.getY()).thenReturn(64); // at sea level
@ -545,12 +547,12 @@ public class ZoneVolumeSpecTest {
@Test @Test
public void setSoutheast_whenCreatingAndCorner2AlreadySet_shouldSetCorner1AtBottom() throws NotSoutheastException, TooSmallException, TooBigException{ // se always goes to bottom public void setSoutheast_whenCreatingAndCorner2AlreadySet_shouldSetCorner1AtBottom() throws NotSoutheastException, TooSmallException, TooBigException{ // se always goes to bottom
// Arrange // Arrange
War warMock = mock(War.class);
World worldMock = mock(World.class); World worldMock = mock(World.class);
Warzone zoneMock = mock(Warzone.class); Warzone zoneMock = mock(Warzone.class);
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>()); when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>()); when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock); ZoneVolume volume = new ZoneVolume("test", warMock, worldMock, zoneMock);
Block blockMock = mock(Block.class); Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(64); // further south when(blockMock.getX()).thenReturn(64); // further south
when(blockMock.getY()).thenReturn(64); // at sea level when(blockMock.getY()).thenReturn(64); // at sea level
@ -581,12 +583,12 @@ public class ZoneVolumeSpecTest {
@Test @Test
public void setSoutheast_whenCreating_AndCorner2AlreadySet_ButNewCornerBlockIsToWestOfCorner2_shouldThrowNotSoutheastException() throws TooSmallException, TooBigException{ public void setSoutheast_whenCreating_AndCorner2AlreadySet_ButNewCornerBlockIsToWestOfCorner2_shouldThrowNotSoutheastException() throws TooSmallException, TooBigException{
// Arrange // Arrange
War warMock = mock(War.class);
World worldMock = mock(World.class); World worldMock = mock(World.class);
Warzone zoneMock = mock(Warzone.class); Warzone zoneMock = mock(Warzone.class);
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>()); when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>()); when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock); ZoneVolume volume = new ZoneVolume("test", warMock, worldMock, zoneMock);
Block blockMock = mock(Block.class); Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(64); // further south when(blockMock.getX()).thenReturn(64); // further south
when(blockMock.getY()).thenReturn(64); // at sea level when(blockMock.getY()).thenReturn(64); // at sea level
@ -615,12 +617,12 @@ public class ZoneVolumeSpecTest {
@Test @Test
public void setSoutheast_whenCreating_AndCorner2AlreadySet_ButNewCornerBlockIsToNorthOfCorner2_shouldThrowNotSoutheastException() throws TooSmallException, TooBigException{ public void setSoutheast_whenCreating_AndCorner2AlreadySet_ButNewCornerBlockIsToNorthOfCorner2_shouldThrowNotSoutheastException() throws TooSmallException, TooBigException{
// Arrange // Arrange
War warMock = mock(War.class);
World worldMock = mock(World.class); World worldMock = mock(World.class);
Warzone zoneMock = mock(Warzone.class); Warzone zoneMock = mock(Warzone.class);
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>()); when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>()); when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock); ZoneVolume volume = new ZoneVolume("test", warMock, worldMock, zoneMock);
Block blockMock = mock(Block.class); Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(-64); // further north when(blockMock.getX()).thenReturn(-64); // further north
when(blockMock.getY()).thenReturn(64); // at sea level when(blockMock.getY()).thenReturn(64); // at sea level
@ -649,12 +651,12 @@ public class ZoneVolumeSpecTest {
@Test @Test
public void setSoutheast_whenChangingVolumeWithCorner1NwCorner2Se_shouldMoveCorner2() throws NotSoutheastException, TooSmallException, TooBigException{ public void setSoutheast_whenChangingVolumeWithCorner1NwCorner2Se_shouldMoveCorner2() throws NotSoutheastException, TooSmallException, TooBigException{
// Arrange // Arrange
War warMock = mock(War.class);
World worldMock = mock(World.class); World worldMock = mock(World.class);
Warzone zoneMock = mock(Warzone.class); Warzone zoneMock = mock(Warzone.class);
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>()); when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>()); when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock); ZoneVolume volume = new ZoneVolume("test", warMock, worldMock, zoneMock);
Block blockMock = mock(Block.class); Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(64); // further south when(blockMock.getX()).thenReturn(64); // further south
when(blockMock.getY()).thenReturn(64); // at sea level when(blockMock.getY()).thenReturn(64); // at sea level
@ -688,12 +690,12 @@ public class ZoneVolumeSpecTest {
@Test @Test
public void setSoutheast_whenChangingVolumeWithCorner1SeCorner2Nw_shouldMoveCorner1() throws NotSoutheastException, TooSmallException, TooBigException{ public void setSoutheast_whenChangingVolumeWithCorner1SeCorner2Nw_shouldMoveCorner1() throws NotSoutheastException, TooSmallException, TooBigException{
// Arrange // Arrange
War warMock = mock(War.class);
World worldMock = mock(World.class); World worldMock = mock(World.class);
Warzone zoneMock = mock(Warzone.class); Warzone zoneMock = mock(Warzone.class);
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>()); when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>()); when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock); ZoneVolume volume = new ZoneVolume("test", warMock, worldMock, zoneMock);
Block blockMock = mock(Block.class); Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(64); // further south when(blockMock.getX()).thenReturn(64); // further south
when(blockMock.getY()).thenReturn(64); // at sea level when(blockMock.getY()).thenReturn(64); // at sea level
@ -727,12 +729,12 @@ public class ZoneVolumeSpecTest {
@Test @Test
public void setSoutheast_whenChangingVolumeWithCorner1NeCorner2Sw_shouldMoveCorner1ZAndCorner2X() throws NotSoutheastException, TooSmallException, TooBigException{ public void setSoutheast_whenChangingVolumeWithCorner1NeCorner2Sw_shouldMoveCorner1ZAndCorner2X() throws NotSoutheastException, TooSmallException, TooBigException{
// Arrange // Arrange
War warMock = mock(War.class);
World worldMock = mock(World.class); World worldMock = mock(World.class);
Warzone zoneMock = mock(Warzone.class); Warzone zoneMock = mock(Warzone.class);
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>()); when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>()); when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock); ZoneVolume volume = new ZoneVolume("test", warMock, worldMock, zoneMock);
Block blockMock = mock(Block.class); Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(64); // further south when(blockMock.getX()).thenReturn(64); // further south
when(blockMock.getY()).thenReturn(64); // at sea level when(blockMock.getY()).thenReturn(64); // at sea level
@ -766,12 +768,12 @@ public class ZoneVolumeSpecTest {
@Test @Test
public void setSoutheast_whenChangingVolumeWithCorner1SwCorner2Ne_shouldMoveCorner1XAndCorner2Z() throws NotSoutheastException, TooSmallException, TooBigException{ public void setSoutheast_whenChangingVolumeWithCorner1SwCorner2Ne_shouldMoveCorner1XAndCorner2Z() throws NotSoutheastException, TooSmallException, TooBigException{
// Arrange // Arrange
War warMock = mock(War.class);
World worldMock = mock(World.class); World worldMock = mock(World.class);
Warzone zoneMock = mock(Warzone.class); Warzone zoneMock = mock(Warzone.class);
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>()); when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>()); when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock); ZoneVolume volume = new ZoneVolume("test", warMock, worldMock, zoneMock);
Block blockMock = mock(Block.class); Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(64); // further south when(blockMock.getX()).thenReturn(64); // further south
when(blockMock.getY()).thenReturn(64); // at sea level when(blockMock.getY()).thenReturn(64); // at sea level