From 06653e6633c797a81bb377d49748d2cd85333365 Mon Sep 17 00:00:00 2001 From: taoneill Date: Sun, 3 Jul 2011 16:42:18 -0400 Subject: [PATCH] Closes gh-227. Emtpy chests and dispenser don't crash teh zone reset (or the server) anymore. Sorry. --- .../tommytony/war/WarEntityListener.java | 3 +- war/src/main/java/com/tommytony/war/Team.java | 1 - .../main/java/com/tommytony/war/Warzone.java | 3 ++ .../war/jobs/RestoreWarzonesJob.java | 2 +- .../tommytony/war/mappers/WarzoneMapper.java | 3 +- .../war/mappers/ZoneVolumeMapper.java | 40 ++++++++++--------- war/src/main/java/plugin.yml | 2 +- war/target/classes/plugin.yml | 2 +- 8 files changed, 30 insertions(+), 26 deletions(-) diff --git a/war/src/main/java/bukkit/tommytony/war/WarEntityListener.java b/war/src/main/java/bukkit/tommytony/war/WarEntityListener.java index 783b3e4..db4269a 100644 --- a/war/src/main/java/bukkit/tommytony/war/WarEntityListener.java +++ b/war/src/main/java/bukkit/tommytony/war/WarEntityListener.java @@ -16,6 +16,7 @@ import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityListener; import org.bukkit.event.entity.EntityRegainHealthEvent; +import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason; //import org.bukkit.event.entity.EntityRegainHealthEvent; import com.tommytony.war.Team; @@ -213,7 +214,7 @@ public class WarEntityListener extends EntityListener { } public void onEntityRegainHealth(EntityRegainHealthEvent event) { - if(war.isLoaded()) { + if(war.isLoaded() && event.getRegainReason() == RegainReason.REGEN) { Entity entity = event.getEntity(); if(entity instanceof Player) { Player player = (Player) entity; diff --git a/war/src/main/java/com/tommytony/war/Team.java b/war/src/main/java/com/tommytony/war/Team.java index a127af8..1e6deec 100644 --- a/war/src/main/java/com/tommytony/war/Team.java +++ b/war/src/main/java/com/tommytony/war/Team.java @@ -75,7 +75,6 @@ public class Team { int y = teamSpawn.getBlockY(); int z = teamSpawn.getBlockZ(); - if(warzone.getSpawnStyle().equals(TeamSpawnStyles.INVISIBLE)) { // nothing but glowstone warzone.getWorld().getBlockAt(x, y-1, z).setType(Material.GLOWSTONE); diff --git a/war/src/main/java/com/tommytony/war/Warzone.java b/war/src/main/java/com/tommytony/war/Warzone.java index d13d9a2..445de8f 100644 --- a/war/src/main/java/com/tommytony/war/Warzone.java +++ b/war/src/main/java/com/tommytony/war/Warzone.java @@ -321,6 +321,9 @@ public class Warzone { public void setLifePool(int lifePool) { this.lifePool = lifePool; + for(Team team : teams) { + team.setRemainingLives(lifePool); + } } public int getLifePool() { 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 5602f76..64eed13 100644 --- a/war/src/main/java/com/tommytony/war/jobs/RestoreWarzonesJob.java +++ b/war/src/main/java/com/tommytony/war/jobs/RestoreWarzonesJob.java @@ -23,7 +23,7 @@ public class RestoreWarzonesJob implements Runnable { for(String warzoneName : warzoneSplit) { if(warzoneName != null && !warzoneName.equals("")){ war.logInfo("Restoring zone " + warzoneName + "..."); - Warzone zone = WarzoneMapper.load(war, warzoneName, !newWarInstall); // cascade load, only load blocks if warzone exists + Warzone zone = WarzoneMapper.load(war, warzoneName, !newWarInstall); if(zone != null) { // could have failed, would've been logged already war.getWarzones().add(zone); //zone.getVolume().loadCorners(); 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 6fdd037..315064a 100644 --- a/war/src/main/java/com/tommytony/war/mappers/WarzoneMapper.java +++ b/war/src/main/java/com/tommytony/war/mappers/WarzoneMapper.java @@ -47,7 +47,6 @@ public class WarzoneMapper { world = war.getServer().getWorld(worldStr); } - if(world == null) { war.logWarn("Failed to restore warzone " + name + ". The specified world (name: " + worldStr + ") does not exist!"); } else { @@ -144,7 +143,7 @@ public class WarzoneMapper { } } - // life pool + // life pool (always set after teams, so the teams' remaining lives get initialized properly by this setter) warzone.setLifePool(warzoneConfig.getInt("lifePool")); // monument heal //SY 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 a14af8a..61e4f75 100644 --- a/war/src/main/java/com/tommytony/war/mappers/ZoneVolumeMapper.java +++ b/war/src/main/java/com/tommytony/war/mappers/ZoneVolumeMapper.java @@ -271,25 +271,27 @@ public class ZoneVolumeMapper { private static List readInventoryString(String invString) { List items = new ArrayList(); - String[] itemsStrSplit = invString.split(";;"); - for(String itemStr : itemsStrSplit) { - String[] itemStrSplit = itemStr.split(";"); - if(itemStrSplit.length == 4) { - ItemStack stack = new ItemStack(Integer.parseInt(itemStrSplit[0]), - Integer.parseInt(itemStrSplit[1])); - stack.setData(new MaterialData(stack.getTypeId(),Byte.parseByte(itemStrSplit[3]))); - short durability = (short)Integer.parseInt(itemStrSplit[2]); - stack.setDurability(durability); - items.add(stack); - } else if(itemStrSplit.length == 3) { - ItemStack stack = new ItemStack(Integer.parseInt(itemStrSplit[0]), - Integer.parseInt(itemStrSplit[1])); - short durability = (short)Integer.parseInt(itemStrSplit[2]); - stack.setDurability(durability); - items.add(stack); - } else { - items.add(new ItemStack(Integer.parseInt(itemStrSplit[0]), - Integer.parseInt(itemStrSplit[1]))); + if(invString != null && !invString.equals("")) { + String[] itemsStrSplit = invString.split(";;"); + for(String itemStr : itemsStrSplit) { + String[] itemStrSplit = itemStr.split(";"); + if(itemStrSplit.length == 4) { + ItemStack stack = new ItemStack(Integer.parseInt(itemStrSplit[0]), + Integer.parseInt(itemStrSplit[1])); + stack.setData(new MaterialData(stack.getTypeId(),Byte.parseByte(itemStrSplit[3]))); + short durability = (short)Integer.parseInt(itemStrSplit[2]); + stack.setDurability(durability); + items.add(stack); + } else if(itemStrSplit.length == 3) { + ItemStack stack = new ItemStack(Integer.parseInt(itemStrSplit[0]), + Integer.parseInt(itemStrSplit[1])); + short durability = (short)Integer.parseInt(itemStrSplit[2]); + stack.setDurability(durability); + items.add(stack); + } else { + items.add(new ItemStack(Integer.parseInt(itemStrSplit[0]), + Integer.parseInt(itemStrSplit[1]))); + } } } return items; diff --git a/war/src/main/java/plugin.yml b/war/src/main/java/plugin.yml index 97ed05e..c3b81ce 100644 --- a/war/src/main/java/plugin.yml +++ b/war/src/main/java/plugin.yml @@ -1,5 +1,5 @@ name: War -version: 1.6 (de Gaulle) +version: 1.6 (de Gaulle) PREVIEW 2 description: Lets you create TDM and CTF (warzones) for a more structured PVP experience. author: tommytony website: war.tommytony.com diff --git a/war/target/classes/plugin.yml b/war/target/classes/plugin.yml index 97ed05e..c3b81ce 100644 --- a/war/target/classes/plugin.yml +++ b/war/target/classes/plugin.yml @@ -1,5 +1,5 @@ name: War -version: 1.6 (de Gaulle) +version: 1.6 (de Gaulle) PREVIEW 2 description: Lets you create TDM and CTF (warzones) for a more structured PVP experience. author: tommytony website: war.tommytony.com