From af3e0f08b37c4508fee154b5c59ad72b00cc952e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Wed, 27 Jul 2011 15:04:16 +0200 Subject: [PATCH] Revert "Reverting e9193565f300f (the War singleton) because it caused unpredictable behavior. For example, doubly nested scheduler calls would cause NPEs when accessing the somehow null singleton. Sorry Tim." This reverts commit 797ca9246bd926122849e709ee1a9e8a24a73906. --- .../main/java/bukkit/tommytony/war/War.java | 60 +++---- .../tommytony/war/WarBlockListener.java | 76 ++++----- .../tommytony/war/WarEntityListener.java | 86 +++++----- .../tommytony/war/WarPlayerListener.java | 155 +++++++++--------- .../main/java/com/tommytony/war/Monument.java | 10 +- war/src/main/java/com/tommytony/war/Team.java | 12 +- .../main/java/com/tommytony/war/WarHub.java | 27 ++- .../main/java/com/tommytony/war/Warzone.java | 73 ++++----- .../java/com/tommytony/war/ZoneLobby.java | 22 +-- .../java/com/tommytony/war/ZoneSetter.java | 74 ++++----- .../tommytony/war/jobs/RestoreWarhubJob.java | 20 +-- .../war/jobs/RestoreWarzonesJob.java | 16 +- .../tommytony/war/jobs/ZoneVolumeSaveJob.java | 8 +- .../mappers/PreDeGaulleZoneVolumeMapper.java | 14 +- .../tommytony/war/mappers/VolumeMapper.java | 34 ++-- .../com/tommytony/war/mappers/WarMapper.java | 130 +++++++-------- .../tommytony/war/mappers/WarzoneMapper.java | 60 +++---- .../war/mappers/ZoneVolumeMapper.java | 64 ++++---- .../tommytony/war/volumes/CenteredVolume.java | 14 +- .../tommytony/war/volumes/VerticalVolume.java | 12 +- .../com/tommytony/war/volumes/Volume.java | 26 ++- .../com/tommytony/war/volumes/ZoneVolume.java | 14 +- .../war/spec/volumes/ZoneVolumeSpecTest.java | 90 +++++----- 23 files changed, 517 insertions(+), 580 deletions(-) diff --git a/war/src/main/java/bukkit/tommytony/war/War.java b/war/src/main/java/bukkit/tommytony/war/War.java index f207e5c..5f80737 100644 --- a/war/src/main/java/bukkit/tommytony/war/War.java +++ b/war/src/main/java/bukkit/tommytony/war/War.java @@ -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: == /setzone <'northwest'/'southeast'/'nw'/'se'> (NW defaults to top block, SE to bottom). " + "== /setzone wand (gives you a wooden sword to right and left click, drop to disable). " + "== /setzone <'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); } } diff --git a/war/src/main/java/bukkit/tommytony/war/WarBlockListener.java b/war/src/main/java/bukkit/tommytony/war/WarBlockListener.java index 6b72ba0..7dda589 100644 --- a/war/src/main/java/bukkit/tommytony/war/WarBlockListener.java +++ b/war/src/main/java/bukkit/tommytony/war/WarBlockListener.java @@ -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; } diff --git a/war/src/main/java/bukkit/tommytony/war/WarEntityListener.java b/war/src/main/java/bukkit/tommytony/war/WarEntityListener.java index 18ae15c..fe3b84f 100644 --- a/war/src/main/java/bukkit/tommytony/war/WarEntityListener.java +++ b/war/src/main/java/bukkit/tommytony/war/WarEntityListener.java @@ -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 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); } diff --git a/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java b/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java index 9f85c8a..8832f97 100644 --- a/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java +++ b/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java @@ -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 { diff --git a/war/src/main/java/com/tommytony/war/Monument.java b/war/src/main/java/com/tommytony/war/Monument.java index 050485e..25a29b2 100644 --- a/war/src/main/java/com/tommytony/war/Monument.java +++ b/war/src/main/java/com/tommytony/war/Monument.java @@ -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(); diff --git a/war/src/main/java/com/tommytony/war/Team.java b/war/src/main/java/com/tommytony/war/Team.java index aa8fbc7..958e504 100644 --- a/war/src/main/java/com/tommytony/war/Team.java +++ b/war/src/main/java/com/tommytony/war/Team.java @@ -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(); diff --git a/war/src/main/java/com/tommytony/war/WarHub.java b/war/src/main/java/com/tommytony/war/WarHub.java index 71df8e9..69eaa81 100644 --- a/war/src/main/java/com/tommytony/war/WarHub.java +++ b/war/src/main/java/com/tommytony/war/WarHub.java @@ -20,17 +20,13 @@ 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 zoneGateBlocks = new HashMap(); private BlockFace orientation; - public WarHub(War war, Location location, String hubOrientation) { - this.war = war; - this.location = location; + public WarHub(Location location, String hubOrientation) { int yaw = 0; - if (hubOrientation.equals("south")) { yaw = 270; this.setOrientation(BlockFace.SOUTH); @@ -50,14 +46,13 @@ public class WarHub { location.getY(), location.getZ(), yaw, 0); - this.volume = new Volume("warhub", war, location.getWorld()); + this.volume = new Volume("warhub", location.getWorld()); } // 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); } @@ -98,7 +93,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; @@ -108,12 +103,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; @@ -160,7 +155,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); @@ -184,10 +179,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); } @@ -240,7 +235,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) { diff --git a/war/src/main/java/com/tommytony/war/Warzone.java b/war/src/main/java/com/tommytony/war/Warzone.java index 43be6f2..6e981d3 100644 --- a/war/src/main/java/com/tommytony/war/Warzone.java +++ b/war/src/main/java/com/tommytony/war/Warzone.java @@ -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 zoneWallGuards = new ArrayList(); - private War war; private ZoneLobby lobby; private boolean autoAssignOnly; private boolean blockHeads; @@ -67,25 +66,24 @@ public class Warzone { private HashMap deadMenInventories = new HashMap(); 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() + "."); @@ -676,10 +674,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 @@ -751,7 +750,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) { } @@ -769,7 +768,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()); @@ -797,9 +796,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; @@ -817,7 +816,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); } } } @@ -877,15 +876,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); } } @@ -972,7 +971,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); diff --git a/war/src/main/java/com/tommytony/war/ZoneLobby.java b/war/src/main/java/com/tommytony/war/ZoneLobby.java index c3f3876..12ead00 100644 --- a/war/src/main/java/com/tommytony/war/ZoneLobby.java +++ b/war/src/main/java/com/tommytony/war/ZoneLobby.java @@ -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; @@ -225,7 +221,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(); } @@ -261,7 +257,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 @@ -319,7 +315,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) { @@ -330,7 +326,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); } } @@ -627,7 +623,7 @@ public class ZoneLobby { } } - SignHelper.setToSign(this.war, block, data, lines); + SignHelper.setToSign(War.war, block, data, lines); } public boolean isLeavingZone(Location location) { @@ -668,7 +664,7 @@ public class ZoneLobby { private boolean leaving(Location location, Block gate, BlockFace inside, BlockFace left, BlockFace right) { // 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)); diff --git a/war/src/main/java/com/tommytony/war/ZoneSetter.java b/war/src/main/java/com/tommytony/war/ZoneSetter.java index 177aa11..9678361 100644 --- a/war/src/main/java/com/tommytony/war/ZoneSetter.java +++ b/war/src/main/java/com/tommytony/war/ZoneSetter.java @@ -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 to change its position."); + War.war.msg(this.player, "Default lobby created on south side of zone. Use /setzonelobby 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()); } } diff --git a/war/src/main/java/com/tommytony/war/jobs/RestoreWarhubJob.java b/war/src/main/java/com/tommytony/war/jobs/RestoreWarhubJob.java index 851e4b9..a3db69d 100644 --- a/war/src/main/java/com/tommytony/war/jobs/RestoreWarhubJob.java +++ b/war/src/main/java/com/tommytony/war/jobs/RestoreWarhubJob.java @@ -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); } } } diff --git a/war/src/main/java/com/tommytony/war/jobs/RestoreWarzonesJob.java b/war/src/main/java/com/tommytony/war/jobs/RestoreWarzonesJob.java index 87e4ca2..4e0b6b3 100644 --- a/war/src/main/java/com/tommytony/war/jobs/RestoreWarzonesJob.java +++ b/war/src/main/java/com/tommytony/war/jobs/RestoreWarzonesJob.java @@ -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); } } diff --git a/war/src/main/java/com/tommytony/war/jobs/ZoneVolumeSaveJob.java b/war/src/main/java/com/tommytony/war/jobs/ZoneVolumeSaveJob.java index 058bc95..f004661 100644 --- a/war/src/main/java/com/tommytony/war/jobs/ZoneVolumeSaveJob.java +++ b/war/src/main/java/com/tommytony/war/jobs/ZoneVolumeSaveJob.java @@ -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); } } diff --git a/war/src/main/java/com/tommytony/war/mappers/PreDeGaulleZoneVolumeMapper.java b/war/src/main/java/com/tommytony/war/mappers/PreDeGaulleZoneVolumeMapper.java index 5130dca..f43c6d6 100644 --- a/war/src/main/java/com/tommytony/war/mappers/PreDeGaulleZoneVolumeMapper.java +++ b/war/src/main/java/com/tommytony/war/mappers/PreDeGaulleZoneVolumeMapper.java @@ -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(); } } diff --git a/war/src/main/java/com/tommytony/war/mappers/VolumeMapper.java b/war/src/main/java/com/tommytony/war/mappers/VolumeMapper.java index 7a7a565..5a3d099 100644 --- a/war/src/main/java/com/tommytony/war/mappers/VolumeMapper.java +++ b/war/src/main/java/com/tommytony/war/mappers/VolumeMapper.java @@ -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(); } } diff --git a/war/src/main/java/com/tommytony/war/mappers/WarMapper.java b/war/src/main/java/com/tommytony/war/mappers/WarMapper.java index 38ebe65..e40022d 100644 --- a/war/src/main/java/com/tommytony/war/mappers/WarMapper.java +++ b/war/src/main/java/com/tommytony/war/mappers/WarMapper.java @@ -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 items = war.getDefaultLoadout(); + HashMap 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 rewardItems = war.getDefaultReward(); + HashMap 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); diff --git a/war/src/main/java/com/tommytony/war/mappers/WarzoneMapper.java b/war/src/main/java/com/tommytony/war/mappers/WarzoneMapper.java index 8f53d64..47773e0 100644 --- a/war/src/main/java/com/tommytony/war/mappers/WarzoneMapper.java +++ b/war/src/main/java/com/tommytony/war/mappers/WarzoneMapper.java @@ -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); } } diff --git a/war/src/main/java/com/tommytony/war/mappers/ZoneVolumeMapper.java b/war/src/main/java/com/tommytony/war/mappers/ZoneVolumeMapper.java index 57054f0..eb30ab0 100644 --- a/war/src/main/java/com/tommytony/war/mappers/ZoneVolumeMapper.java +++ b/war/src/main/java/com/tommytony/war/mappers/ZoneVolumeMapper.java @@ -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); } } } diff --git a/war/src/main/java/com/tommytony/war/volumes/CenteredVolume.java b/war/src/main/java/com/tommytony/war/volumes/CenteredVolume.java index 322c41e..530f92f 100644 --- a/war/src/main/java/com/tommytony/war/volumes/CenteredVolume.java +++ b/war/src/main/java/com/tommytony/war/volumes/CenteredVolume.java @@ -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); diff --git a/war/src/main/java/com/tommytony/war/volumes/VerticalVolume.java b/war/src/main/java/com/tommytony/war/volumes/VerticalVolume.java index c030b8b..fad1a4d 100644 --- a/war/src/main/java/com/tommytony/war/volumes/VerticalVolume.java +++ b/war/src/main/java/com/tommytony/war/volumes/VerticalVolume.java @@ -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; } diff --git a/war/src/main/java/com/tommytony/war/volumes/Volume.java b/war/src/main/java/com/tommytony/war/volumes/Volume.java index abf6be6..246761b 100644 --- a/war/src/main/java/com/tommytony/war/volumes/Volume.java +++ b/war/src/main/java/com/tommytony/war/volumes/Volume.java @@ -36,11 +36,9 @@ public class Volume { private byte[][][] blockDatas = null; private HashMap signLines = new HashMap(); private HashMap> invBlockContents = new HashMap>(); - 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; } } diff --git a/war/src/main/java/com/tommytony/war/volumes/ZoneVolume.java b/war/src/main/java/com/tommytony/war/volumes/ZoneVolume.java index 05c4f8d..1013398 100644 --- a/war/src/main/java/com/tommytony/war/volumes/ZoneVolume.java +++ b/war/src/main/java/com/tommytony/war/volumes/ZoneVolume.java @@ -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; } diff --git a/war/src/test/java/com/tommytony/war/spec/volumes/ZoneVolumeSpecTest.java b/war/src/test/java/com/tommytony/war/spec/volumes/ZoneVolumeSpecTest.java index 552a077..1e356ef 100644 --- a/war/src/test/java/com/tommytony/war/spec/volumes/ZoneVolumeSpecTest.java +++ b/war/src/test/java/com/tommytony/war/spec/volumes/ZoneVolumeSpecTest.java @@ -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()); when(zoneMock.getMonuments()).thenReturn(new ArrayList()); - 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()); when(zoneMock.getMonuments()).thenReturn(new ArrayList()); - 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()); when(zoneMock.getMonuments()).thenReturn(new ArrayList()); - 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()); when(zoneMock.getMonuments()).thenReturn(new ArrayList()); - 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()); when(zoneMock.getMonuments()).thenReturn(new ArrayList()); - 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()); when(zoneMock.getMonuments()).thenReturn(new ArrayList()); - 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()); when(zoneMock.getMonuments()).thenReturn(new ArrayList()); - 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()); when(zoneMock.getMonuments()).thenReturn(new ArrayList()); - 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()); when(zoneMock.getMonuments()).thenReturn(new ArrayList()); - 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()); when(zoneMock.getMonuments()).thenReturn(new ArrayList()); - 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()); when(zoneMock.getMonuments()).thenReturn(new ArrayList()); - 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()); when(zoneMock.getMonuments()).thenReturn(new ArrayList()); - 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()); when(zoneMock.getMonuments()).thenReturn(new ArrayList()); - 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()); when(zoneMock.getMonuments()).thenReturn(new ArrayList()); - 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()); when(zoneMock.getMonuments()).thenReturn(new ArrayList()); - 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()); when(zoneMock.getMonuments()).thenReturn(new ArrayList()); - 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()); when(zoneMock.getMonuments()).thenReturn(new ArrayList()); - 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()); when(zoneMock.getMonuments()).thenReturn(new ArrayList()); - 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()); when(zoneMock.getMonuments()).thenReturn(new ArrayList()); - 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()); when(zoneMock.getMonuments()).thenReturn(new ArrayList()); - 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()); when(zoneMock.getMonuments()).thenReturn(new ArrayList()); - 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()); when(zoneMock.getMonuments()).thenReturn(new ArrayList()); - 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