From 1b9f06e3ca22565ae0f87d78bd1683255f2c968a Mon Sep 17 00:00:00 2001 From: taoneill Date: Tue, 6 Dec 2011 20:58:33 -0500 Subject: [PATCH] Closes gh-300. Closes gh-314. Fixed NPE in explosion handling. Lobby doesn't flash at game end anymore (no more dropping to the ground). Meddled with monument healing - it's still wonky although at least it wont give max hp all the time anymore. Added error handling of bad team name. --- .../tommytony/war/WarEntityListener.java | 4 +-- .../tommytony/war/WarPlayerListener.java | 2 +- .../tommytony/war/command/SetTeamCommand.java | 33 +++++++++++-------- .../war/command/SetZoneLobbyCommand.java | 2 +- .../main/java/com/tommytony/war/Warzone.java | 5 +-- 5 files changed, 24 insertions(+), 22 deletions(-) diff --git a/war/src/main/java/bukkit/tommytony/war/WarEntityListener.java b/war/src/main/java/bukkit/tommytony/war/WarEntityListener.java index 4233996..1ff745a 100644 --- a/war/src/main/java/bukkit/tommytony/war/WarEntityListener.java +++ b/war/src/main/java/bukkit/tommytony/war/WarEntityListener.java @@ -193,11 +193,11 @@ public class WarEntityListener extends EntityListener { if (!War.war.isLoaded()) { return; } - // protect zones elements, lobbies and warhub from creepers + // protect zones elements, lobbies and warhub from creepers and tnt List explodedBlocks = event.blockList(); List dontExplode = new ArrayList(); - boolean explosionInAWarzone = Warzone.getZoneByLocation(event.getEntity().getLocation()) != null; + boolean explosionInAWarzone = event.getEntity() != null && Warzone.getZoneByLocation(event.getEntity().getLocation()) != null; if (!explosionInAWarzone && War.war.isTntInZonesOnly() && event.getEntity() instanceof TNTPrimed) { // if tntinzonesonly:true, no tnt blows up outside zones diff --git a/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java b/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java index ba2e5de..209b32a 100644 --- a/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java +++ b/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java @@ -439,7 +439,7 @@ public class WarPlayerListener extends PlayerListener { 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 = player.getHealth(); - int newHp = Math.max(20, currentHp + locZone.getMonumentHeal()); + int newHp = Math.min(20, currentHp + locZone.getMonumentHeal()); player.setHealth(newHp); String isS = "s"; diff --git a/war/src/main/java/bukkit/tommytony/war/command/SetTeamCommand.java b/war/src/main/java/bukkit/tommytony/war/command/SetTeamCommand.java index 73661e1..328d847 100644 --- a/war/src/main/java/bukkit/tommytony/war/command/SetTeamCommand.java +++ b/war/src/main/java/bukkit/tommytony/war/command/SetTeamCommand.java @@ -41,22 +41,27 @@ public class SetTeamCommand extends AbstractZoneMakerCommand { } TeamKind teamKind = TeamKind.teamKindFromString(this.args[0]); - Team existingTeam = zone.getTeamByKind(teamKind); - if (existingTeam != null) { - // relocate - existingTeam.setTeamSpawn(player.getLocation()); - this.msg("Team " + existingTeam.getName() + " spawn relocated."); + + if (teamKind == null) { + return false; } else { - // new team (use default TeamKind name for now) - Team newTeam = new Team(teamKind.toString(), teamKind, player.getLocation(), zone); - newTeam.setRemainingLives(zone.getLifePool()); - zone.getTeams().add(newTeam); - if (zone.getLobby() != null) { - zone.getLobby().getVolume().resetBlocks(); - zone.getLobby().initialize(); + Team existingTeam = zone.getTeamByKind(teamKind); + if (existingTeam != null) { + // relocate + existingTeam.setTeamSpawn(player.getLocation()); + this.msg("Team " + existingTeam.getName() + " spawn relocated."); + } else { + // new team (use default TeamKind name for now) + Team newTeam = new Team(teamKind.toString(), teamKind, player.getLocation(), zone); + newTeam.setRemainingLives(zone.getLifePool()); + zone.getTeams().add(newTeam); + if (zone.getLobby() != null) { + zone.getLobby().getVolume().resetBlocks(); + zone.getLobby().initialize(); + } + newTeam.setTeamSpawn(player.getLocation()); + this.msg("Team " + newTeam.getName() + " created with spawn here."); } - newTeam.setTeamSpawn(player.getLocation()); - this.msg("Team " + newTeam.getName() + " created with spawn here."); } WarzoneMapper.save(zone, false); diff --git a/war/src/main/java/bukkit/tommytony/war/command/SetZoneLobbyCommand.java b/war/src/main/java/bukkit/tommytony/war/command/SetZoneLobbyCommand.java index dec7faf..68f0c0e 100644 --- a/war/src/main/java/bukkit/tommytony/war/command/SetZoneLobbyCommand.java +++ b/war/src/main/java/bukkit/tommytony/war/command/SetZoneLobbyCommand.java @@ -45,7 +45,7 @@ public class SetZoneLobbyCommand extends AbstractZoneMakerCommand { Warzone givenWarzone = Warzone.getZoneByName(this.args[0]); if (givenWarzone == null) { return false; - } else if (!this.isSenderAuthorOfZone(zone)) { + } else if (!this.isSenderAuthorOfZone(givenWarzone)) { return true; } else { // Move the warzone lobby diff --git a/war/src/main/java/com/tommytony/war/Warzone.java b/war/src/main/java/com/tommytony/war/Warzone.java index f0e7455..1ebfbc6 100644 --- a/war/src/main/java/com/tommytony/war/Warzone.java +++ b/war/src/main/java/com/tommytony/war/Warzone.java @@ -991,13 +991,10 @@ public class Warzone { // Score cap reached. Reset everything. ScoreCapReachedJob job = new ScoreCapReachedJob(this, winnersStr); War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, job); - if (this.getLobby() != null) { - this.getLobby().getVolume().resetBlocksAsJob(); - } this.getVolume().resetBlocksAsJob(); this.initializeZoneAsJob(player); if (War.war.getWarHub() != null) { - // TODO: test if warhub sign give the correct info despite the jobs + // TODO: test if warhub sign gives the correct info despite the jobs War.war.getWarHub().resetZoneSign(this); } }