ZoneLobby locLobby = ZoneLobby.getLobbyByLocation(playerLoc);
boolean isMaker = War.war.isZoneMaker(player);
// Zone walls
Team currentTeam = Team.getTeamByPlayerName(player.getName());
Warzone playerWarzone = Warzone.getZoneByPlayerName(player.getName()); // this uses the teams, so it asks: get the player's team's warzone
boolean protecting = false;
if (currentTeam != null) {
if (playerWarzone.getWarzoneConfig().getBoolean(WarzoneConfig.GLASSWALLS)) {
protecting = playerWarzone.protectZoneWallAgainstPlayer(player);
}
} else {
Warzone nearbyZone = War.war.zoneOfZoneWallAtProximity(playerLoc);
if (nearbyZone != null && nearbyZone.getWarzoneConfig().getBoolean(WarzoneConfig.GLASSWALLS) && !isMaker) {
protecting = nearbyZone.protectZoneWallAgainstPlayer(player);
}
}
if (!protecting) {
// zone makers still need to delete their walls
// make sure to delete any wall guards as you leave
for (Warzone zone : War.war.getWarzones()) {
zone.dropZoneWallGuardIfAny(player);
}
}
// Warzone lobby gates
if (locLobby != null && currentTeam == null && locLobby.isInAnyGate(playerLoc)) {
Warzone zone = locLobby.getZone();
Team locTeamGate = locLobby.getTeamGate(playerLoc);
if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.DISABLED) || zone.isReinitializing()) {
War.war.badMsg(player, "join.disabled");
event.setTo(zone.getTeleport());
} else if (!zone.getWarzoneConfig().getBoolean(WarzoneConfig.JOINMIDBATTLE) && zone.isEnoughPlayers()) {
War.war.badMsg(player, "join.progress");
event.setTo(zone.getTeleport());
} else if (zone.isFull()) {
War.war.badMsg(player, "join.full.all");
event.setTo(zone.getTeleport());
} else if (zone.isFull(player)) {
War.war.badMsg(player, "join.permission.all");
event.setTo(zone.getTeleport());
} else if (locTeamGate != null && locTeamGate.isFull()) {
War.war.badMsg(player, "join.full.single", locTeamGate.getName());
event.setTo(zone.getTeleport());
} else if (locTeamGate != null && !War.war.canPlayWar(player, locTeamGate)) {
War.war.badMsg(player, "join.permission.single", locTeamGate.getName());
event.setTo(zone.getTeleport());
} else if (zone.getLobby().isAutoAssignGate(playerLoc)) {
zone.autoAssign(player);
} else if (locTeamGate != null) {
zone.assign(player, locTeamGate);
}
return;
} else if (locLobby != null && currentTeam == null
&& locLobby.isInWarHubLinkGate(playerLoc)
&& War.war.getWarHub() != null) {
War.war.msg(player, "warhub.teleport");
event.setTo(War.war.getWarHub().getLocation());
return;
}
// Warhub zone gates
WarHub hub = War.war.getWarHub();
if (hub != null && hub.getVolume().contains(player.getLocation())) {
Warzone zone = hub.getDestinationWarzoneForLocation(playerLoc);
if (zone != null && zone.getTeleport() != null) {
if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.AUTOJOIN)
&& zone.getTeams().size() >= 1 && currentTeam == null) {
if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.DISABLED) || zone.isReinitializing()) {
War.war.badMsg(player, "join.disabled");
event.setTo(hub.getLocation());
} else if (!zone.getWarzoneConfig().getBoolean(WarzoneConfig.JOINMIDBATTLE) && zone.isEnoughPlayers()) {
War.war.badMsg(player, "join.progress");
event.setTo(hub.getLocation());
} else if (zone.isFull()) {
War.war.badMsg(player, "join.full.all");
event.setTo(hub.getLocation());
} else if (zone.isFull(player)) {
War.war.badMsg(player, "join.permission.all");
event.setTo(hub.getLocation());
} else {
zone.autoAssign(player);
}
return;
}
event.setTo(zone.getTeleport());
War.war.msg(player, "zone.teleport", zone.getName());
return;
}
}
boolean isLeaving = playerWarzone != null && playerWarzone.getLobby().isLeavingZone(playerLoc);
Team playerTeam = Team.getTeamByPlayerName(player.getName());
if (isLeaving) { // already in a team and in warzone, leaving
// same as leave
if (playerTeam != null) {
boolean atSpawnAlready = playerTeam.isSpawnLocation(playerLoc);
if (!atSpawnAlready) {
playerWarzone.handlePlayerLeave(player, playerWarzone.getWarzoneConfig().getBoolean(WarzoneConfig.AUTOJOIN) ?
War.war.getWarHub().getLocation() : playerWarzone.getTeleport(), event, true);
return;
}
return;
}
}
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) {
List<BlockFace> nearestWalls = playerWarzone.getNearestWalls(playerLoc);
if (!playerWarzone.getWarzoneConfig().getBoolean(WarzoneConfig.REALDEATHS)) {
War.war.badMsg(player, "zone.leavenotice");
}
if(nearestWalls != null && nearestWalls.size() > 0) {
// First, try to bump the player back in
int northSouthMove = 0;
int eastWestMove = 0;
int upDownMove = 0;
int moveDistance = 1;
if (nearestWalls.contains(Direction.NORTH())) {
// move south
northSouthMove += moveDistance;
} else if (nearestWalls.contains(Direction.SOUTH())) {
// move north
northSouthMove -= moveDistance;
}
if (nearestWalls.contains(Direction.EAST())) {
// move west
eastWestMove += moveDistance;
} else if (nearestWalls.contains(Direction.WEST())) {
// move east
eastWestMove -= moveDistance;
}
if (nearestWalls.contains(BlockFace.UP)) {
upDownMove -= moveDistance;
} else if (nearestWalls.contains(BlockFace.DOWN)) {
// fell off the map, back to spawn (still need to drop objects)
playerWarzone.dropAllStolenObjects(event.getPlayer(), false);
playerWarzone.respawnPlayer(event, playerTeam, event.getPlayer());
return;
}
event.setTo(new Location(playerLoc.getWorld(),
playerLoc.getX() + northSouthMove,
playerLoc.getY() + upDownMove,
playerLoc.getZ() + eastWestMove,
playerLoc.getYaw(),
playerLoc.getPitch()));
return;
// Otherwise, send him to spawn (first make sure he drops his flag/cake/bomb to prevent auto-cap and as punishment)
} else {
playerWarzone.dropAllStolenObjects(event.getPlayer(), false);
playerWarzone.respawnPlayer(event, playerTeam, event.getPlayer());
return;
}
}
LoadoutSelection loadoutSelectionState = playerWarzone.getLoadoutSelections().get(player.getName());
FlagReturn flagReturn = playerTeam.getTeamConfig().resolveFlagReturn();
if (!playerTeam.isSpawnLocation(playerLoc)) {
if (!playerWarzone.isEnoughPlayers() && loadoutSelectionState != null && loadoutSelectionState.isStillInSpawn()) {
// Be sure to keep only players that just respawned locked inside the spawn for minplayer/minteams restrictions - otherwise
// this will conflict with the can't-renter-spawn bump just a few lines below
War.war.badMsg(player, "zone.spawn.minplayers", playerWarzone.getWarzoneConfig().getInt(WarzoneConfig.MINPLAYERS),
playerWarzone.getWarzoneConfig().getInt(WarzoneConfig.MINTEAMS));
event.setTo(playerTeam.getRandomSpawn());
return;
}
if (playerWarzone.isRespawning(player)) {
int rt = playerTeam.getTeamConfig().resolveInt(TeamConfig.RESPAWNTIMER);
War.war.badMsg(player, "zone.spawn.timer", rt);
event.setTo(playerTeam.getRandomSpawn());
return;
}
if (playerWarzone.isReinitializing()) {
// don't let players wander about outside spawns during reset
// (they could mess up the blocks that have already been reset
// before the start of the new battle)
War.war.msg(player, "zone.battle.reset");
event.setTo(playerTeam.getRandomSpawn());
return;
}
} else if (loadoutSelectionState != null && !loadoutSelectionState.isStillInSpawn()
&& !playerWarzone.isCakeThief(player.getName())
&& (flagReturn.equals(FlagReturn.BOTH) || flagReturn.equals(FlagReturn.SPAWN))
&& !playerWarzone.isFlagThief(player.getName())) {
// player is in spawn, but has left already: he should NOT be let back in - kick him out gently
// if he sticks around too long.
// (also, be sure you aren't preventing the flag or cake from being captured)
// if (!CantReEnterSpawnJob.getPlayersUnderSuspicion().contains(player.getName())) {
// CantReEnterSpawnJob job = new CantReEnterSpawnJob(player, playerTeam);
// War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, job, 12);
// }
return;
}
// Monuments
if (playerTeam != null && playerWarzone.nearAnyOwnedMonument(playerLoc, playerTeam) && player.getHealth() < 20 && player.getHealth() > 0 // don't heal the dead
&& this.random.nextInt(7) == 3) { // one chance out of many of getting healed
int currentHp = (int) player.getHealth();
int newHp = Math.min(20, currentHp + locZone.getWarzoneConfig().getInt(WarzoneConfig.MONUMENTHEAL));
player.setHealth(newHp);
double heartNum = ((double) newHp - currentHp) / 2;
War.war.msg(player, "zone.monument.voodoo", heartNum);
return;
}
// Flag capture
if (playerWarzone.isFlagThief(player.getName())) {
// smoky
if (System.currentTimeMillis() % 13 == 0) {
playerWarzone.getWorld().playEffect(player.getLocation(), Effect.POTION_BREAK, playerTeam.getKind().getPotionEffectColor());
}
// Make sure game ends can't occur simultaneously.
// See Warzone.handleDeath() for details.
boolean inSpawn = playerTeam.isSpawnLocation(player.getLocation());
boolean inFlag = (playerTeam.getFlagVolume() != null && playerTeam.getFlagVolume().contains(player.getLocation()));
if (playerTeam.getTeamConfig().resolveFlagReturn().equals(FlagReturn.BOTH)) {
if (!inSpawn && !inFlag) {
return;
}
} else if (playerTeam.getTeamConfig().resolveFlagReturn().equals(FlagReturn.SPAWN)) {
if (inFlag) {
War.war.badMsg(player, "zone.flagreturn.spawn");
return;
} else if (!inSpawn) {
return;
}
} else if (playerTeam.getTeamConfig().resolveFlagReturn().equals(FlagReturn.FLAG)) {
if (inSpawn) {
War.war.badMsg(player, "zone.flagreturn.flag");
return;
} else if (!inFlag) {
return;
}
}
if (!playerTeam.getPlayers().contains(player)) {
// Make sure player is still part of team, game may have ended while waiting)
// Ignore the scorers that happened immediately after the game end.
return;
}
if (playerWarzone.isTeamFlagStolen(playerTeam) && playerTeam.getTeamConfig().resolveBoolean(TeamConfig.FLAGMUSTBEHOME)) {
War.war.badMsg(player, "zone.flagreturn.deadlock");
} else {
// flags can be captured at own spawn or own flag pole
if (playerWarzone.isReinitializing()) {
// Battle already ended or interrupted
playerWarzone.respawnPlayer(event, playerTeam, player);
} else {
// All good - proceed with scoring
playerTeam.addPoint();
Team victim = playerWarzone.getVictimTeamForFlagThief(player.getName());
// Notify everyone
for (Team t : playerWarzone.getTeams()) {
if (War.war.isSpoutServer()) {
for (Player p : t.getPlayers()) {
SpoutPlayer sp = SpoutManager.getPlayer(p);
if (sp.isSpoutCraftEnabled()) {
sp.sendNotification(
SpoutDisplayer.cleanForNotification(playerTeam.getKind().getColor() + player.getName() + ChatColor.YELLOW + " captured"),
SpoutDisplayer.cleanForNotification(victim.getKind().getColor() + victim.getName() + ChatColor.YELLOW + " flag!"),
victim.getKind().getMaterial(),
victim.getKind().getData(),
10000);
}
}
}
t.teamcast("zone.flagcapture.broadcast", playerTeam.getKind().getColor() + player.getName() + ChatColor.WHITE,
victim.getName(), playerTeam.getName());
}
// Detect win conditions
if (playerTeam.getPoints() >= playerTeam.getTeamConfig().resolveInt(TeamConfig.MAXSCORE)) {
if (playerWarzone.hasPlayerState(player.getName())) {
playerWarzone.restorePlayerState(player);
}
playerWarzone.handleScoreCapReached(playerTeam.getName());
event.setTo(playerWarzone.getTeleport());
} else {
// just added a point
victim.getFlagVolume().resetBlocks(); // bring back flag to team that lost it
victim.initializeTeamFlag();
playerWarzone.respawnPlayer(event, playerTeam, player);
playerTeam.resetSign();
playerWarzone.getLobby().resetTeamGateSign(playerTeam);
}
}
playerWarzone.removeFlagThief(player.getName());
return;
}
}
// Bomb detonation
if (playerWarzone.isBombThief(player.getName())) {
// smoky
playerWarzone.getWorld().playEffect(player.getLocation(), Effect.SMOKE, 0);
// Make sure game ends can't occur simultaneously.
// Not thread safe. See Warzone.handleDeath() for details.
boolean inEnemySpawn = false;
Team victim = null;
for (Team team : playerWarzone.getTeams()) {
if (team != playerTeam
&& team.isSpawnLocation(player.getLocation())
&& team.getPlayers().size() > 0) {
inEnemySpawn = true;
victim = team;
break;
}
}
if (inEnemySpawn && playerTeam.getPlayers().contains(player)) {
// Made sure player is still part of team, game may have ended while waiting.
// Ignored the scorers that happened immediately after the game end.
Bomb bomb = playerWarzone.getBombForThief(player.getName());
// Boom!
if (!playerWarzone.getWarzoneConfig().getBoolean(WarzoneConfig.UNBREAKABLE)) {
// Don't blow up if warzone is unbreakable
playerWarzone.getWorld().createExplosion(player.getLocation(), 2F);
}
if (playerWarzone.isReinitializing()) {
// Battle already ended or interrupted
playerWarzone.respawnPlayer(event, playerTeam, player);
} else {
// All good - proceed with scoring
playerTeam.addPoint();
// Notify everyone
for (Team t : playerWarzone.getTeams()) {
if (War.war.isSpoutServer()) {
for (Player p : t.getPlayers()) {
SpoutPlayer sp = SpoutManager.getPlayer(p);
if (sp.isSpoutCraftEnabled()) {
sp.sendNotification(
SpoutDisplayer.cleanForNotification(playerTeam.getKind().getColor() + player.getName() + ChatColor.YELLOW + " blew up "),
SpoutDisplayer.cleanForNotification(victim.getKind().getColor() + victim.getName() + ChatColor.YELLOW + "'s spawn!"),
victim.getKind().getMaterial(),
victim.getKind().getData(),
10000);
}
}
}
t.teamcast("zone.bomb.broadcast", playerTeam.getKind().getColor() + player.getName() + ChatColor.WHITE,
victim.getName(), playerTeam.getName());
}
// Detect win conditions
if (playerTeam.getPoints() >= playerTeam.getTeamConfig().resolveInt(TeamConfig.MAXSCORE)) {
if (playerWarzone.hasPlayerState(player.getName())) {
playerWarzone.restorePlayerState(player);
}
playerWarzone.handleScoreCapReached(playerTeam.getName());
event.setTo(playerWarzone.getTeleport());
} else {
// just added a point
// restore bombed team's spawn
for (Volume spawnVolume : victim.getSpawnVolumes().values()) {
spawnVolume.resetBlocks();
}
victim.initializeTeamSpawns();
// bring back tnt
bomb.getVolume().resetBlocks();
bomb.addBombBlocks();