From 567718662aab5f804155290ba49ec0addb2e6671 Mon Sep 17 00:00:00 2001 From: taoneill Date: Sat, 15 Jan 2011 23:22:55 -0500 Subject: [PATCH] Added zone maker exceptions. Got to nail down the spammy death problem. --- .../tommytony/war/WarPlayerListener.java | 65 +++++++++++++------ .../main/java/com/tommytony/war/Warzone.java | 64 +++++++++++------- 2 files changed, 85 insertions(+), 44 deletions(-) diff --git a/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java b/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java index 5b35451..2d0ec17 100644 --- a/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java +++ b/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java @@ -275,23 +275,34 @@ public class WarPlayerListener extends PlayerListener { } else { // change existing warzone if(arguments[1].equals("northwest") || arguments[1].equals("nw")) { - int reset = warzone.getVolume().resetBlocks(); - warzone.setNorthwest(player.getLocation()); - warzone.saveState(); - warzone.initializeZone(); - message += "Northwesternmost point set at x=" + (int)warzone.getNorthwest().getBlockX() - + " z=" + (int)warzone.getNorthwest().getBlockZ() + " on warzone " + warzone.getName() + ". " + - reset + " blocks reset. Zone saved."; - + if(warzone.getSoutheast() != null + && (player.getLocation().getBlockX() >= warzone.getSoutheast().getBlockX() + || player.getLocation().getBlockZ() <= warzone.getSoutheast().getBlockZ())) { + player.sendMessage(war.str("You must place that corner northwest relative to the existing southeast corner!")); + } else { + int reset = warzone.getVolume().resetBlocks(); + warzone.setNorthwest(player.getLocation()); + warzone.saveState(); + warzone.initializeZone(); + message += "Northwesternmost point set at x=" + (int)warzone.getNorthwest().getBlockX() + + " z=" + (int)warzone.getNorthwest().getBlockZ() + " on warzone " + warzone.getName() + ". " + + reset + " blocks reset. Zone saved."; + } } else { - int reset = warzone.getVolume().resetBlocks(); - warzone.setSoutheast(player.getLocation()); - warzone.saveState(); - warzone.initializeZone(); - - message += "Southeasternmost point set at x=" + (int)warzone.getSoutheast().getBlockX() - + " z=" + (int)warzone.getSoutheast().getBlockZ() + " on warzone " + warzone.getName() + ". " + - reset + " blocks reset. Zone saved."; + if(warzone.getNorthwest() != null + && (player.getLocation().getBlockX() <= warzone.getNorthwest().getBlockX() + || player.getLocation().getBlockZ() >= warzone.getNorthwest().getBlockZ())) { + player.sendMessage(war.str("You must place that corner southeast relative to the existing northwest corner!")); + } else { + int reset = warzone.getVolume().resetBlocks(); + warzone.setSoutheast(player.getLocation()); + warzone.saveState(); + warzone.initializeZone(); + + message += "Southeasternmost point set at x=" + (int)warzone.getSoutheast().getBlockX() + + " z=" + (int)warzone.getSoutheast().getBlockZ() + " on warzone " + warzone.getName() + ". " + + reset + " blocks reset. Zone saved."; + } } WarzoneMapper.save(war, warzone, true); } @@ -604,8 +615,8 @@ public class WarPlayerListener extends PlayerListener { if(playerWarzone != null) { Team team = war.getPlayerTeam(player.getName()); - // Player belongs to a warzone team but is outside: he just died! Handle death! - if(to != null && war.warzone(player.getLocation()) == null && team != null) { + // Player belongs to a warzone team but is outside: he just died! Handle death! Exempt the zone maker. + if(from != null && war.warzone(player.getLocation()) == null && team != null && !war.isZoneMaker(player.getName())) { // teleport to team spawn upon death boolean roundOver = false; @@ -623,7 +634,6 @@ public class WarPlayerListener extends PlayerListener { t.resetSign(); } } - playerWarzone.endRound(); playerWarzone.getVolume().resetBlocks(); playerWarzone.initializeZone(); roundOver = true; @@ -651,7 +661,7 @@ public class WarPlayerListener extends PlayerListener { player.setHealth(20); player.sendMessage(war.str("Your dance pleases the monument's voodoo. You gain full health!")); } - } else if (war.inAnyWarzone(player.getLocation())) { // player is not in any team, but inside warzone boundaries, get him out + } else if (war.inAnyWarzone(player.getLocation()) && !war.isZoneMaker(player.getName())) { // player is not in any team, but inside warzone boundaries, get him out Warzone zone = war.warzone(player.getLocation()); event.setTo(zone.getTeleport()); player.sendMessage(war.str("You can't be inside a warzone without a team.")); @@ -667,7 +677,7 @@ public class WarPlayerListener extends PlayerListener { if(zone.getLobby().isAutoAssignGate(to)) { dropFromOldTeamIfAny(player); zone.autoAssign(event, player); - } else if (zone.getLobby().isInTeamGate(TeamMaterials.TEAMDIAMOND, from)){ + } else if (zone.getLobby().isInTeamGate(TeamMaterials.TEAMDIAMOND, to)){ dropFromOldTeamIfAny(player); Team diamondTeam = zone.getTeamByMaterial(TeamMaterials.TEAMDIAMOND); diamondTeam.addPlayer(player); @@ -702,6 +712,19 @@ public class WarPlayerListener extends PlayerListener { event.setTo(to); player.teleportTo(war.getWarHub().getLocation()); } + } else if(war.inAnyWarzone(event.getFrom())) { // already in a team and in warzone, leaving + if(zone.getLobby().isAutoAssignGate(to) + || zone.getLobby().isInTeamGate(TeamMaterials.TEAMDIAMOND, to) + || zone.getLobby().isInTeamGate(TeamMaterials.TEAMIRON, to) + || zone.getLobby().isInTeamGate(TeamMaterials.TEAMGOLD, to)) { + // same as leave, except event.setTo + Team playerTeam = war.getPlayerTeam(player.getName()); + playerTeam.removePlayer(player.getName()); + event.setTo(playerWarzone.getTeleport()); + player.sendMessage(war.str("Left the zone.")); + playerWarzone.restorePlayerInventory(player); + player.sendMessage(war.str("Your inventory has (hopefully) been restored.")); + } } } } diff --git a/war/src/main/java/com/tommytony/war/Warzone.java b/war/src/main/java/com/tommytony/war/Warzone.java index 5cc85bb..7b91df4 100644 --- a/war/src/main/java/com/tommytony/war/Warzone.java +++ b/war/src/main/java/com/tommytony/war/Warzone.java @@ -206,15 +206,6 @@ public class Warzone { */ public void initializeZone() { if(ready() && volume.isSaved()){ - - // add wall outlines - if(drawZoneOutline) { - addZoneOutline(BlockFace.North); - addZoneOutline(BlockFace.East); - addZoneOutline(BlockFace.South); - addZoneOutline(BlockFace.West); - } - // everyone back to team spawn with full health for(Team team : teams) { for(Player player : team.getPlayers()) { @@ -225,21 +216,48 @@ public class Warzone { team.resetSign(); } - // reset monuments - for(Monument monument : monuments) { - monument.getVolume().resetBlocks(); - monument.addMonumentBlocks(); - } - - // reset lobby - if(lobby != null) { - lobby.initialize(); - } - - this.setNorthwest(this.getNorthwest()); - this.setSoutheast(this.getSoutheast()); + initZone(); } } + + public void initializeZone(PlayerMoveEvent event) { + if(ready() && volume.isSaved()){ + // everyone back to team spawn with full health + for(Team team : teams) { + for(Player player : team.getPlayers()) { + if(player.getName().equals(event.getPlayer().getName())) respawnPlayer(event, team, player); + respawnPlayer(team, player); + } + team.setRemainingTickets(lifePool); + team.setTeamSpawn(team.getTeamSpawn()); + team.resetSign(); + } + } + } + + private void initZone() { + // add wall outlines + if(drawZoneOutline) { + addZoneOutline(BlockFace.North); + addZoneOutline(BlockFace.East); + addZoneOutline(BlockFace.South); + addZoneOutline(BlockFace.West); + } + + // reset monuments + for(Monument monument : monuments) { + monument.getVolume().resetBlocks(); + monument.addMonumentBlocks(); + } + + // reset lobby + if(lobby != null) { + lobby.initialize(); + } + + this.setNorthwest(this.getNorthwest()); + this.setSoutheast(this.getSoutheast()); + } private void addZoneOutline(BlockFace wall) { int c1maxY = world.getHighestBlockYAt(volume.getMinX(), volume.getMinZ()); @@ -350,7 +368,7 @@ public class Warzone { playerInv.setHelmet(new ItemStack(Material.IRON_BOOTS)); } - player.setHealth(20); + //player.setHealth(20); }