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
*
* @author tommytony, Tim Düsterhus
* @package bukkit.tommytony.war
* @author tommytony, Tim Düsterhus
* @package bukkit.tommytony.war
*/
public class War extends JavaPlugin {
public static PermissionHandler permissionHandler;
public static War war;
// general
private WarPlayerListener playerListener = new WarPlayerListener();
private WarEntityListener entityListener = new WarEntityListener();
private WarBlockListener blockListener = new WarBlockListener();
private WarPlayerListener playerListener = new WarPlayerListener(this);
private WarEntityListener entityListener = new WarEntityListener(this);
private WarBlockListener blockListener = new WarBlockListener(this);
private Logger log;
private PluginDescriptionFile desc = null;
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.getDefaultReward().put(0, new ItemStack(Material.CAKE, 1));
WarMapper.load();
WarMapper.load(this);
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.msg(player, "You are back as a zone maker.");
}
WarMapper.save();
WarMapper.save(this);
}
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.");
}
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.");
} else {
if (this.updateFromNamedParams(player, arguments)) {
WarMapper.save();
WarMapper.save(this);
this.msg(player, "War config saved.");
} else {
this.badMsg(player, "Failed to read named parameters.");
@ -376,7 +376,7 @@ public class War extends JavaPlugin {
} else {
this.badMsg(player, "No War hub to delete.");
}
WarMapper.save();
WarMapper.save(this);
}
public void performSetWarhub(Player player) {
@ -388,7 +388,7 @@ public class War extends JavaPlugin {
this.warHub.initialize();
this.msg(player, "War hub moved.");
} else {
this.warHub = new WarHub(player.getLocation());
this.warHub = new WarHub(this, player.getLocation());
this.warHub.initialize();
for (Warzone zone : this.warzones) {
if (zone.getLobby() != null) {
@ -398,7 +398,7 @@ public class War extends JavaPlugin {
}
this.msg(player, "War hub created.");
}
WarMapper.save();
WarMapper.save(this);
} else {
this.badMsg(player, "No warzones yet.");
}
@ -420,7 +420,7 @@ public class War extends JavaPlugin {
if (monument != null) {
monument.getVolume().resetBlocks();
warzone.getMonuments().remove(monument);
WarzoneMapper.save(warzone, false);
WarzoneMapper.save(this, warzone, false);
this.msg(player, "Monument " + monument.getName() + " removed.");
} else {
this.badMsg(player, "No such monument.");
@ -442,11 +442,11 @@ public class War extends JavaPlugin {
this.msg(player, "Monument " + monument.getName() + " was moved.");
} else {
// 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);
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.getLobby().initialize();
}
WarzoneMapper.save(warzone, false);
WarzoneMapper.save(this, warzone, false);
this.msg(player, "Team " + team.getName() + " removed.");
} else {
this.badMsg(player, "No such team.");
@ -499,7 +499,7 @@ public class War extends JavaPlugin {
Location playerLoc = player.getLocation();
player.teleport(new Location(playerLoc.getWorld(), playerLoc.getBlockX() + 1, playerLoc.getBlockY(), playerLoc.getBlockZ()));
this.msg(player, "Team " + team.getName() + " flag added here.");
WarzoneMapper.save(warzone, false);
WarzoneMapper.save(this, warzone, false);
} else {
// relocate flag
team.getFlagVolume().resetBlocks();
@ -507,7 +507,7 @@ public class War extends JavaPlugin {
Location playerLoc = player.getLocation();
player.teleport(new Location(playerLoc.getWorld(), playerLoc.getBlockX() + 1, playerLoc.getBlockY(), playerLoc.getBlockZ() + 1));
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.");
} else {
// 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());
warzone.getTeams().add(newTeam);
if (warzone.getLobby() != null) {
@ -538,7 +538,7 @@ public class War extends JavaPlugin {
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();
this.getWarzones().remove(warzone);
WarMapper.save();
WarzoneMapper.delete(warzone.getName());
WarMapper.save(this);
WarzoneMapper.delete(this, warzone.getName());
if (this.warHub != null) { // warhub has to change
this.warHub.getVolume().resetBlocks();
this.warHub.initialize();
@ -644,7 +644,7 @@ public class War extends JavaPlugin {
}
if (this.updateZoneFromNamedParams(warzone, player, arguments)) {
this.msg(player, "Saving config and resetting warzone " + warzone.getName() + ".");
WarzoneMapper.save(warzone, false);
WarzoneMapper.save(this, warzone, false);
warzone.getVolume().resetBlocks();
if (lobby != null) {
lobby.getVolume().resetBlocks();
@ -678,7 +678,7 @@ public class War extends JavaPlugin {
if (arguments.length > 0) {
// changed settings: must reinitialize with new settings
this.updateZoneFromNamedParams(warzone, player, arguments);
WarzoneMapper.save(warzone, true);
WarzoneMapper.save(this, warzone, true);
warzone.getVolume().resetBlocks();
if (lobby != null) {
lobby.getVolume().resetBlocks();
@ -735,7 +735,7 @@ public class War extends JavaPlugin {
this.msg(player, "Warzone lobby moved to " + wallStr + " side of zone.");
} else {
// new lobby
lobby = new ZoneLobby(warzone, wall);
lobby = new ZoneLobby(this, warzone, wall);
warzone.setLobby(lobby);
lobby.initialize();
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.");
}
WarzoneMapper.save(warzone, false);
WarzoneMapper.save(this, warzone, false);
} else {
// Not in a warzone: set the lobby position to where the player is standing
Warzone warzone = this.matchWarzone(arguments[0]);
@ -761,7 +761,7 @@ public class War extends JavaPlugin {
this.msg(player, "Warzone lobby moved to your location.");
} else {
// new lobby
lobby = new ZoneLobby(warzone, player.getLocation());
lobby = new ZoneLobby(this, warzone, player.getLocation());
warzone.setLobby(lobby);
lobby.initialize();
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.");
}
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.");
}
} 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")) {
setter.placeNorthwest();
} 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.");
} else {
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;
/**
*
*
* @author tommytony
*
*
*/
public class WarBlockListener extends BlockListener {
private War war;
public WarBlockListener(War war) {
this.war = war;
}
@Override
public void onBlockPlace(BlockPlaceEvent event) {
if (War.war.isLoaded()) {
if (this.war.isLoaded()) {
Player player = event.getPlayer();
Block block = event.getBlock();
if (player != null && block != null) {
Team team = War.war.getPlayerTeam(player.getName());
Warzone zone = War.war.warzone(player.getLocation());
Team team = this.war.getPlayerTeam(player.getName());
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()) {
Monument monument = zone.getMonumentFromCenterBlock(block);
if (monument != null && !monument.hasOwner()) {
@ -43,49 +49,49 @@ public class WarBlockListener extends BlockListener {
event.setCancelled(false);
return; // important otherwise cancelled down a few line by isImportantblock
} 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);
return;
}
}
boolean isZoneMaker = War.war.isZoneMaker(player);
boolean isZoneMaker = this.war.isZoneMaker(player);
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);
return;
}
// 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)) {
War.war.badMsg(player, "Can't build here.");
this.war.badMsg(player, "Can't build here.");
event.setCancelled(true);
return;
}
}
// protect the hub
if (War.war.getWarHub() != null && War.war.getWarHub().getVolume().contains(block)) {
War.war.badMsg(player, "Can't build here.");
if (this.war.getWarHub() != null && this.war.getWarHub().getVolume().contains(block)) {
this.war.badMsg(player, "Can't build here.");
event.setCancelled(true);
return;
}
// buildInZonesOnly
if (zone == null && War.war.isBuildInZonesOnly() && !War.war.canBuildOutsideZone(player)) {
War.war.badMsg(player, "You can only build inside warzones. Ask for the 'war.build' permission to build outside.");
if (zone == null && this.war.isBuildInZonesOnly() && !this.war.canBuildOutsideZone(player)) {
this.war.badMsg(player, "You can only build inside warzones. Ask for the 'war.build' permission to build outside.");
event.setCancelled(true);
return;
}
// can't place a block of your team's color
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);
return;
}
if (team != null && zone != null && zone.isFlagThief(player.getName())) {
// 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);
}
@ -93,7 +99,7 @@ public class WarBlockListener extends BlockListener {
// unbreakableZoneBlocks
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)
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);
return;
}
@ -103,7 +109,7 @@ public class WarBlockListener extends BlockListener {
@Override
public void onBlockBreak(BlockBreakEvent event) {
if (War.war.isLoaded()) {
if (this.war.isLoaded()) {
Player player = event.getPlayer();
Block block = event.getBlock();
if (player != null && block != null) {
@ -113,13 +119,13 @@ public class WarBlockListener extends BlockListener {
}
private void handleBreakOrDamage(Player player, Block block, Cancellable event) {
Warzone warzone = War.war.warzone(player.getLocation());
Team team = War.war.getPlayerTeam(player.getName());
boolean isZoneMaker = War.war.isZoneMaker(player);
Warzone warzone = this.war.warzone(player.getLocation());
Team team = this.war.getPlayerTeam(player.getName());
boolean isZoneMaker = this.war.isZoneMaker(player);
if (warzone != null && team == null && !isZoneMaker) {
// 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);
return;
} 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)) {
ItemStack teamKindBlock = new ItemStack(team.getKind().getMaterial(), team.getKind().getData());
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);
return;
} else {
@ -150,7 +156,7 @@ public class WarBlockListener extends BlockListener {
} else if (team != null && warzone.isEnemyTeamFlagBlock(team, block)) {
if (warzone.isFlagThief(player.getName())) {
// 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 {
Team lostFlagTeam = warzone.getTeamForFlagBlock(block);
if (lostFlagTeam.getPlayers().size() != 0) {
@ -168,15 +174,15 @@ public class WarBlockListener extends BlockListener {
+ " 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 {
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);
return;
} else if (!warzone.isMonumentCenterBlock(block)) {
War.war.badMsg(player, "Can't destroy this.");
this.war.badMsg(player, "Can't destroy this.");
event.setCancelled(true);
return;
}
@ -184,9 +190,9 @@ public class WarBlockListener extends BlockListener {
// protect warzone lobbies
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)) {
War.war.badMsg(player, "Can't destroy this.");
this.war.badMsg(player, "Can't destroy this.");
event.setCancelled(true);
return;
}
@ -194,16 +200,16 @@ public class WarBlockListener extends BlockListener {
}
// protect the hub
if (War.war.getWarHub() != null && War.war.getWarHub().getVolume().contains(block)) {
War.war.badMsg(player, "Can't destroy this.");
if (this.war.getWarHub() != null && this.war.getWarHub().getVolume().contains(block)) {
this.war.badMsg(player, "Can't destroy this.");
event.setCancelled(true);
return;
}
// buildInZonesOnly
Warzone blockZone = War.war.warzone(new Location(block.getWorld(), block.getX(), block.getY(), block.getZ()));
if (blockZone == null && War.war.isBuildInZonesOnly() && !War.war.canBuildOutsideZone(player)) {
War.war.badMsg(player, "You can only build inside warzones. Ask for the 'war.build' permission to build outside.");
Warzone blockZone = this.war.warzone(new Location(block.getWorld(), block.getX(), block.getY(), block.getZ()));
if (blockZone == null && this.war.isBuildInZonesOnly() && !this.war.canBuildOutsideZone(player)) {
this.war.badMsg(player, "You can only build inside warzones. Ask for the 'war.build' permission to build outside.");
event.setCancelled(true);
return;
}
@ -211,7 +217,7 @@ public class WarBlockListener extends BlockListener {
// unbreakableZoneBlocks
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
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);
return;
}

View File

@ -15,6 +15,7 @@ import org.bukkit.event.entity.EntityCombustEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageByProjectileEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntityListener;
import org.bukkit.event.entity.EntityRegainHealthEvent;
@ -31,6 +32,17 @@ import com.tommytony.war.Warzone;
*/
public class WarEntityListener extends EntityListener {
/**
* Instance of war
*
* @var War
*/
private final War war;
public WarEntityListener(War war) {
this.war = war;
}
/**
* Handles PVP-Damage
*
@ -44,21 +56,21 @@ public class WarEntityListener extends EntityListener {
// only let adversaries (same warzone, different team) attack each other
Player a = (Player) attacker;
Player d = (Player) defender;
Warzone attackerWarzone = War.war.getPlayerTeamWarzone(a.getName());
Team attackerTeam = War.war.getPlayerTeam(a.getName());
Warzone defenderWarzone = War.war.getPlayerTeamWarzone(d.getName());
Team defenderTeam = War.war.getPlayerTeam(d.getName());
Warzone attackerWarzone = this.war.getPlayerTeamWarzone(a.getName());
Team attackerTeam = this.war.getPlayerTeam(a.getName());
Warzone defenderWarzone = this.war.getPlayerTeamWarzone(d.getName());
Team defenderTeam = this.war.getPlayerTeam(d.getName());
if (attackerTeam != null && defenderTeam != null && attackerTeam != defenderTeam && attackerWarzone == defenderWarzone) {
// Make sure one of the players isn't in the spawn
if (defenderTeam.getSpawnVolume().contains(d.getLocation())) { // attacking person in spawn
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);
}
} 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
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);
}
}
@ -77,30 +89,30 @@ public class WarEntityListener extends EntityListener {
} else if (attackerTeam != null && defenderTeam != null && attackerTeam == defenderTeam && attackerWarzone == defenderWarzone && attacker.getEntityId() != defender.getEntityId()) {
// same team, but not same person
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 {
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
}
} 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
} else if (attackerTeam == null && defenderTeam == null && !War.war.canPvpOutsideZones(a)) {
if (!War.war.isDisablePvpMessage()) {
War.war.badMsg(a, "You need the 'war.pvp' permission to attack players outside warzones.");
} else if (attackerTeam == null && defenderTeam == null && !this.war.canPvpOutsideZones(a)) {
if (!this.war.isDisablePvpMessage()) {
this.war.badMsg(a, "You need the 'war.pvp' permission to attack players outside warzones.");
}
event.setCancelled(true); // global pvp is off
} else {
War.war.badMsg(a, "Your attack missed!");
this.war.badMsg(a, "Your attack missed!");
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) {
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()) {
// You just hit yourself, probably with a bouncing arrow
} 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) {
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
}
@ -109,15 +121,15 @@ public class WarEntityListener extends EntityListener {
// attacked by dispenser arrow most probably
// Detect death, prevent it and respawn the player
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()) {
String deathMessage = "";
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)
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
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()) {
team.teamcast(deathMessage);
}
@ -132,23 +144,23 @@ public class WarEntityListener extends EntityListener {
*/
@Override
public void onEntityExplode(EntityExplodeEvent event) {
if (War.war.isLoaded()) {
if (this.war.isLoaded()) {
// protect zones elements, lobbies and warhub from creepers
List<Block> explodedBlocks = event.blockList();
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);
War.war.log("Explosion prevented at warhub.", Level.INFO);
this.war.log("Explosion prevented at warhub.", Level.INFO);
return;
}
for (Warzone zone : War.war.getWarzones()) {
for (Warzone zone : this.war.getWarzones()) {
if (zone.isImportantBlock(block)) {
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;
} else if (zone.getLobby() != null && zone.getLobby().getVolume().contains(block)) {
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;
}
}
@ -161,10 +173,10 @@ public class WarEntityListener extends EntityListener {
*/
@Override
public void onEntityDamage(EntityDamageEvent event) {
if (War.war.isLoaded()) {
if (this.war.isLoaded()) {
Entity entity = event.getEntity();
// 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);
}
@ -175,10 +187,10 @@ public class WarEntityListener extends EntityListener {
// Detect death, prevent it and respawn the player
if (entity instanceof Player) {
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()) {
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()) {
team.teamcast(deathMessage);
}
@ -192,11 +204,11 @@ public class WarEntityListener extends EntityListener {
@Override
public void onEntityCombust(EntityCombustEvent event) {
if (War.war.isLoaded()) {
if (this.war.isLoaded()) {
Entity entity = event.getEntity();
if (entity instanceof Player) {
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())) {
// smother out the fire that didn't burn out when you respawned
// Stop fire (upcast, watch out!)
@ -215,9 +227,9 @@ public class WarEntityListener extends EntityListener {
*/
@Override
public void onCreatureSpawn(CreatureSpawnEvent event) {
if (War.war.isLoaded()) {
if (this.war.isLoaded()) {
Location location = event.getLocation();
Warzone zone = War.war.warzone(location);
Warzone zone = this.war.warzone(location);
if (zone != null && zone.isNoCreatures()) {
event.setCancelled(true);
// war.logInfo("Prevented " + event.getMobType().getName() + " from spawning in zone " + zone.getName());
@ -230,12 +242,12 @@ public class WarEntityListener extends EntityListener {
*/
@Override
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();
if (entity instanceof Player) {
Player player = (Player) entity;
Location location = player.getLocation();
Warzone zone = War.war.warzone(location);
Warzone zone = this.war.warzone(location);
if (zone != null) {
event.setCancelled(true);
}

View File

@ -1,5 +1,7 @@
package bukkit.tommytony.war;
import java.util.Random;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
@ -28,41 +30,48 @@ import com.tommytony.war.ZoneLobby;
import com.tommytony.war.ZoneSetter;
/**
* @author tommytony, Tim Düsterhus
* @package bukkit.tommytony.war
*
* @author tommytony
*
*/
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
public void onPlayerQuit(PlayerQuitEvent event) {
if (War.war.isLoaded()) {
if (this.war.isLoaded()) {
Player player = event.getPlayer();
Team team = War.war.getPlayerTeam(player.getName());
Team team = this.war.getPlayerTeam(player.getName());
if (team != null) {
Warzone zone = War.war.getPlayerTeamWarzone(player.getName());
Warzone zone = this.war.getPlayerTeamWarzone(player.getName());
if (zone != null) {
zone.handlePlayerLeave(player, zone.getTeleport(), true);
}
}
if (War.war.isWandBearer(player)) {
War.war.removeWandBearer(player);
if (this.war.isWandBearer(player)) {
this.war.removeWandBearer(player);
}
}
}
@Override
public void onPlayerDropItem(PlayerDropItemEvent event) {
if (War.war.isLoaded()) {
if (this.war.isLoaded()) {
Player player = event.getPlayer();
Team team = War.war.getPlayerTeam(player.getName());
Team team = this.war.getPlayerTeam(player.getName());
if (team != null) {
Warzone zone = War.war.getPlayerTeamWarzone(player.getName());
Warzone zone = this.war.getPlayerTeamWarzone(player.getName());
if (zone.isFlagThief(player.getName())) {
// 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);
} else {
@ -71,25 +80,25 @@ public class WarPlayerListener extends PlayerListener {
ItemStack itemStack = item.getItemStack();
if (itemStack != null && itemStack.getType() == team.getKind().getMaterial() && itemStack.getData().getData() == team.getKind().getData()) {
// 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);
return;
}
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);
return;
}
}
}
}
if (War.war.isWandBearer(player)) {
if (this.war.isWandBearer(player)) {
Item item = event.getItemDrop();
if (item.getItemStack().getType() == Material.WOOD_SWORD) {
String zoneName = War.war.getWandBearerZone(player);
War.war.removeWandBearer(player);
War.war.msg(player, "You dropped the zone " + zoneName + " wand.");
String zoneName = this.war.getWandBearerZone(player);
this.war.removeWandBearer(player);
this.war.msg(player, "You dropped the zone " + zoneName + " wand.");
}
}
}
@ -97,11 +106,11 @@ public class WarPlayerListener extends PlayerListener {
@Override
public void onPlayerPickupItem(PlayerPickupItemEvent event) {
if (War.war.isLoaded()) {
if (this.war.isLoaded()) {
Player player = event.getPlayer();
Team team = War.war.getPlayerTeam(player.getName());
Team team = this.war.getPlayerTeam(player.getName());
if (team != null) {
Warzone zone = War.war.getPlayerTeamWarzone(player.getName());
Warzone zone = this.war.getPlayerTeamWarzone(player.getName());
if (zone.isFlagThief(player.getName())) {
// a flag thief can't pick up anything
@ -127,10 +136,10 @@ public class WarPlayerListener extends PlayerListener {
@Override
public void onInventoryOpen(PlayerInventoryEvent event) {
if (War.war.isLoaded()) {
if (this.war.isLoaded()) {
Player player = event.getPlayer();
Inventory inventory = event.getInventory();
Team team = War.war.getPlayerTeam(player.getName());
Team team = this.war.getPlayerTeam(player.getName());
if (team != null && inventory instanceof PlayerInventory) {
// make sure the player doesn't have too many precious blocks
// or illegal armor (i.e. armor not found in loadout)
@ -139,7 +148,7 @@ public class WarPlayerListener extends PlayerListener {
if (playerInv.contains(teamKindBlock, 2)) {
playerInv.remove(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
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
if (War.war.isLoaded()) {
if (this.war.isLoaded()) {
Player player = event.getPlayer();
Team talkingPlayerTeam = War.war.getPlayerTeam(player.getName());
Team talkingPlayerTeam = this.war.getPlayerTeam(player.getName());
if (talkingPlayerTeam != null) {
String msg = event.getMessage();
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);
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)) {
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);
}
}
@ -171,19 +180,19 @@ public class WarPlayerListener extends PlayerListener {
@Override
public void onPlayerKick(PlayerKickEvent event) {
if (War.war.isLoaded()) {
if (this.war.isLoaded()) {
Player player = event.getPlayer();
String reason = event.getReason();
if (reason.contains("moved") || reason.contains("too quickly") || reason.contains("Hacking")) {
boolean inWarzone = War.war.inAnyWarzone(player.getLocation());
boolean inLobby = War.war.inAnyWarzone(player.getLocation());
boolean inWarzone = this.war.inAnyWarzone(player.getLocation());
boolean inLobby = this.war.inAnyWarzone(player.getLocation());
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;
}
if (inWarzone || inLobby || inWarhub) {
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
public void onPlayerInteract(PlayerInteractEvent event) {
if (War.war.isLoaded()) {
if (this.war.isLoaded()) {
Player player = event.getPlayer();
if (player.getItemInHand().getType() == Material.WOOD_SWORD && War.war.isWandBearer(player)) {
String zoneName = War.war.getWandBearerZone(player);
ZoneSetter setter = new ZoneSetter(player, zoneName);
if (player.getItemInHand().getType() == Material.WOOD_SWORD && this.war.isWandBearer(player)) {
String zoneName = this.war.getWandBearerZone(player);
ZoneSetter setter = new ZoneSetter(this.war, player, zoneName);
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) {
setter.placeCorner1(event.getClickedBlock());
event.setUseItemInHand(Result.ALLOW);
@ -211,25 +220,25 @@ public class WarPlayerListener extends PlayerListener {
@Override
public void onPlayerMove(PlayerMoveEvent event) {
if (War.war.isLoaded()) {
if (this.war.isLoaded()) {
Player player = event.getPlayer();
Location playerLoc = event.getFrom(); // same as player.getLoc. Don't call again we need same result.
Warzone locZone = null;
ZoneLobby locLobby = null;
locZone = War.war.warzone(playerLoc);
locLobby = War.war.lobby(playerLoc);
boolean canPlay = War.war.canPlayWar(player);
boolean isMaker = War.war.isZoneMaker(player);
locZone = this.war.warzone(playerLoc);
locLobby = this.war.lobby(playerLoc);
boolean canPlay = this.war.canPlayWar(player);
boolean isMaker = this.war.isZoneMaker(player);
// Zone walls
Team currentTeam = War.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
Team currentTeam = this.war.getPlayerTeam(player.getName());
Warzone playerWarzone = this.war.getPlayerTeamWarzone(player.getName()); // this uses the teams, so it asks: get the player's team's warzone
boolean protecting = false;
if (currentTeam != null) {
// Warzone nearbyZone = war.zoneOfZoneWallAtProximity(playerLoc);
protecting = playerWarzone.protectZoneWallAgainstPlayer(player);
} else {
Warzone nearbyZone = War.war.zoneOfZoneWallAtProximity(playerLoc);
Warzone nearbyZone = this.war.zoneOfZoneWallAtProximity(playerLoc);
if (nearbyZone != null && !isMaker) {
protecting = nearbyZone.protectZoneWallAgainstPlayer(player);
}
@ -238,7 +247,7 @@ public class WarPlayerListener extends PlayerListener {
if (!protecting) {
// zone makers still need to delete their walls
// 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);
}
}
@ -246,7 +255,7 @@ public class WarPlayerListener extends PlayerListener {
// Warzone lobby gates
if (locLobby != null) {
Warzone zone = locLobby.getZone();
Team oldTeam = War.war.getPlayerTeam(player.getName());
Team oldTeam = this.war.getPlayerTeam(player.getName());
boolean isAutoAssignGate = false;
if (oldTeam == null && canPlay) { // trying to counter spammy player move
isAutoAssignGate = zone.getLobby().isAutoAssignGate(playerLoc);
@ -262,13 +271,13 @@ public class WarPlayerListener extends PlayerListener {
if (noOfPlayers < zone.getTeams().size() * zone.getTeamCap()) {
zone.autoAssign(player);
if (War.war.getWarHub() != null) {
War.war.getWarHub().resetZoneSign(zone);
if (this.war.getWarHub() != null) {
this.war.getWarHub().resetZoneSign(zone);
}
} else {
event.setTo(zone.getTeleport());
// player.teleport(zone.getTeleport());
War.war.badMsg(player, "All teams are full.");
this.war.badMsg(player, "All teams are full.");
}
}
return;
@ -283,28 +292,28 @@ public class WarPlayerListener extends PlayerListener {
} else if (team.getPlayers().size() < zone.getTeamCap()) {
team.addPlayer(player);
team.resetSign();
if (War.war.getWarHub() != null) {
War.war.getWarHub().resetZoneSign(zone);
if (this.war.getWarHub() != null) {
this.war.getWarHub().resetZoneSign(zone);
}
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);
for (Team t : zone.getTeams()) {
t.teamcast("" + player.getName() + " joined team " + team.getName() + ".");
}
} else {
event.setTo(zone.getTeleport());
War.war.badMsg(player, "Team " + team.getName() + " is full.");
this.war.badMsg(player, "Team " + team.getName() + " is full.");
}
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);
event.setTo(War.war.getWarHub().getLocation());
event.setTo(this.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;
}
}
@ -312,19 +321,19 @@ public class WarPlayerListener extends PlayerListener {
}
// Warhub zone gates
WarHub hub = War.war.getWarHub();
WarHub hub = this.war.getWarHub();
if (hub != null && hub.getVolume().contains(player.getLocation())) {
Warzone zone = hub.getDestinationWarzoneForLocation(playerLoc);
if (zone != null && zone.getTeleport() != null) {
event.setTo(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;
}
}
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
// same as leave
if (playerTeam != null) {
@ -339,7 +348,7 @@ public class WarPlayerListener extends PlayerListener {
if (playerWarzone != null) {
// 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) {
War.war.badMsg(player, "Use /leave to exit the zone.");
this.war.badMsg(player, "Use /leave to exit the zone.");
event.setTo(playerTeam.getTeamSpawn());
return;
}
@ -365,14 +374,14 @@ public class WarPlayerListener extends PlayerListener {
} else {
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;
}
// Flag capture
if (playerWarzone.isFlagThief(player.getName()) && (playerTeam.getSpawnVolume().contains(player.getLocation()) || (playerTeam.getFlagVolume() != null && playerTeam.getFlagVolume().contains(player.getLocation())))) {
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 {
synchronized (playerWarzone) {
// 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.initializeTeamFlag();
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.");
}
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) {
// 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());
// 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;
}
}
@ -415,25 +424,25 @@ public class WarPlayerListener extends PlayerListener {
private void handleDisabledZone(PlayerMoveEvent event, Player player, Warzone zone) {
if (zone.getLobby() != null) {
War.war.badMsg(player, "This warzone is disabled.");
this.war.badMsg(player, "This warzone is disabled.");
event.setTo(zone.getTeleport());
}
}
private void dropFromOldTeamIfAny(Player player) {
// 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.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) {
String teamsMessage = "Teams: ";
Warzone warzone = War.war.warzone(player.getLocation());
ZoneLobby lobby = War.war.lobby(player.getLocation());
Warzone warzone = this.war.warzone(player.getLocation());
ZoneLobby lobby = this.war.lobby(player.getLocation());
if (warzone == null && lobby != null) {
warzone = lobby.getZone();
} else {

View File

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

View File

@ -30,12 +30,14 @@ public class Team {
private Volume flagVolume;
private final Warzone warzone;
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.setName(name);
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.setFlagVolume(null); // no flag at the start
}
@ -296,7 +298,7 @@ public class Team {
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) {
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() {
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()) {
this.flagVolume.resetBlocks();

View File

@ -20,13 +20,17 @@ import com.tommytony.war.volumes.Volume;
* @package com.tommytony.war
*/
public class WarHub {
private final War war;
private Location location;
private Volume volume;
private Map<String, Block> zoneGateBlocks = new HashMap<String, Block>();
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;
if (hubOrientation.equals("south")) {
yaw = 270;
this.setOrientation(BlockFace.SOUTH);
@ -46,13 +50,14 @@ public class WarHub {
location.getY(),
location.getZ(),
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)
public WarHub(Location location) {
public WarHub(War war, Location location) {
this.war = war;
this.location = location;
this.volume = new Volume("warhub", location.getWorld());
this.volume = new Volume("warhub", war, location.getWorld());
setLocation(location);
}
@ -93,7 +98,7 @@ public class WarHub {
for (String zoneName : this.zoneGateBlocks.keySet()) {
Block gate = this.zoneGateBlocks.get(zoneName);
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;
@ -103,12 +108,12 @@ public class WarHub {
// for now, draw the wall of gates to the west
this.zoneGateBlocks.clear();
int disabled = 0;
for (Warzone zone : War.war.getWarzones()) {
for (Warzone zone : this.war.getWarzones()) {
if (zone.isDisabled()) {
disabled++;
}
}
int noOfWarzones = War.war.getWarzones().size() - disabled;
int noOfWarzones = this.war.getWarzones().size() - disabled;
if (noOfWarzones > 0) {
int hubWidth = noOfWarzones * 4 + 2;
int halfHubWidth = hubWidth / 2;
@ -155,7 +160,7 @@ public class WarHub {
// draw gates
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()) {
this.zoneGateBlocks.put(zone.getName(), currentGateBlock);
currentGateBlock.getFace(BlockFace.DOWN).setType(Material.GLOWSTONE);
@ -179,10 +184,10 @@ public class WarHub {
lines[1] = "(/warhub)";
lines[2] = "Pick your";
lines[3] = "battle!";
SignHelper.setToSign(War.war, signBlock, data, lines);
SignHelper.setToSign(this.war, signBlock, data, lines);
// Warzone signs
for (Warzone zone : War.war.getWarzones()) {
for (Warzone zone : this.war.getWarzones()) {
if (!zone.isDisabled() && zone.ready()) {
this.resetZoneSign(zone);
}
@ -235,7 +240,7 @@ public class WarHub {
lines[1] = zone.getName();
lines[2] = zonePlayers + "/" + zoneCap + " players";
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) {

View File

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

View File

@ -22,6 +22,7 @@ import com.tommytony.war.volumes.ZoneVolume;
*
*/
public class ZoneLobby {
private final War war;
private final Warzone warzone;
private BlockFace wall;
private Volume volume;
@ -46,7 +47,8 @@ public class ZoneLobby {
* @param wall
* 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;
int lobbyWidth = warzone.getTeams().size() * 4 + 5;
this.lobbyHalfSide = lobbyWidth / 2;
@ -64,7 +66,8 @@ public class ZoneLobby {
* @param wall
* 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;
int lobbyWidth = warzone.getTeams().size() * 4 + 5;
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.
*/
public ZoneLobby(Warzone warzone, BlockFace wall, Volume volume) {
public ZoneLobby(War war, Warzone warzone, BlockFace wall, Volume volume) {
this.war = war;
this.warzone = warzone;
int lobbyWidth = warzone.getTeams().size() * 4 + 5;
this.lobbyHalfSide = lobbyWidth / 2;
@ -221,7 +225,7 @@ public class ZoneLobby {
private void createVolumeOrReset() {
if (this.volume == null) {
// 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()) {
this.volume.resetBlocks();
}
@ -257,7 +261,7 @@ public class ZoneLobby {
this.volume.setFaceMaterial(BlockFace.DOWN, Material.GLASS); // beautiful
// add war hub link gate
if (War.war.getWarHub() != null) {
if (this.war.getWarHub() != null) {
Block linkGateBlock = BlockInfo.getBlock(this.warzone.getWorld(), this.warHubLinkGate);
this.placeGate(linkGateBlock, Material.OBSIDIAN);
// add warhub sign
@ -315,7 +319,7 @@ public class ZoneLobby {
lines[2] = "";
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
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);
}
} 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) {
@ -664,7 +668,7 @@ public class ZoneLobby {
private boolean leaving(Location location, Block gate, BlockFace inside, BlockFace left, BlockFace right) {
// 3x4x1 deep
Volume gateExitVolume = new Volume("tempGateExit", location.getWorld());
Volume gateExitVolume = new Volume("tempGateExit", this.war, location.getWorld());
Block out = gate.getFace(inside);
gateExitVolume.setCornerOne(out.getFace(left).getFace(BlockFace.DOWN));
gateExitVolume.setCornerTwo(gate.getFace(right, 1).getFace(BlockFace.UP, 3));

View File

@ -15,25 +15,27 @@ import bukkit.tommytony.war.War;
public class ZoneSetter {
private final War war;
private final Player player;
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.zoneName = zoneName;
}
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());
StringBuilder msgString = new StringBuilder();
try {
if (warzone == null) {
// create the warzone
warzone = new Warzone(this.player.getLocation().getWorld(), this.zoneName);
War.war.getIncompleteZones().add(warzone);
warzone = new Warzone(this.war, this.player.getLocation().getWorld(), this.zoneName);
this.war.getIncompleteZones().add(warzone);
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 {
// change existing warzone
this.resetWarzone(warzone, msgString);
@ -42,7 +44,7 @@ public class ZoneSetter {
}
this.saveIfReady(warzone, msgString);
} 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()) {
warzone.initializeZone(); // was reset before changing
}
@ -60,16 +62,16 @@ public class ZoneSetter {
}
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());
StringBuilder msgString = new StringBuilder();
try {
if (warzone == null) {
// create the warzone
warzone = new Warzone(this.player.getLocation().getWorld(), this.zoneName);
War.war.getIncompleteZones().add(warzone);
warzone = new Warzone(this.war, this.player.getLocation().getWorld(), this.zoneName);
this.war.getIncompleteZones().add(warzone);
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 {
// change existing warzone
this.resetWarzone(warzone, msgString);
@ -78,7 +80,7 @@ public class ZoneSetter {
}
this.saveIfReady(warzone, msgString);
} 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()) {
warzone.initializeZone(); // was reset before changing
}
@ -101,15 +103,15 @@ public class ZoneSetter {
}
public void placeCorner1(Block corner1Block) {
Warzone warzone = War.war.findWarzone(this.zoneName);
Warzone warzone = this.war.findWarzone(this.zoneName);
StringBuilder msgString = new StringBuilder();
try {
if (warzone == null) {
// create the warzone
warzone = new Warzone(this.player.getLocation().getWorld(), this.zoneName);
War.war.getIncompleteZones().add(warzone);
warzone = new Warzone(this.war, this.player.getLocation().getWorld(), this.zoneName);
this.war.getIncompleteZones().add(warzone);
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 {
// change existing warzone
this.resetWarzone(warzone, msgString);
@ -136,15 +138,15 @@ public class ZoneSetter {
}
public void placeCorner2(Block corner2Block) {
Warzone warzone = War.war.findWarzone(this.zoneName);
Warzone warzone = this.war.findWarzone(this.zoneName);
StringBuilder msgString = new StringBuilder();
try {
if (warzone == null) {
// create the warzone
warzone = new Warzone(this.player.getLocation().getWorld(), this.zoneName);
War.war.getIncompleteZones().add(warzone);
warzone = new Warzone(this.war, this.player.getLocation().getWorld(), this.zoneName);
this.war.getIncompleteZones().add(warzone);
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 {
// change existing warzone
this.resetWarzone(warzone, msgString);
@ -167,7 +169,7 @@ public class ZoneSetter {
private void resetWarzone(Warzone warzone, StringBuilder msgString) {
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) {
warzone.getLobby().getVolume().resetBlocks();
}
@ -177,48 +179,48 @@ public class ZoneSetter {
}
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() {
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) {
if (warzone.ready()) {
if (!War.war.getWarzones().contains(warzone)) {
War.war.addWarzone(warzone);
if (!this.war.getWarzones().contains(warzone)) {
this.war.addWarzone(warzone);
}
if (War.war.getIncompleteZones().contains(warzone)) {
War.war.getIncompleteZones().remove(warzone);
if (this.war.getIncompleteZones().contains(warzone)) {
this.war.getIncompleteZones().remove(warzone);
}
WarMapper.save();
WarMapper.save(this.war);
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
if (warzone.getLobby() == null) {
// 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);
if (War.war.getWarHub() != null) { // warhub has to change
War.war.getWarHub().getVolume().resetBlocks();
War.war.getWarHub().initialize();
if (this.war.getWarHub() != null) { // warhub has to change
this.war.getWarHub().getVolume().resetBlocks();
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 {
// gotta move the lobby (or dont because zone.initzon does it for you)
// warzone.getLobby().changeWall(warzone.getLobby().getWall());
// }
warzone.initializeZone();
WarzoneMapper.save(warzone, true);
War.war.msg(this.player, "Warzone saved.");
WarzoneMapper.save(this.war, warzone, true);
this.war.msg(this.player, "Warzone saved.");
} else {
if (warzone.getVolume().getCornerOne() == null) {
msgString.append("Still missing corner 1.");
} else if (warzone.getVolume().getCornerTwo() == null) {
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 {
private final War war;
private final String hubStr;
public RestoreWarhubJob(String hubStr) {
public RestoreWarhubJob(War war, String hubStr) {
this.war = war;
this.hubStr = hubStr;
}
@ -31,33 +33,33 @@ public class RestoreWarhubJob implements Runnable {
String hubOrientation = "west";
if (hubStrSplit.length > 3) {
worldName = hubStrSplit[3];
world = War.war.getServer().getWorld(worldName);
world = this.war.getServer().getWorld(worldName);
if(hubStrSplit.length > 4) {
hubOrientation = hubStrSplit[4];
}
} else {
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) {
Location hubLocation = new Location(world, hubX, hubY, hubZ);
WarHub hub = new WarHub(hubLocation, hubOrientation);
War.war.setWarHub(hub);
Volume vol = VolumeMapper.loadVolume("warhub", "", world);
WarHub hub = new WarHub(this.war, hubLocation, hubOrientation);
this.war.setWarHub(hub);
Volume vol = VolumeMapper.loadVolume("warhub", "", this.war, world);
hub.setVolume(vol);
hub.getVolume().resetBlocks();
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)
for (Warzone zone : War.war.getWarzones()) {
for (Warzone zone : this.war.getWarzones()) {
if (zone.getLobby() != null) {
zone.getLobby().getVolume().resetBlocks();
zone.getLobby().initialize();
}
}
War.war.log("Warhub ready.", Level.INFO);
this.war.log("Warhub ready.", Level.INFO);
} 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 {
private final War war;
private final String warzonesStr;
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.newWarInstall = newWarInstall;
}
public void run() {
String[] warzoneSplit = this.warzonesStr.split(",");
War.war.getWarzones().clear();
this.war.getWarzones().clear();
for (String warzoneName : warzoneSplit) {
if (warzoneName != null && !warzoneName.equals("")) {
War.war.log("Loading zone " + warzoneName + "...", Level.INFO);
Warzone zone = WarzoneMapper.load(warzoneName, !this.newWarInstall);
this.war.log("Loading zone " + warzoneName + "...", Level.INFO);
Warzone zone = WarzoneMapper.load(this.war, warzoneName, !this.newWarInstall);
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();
if (zone.getLobby() != null) {
@ -38,8 +40,8 @@ public class RestoreWarzonesJob implements Runnable {
}
}
}
if (War.war.getWarzones().size() > 0) {
War.war.log("Warzones ready.", Level.INFO);
if (this.war.getWarzones().size() > 0) {
this.war.log("Warzones ready.", Level.INFO);
}
}

View File

@ -1,19 +1,23 @@
package com.tommytony.war.jobs;
import bukkit.tommytony.war.War;
import com.tommytony.war.mappers.ZoneVolumeMapper;
import com.tommytony.war.volumes.Volume;
public class ZoneVolumeSaveJob extends Thread {
private final Volume volume;
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.zoneName = zoneName;
this.war = war;
}
@Override
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;
}
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;
int noOfResetBlocks = 0;
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();
if (firstLine != null && !firstLine.equals("")) {
@ -240,7 +240,7 @@ public class PreDeGaulleZoneVolumeMapper {
}
} 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();
} finally {
z++;
@ -257,15 +257,15 @@ public class PreDeGaulleZoneVolumeMapper {
x++;
}
if (!deferred.isEmpty()) {
War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, deferred, 1);
war.getServer().getScheduler().scheduleSyncDelayedTask(war, deferred, 1);
}
}
}
} 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();
} 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();
} finally {
if (in != null) {
@ -276,7 +276,7 @@ public class PreDeGaulleZoneVolumeMapper {
// scanner.close();
// scanner = null;
} 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();
}
}

View File

@ -26,9 +26,9 @@ import com.tommytony.war.volumes.Volume;
*/
public class VolumeMapper {
public static Volume loadVolume(String volumeName, String zoneName, World world) {
Volume volume = new Volume(volumeName, world);
VolumeMapper.load(volume, zoneName, world);
public static Volume loadVolume(String volumeName, String zoneName, War war, World world) {
Volume volume = new Volume(volumeName, war, world);
VolumeMapper.load(volume, zoneName, war, world);
return volume;
}
@ -39,13 +39,13 @@ public class VolumeMapper {
// 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;
try {
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 {
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();
if (firstLine != null && !firstLine.equals("")) {
@ -151,7 +151,7 @@ public class VolumeMapper {
blockReads++;
}
} 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();
}
}
@ -164,31 +164,31 @@ public class VolumeMapper {
}
}
} 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();
} 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();
} finally {
if (in != null) {
try {
in.close();
} 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();
}
}
}
}
public static void save(Volume volume, String zoneName) {
public static void save(Volume volume, String zoneName, War war) {
if (volume.hasTwoCorners()) {
BufferedWriter out = null;
try {
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 {
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");
@ -260,24 +260,24 @@ public class VolumeMapper {
}
out.newLine();
} 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();
}
}
}
}
} 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();
} 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();
} finally {
if (out != null) {
try {
out.close();
} 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();
}
}

View File

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

View File

@ -29,13 +29,13 @@ import com.tommytony.war.volumes.ZoneVolume;
*/
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...");
PropertiesFile warzoneConfig = new PropertiesFile(War.war.getDataFolder().getPath() + "/warzone-" + name + ".txt");
PropertiesFile warzoneConfig = new PropertiesFile(war.getDataFolder().getPath() + "/warzone-" + name + ".txt");
try {
warzoneConfig.load();
} 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();
}
@ -43,21 +43,21 @@ public class WarzoneMapper {
String worldStr = warzoneConfig.getProperty("world");
World world = null;
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 {
world = War.war.getServer().getWorld(worldStr);
world = war.getServer().getWorld(worldStr);
}
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 {
// Create the zone
Warzone warzone = new Warzone(world, name);
Warzone warzone = new Warzone(war, world, name);
// Create file if needed
if (!warzoneConfig.containsKey("name")) {
WarzoneMapper.save(warzone, false);
War.war.getLogger().info("Warzone " + name + " config file created.");
WarzoneMapper.save(war, warzone, false);
war.getLogger().info("Warzone " + name + " config file created.");
try {
warzoneConfig.load();
} catch (IOException e) {
@ -93,7 +93,7 @@ public class WarzoneMapper {
int yaw = Integer.parseInt(teamStrSplit[4]);
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());
warzone.getTeams().add(team);
}
@ -230,7 +230,7 @@ public class WarzoneMapper {
int monumentX = Integer.parseInt(monumentStrSplit[1]);
int monumentY = Integer.parseInt(monumentStrSplit[2]);
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);
}
}
@ -242,20 +242,20 @@ public class WarzoneMapper {
warzoneConfig.close();
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);
}
// monument blocks
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
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) {
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")) {
lobbyFace = BlockFace.WEST;
}
Volume lobbyVolume = VolumeMapper.loadVolume("lobby", warzone.getName(), world);
ZoneLobby lobby = new ZoneLobby(warzone, lobbyFace, lobbyVolume);
Volume lobbyVolume = VolumeMapper.loadVolume("lobby", warzone.getName(), war, world);
ZoneLobby lobby = new ZoneLobby(war, warzone, lobbyFace, lobbyVolume);
warzone.setLobby(lobby);
}
@ -281,9 +281,9 @@ public class WarzoneMapper {
return null;
}
public static void save(Warzone warzone, boolean saveAllBlocks) {
(new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + warzone.getName())).mkdir();
PropertiesFile warzoneConfig = new PropertiesFile(War.war.getDataFolder().getPath() + "/warzone-" + warzone.getName() + ".txt");
public static void save(War war, Warzone warzone, boolean saveAllBlocks) {
(new File(war.getDataFolder().getPath() + "/dat/warzone-" + warzone.getName())).mkdir();
PropertiesFile warzoneConfig = new PropertiesFile(war.getDataFolder().getPath() + "/warzone-" + warzone.getName() + ".txt");
// war.getLogger().info("Saving warzone " + warzone.getName() + "...");
// name
@ -446,19 +446,19 @@ public class WarzoneMapper {
// monument blocks
for (Monument monument : monuments) {
VolumeMapper.save(monument.getVolume(), warzone.getName());
VolumeMapper.save(monument.getVolume(), warzone.getName(), war);
}
// team spawn & flag blocks
for (Team team : teams) {
VolumeMapper.save(team.getSpawnVolume(), warzone.getName());
VolumeMapper.save(team.getSpawnVolume(), warzone.getName(), war);
if (team.getFlagVolume() != null) {
VolumeMapper.save(team.getFlagVolume(), warzone.getName());
VolumeMapper.save(team.getFlagVolume(), warzone.getName(), war);
}
}
if (warzone.getLobby() != null) {
VolumeMapper.save(warzone.getLobby().getVolume(), warzone.getName());
VolumeMapper.save(warzone.getLobby().getVolume(), warzone.getName(), war);
}
// if (saveBlocks) {
@ -468,23 +468,23 @@ public class WarzoneMapper {
// }
}
public static void delete(String name) {
File zoneFolder = new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + name);
public static void delete(War war, String name) {
File zoneFolder = new File(war.getDataFolder().getPath() + "/dat/warzone-" + name);
File[] files = zoneFolder.listFiles();
for (File file : files) {
boolean deletedData = file.delete();
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();
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();
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 String zoneName Zone to load the volume from
* @param War war Instance of War
* @param World world The world the zone is located
* @param boolean onlyLoadCorners Should only the corners be loaded
* @return integer Changed blocks
*/
public static int load(ZoneVolume volume, String zoneName, World world, boolean onlyLoadCorners) {
File cornersFile = new File(War.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 signsFile = new File(War.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");
public static int load(ZoneVolume volume, String zoneName, War war, World world, boolean onlyLoadCorners) {
File cornersFile = new File(war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".corners");
File blocksFile = new File(war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".blocks");
File signsFile = new File(war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".signs");
File invsFile = new File(war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".invs");
int noOfResetBlocks = 0;
if (!blocksFile.exists()) {
// The post 1.6 formatted files haven't been created yet so
// 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 ),
// so let's save to the new format as soon as the zone is fully reset.
ZoneVolumeMapper.saveAsJob(volume, zoneName, 2);
War.war.log("Warzone " + zoneName + " file converted!", Level.INFO);
ZoneVolumeMapper.saveAsJob(volume, zoneName, war, 2);
war.log("Warzone " + zoneName + " file converted!", Level.INFO);
return noOfResetBlocks;
} else {
@ -229,7 +230,7 @@ public class ZoneVolumeMapper {
blockReads++;
} 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();
} finally {
z++;
@ -240,14 +241,14 @@ public class ZoneVolumeMapper {
x++;
}
if (!deferred.isEmpty()) {
War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, deferred, 1);
war.getServer().getScheduler().scheduleSyncDelayedTask(war, deferred, 1);
}
}
} 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();
} 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();
} finally {
try {
@ -264,7 +265,7 @@ public class ZoneVolumeMapper {
invsReader.close();
}
} 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();
}
}
@ -308,9 +309,10 @@ public class ZoneVolumeMapper {
*
* @param Volume volume Volume to save
* @param String zoneName The warzone the volume is located
* @param War war Instance of war
* @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;
if (volume.hasTwoCorners()) {
BufferedWriter cornersWriter = null;
@ -318,8 +320,8 @@ public class ZoneVolumeMapper {
BufferedWriter signsWriter = null;
BufferedWriter invsWriter = null;
try {
(new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName)).mkdir();
String path = War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName();
(new File(war.getDataFolder().getPath() + "/dat/warzone-" + zoneName)).mkdir();
String path = war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName();
cornersWriter = new BufferedWriter(new FileWriter(new File(path + ".corners")));
blocksOutput = new FileOutputStream(new File(path + ".blocks"));
signsWriter = new BufferedWriter(new FileWriter(new File(path + ".signs")));
@ -431,7 +433,7 @@ public class ZoneVolumeMapper {
}
noOfSavedBlocks++;
} 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();
} finally {
z++;
@ -442,10 +444,10 @@ public class ZoneVolumeMapper {
x++;
}
} 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();
} 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();
} finally {
try {
@ -462,7 +464,7 @@ public class ZoneVolumeMapper {
invsWriter.close();
}
} 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();
}
}
@ -478,9 +480,9 @@ public class ZoneVolumeMapper {
* @param War war Instance of war
* @param long tickDelay delay before beginning the task
*/
private static void saveAsJob(ZoneVolume volume, String zoneName, long tickDelay) {
ZoneVolumeSaveJob job = new ZoneVolumeSaveJob(volume, zoneName);
War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, job, tickDelay);
private static void saveAsJob(ZoneVolume volume, String zoneName, War war, long tickDelay) {
ZoneVolumeSaveJob job = new ZoneVolumeSaveJob(volume, zoneName, war);
war.getServer().getScheduler().scheduleSyncDelayedTask(war, job, tickDelay);
}
/**
@ -489,12 +491,12 @@ public class ZoneVolumeMapper {
* @param Volume volume volume to delete
* @param War war Instance of war
*/
public static void delete(Volume volume) {
ZoneVolumeMapper.deleteFile("War/dat/volume-" + volume.getName() + ".dat");
ZoneVolumeMapper.deleteFile("War/dat/volume-" + volume.getName() + ".corners");
ZoneVolumeMapper.deleteFile("War/dat/volume-" + volume.getName() + ".blocks");
ZoneVolumeMapper.deleteFile("War/dat/volume-" + volume.getName() + ".signs");
ZoneVolumeMapper.deleteFile("War/dat/volume-" + volume.getName() + ".invs");
public static void delete(Volume volume, War war) {
ZoneVolumeMapper.deleteFile("War/dat/volume-" + volume.getName() + ".dat", war);
ZoneVolumeMapper.deleteFile("War/dat/volume-" + volume.getName() + ".corners", war);
ZoneVolumeMapper.deleteFile("War/dat/volume-" + volume.getName() + ".blocks", war);
ZoneVolumeMapper.deleteFile("War/dat/volume-" + volume.getName() + ".signs", war);
ZoneVolumeMapper.deleteFile("War/dat/volume-" + volume.getName() + ".invs", war);
}
/**
@ -503,12 +505,12 @@ public class ZoneVolumeMapper {
* @param String path path of file
* @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);
if (volFile.exists()) {
boolean deletedData = volFile.delete();
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.block.Block;
import bukkit.tommytony.war.War;
/**
*
* @author tommytony
* @deprecated Broken, don't use.
*
* @author tommytony
*
* Broken, don't use.
*
*/
@Deprecated
public class CenteredVolume extends Volume {
@ -16,8 +20,8 @@ public class CenteredVolume extends Volume {
private int sideSize = -1;
private final World world;
public CenteredVolume(String name, Block center, int sideSize, World world) {
super(name, world);
public CenteredVolume(String name, Block center, int sideSize, War war, World world) {
super(name, war, world);
this.world = world;
this.setCenter(center);
this.setSideSize(sideSize);

View File

@ -1,7 +1,5 @@
package com.tommytony.war.volumes;
import java.util.logging.Level;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
@ -10,15 +8,15 @@ import org.bukkit.block.BlockFace;
import bukkit.tommytony.war.War;
/**
*
*
* @author tommytony
*
*
*/
@Deprecated
public class VerticalVolume extends Volume {
public VerticalVolume(String name, World world) {
super(name, world);
public VerticalVolume(String name, War war, World world) {
super(name, war, world);
}
@ -143,7 +141,7 @@ public class VerticalVolume extends Volume {
}
}
} 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;
}

View File

@ -36,9 +36,11 @@ public class Volume {
private byte[][][] blockDatas = null;
private HashMap<String, String[]> signLines = new HashMap<String, String[]>();
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.war = war;
this.world = world;
}
@ -120,7 +122,7 @@ public class Volume {
noOfSavedBlocks++;
} 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();
} finally {
z++;
@ -132,7 +134,7 @@ public class Volume {
}
}
} 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();
}
return noOfSavedBlocks;
@ -140,7 +142,7 @@ public class Volume {
public void resetBlocksAsJob() {
BlockResetJob job = new BlockResetJob(this);
War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, job);
this.war.getServer().getScheduler().scheduleSyncDelayedTask(this.war, job);
}
public int resetBlocks() {
@ -268,7 +270,7 @@ public class Volume {
}
visitedBlocks++;
} 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();
} finally {
z++;
@ -280,7 +282,7 @@ public class Volume {
}
}
} 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();
}
return noOfResetBlocks;
@ -415,6 +417,10 @@ public class Volume {
this.blockTypes = blockTypes;
}
public War getWar() {
return this.war;
}
public String getName() {
return this.name;
}
@ -438,7 +444,7 @@ public class Volume {
}
}
} 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) {
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) {
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.invBlockContents.clear();
this.invBlockContents = null;
War.war = null;
this.war = null;
}
}

View File

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

View File

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