Moved War out of Parameter but into a kind of Singleton

This commit is contained in:
Tim Düsterhus 2011-07-17 10:56:55 +02:00
parent 57f81479fe
commit e9193565f3
23 changed files with 517 additions and 578 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(this);
private WarEntityListener entityListener = new WarEntityListener(this);
private WarBlockListener blockListener = new WarBlockListener(this);
private WarPlayerListener playerListener = new WarPlayerListener();
private WarEntityListener entityListener = new WarEntityListener();
private WarBlockListener blockListener = new WarBlockListener();
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(this);
WarMapper.load();
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(this);
WarMapper.save();
}
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(this);
WarMapper.save();
}
}
@ -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(this);
WarMapper.save();
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(this);
WarMapper.save();
}
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(this, player.getLocation());
this.warHub = new WarHub(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(this);
WarMapper.save();
} 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(this, warzone, false);
WarzoneMapper.save(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], this, warzone, player.getLocation());
Monument monument = new Monument(arguments[0], warzone, player.getLocation());
warzone.getMonuments().add(monument);
this.msg(player, "Monument " + monument.getName() + " created.");
}
WarzoneMapper.save(this, warzone, false);
WarzoneMapper.save(warzone, false);
}
}
@ -475,7 +475,7 @@ public class War extends JavaPlugin {
// warzone.addZoneOutline(warzone.getLobby().getWall());
warzone.getLobby().initialize();
}
WarzoneMapper.save(this, warzone, false);
WarzoneMapper.save(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(this, warzone, false);
WarzoneMapper.save(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(this, warzone, false);
WarzoneMapper.save(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(), this, warzone);
Team newTeam = new Team(teamKind.getDefaultName(), teamKind, player.getLocation(), 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(this, warzone, false);
WarzoneMapper.save(warzone, false);
}
}
@ -589,8 +589,8 @@ public class War extends JavaPlugin {
}
warzone.getVolume().resetBlocks();
this.getWarzones().remove(warzone);
WarMapper.save(this);
WarzoneMapper.delete(this, warzone.getName());
WarMapper.save();
WarzoneMapper.delete(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(this, warzone, false);
WarzoneMapper.save(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(this, warzone, true);
WarzoneMapper.save(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(this, warzone, wall);
lobby = new ZoneLobby(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(this, warzone, false);
WarzoneMapper.save(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(this, warzone, player.getLocation());
lobby = new ZoneLobby(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(this, warzone, false);
WarzoneMapper.save(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(this, player, arguments[0]);
ZoneSetter setter = new ZoneSetter(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(this, zone, false);
WarzoneMapper.save(zone, false);
}
}

View File

@ -18,26 +18,20 @@ 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 (this.war.isLoaded()) {
if (War.war.isLoaded()) {
Player player = event.getPlayer();
Block block = event.getBlock();
if (player != null && block != null) {
Team team = this.war.getPlayerTeam(player.getName());
Warzone zone = this.war.warzone(player.getLocation());
Team team = War.war.getPlayerTeam(player.getName());
Warzone zone = War.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()) {
@ -49,49 +43,49 @@ public class WarBlockListener extends BlockListener {
event.setCancelled(false);
return; // important otherwise cancelled down a few line by isImportantblock
} else {
this.war.badMsg(player, "You can't capture a monument without a block of your team's material. Get one from your team spawn.");
War.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 = this.war.isZoneMaker(player);
boolean isZoneMaker = War.war.isZoneMaker(player);
if (zone != null && zone.isImportantBlock(block) && (!isZoneMaker || (isZoneMaker && team != null))) {
this.war.badMsg(player, "Can't build here.");
War.war.badMsg(player, "Can't build here.");
event.setCancelled(true);
return;
}
// protect warzone lobbies
for (Warzone wz : this.war.getWarzones()) {
for (Warzone wz : War.war.getWarzones()) {
if (wz.getLobby() != null && wz.getLobby().getVolume() != null && wz.getLobby().getVolume().contains(block)) {
this.war.badMsg(player, "Can't build here.");
War.war.badMsg(player, "Can't build here.");
event.setCancelled(true);
return;
}
}
// protect the hub
if (this.war.getWarHub() != null && this.war.getWarHub().getVolume().contains(block)) {
this.war.badMsg(player, "Can't build here.");
if (War.war.getWarHub() != null && War.war.getWarHub().getVolume().contains(block)) {
War.war.badMsg(player, "Can't build here.");
event.setCancelled(true);
return;
}
// buildInZonesOnly
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.");
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.");
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()) {
this.war.badMsg(player, "You can only use your team's blocks to capture monuments.");
War.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
this.war.badMsg(player, "Can't drop the flag. What are you doing? Run!");
War.war.badMsg(player, "Can't drop the flag. What are you doing? Run!");
event.setCancelled(true);
}
@ -99,7 +93,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)
this.war.badMsg(player, "The blocks in this zone are unbreakable - this also means you can't build!");
War.war.badMsg(player, "The blocks in this zone are unbreakable - this also means you can't build!");
event.setCancelled(true);
return;
}
@ -109,7 +103,7 @@ public class WarBlockListener extends BlockListener {
@Override
public void onBlockBreak(BlockBreakEvent event) {
if (this.war.isLoaded()) {
if (War.war.isLoaded()) {
Player player = event.getPlayer();
Block block = event.getBlock();
if (player != null && block != null) {
@ -119,13 +113,13 @@ public class WarBlockListener extends BlockListener {
}
private void handleBreakOrDamage(Player player, Block block, Cancellable event) {
Warzone warzone = this.war.warzone(player.getLocation());
Team team = this.war.getPlayerTeam(player.getName());
boolean isZoneMaker = this.war.isZoneMaker(player);
Warzone warzone = War.war.warzone(player.getLocation());
Team team = War.war.getPlayerTeam(player.getName());
boolean isZoneMaker = War.war.isZoneMaker(player);
if (warzone != null && team == null && !isZoneMaker) {
// can't actually destroy blocks in a warzone if not part of a team
this.war.badMsg(player, "Can't destroy part of a warzone if you're not in a team.");
War.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)) {
@ -145,7 +139,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)) {
this.war.badMsg(player, "You already have a " + team.getName() + " block.");
War.war.badMsg(player, "You already have a " + team.getName() + " block.");
event.setCancelled(true);
return;
} else {
@ -156,7 +150,7 @@ public class WarBlockListener extends BlockListener {
} else if (team != null && warzone.isEnemyTeamFlagBlock(team, block)) {
if (warzone.isFlagThief(player.getName())) {
// detect audacious thieves
this.war.badMsg(player, "You can only steal one flag at a time!");
War.war.badMsg(player, "You can only steal one flag at a time!");
} else {
Team lostFlagTeam = warzone.getTeamForFlagBlock(block);
if (lostFlagTeam.getPlayers().size() != 0) {
@ -174,15 +168,15 @@ public class WarBlockListener extends BlockListener {
+ " from reaching team " + team.getName() + "'s spawn or flag.");
}
}
this.war.msg(player, "You have team " + lostFlagTeam.getName() + "'s flag. Reach your team spawn or flag to capture it!");
War.war.msg(player, "You have team " + lostFlagTeam.getName() + "'s flag. Reach your team spawn or flag to capture it!");
} else {
this.war.msg(player, "You can't steal team " + lostFlagTeam.getName() + "'s flag since no players are on that team.");
War.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)) {
this.war.badMsg(player, "Can't destroy this.");
War.war.badMsg(player, "Can't destroy this.");
event.setCancelled(true);
return;
}
@ -190,9 +184,9 @@ public class WarBlockListener extends BlockListener {
// protect warzone lobbies
if (block != null) {
for (Warzone zone : this.war.getWarzones()) {
for (Warzone zone : War.war.getWarzones()) {
if (zone.getLobby() != null && zone.getLobby().getVolume() != null && zone.getLobby().getVolume().contains(block)) {
this.war.badMsg(player, "Can't destroy this.");
War.war.badMsg(player, "Can't destroy this.");
event.setCancelled(true);
return;
}
@ -200,16 +194,16 @@ public class WarBlockListener extends BlockListener {
}
// protect the hub
if (this.war.getWarHub() != null && this.war.getWarHub().getVolume().contains(block)) {
this.war.badMsg(player, "Can't destroy this.");
if (War.war.getWarHub() != null && War.war.getWarHub().getVolume().contains(block)) {
War.war.badMsg(player, "Can't destroy this.");
event.setCancelled(true);
return;
}
// buildInZonesOnly
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.");
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.");
event.setCancelled(true);
return;
}
@ -217,7 +211,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
this.war.badMsg(player, "The blocks in this zone are unbreakable!");
War.war.badMsg(player, "The blocks in this zone are unbreakable!");
event.setCancelled(true);
return;
}

View File

@ -15,7 +15,6 @@ 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;
@ -32,17 +31,6 @@ 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
*
@ -56,21 +44,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 = 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());
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());
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
this.war.badMsg(a, "Can't attack a player that's inside his team's spawn.");
War.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
this.war.badMsg(a, "Can't attack a player from inside your spawn.");
War.war.badMsg(a, "Can't attack a player from inside your spawn.");
event.setCancelled(true);
}
}
@ -89,30 +77,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()) {
this.war.badMsg(a, "Friendly fire is on! Please, don't hurt your teammates."); // if ff is on, let the attack go through
War.war.badMsg(a, "Friendly fire is on! Please, don't hurt your teammates."); // if ff is on, let the attack go through
} else {
this.war.badMsg(a, "Your attack missed! Your target is on your team.");
War.war.badMsg(a, "Your attack missed! Your target is on your team.");
event.setCancelled(true); // ff is off
}
} else if (attackerTeam == null && defenderTeam == null && this.war.canPvpOutsideZones(a)) {
} else if (attackerTeam == null && defenderTeam == null && War.war.canPvpOutsideZones(a)) {
// let normal PVP through is its not turned off or if you have perms
} 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.");
} 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.");
}
event.setCancelled(true); // global pvp is off
} else {
this.war.badMsg(a, "Your attack missed!");
War.war.badMsg(a, "Your attack missed!");
if (attackerTeam == null) {
this.war.badMsg(a, "You must join a team " + ", then you'll be able to damage people " + "in the other teams in that warzone.");
War.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) {
this.war.badMsg(a, "Your target is not in a team.");
War.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) {
this.war.badMsg(a, "Your target is on your team.");
War.war.badMsg(a, "Your target is on your team.");
} else if (attackerWarzone != defenderWarzone) {
this.war.badMsg(a, "Your target is playing in another warzone.");
War.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
}
@ -121,15 +109,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 = this.war.getPlayerTeamWarzone(d.getName());
Warzone defenderWarzone = War.war.getPlayerTeamWarzone(d.getName());
if (d != null && defenderWarzone != null && event.getDamage() >= d.getHealth()) {
String deathMessage = "";
if (event instanceof EntityDamageByProjectileEvent)
deathMessage = "A dispenser killed " + this.war.getPlayerTeam(d.getName()).getKind().getColor() + d.getDisplayName();
deathMessage = "A dispenser killed " + War.war.getPlayerTeam(d.getName()).getKind().getColor() + d.getDisplayName();
else if (event.getDamager() instanceof CraftTNTPrimed)
deathMessage = this.war.getPlayerTeam(d.getName()).getKind().getColor() + d.getDisplayName() + ChatColor.WHITE + " exploded";
deathMessage = War.war.getPlayerTeam(d.getName()).getKind().getColor() + d.getDisplayName() + ChatColor.WHITE + " exploded";
else
deathMessage = this.war.getPlayerTeam(d.getName()).getKind().getColor() + d.getDisplayName() + ChatColor.WHITE + " died";
deathMessage = War.war.getPlayerTeam(d.getName()).getKind().getColor() + d.getDisplayName() + ChatColor.WHITE + " died";
for (Team team : defenderWarzone.getTeams()) {
team.teamcast(deathMessage);
}
@ -144,23 +132,23 @@ public class WarEntityListener extends EntityListener {
*/
@Override
public void onEntityExplode(EntityExplodeEvent event) {
if (this.war.isLoaded()) {
if (War.war.isLoaded()) {
// protect zones elements, lobbies and warhub from creepers
List<Block> explodedBlocks = event.blockList();
for (Block block : explodedBlocks) {
if (this.war.getWarHub() != null && this.war.getWarHub().getVolume().contains(block)) {
if (War.war.getWarHub() != null && War.war.getWarHub().getVolume().contains(block)) {
event.setCancelled(true);
this.war.log("Explosion prevented at warhub.", Level.INFO);
War.war.log("Explosion prevented at warhub.", Level.INFO);
return;
}
for (Warzone zone : this.war.getWarzones()) {
for (Warzone zone : War.war.getWarzones()) {
if (zone.isImportantBlock(block)) {
event.setCancelled(true);
this.war.log("Explosion prevented in zone " + zone.getName() + ".", Level.INFO);
War.war.log("Explosion prevented in zone " + zone.getName() + ".", Level.INFO);
return;
} else if (zone.getLobby() != null && zone.getLobby().getVolume().contains(block)) {
event.setCancelled(true);
this.war.log("Explosion prevented at zone " + zone.getName() + " lobby.", Level.INFO);
War.war.log("Explosion prevented at zone " + zone.getName() + " lobby.", Level.INFO);
return;
}
}
@ -173,10 +161,10 @@ public class WarEntityListener extends EntityListener {
*/
@Override
public void onEntityDamage(EntityDamageEvent event) {
if (this.war.isLoaded()) {
if (War.war.isLoaded()) {
Entity entity = event.getEntity();
// prevent godmode
if (entity instanceof Player && this.war.getPlayerTeamWarzone(((Player) entity).getName()) != null) {
if (entity instanceof Player && War.war.getPlayerTeamWarzone(((Player) entity).getName()) != null) {
event.setCancelled(false);
}
@ -187,10 +175,10 @@ public class WarEntityListener extends EntityListener {
// Detect death, prevent it and respawn the player
if (entity instanceof Player) {
Player player = (Player) entity;
Warzone zone = this.war.getPlayerTeamWarzone(player.getName());
Warzone zone = War.war.getPlayerTeamWarzone(player.getName());
if (zone != null && event.getDamage() >= player.getHealth()) {
String deathMessage = "";
deathMessage = this.war.getPlayerTeam(player.getName()).getKind().getColor() + player.getDisplayName() + ChatColor.WHITE + " died";
deathMessage = War.war.getPlayerTeam(player.getName()).getKind().getColor() + player.getDisplayName() + ChatColor.WHITE + " died";
for (Team team : zone.getTeams()) {
team.teamcast(deathMessage);
}
@ -204,11 +192,11 @@ public class WarEntityListener extends EntityListener {
@Override
public void onEntityCombust(EntityCombustEvent event) {
if (this.war.isLoaded()) {
if (War.war.isLoaded()) {
Entity entity = event.getEntity();
if (entity instanceof Player) {
Player player = (Player) entity;
Team team = this.war.getPlayerTeam(player.getName());
Team team = War.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!)
@ -227,9 +215,9 @@ public class WarEntityListener extends EntityListener {
*/
@Override
public void onCreatureSpawn(CreatureSpawnEvent event) {
if (this.war.isLoaded()) {
if (War.war.isLoaded()) {
Location location = event.getLocation();
Warzone zone = this.war.warzone(location);
Warzone zone = War.war.warzone(location);
if (zone != null && zone.isNoCreatures()) {
event.setCancelled(true);
// war.logInfo("Prevented " + event.getMobType().getName() + " from spawning in zone " + zone.getName());
@ -242,12 +230,12 @@ public class WarEntityListener extends EntityListener {
*/
@Override
public void onEntityRegainHealth(EntityRegainHealthEvent event) {
if (this.war.isLoaded() && event.getRegainReason() == RegainReason.REGEN) {
if (War.war.isLoaded() && event.getRegainReason() == RegainReason.REGEN) {
Entity entity = event.getEntity();
if (entity instanceof Player) {
Player player = (Player) entity;
Location location = player.getLocation();
Warzone zone = this.war.warzone(location);
Warzone zone = War.war.warzone(location);
if (zone != null) {
event.setCancelled(true);
}

View File

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

View File

@ -5,14 +5,12 @@ 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;
@ -22,11 +20,11 @@ public class Monument {
private final String name;
private Warzone warzone;
public Monument(String name, War war, Warzone warzone, Location location) {
public Monument(String name, Warzone warzone, Location location) {
this.name = name;
this.location = location;
this.warzone = warzone;
this.volume = new Volume(name, war, warzone.getWorld());
this.volume = new Volume(name, warzone.getWorld());
this.setLocation(location);
this.addMonumentBlocks();

View File

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

View File

@ -20,16 +20,14 @@ 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(War war, Location location, String hubOrientation) {
this.war = war;
public WarHub(Location location, String hubOrientation) {
this.location = location;
this.volume = new Volume("warhub", war, location.getWorld());
this.volume = new Volume("warhub", location.getWorld());
if (hubOrientation.equals("south")) {
this.setOrientation(BlockFace.SOUTH);
} else if (hubOrientation.equals("north")) {
@ -43,10 +41,9 @@ public class WarHub {
}
// Use when creating from player location (with yaw)
public WarHub(War war, Location location) {
this.war = war;
public WarHub(Location location) {
this.location = location;
this.volume = new Volume("warhub", war, location.getWorld());
this.volume = new Volume("warhub", location.getWorld());
setLocation(location);
}
@ -87,7 +84,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 = this.war.findWarzone(zoneName);
zone = War.war.findWarzone(zoneName);
}
}
return zone;
@ -97,12 +94,12 @@ public class WarHub {
// for now, draw the wall of gates to the west
this.zoneGateBlocks.clear();
int disabled = 0;
for (Warzone zone : this.war.getWarzones()) {
for (Warzone zone : War.war.getWarzones()) {
if (zone.isDisabled()) {
disabled++;
}
}
int noOfWarzones = this.war.getWarzones().size() - disabled;
int noOfWarzones = War.war.getWarzones().size() - disabled;
if (noOfWarzones > 0) {
int hubWidth = noOfWarzones * 4 + 2;
int halfHubWidth = hubWidth / 2;
@ -149,7 +146,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 : this.war.getWarzones()) { // gonna use the index to find it again
for (Warzone zone : War.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);
@ -175,10 +172,10 @@ public class WarHub {
lines[1] = "(/warhub)";
lines[2] = "Pick your";
lines[3] = "battle!";
SignHelper.setToSign(this.war, signBlock, data, lines);
SignHelper.setToSign(War.war, signBlock, data, lines);
// Warzone signs
for (Warzone zone : this.war.getWarzones()) {
for (Warzone zone : War.war.getWarzones()) {
if (!zone.isDisabled() && zone.ready()) {
this.resetZoneSign(zone);
}
@ -232,7 +229,7 @@ public class WarHub {
lines[1] = zone.getName();
lines[2] = zonePlayers + "/" + zoneCap + " players";
lines[3] = zone.getTeams().size() + " teams";
SignHelper.setToSign(this.war, block, data, lines);
SignHelper.setToSign(War.war, block, data, lines);
}
public void setVolume(Volume vol) {

View File

@ -27,8 +27,8 @@ import com.tommytony.war.volumes.ZoneVolume;
/**
*
* @author tommytony
*
* @author tommytony
* @package com.tommytony.war
*/
public class Warzone {
private String name;
@ -51,7 +51,6 @@ 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;
@ -67,25 +66,24 @@ public class Warzone {
private HashMap<String, InventoryStash> deadMenInventories = new HashMap<String, InventoryStash>();
private Location rallyPoint;
public Warzone(War war, World world, String name) {
public Warzone(World world, String name) {
this.world = world;
this.war = war;
this.name = name;
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);
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);
}
public boolean ready() {
@ -188,12 +186,12 @@ public class Warzone {
public void initializeZoneAsJob(Player respawnExempted) {
InitZoneJob job = new InitZoneJob(this, respawnExempted);
this.war.getServer().getScheduler().scheduleSyncDelayedTask(this.war, job);
War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, job);
}
public void initializeZoneAsJob() {
InitZoneJob job = new InitZoneJob(this);
this.war.getServer().getScheduler().scheduleSyncDelayedTask(this.war, job);
War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, job);
}
private void initZone() {
@ -235,7 +233,7 @@ public class Warzone {
player.setHealth(20);
LoadoutResetJob job = new LoadoutResetJob(this, team, player);
this.war.getServer().getScheduler().scheduleSyncDelayedTask(this.war, job);
War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, job);
}
public void resetInventory(Team team, Player player) {
@ -581,7 +579,7 @@ public class Warzone {
guard.updatePlayerPosition(player.getLocation());
} else {
// new guard
guard = new ZoneWallGuard(player, this.war, this, wall);
guard = new ZoneWallGuard(player, War.war, this, wall);
this.zoneWallGuards.add(guard);
}
protecting = true;
@ -639,7 +637,7 @@ public class Warzone {
if (!this.hasPlayerInventory(player.getName())) {
this.keepPlayerInventory(player);
}
this.war.msg(player, "Your inventory is in storage until you /leave.");
War.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() + ".");
@ -673,10 +671,11 @@ public class Warzone {
}
public void handleDeath(Player player) {
Team playerTeam = this.war.getPlayerTeam(player.getName());
Warzone playerWarzone = this.war.getPlayerTeamWarzone(player.getName());
Team playerTeam = War.war.getPlayerTeam(player.getName());
Warzone playerWarzone = War.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
@ -748,7 +747,7 @@ public class Warzone {
}
}
playerTeam.resetSign();
Plugin heroicDeath = this.war.getServer().getPluginManager().getPlugin("HeroicDeath");
Plugin heroicDeath = War.war.getServer().getPluginManager().getPlugin("HeroicDeath");
if (heroicDeath != null) {
}
@ -766,7 +765,7 @@ public class Warzone {
}
private void handlePlayerLeave(Player player, boolean removeFromTeam) {
Team playerTeam = this.war.getPlayerTeam(player.getName());
Team playerTeam = War.war.getPlayerTeam(player.getName());
if (playerTeam != null) {
if (removeFromTeam) {
playerTeam.removePlayer(player.getName());
@ -794,9 +793,9 @@ public class Warzone {
player.setFireTicks(0);
player.setRemainingAir(300);
this.war.msg(player, "Left the zone. Your inventory has been restored.");
if (this.war.getWarHub() != null) {
this.war.getWarHub().resetZoneSign(this);
War.war.msg(player, "Left the zone. Your inventory has been restored.");
if (War.war.getWarHub() != null) {
War.war.getWarHub().resetZoneSign(this);
}
boolean zoneEmpty = true;
@ -814,7 +813,7 @@ public class Warzone {
}
this.getVolume().resetBlocksAsJob();
this.initializeZoneAsJob();
this.war.log("Last player left warzone " + this.getName() + ". Warzone blocks resetting automatically...", Level.INFO);
War.war.log("Last player left warzone " + this.getName() + ". Warzone blocks resetting automatically...", Level.INFO);
}
}
}
@ -874,15 +873,15 @@ public class Warzone {
winnersStr += ". Resetting warzone and your inventory...";
// Score cap reached. Reset everything.
ScoreCapReachedJob job = new ScoreCapReachedJob(this, winnersStr);
this.war.getServer().getScheduler().scheduleSyncDelayedTask(this.war, job);
War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, job);
if (this.getLobby() != null) {
this.getLobby().getVolume().resetBlocksAsJob();
}
this.getVolume().resetBlocksAsJob();
this.initializeZoneAsJob(player);
if (this.war.getWarHub() != null) {
if (War.war.getWarHub() != null) {
// TODO: test if warhub sign give the correct info despite the jobs
this.war.getWarHub().resetZoneSign(this);
War.war.getWarHub().resetZoneSign(this);
}
}
@ -969,7 +968,7 @@ public class Warzone {
}
public void unload() {
this.war.log("Unloading zone " + this.getName() + "...", Level.INFO);
War.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,7 +22,6 @@ import com.tommytony.war.volumes.ZoneVolume;
*
*/
public class ZoneLobby {
private final War war;
private final Warzone warzone;
private BlockFace wall;
private Volume volume;
@ -47,8 +46,7 @@ public class ZoneLobby {
* @param wall
* On which wall of the warzone will the lobby be stuck to at mid-weight
*/
public ZoneLobby(War war, Warzone warzone, BlockFace wall) {
this.war = war;
public ZoneLobby(Warzone warzone, BlockFace wall) {
this.warzone = warzone;
int lobbyWidth = warzone.getTeams().size() * 4 + 5;
this.lobbyHalfSide = lobbyWidth / 2;
@ -66,8 +64,7 @@ public class ZoneLobby {
* @param wall
* On which wall of the warzone will the lobby be stuck to at mid-weight
*/
public ZoneLobby(War war, Warzone warzone, Location playerLocation) {
this.war = war;
public ZoneLobby(Warzone warzone, Location playerLocation) {
this.warzone = warzone;
int lobbyWidth = warzone.getTeams().size() * 4 + 5;
this.lobbyHalfSide = lobbyWidth / 2;
@ -80,8 +77,7 @@ 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(War war, Warzone warzone, BlockFace wall, Volume volume) {
this.war = war;
public ZoneLobby(Warzone warzone, BlockFace wall, Volume volume) {
this.warzone = warzone;
int lobbyWidth = warzone.getTeams().size() * 4 + 5;
this.lobbyHalfSide = lobbyWidth / 2;
@ -226,7 +222,7 @@ public class ZoneLobby {
private void createVolumeOrReset() {
if (this.volume == null) {
// no previous wall
this.volume = new Volume("lobby", this.war, this.warzone.getWorld());
this.volume = new Volume("lobby", this.warzone.getWorld());
} else if (this.volume.isSaved()) {
this.volume.resetBlocks();
}
@ -259,7 +255,7 @@ public class ZoneLobby {
this.volume.setFaceMaterial(BlockFace.DOWN, Material.GLASS); // beautiful
// add war hub link gate
if (this.war.getWarHub() != null) {
if (War.war.getWarHub() != null) {
Block linkGateBlock = BlockInfo.getBlock(this.warzone.getWorld(), this.warHubLinkGate);
this.placeGate(linkGateBlock, Material.OBSIDIAN);
// add warhub sign
@ -317,7 +313,7 @@ public class ZoneLobby {
lines[2] = "";
lines[3] = "Pick your team.";
}
SignHelper.setToSign(this.war, zoneSignBlock, data, lines);
SignHelper.setToSign(War.war, zoneSignBlock, data, lines);
// lets get some light in here
if (this.wall == BlockFace.NORTH || this.wall == BlockFace.SOUTH) {
@ -328,7 +324,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 {
this.war.log("Failed to initalize zone lobby for zone " + this.warzone.getName(), java.util.logging.Level.WARNING);
War.war.log("Failed to initalize zone lobby for zone " + this.warzone.getName(), java.util.logging.Level.WARNING);
}
}
@ -662,7 +658,7 @@ public class ZoneLobby {
}
}
SignHelper.setToSign(this.war, block, data, lines);
SignHelper.setToSign(War.war, block, data, lines);
}
public boolean isLeavingZone(Location location) {
@ -708,7 +704,7 @@ public class ZoneLobby {
// int z = location.getBlockZ();
//
// 3x4x1 deep
Volume gateExitVolume = new Volume("tempGateExit", this.war, location.getWorld());
Volume gateExitVolume = new Volume("tempGateExit", 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,27 +15,25 @@ import bukkit.tommytony.war.War;
public class ZoneSetter {
private final War war;
private final Player player;
private final String zoneName;
public ZoneSetter(War war, Player player, String zoneName) {
this.war = war;
public ZoneSetter(Player player, String zoneName) {
this.player = player;
this.zoneName = zoneName;
}
public void placeNorthwest() {
Warzone warzone = this.war.findWarzone(this.zoneName);
Warzone warzone = War.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.war, this.player.getLocation().getWorld(), this.zoneName);
this.war.getIncompleteZones().add(warzone);
warzone = new Warzone(this.player.getLocation().getWorld(), this.zoneName);
War.war.getIncompleteZones().add(warzone);
warzone.getVolume().setNorthwest(northwestBlock);
this.war.msg(this.player, "Warzone " + warzone.getName() + " created. Northwesternmost point set to x:" + warzone.getVolume().getNorthwestX() + " z:" + warzone.getVolume().getNorthwestZ() + ". ");
War.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);
@ -44,7 +42,7 @@ public class ZoneSetter {
}
this.saveIfReady(warzone, msgString);
} catch (NotNorthwestException e) {
this.war.badMsg(this.player, "The block you selected is not to the northwest of the existing southeasternmost block.");
War.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
}
@ -62,16 +60,16 @@ public class ZoneSetter {
}
public void placeSoutheast() {
Warzone warzone = this.war.findWarzone(this.zoneName);
Warzone warzone = War.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.war, this.player.getLocation().getWorld(), this.zoneName);
this.war.getIncompleteZones().add(warzone);
warzone = new Warzone(this.player.getLocation().getWorld(), this.zoneName);
War.war.getIncompleteZones().add(warzone);
warzone.getVolume().setSoutheast(southeastBlock);
this.war.msg(this.player, "Warzone " + warzone.getName() + " created. Southeasternmost point set to x:" + warzone.getVolume().getSoutheastX() + " z:" + warzone.getVolume().getSoutheastZ() + ". ");
War.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);
@ -80,7 +78,7 @@ public class ZoneSetter {
}
this.saveIfReady(warzone, msgString);
} catch (NotSoutheastException e) {
this.war.badMsg(this.player, "The block you selected is not to the southeast of the existing northwestnmost block.");
War.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
}
@ -103,15 +101,15 @@ public class ZoneSetter {
}
public void placeCorner1(Block corner1Block) {
Warzone warzone = this.war.findWarzone(this.zoneName);
Warzone warzone = War.war.findWarzone(this.zoneName);
StringBuilder msgString = new StringBuilder();
try {
if (warzone == null) {
// create the warzone
warzone = new Warzone(this.war, this.player.getLocation().getWorld(), this.zoneName);
this.war.getIncompleteZones().add(warzone);
warzone = new Warzone(this.player.getLocation().getWorld(), this.zoneName);
War.war.getIncompleteZones().add(warzone);
warzone.getVolume().setZoneCornerOne(corner1Block);
this.war.msg(this.player, "Warzone " + warzone.getName() + " created. Corner 1 set to x:" + corner1Block.getX() + " y:" + corner1Block.getY() + " z:" + corner1Block.getZ() + ". ");
War.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);
@ -138,15 +136,15 @@ public class ZoneSetter {
}
public void placeCorner2(Block corner2Block) {
Warzone warzone = this.war.findWarzone(this.zoneName);
Warzone warzone = War.war.findWarzone(this.zoneName);
StringBuilder msgString = new StringBuilder();
try {
if (warzone == null) {
// create the warzone
warzone = new Warzone(this.war, this.player.getLocation().getWorld(), this.zoneName);
this.war.getIncompleteZones().add(warzone);
warzone = new Warzone(this.player.getLocation().getWorld(), this.zoneName);
War.war.getIncompleteZones().add(warzone);
warzone.getVolume().setZoneCornerTwo(corner2Block);
this.war.msg(this.player, "Warzone " + warzone.getName() + " created. Corner 2 set to x:" + corner2Block.getX() + " y:" + corner2Block.getY() + " z:" + corner2Block.getZ() + ". ");
War.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);
@ -169,7 +167,7 @@ public class ZoneSetter {
private void resetWarzone(Warzone warzone, StringBuilder msgString) {
if (warzone.getVolume().isSaved()) {
this.war.msg(this.player, "Resetting " + warzone.getName() + " blocks.");
War.war.msg(this.player, "Resetting " + warzone.getName() + " blocks.");
if (warzone.getLobby() != null && warzone.getLobby().getVolume() != null) {
warzone.getLobby().getVolume().resetBlocks();
}
@ -179,48 +177,48 @@ public class ZoneSetter {
}
private void handleTooSmall() {
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.");
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.");
}
private void handleTooBig() {
this.war.badMsg(this.player, "That would make the " + this.zoneName + " warzone too big. Sides must be less than 750 blocks.");
War.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 (!this.war.getWarzones().contains(warzone)) {
this.war.addWarzone(warzone);
if (!War.war.getWarzones().contains(warzone)) {
War.war.addWarzone(warzone);
}
if (this.war.getIncompleteZones().contains(warzone)) {
this.war.getIncompleteZones().remove(warzone);
if (War.war.getIncompleteZones().contains(warzone)) {
War.war.getIncompleteZones().remove(warzone);
}
WarMapper.save(this.war);
WarMapper.save();
msgString.append("Saving new warzone blocks...");
this.war.msg(this.player, msgString.toString());
War.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(this.war, warzone, BlockFace.SOUTH);
ZoneLobby lobby = new ZoneLobby(warzone, BlockFace.SOUTH);
warzone.setLobby(lobby);
if (this.war.getWarHub() != null) { // warhub has to change
this.war.getWarHub().getVolume().resetBlocks();
this.war.getWarHub().initialize();
if (War.war.getWarHub() != null) { // warhub has to change
War.war.getWarHub().getVolume().resetBlocks();
War.war.getWarHub().initialize();
}
this.war.msg(this.player, "Default lobby created on south side of zone. Use /setzonelobby <n/s/e/w> to change its position.");
War.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(this.war, warzone, true);
this.war.msg(this.player, "Warzone saved.");
WarzoneMapper.save(warzone, true);
War.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.");
}
this.war.msg(this.player, msgString.toString());
War.war.msg(this.player, msgString.toString());
}
}

View File

@ -14,11 +14,9 @@ import com.tommytony.war.volumes.Volume;
public class RestoreWarhubJob implements Runnable {
private final War war;
private final String hubStr;
public RestoreWarhubJob(War war, String hubStr) {
this.war = war;
public RestoreWarhubJob(String hubStr) {
this.hubStr = hubStr;
}
@ -33,33 +31,33 @@ public class RestoreWarhubJob implements Runnable {
String hubOrientation = "west";
if (hubStrSplit.length > 3) {
worldName = hubStrSplit[3];
world = this.war.getServer().getWorld(worldName);
world = War.war.getServer().getWorld(worldName);
if(hubStrSplit.length > 4) {
hubOrientation = hubStrSplit[4];
}
} else {
worldName = "DEFAULT";
world = this.war.getServer().getWorlds().get(0); // default to first world
world = War.war.getServer().getWorlds().get(0); // default to first world
}
if (world != null) {
Location hubLocation = new Location(world, hubX, hubY, hubZ);
WarHub hub = new WarHub(this.war, hubLocation, hubOrientation);
this.war.setWarHub(hub);
Volume vol = VolumeMapper.loadVolume("warhub", "", this.war, world);
WarHub hub = new WarHub(hubLocation, hubOrientation);
War.war.setWarHub(hub);
Volume vol = VolumeMapper.loadVolume("warhub", "", 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 : this.war.getWarzones()) {
for (Warzone zone : War.war.getWarzones()) {
if (zone.getLobby() != null) {
zone.getLobby().getVolume().resetBlocks();
zone.getLobby().initialize();
}
}
this.war.log("Warhub ready.", Level.INFO);
War.war.log("Warhub ready.", Level.INFO);
} else {
this.war.log("Failed to restore warhub. The specified world (name: " + worldName + ") does not exist!", Level.WARNING);
War.war.log("Failed to restore warhub. The specified world (name: " + worldName + ") does not exist!", Level.WARNING);
}
}
}

View File

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

View File

@ -1,23 +1,19 @@
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, War war) {
public ZoneVolumeSaveJob(Volume volume, String zoneName) {
this.volume = volume;
this.zoneName = zoneName;
this.war = war;
}
@Override
public void run() {
ZoneVolumeMapper.save(this.volume, this.zoneName, this.war);
ZoneVolumeMapper.save(this.volume, this.zoneName);
}
}

View File

@ -59,11 +59,11 @@ public class PreDeGaulleZoneVolumeMapper {
return items;
}
public static int load(ZoneVolume volume, String zoneName, War war, World world, boolean onlyLoadCorners) {
public static int load(ZoneVolume volume, String zoneName, World world, boolean onlyLoadCorners) {
BufferedReader in = null;
int noOfResetBlocks = 0;
try {
in = new BufferedReader(new FileReader(new File(war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".dat")));
in = new BufferedReader(new FileReader(new File(War.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) {
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());
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());
e.printStackTrace();
} finally {
z++;
@ -257,15 +257,15 @@ public class PreDeGaulleZoneVolumeMapper {
x++;
}
if (!deferred.isEmpty()) {
war.getServer().getScheduler().scheduleSyncDelayedTask(war, deferred, 1);
War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, deferred, 1);
}
}
}
} catch (IOException e) {
war.log("Failed to read volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
War.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.log("Unexpected error caused failure to read volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
War.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.log("Failed to close file reader for volume " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
War.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, War war, World world) {
Volume volume = new Volume(volumeName, war, world);
VolumeMapper.load(volume, zoneName, war, world);
public static Volume loadVolume(String volumeName, String zoneName, World world) {
Volume volume = new Volume(volumeName, world);
VolumeMapper.load(volume, zoneName, world);
return volume;
}
@ -39,13 +39,13 @@ public class VolumeMapper {
// return volume;
// }
public static void load(Volume volume, String zoneName, War war, World world) {
public static void load(Volume volume, String zoneName, World world) {
BufferedReader in = null;
try {
if (zoneName.equals("")) {
in = new BufferedReader(new FileReader(new File(war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".dat"))); // for the warhub
in = new BufferedReader(new FileReader(new File(War.war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".dat"))); // for the warhub
} else {
in = new BufferedReader(new FileReader(new File(war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".dat")));
in = new BufferedReader(new FileReader(new File(War.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.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.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.log("Failed to read volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
War.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.log("Unexpected error caused failure to read volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
War.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.log("Failed to close file reader for volume " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
War.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, War war) {
public static void save(Volume volume, String zoneName) {
if (volume.hasTwoCorners()) {
BufferedWriter out = null;
try {
if (zoneName.equals("")) {
out = new BufferedWriter(new FileWriter(new File(war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".dat")));
out = new BufferedWriter(new FileWriter(new File(War.war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".dat")));
} else {
out = new BufferedWriter(new FileWriter(new File(war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".dat")));
out = new BufferedWriter(new FileWriter(new File(War.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.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.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.log("Failed to write volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
War.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.log("Unexpected error caused failure to write volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
War.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.log("Failed to close file writer for volume " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
War.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(War war) {
public static void load() {
// war.getLogger().info("Loading war config...");
(war.getDataFolder()).mkdir();
(new File(war.getDataFolder().getPath() + "/dat")).mkdir();
PropertiesFile warConfig = new PropertiesFile(war.getDataFolder().getPath() + "/war.txt");
(War.war.getDataFolder()).mkdir();
(new File(War.war.getDataFolder().getPath() + "/dat")).mkdir();
PropertiesFile warConfig = new PropertiesFile(War.war.getDataFolder().getPath() + "/war.txt");
try {
warConfig.load();
} catch (IOException e) {
war.log("Failed to load war.txt file.", Level.WARNING);
War.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.log("Failed to reload war.txt file after creating it.", Level.WARNING);
War.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(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);
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);
}
// zone makers
String[] makers = warConfig.getString("zoneMakers").split(",");
war.getZoneMakerNames().clear();
War.war.getZoneMakerNames().clear();
for (String makerName : makers) {
if (makerName != null && !makerName.equals("")) {
war.getZoneMakerNames().add(makerName);
War.war.getZoneMakerNames().add(makerName);
}
}
// command whitelist
String[] whitelist = warConfig.getString("commandWhitelist").split(",");
war.getCommandWhitelist().clear();
War.war.getCommandWhitelist().clear();
for (String command : whitelist) {
if (command != null && !command.equals("")) {
war.getCommandWhitelist().add(command);
War.war.getCommandWhitelist().add(command);
}
}
// defaultLoadout
String defaultLoadoutStr = warConfig.getString("defaultLoadout");
String[] defaultLoadoutSplit = defaultLoadoutStr.split(";");
war.getDefaultLoadout().clear();
War.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.getDefaultLoadout().put(Integer.parseInt(itemStrSplit[2]), item);
War.war.getDefaultLoadout().put(Integer.parseInt(itemStrSplit[2]), item);
}
}
// defaultLifePool
war.setDefaultLifepool(warConfig.getInt("defaultLifePool"));
War.war.setDefaultLifepool(warConfig.getInt("defaultLifePool"));
// defaultMonumentHeal
war.setDefaultMonumentHeal(warConfig.getInt("defaultMonumentHeal"));
War.war.setDefaultMonumentHeal(warConfig.getInt("defaultMonumentHeal"));
// defaultFriendlyFire
war.setDefaultFriendlyFire(warConfig.getBoolean("defaultFriendlyFire"));
War.war.setDefaultFriendlyFire(warConfig.getBoolean("defaultFriendlyFire"));
// defaultAutoAssignOnly
war.setDefaultAutoAssignOnly(warConfig.getBoolean("defaultAutoAssignOnly"));
War.war.setDefaultAutoAssignOnly(warConfig.getBoolean("defaultAutoAssignOnly"));
// defaultTeamCap
war.setDefaultTeamCap(warConfig.getInt("defaultTeamCap"));
War.war.setDefaultTeamCap(warConfig.getInt("defaultTeamCap"));
// defaultScoreCap
war.setDefaultScoreCap(warConfig.getInt("defaultScoreCap"));
War.war.setDefaultScoreCap(warConfig.getInt("defaultScoreCap"));
// pvpInZonesOnly
war.setPvpInZonesOnly(warConfig.getBoolean("pvpInZonesOnly"));
War.war.setPvpInZonesOnly(warConfig.getBoolean("pvpInZonesOnly"));
// defaultBlockHeads
war.setDefaultBlockHeads(warConfig.getBoolean("defaultBlockHeads"));
War.war.setDefaultBlockHeads(warConfig.getBoolean("defaultBlockHeads"));
// buildInZonesOnly
war.setBuildInZonesOnly(warConfig.getBoolean("buildInZonesOnly"));
War.war.setBuildInZonesOnly(warConfig.getBoolean("buildInZonesOnly"));
// disablePVPMessage
war.setDisablePvpMessage(warConfig.getBoolean("disablePvpMessage"));
War.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.setDefaultSpawnStyle(spawnStyle);
War.war.setDefaultSpawnStyle(spawnStyle);
} else if (spawnStyle.equals(TeamSpawnStyles.FLAT)) {
war.setDefaultSpawnStyle(spawnStyle);
War.war.setDefaultSpawnStyle(spawnStyle);
} else if (spawnStyle.equals(TeamSpawnStyles.INVISIBLE)) {
war.setDefaultSpawnStyle(spawnStyle);
War.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.getDefaultReward().clear();
War.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.getDefaultReward().put(Integer.parseInt(itemStrSplit[2]), item);
War.war.getDefaultReward().put(Integer.parseInt(itemStrSplit[2]), item);
}
}
}
// defaultUnbreakableZoneBlocks
war.setDefaultUnbreakableZoneBlocks(warConfig.getBoolean("defaultUnbreakableZoneBlocks"));
War.war.setDefaultUnbreakableZoneBlocks(warConfig.getBoolean("defaultUnbreakableZoneBlocks"));
// defaultNoCreatures
war.setDefaultNoCreatures(warConfig.getBoolean("defaultNoCreatures"));
War.war.setDefaultNoCreatures(warConfig.getBoolean("defaultNoCreatures"));
// defaultDropLootOnDeath
// war.setDefaultDropLootOnDeath(warConfig.getBoolean("defaultDropLootOnDeath"));
// defaultResetOnEmpty
war.setDefaultResetOnEmpty(warConfig.getBoolean("defaultResetOnEmpty"));
War.war.setDefaultResetOnEmpty(warConfig.getBoolean("defaultResetOnEmpty"));
// defaultResetOnLoad
war.setDefaultResetOnLoad(warConfig.getBoolean("defaultResetOnLoad"));
War.war.setDefaultResetOnLoad(warConfig.getBoolean("defaultResetOnLoad"));
// defaultResetOnUnload
war.setDefaultResetOnUnload(warConfig.getBoolean("defaultResetOnUnload"));
War.war.setDefaultResetOnUnload(warConfig.getBoolean("defaultResetOnUnload"));
// warhub
String hubStr = warConfig.getString("warhub");
if (hubStr != null && !hubStr.equals("")) {
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);
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);
}
}
warConfig.close();
}
public static void save(War war) {
PropertiesFile warConfig = new PropertiesFile(war.getDataFolder().getPath() + "/war.txt");
public static void save() {
PropertiesFile warConfig = new PropertiesFile(War.war.getDataFolder().getPath() + "/war.txt");
String warzonesStr = "";
// warzones
for (Warzone zone : war.getWarzones()) {
for (Warzone zone : War.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.getZoneMakerNames()) {
for (String name : War.war.getZoneMakerNames()) {
makersStr += name + ",";
}
warConfig.setString("zoneMakers", makersStr);
// whitelisted commands during a game
String commandWhitelistStr = ""; // everyone
for (String command : war.getCommandWhitelist()) {
for (String command : War.war.getCommandWhitelist()) {
commandWhitelistStr += command + ",";
}
warConfig.setString("commandWhitelist", makersStr);
// defaultLoadout
String defaultLoadoutStr = "";
HashMap<Integer, ItemStack> items = war.getDefaultLoadout();
HashMap<Integer, ItemStack> items = War.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.getDefaultLifepool());
warConfig.setInt("defaultLifePool", War.war.getDefaultLifepool());
// defaultMonumentHeal
warConfig.setInt("defaultMonumentHeal", war.getDefaultMonumentHeal());
warConfig.setInt("defaultMonumentHeal", War.war.getDefaultMonumentHeal());
// defaultFriendlyFire
warConfig.setBoolean("defaultFriendlyFire", war.getDefaultFriendlyFire());
warConfig.setBoolean("defaultFriendlyFire", War.war.getDefaultFriendlyFire());
// defaultAutoAssignOnly
warConfig.setBoolean("defaultAutoAssignOnly", war.getDefaultAutoAssignOnly());
warConfig.setBoolean("defaultAutoAssignOnly", War.war.getDefaultAutoAssignOnly());
// defaultTeamCap
warConfig.setInt("defaultTeamCap", war.getDefaultTeamCap());
warConfig.setInt("defaultTeamCap", War.war.getDefaultTeamCap());
// defaultScoreCap
warConfig.setInt("defaultScoreCap", war.getDefaultScoreCap());
warConfig.setInt("defaultScoreCap", War.war.getDefaultScoreCap());
// pvpInZonesOnly
warConfig.setBoolean("pvpInZonesOnly", war.isPvpInZonesOnly());
warConfig.setBoolean("pvpInZonesOnly", War.war.isPvpInZonesOnly());
// defaultBlockHeads
warConfig.setBoolean("defaultBlockHeads", war.isDefaultBlockHeads());
warConfig.setBoolean("defaultBlockHeads", War.war.isDefaultBlockHeads());
// buildInZonesOnly
warConfig.setBoolean("buildInZonesOnly", war.isBuildInZonesOnly());
warConfig.setBoolean("buildInZonesOnly", War.war.isBuildInZonesOnly());
// disablePVPMessage
warConfig.setBoolean("disablePvpMessage", war.isDisablePvpMessage());
warConfig.setBoolean("disablePvpMessage", War.war.isDisablePvpMessage());
// spawnStyle
warConfig.setString("spawnStyle", war.getDefaultSpawnStyle());
warConfig.setString("spawnStyle", War.war.getDefaultSpawnStyle());
// defaultReward
String defaultRewardStr = "";
HashMap<Integer, ItemStack> rewardItems = war.getDefaultReward();
HashMap<Integer, ItemStack> rewardItems = War.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.isDefaultUnbreakableZoneBlocks());
warConfig.setBoolean("defaultUnbreakableZoneBlocks", War.war.isDefaultUnbreakableZoneBlocks());
// defaultNoCreatures
warConfig.setBoolean("defaultNoCreatures", war.isDefaultNoCreatures());
warConfig.setBoolean("defaultNoCreatures", War.war.isDefaultNoCreatures());
// defaultResetOnEmpty
warConfig.setBoolean("defaultResetOnEmpty", war.isDefaultResetOnEmpty());
warConfig.setBoolean("defaultResetOnEmpty", War.war.isDefaultResetOnEmpty());
// defaultResetOnLoad
warConfig.setBoolean("defaultResetOnLoad", war.isDefaultResetOnLoad());
warConfig.setBoolean("defaultResetOnLoad", War.war.isDefaultResetOnLoad());
// defaultResetOnUnload
warConfig.setBoolean("defaultResetOnUnload", war.isDefaultResetOnUnload());
warConfig.setBoolean("defaultResetOnUnload", War.war.isDefaultResetOnUnload());
// defaultDropLootOnDeath
// warConfig.setBoolean("defaultDropLootOnDeath", war.isDefaultDropLootOnDeath());
// warhub
String hubStr = "";
WarHub hub = war.getWarHub();
WarHub hub = War.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(), "", war);
VolumeMapper.save(hub.getVolume(), "");
}
warConfig.setString("warhub", hubStr);

View File

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

View File

@ -45,26 +45,25 @@ 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, 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");
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");
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, war, world, onlyLoadCorners);
noOfResetBlocks = PreDeGaulleZoneVolumeMapper.load(volume, zoneName, 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, war, 2);
war.log("Warzone " + zoneName + " file converted!", Level.INFO);
ZoneVolumeMapper.saveAsJob(volume, zoneName, 2);
War.war.log("Warzone " + zoneName + " file converted!", Level.INFO);
return noOfResetBlocks;
} else {
@ -230,7 +229,7 @@ public class ZoneVolumeMapper {
blockReads++;
} catch (Exception e) {
volume.getWar().getLogger().warning("Failed to reset block in zone volume " + volume.getName() + ". " + "Blocks read: " + blockReads + ". Visited blocks so far:" + visitedBlocks + ". Blocks reset: " + noOfResetBlocks + ". Error at x:" + x + " y:" + y + " z:" + z + ". Exception:" + e.getClass().toString() + " " + e.getMessage());
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());
e.printStackTrace();
} finally {
z++;
@ -241,14 +240,14 @@ public class ZoneVolumeMapper {
x++;
}
if (!deferred.isEmpty()) {
war.getServer().getScheduler().scheduleSyncDelayedTask(war, deferred, 1);
War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, deferred, 1);
}
}
} catch (FileNotFoundException e) {
war.log("Failed to find volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
War.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.log("Failed to read volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
War.war.log("Failed to read volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
e.printStackTrace();
} finally {
try {
@ -265,7 +264,7 @@ public class ZoneVolumeMapper {
invsReader.close();
}
} catch (IOException e) {
war.log("Failed to close volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
War.war.log("Failed to close volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
e.printStackTrace();
}
}
@ -309,10 +308,9 @@ 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, War war) {
public static int save(Volume volume, String zoneName) {
int noOfSavedBlocks = 0;
if (volume.hasTwoCorners()) {
BufferedWriter cornersWriter = null;
@ -320,8 +318,8 @@ public class ZoneVolumeMapper {
BufferedWriter signsWriter = null;
BufferedWriter invsWriter = null;
try {
(new File(war.getDataFolder().getPath() + "/dat/warzone-" + zoneName)).mkdir();
String path = war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName();
(new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName)).mkdir();
String path = War.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")));
@ -433,7 +431,7 @@ public class ZoneVolumeMapper {
}
noOfSavedBlocks++;
} catch (Exception e) {
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.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++;
@ -444,10 +442,10 @@ public class ZoneVolumeMapper {
x++;
}
} catch (IOException e) {
war.log("Failed to write volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
War.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.log("Unexpected error caused failure to write volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
War.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 {
@ -464,7 +462,7 @@ public class ZoneVolumeMapper {
invsWriter.close();
}
} catch (IOException e) {
war.log("Failed to close volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
War.war.log("Failed to close volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
e.printStackTrace();
}
}
@ -480,9 +478,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, War war, long tickDelay) {
ZoneVolumeSaveJob job = new ZoneVolumeSaveJob(volume, zoneName, war);
war.getServer().getScheduler().scheduleSyncDelayedTask(war, job, tickDelay);
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);
}
/**
@ -491,12 +489,12 @@ public class ZoneVolumeMapper {
* @param Volume volume volume to delete
* @param War war Instance of war
*/
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);
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");
}
/**
@ -505,12 +503,12 @@ public class ZoneVolumeMapper {
* @param String path path of file
* @param War war Instance of war
*/
private static void deleteFile(String path, War war) {
private static void deleteFile(String path) {
File volFile = new File(path);
if (volFile.exists()) {
boolean deletedData = volFile.delete();
if (!deletedData) {
war.log("Failed to delete file " + volFile.getName(), Level.WARNING);
War.war.log("Failed to delete file " + volFile.getName(), Level.WARNING);
}
}
}

View File

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

View File

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

View File

@ -36,11 +36,9 @@ 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, War war, World world) {
public Volume(String name, World world) {
this.name = name;
this.war = war;
this.world = world;
}
@ -122,7 +120,7 @@ public class Volume {
noOfSavedBlocks++;
} catch (Exception e) {
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());
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());
e.printStackTrace();
} finally {
z++;
@ -134,7 +132,7 @@ public class Volume {
}
}
} catch (Exception e) {
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());
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());
e.printStackTrace();
}
return noOfSavedBlocks;
@ -142,7 +140,7 @@ public class Volume {
public void resetBlocksAsJob() {
BlockResetJob job = new BlockResetJob(this);
this.war.getServer().getScheduler().scheduleSyncDelayedTask(this.war, job);
War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, job);
}
public int resetBlocks() {
@ -270,7 +268,7 @@ public class Volume {
}
visitedBlocks++;
} catch (Exception e) {
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());
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());
e.printStackTrace();
} finally {
z++;
@ -282,7 +280,7 @@ public class Volume {
}
}
} catch (Exception e) {
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);
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);
e.printStackTrace();
}
return noOfResetBlocks;
@ -417,10 +415,6 @@ public class Volume {
this.blockTypes = blockTypes;
}
public War getWar() {
return this.war;
}
public String getName() {
return this.name;
}
@ -444,7 +438,7 @@ public class Volume {
}
}
} catch (Exception e) {
this.getWar().log("Failed to set block to " + material + "in volume " + this.name + "." + e.getClass().toString() + " " + e.getMessage(), Level.WARNING);
War.war.log("Failed to set block to " + material + "in volume " + this.name + "." + e.getClass().toString() + " " + e.getMessage(), Level.WARNING);
}
}
@ -469,7 +463,7 @@ public class Volume {
}
}
} catch (Exception e) {
this.getWar().log("Failed to set block to " + material + "in volume " + this.name + "." + e.getClass().toString() + " " + e.getMessage(), Level.WARNING);
War.war.log("Failed to set block to " + material + "in volume " + this.name + "." + e.getClass().toString() + " " + e.getMessage(), Level.WARNING);
}
}
@ -504,7 +498,7 @@ public class Volume {
}
}
} catch (Exception e) {
this.getWar().log("Failed to switch block to " + newType + "in volume " + this.name + "." + e.getClass().toString() + " " + e.getMessage(), Level.WARNING);
War.war.log("Failed to switch block to " + newType + "in volume " + this.name + "." + e.getClass().toString() + " " + e.getMessage(), Level.WARNING);
}
}
@ -559,6 +553,6 @@ public class Volume {
this.signLines = null;
this.invBlockContents.clear();
this.invBlockContents = null;
this.war = null;
War.war = null;
}
}

View File

@ -20,16 +20,16 @@ public class ZoneVolume extends Volume {
private Warzone zone;
private boolean isSaved = false;
public ZoneVolume(String name, War war, World world, Warzone zone) {
super(name, war, world);
public ZoneVolume(String name, World world, Warzone zone) {
super(name, 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(), this.getWar());
this.getWar().log("Saved " + saved + " blocks in warzone " + this.zone.getName() + ".", java.util.logging.Level.INFO);
int saved = ZoneVolumeMapper.save(this, this.zone.getName());
War.war.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.getWar(), this.getWorld(), true);
ZoneVolumeMapper.load(this, this.zone.getName(), 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.getWar(), this.getWorld(), false);
this.getWar().log("Reset " + reset + " blocks in warzone " + this.zone.getName() + ".", java.util.logging.Level.INFO);
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);
this.isSaved = true;
return reset;
}

View File

@ -9,8 +9,6 @@ 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.*;
@ -21,12 +19,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", warMock, worldMock, zoneMock);
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(0);
when(blockMock.getY()).thenReturn(64); // at sea level
@ -49,12 +47,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", warMock, worldMock, zoneMock);
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(-64); // further north
when(blockMock.getY()).thenReturn(64); // at sea level
@ -83,12 +81,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", warMock, worldMock, zoneMock);
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(64); // further south
when(blockMock.getY()).thenReturn(64); // at sea level
@ -117,12 +115,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", warMock, worldMock, zoneMock);
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(-5); // further south
when(blockMock.getY()).thenReturn(64); // at sea level
@ -151,12 +149,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", warMock, worldMock, zoneMock);
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(-1000); // further south
when(blockMock.getY()).thenReturn(64); // at sea level
@ -185,12 +183,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", warMock, worldMock, zoneMock);
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(-64); // further north
when(blockMock.getY()).thenReturn(64); // at sea level
@ -221,12 +219,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", warMock, worldMock, zoneMock);
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(-64); // further north
when(blockMock.getY()).thenReturn(64); // at sea level
@ -255,12 +253,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", warMock, worldMock, zoneMock);
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(64); // further south
when(blockMock.getY()).thenReturn(64); // at sea level
@ -289,12 +287,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", warMock, worldMock, zoneMock);
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(-64); // further north
when(blockMock.getY()).thenReturn(64); // at sea level
@ -328,12 +326,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", warMock, worldMock, zoneMock);
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(-64); // further north
when(blockMock.getY()).thenReturn(64); // at sea level
@ -367,12 +365,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", warMock, worldMock, zoneMock);
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(-64); // further north
when(blockMock.getY()).thenReturn(64); // at sea level
@ -406,12 +404,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", warMock, worldMock, zoneMock);
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(-64); // further north
when(blockMock.getY()).thenReturn(64); // at sea level
@ -451,12 +449,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", warMock, worldMock, zoneMock);
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(0);
when(blockMock.getY()).thenReturn(64); // at sea level
@ -479,12 +477,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", warMock, worldMock, zoneMock);
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(64); // further south
when(blockMock.getY()).thenReturn(64); // at sea level
@ -513,12 +511,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", warMock, worldMock, zoneMock);
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(-64); // further north
when(blockMock.getY()).thenReturn(64); // at sea level
@ -547,12 +545,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", warMock, worldMock, zoneMock);
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(64); // further south
when(blockMock.getY()).thenReturn(64); // at sea level
@ -583,12 +581,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", warMock, worldMock, zoneMock);
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(64); // further south
when(blockMock.getY()).thenReturn(64); // at sea level
@ -617,12 +615,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", warMock, worldMock, zoneMock);
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(-64); // further north
when(blockMock.getY()).thenReturn(64); // at sea level
@ -651,12 +649,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", warMock, worldMock, zoneMock);
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(64); // further south
when(blockMock.getY()).thenReturn(64); // at sea level
@ -690,12 +688,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", warMock, worldMock, zoneMock);
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(64); // further south
when(blockMock.getY()).thenReturn(64); // at sea level
@ -729,12 +727,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", warMock, worldMock, zoneMock);
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(64); // further south
when(blockMock.getY()).thenReturn(64); // at sea level
@ -768,12 +766,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", warMock, worldMock, zoneMock);
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
Block blockMock = mock(Block.class);
when(blockMock.getX()).thenReturn(64); // further south
when(blockMock.getY()).thenReturn(64); // at sea level