From aba1e25569edf00bc67cfd69e3b4904ffab811d4 Mon Sep 17 00:00:00 2001 From: taoneill Date: Fri, 25 Feb 2011 10:26:53 -0500 Subject: [PATCH] Can't get rid of block freeze bug. Going back to CB 432 (RB2) from CB 439 didnt help. Swallowing sign exceptions until I figure out how to do it properly. I need you guy's help to find a way to reproduc ethe block freeze bug. :( --- .../main/java/bukkit/tommytony/war/War.java | 2 +- .../tommytony/war/WarEntityListener.java | 2 +- .../tommytony/war/WarPlayerListener.java | 4 +- war/src/main/java/com/tommytony/war/Team.java | 23 ++---- .../main/java/com/tommytony/war/WarHub.java | 44 ++++------- .../main/java/com/tommytony/war/Warzone.java | 2 + .../java/com/tommytony/war/ZoneLobby.java | 74 +++++++------------ .../war/{ => jobs}/LootDropperTask.java | 2 +- .../war/{ => jobs}/ResetCursorJob.java | 2 +- .../RestoreDeadmanInventoryJob.java | 4 +- .../war/{ => jobs}/ScoreCapReachedJob.java | 4 +- .../war/{ => utils}/ChatFixUtil.java | 2 +- .../war/{ => utils}/InventoryStash.java | 2 +- .../com/tommytony/war/utils/SignHelper.java | 34 +++++++++ 14 files changed, 97 insertions(+), 104 deletions(-) rename war/src/main/java/com/tommytony/war/{ => jobs}/LootDropperTask.java (93%) rename war/src/main/java/com/tommytony/war/{ => jobs}/ResetCursorJob.java (96%) rename war/src/main/java/com/tommytony/war/{ => jobs}/RestoreDeadmanInventoryJob.java (85%) rename war/src/main/java/com/tommytony/war/{ => jobs}/ScoreCapReachedJob.java (92%) rename war/src/main/java/com/tommytony/war/{ => utils}/ChatFixUtil.java (99%) rename war/src/main/java/com/tommytony/war/{ => utils}/InventoryStash.java (97%) create mode 100644 war/src/main/java/com/tommytony/war/utils/SignHelper.java diff --git a/war/src/main/java/bukkit/tommytony/war/War.java b/war/src/main/java/bukkit/tommytony/war/War.java index b710fec..801186c 100644 --- a/war/src/main/java/bukkit/tommytony/war/War.java +++ b/war/src/main/java/bukkit/tommytony/war/War.java @@ -27,7 +27,6 @@ import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; import com.nijikokun.bukkit.Permissions.Permissions; -import com.tommytony.war.ChatFixUtil; import com.tommytony.war.Monument; import com.tommytony.war.Team; import com.tommytony.war.TeamChatColors; @@ -39,6 +38,7 @@ import com.tommytony.war.ZoneLobby; import com.tommytony.war.mappers.VolumeMapper; import com.tommytony.war.mappers.WarMapper; import com.tommytony.war.mappers.WarzoneMapper; +import com.tommytony.war.utils.ChatFixUtil; /** * diff --git a/war/src/main/java/bukkit/tommytony/war/WarEntityListener.java b/war/src/main/java/bukkit/tommytony/war/WarEntityListener.java index 146cf03..12360a2 100644 --- a/war/src/main/java/bukkit/tommytony/war/WarEntityListener.java +++ b/war/src/main/java/bukkit/tommytony/war/WarEntityListener.java @@ -19,9 +19,9 @@ import org.bukkit.event.entity.EntityListener; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.player.PlayerMoveEvent; -import com.tommytony.war.LootDropperTask; import com.tommytony.war.Team; import com.tommytony.war.Warzone; +import com.tommytony.war.jobs.LootDropperTask; /** * diff --git a/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java b/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java index b529992..60583b3 100644 --- a/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java +++ b/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java @@ -18,13 +18,13 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; -import com.tommytony.war.InventoryStash; -import com.tommytony.war.RestoreDeadmanInventoryJob; import com.tommytony.war.Team; import com.tommytony.war.TeamMaterials; import com.tommytony.war.WarHub; import com.tommytony.war.Warzone; import com.tommytony.war.ZoneLobby; +import com.tommytony.war.jobs.RestoreDeadmanInventoryJob; +import com.tommytony.war.utils.InventoryStash; /** diff --git a/war/src/main/java/com/tommytony/war/Team.java b/war/src/main/java/com/tommytony/war/Team.java index bee60dc..4cd5fe9 100644 --- a/war/src/main/java/com/tommytony/war/Team.java +++ b/war/src/main/java/com/tommytony/war/Team.java @@ -14,6 +14,7 @@ import org.bukkit.material.MaterialData; import bukkit.tommytony.war.War; +import com.tommytony.war.utils.SignHelper; import com.tommytony.war.volumes.Volume; /** @@ -275,22 +276,12 @@ public class Team { // signBlock.setType(Material.SIGN_POST); // } - - if(signBlock.getType() != Material.SIGN_POST) { - signBlock.setType(Material.SIGN_POST); - } - signBlock.setData((byte)signData); - BlockState state = signBlock.getState(); - if(state instanceof Sign) { - Sign sign = (Sign) state; - if(sign.getLines() != null) { - sign.setLine(0, "Team " + name); - sign.setLine(1, remainingLives + "/" + warzone.getLifePool() + " lives left"); - sign.setLine(2, points + "/" + warzone.getScoreCap() + " pts"); - sign.setLine(3, players.size() + "/" + warzone.getTeamCap() + " players"); - sign.update(true); - } - } + String[] lines = new String[4]; + lines[0] = "Team " + name; + lines[1] = remainingLives + "/" + warzone.getLifePool() + " lives left"; + lines[2] = points + "/" + warzone.getScoreCap() + " pts"; + lines[3] = players.size() + "/" + warzone.getTeamCap() + " players"; + SignHelper.setToSign(signBlock, (byte)signData, lines); } } diff --git a/war/src/main/java/com/tommytony/war/WarHub.java b/war/src/main/java/com/tommytony/war/WarHub.java index 831ac18..0c6df7b 100644 --- a/war/src/main/java/com/tommytony/war/WarHub.java +++ b/war/src/main/java/com/tommytony/war/WarHub.java @@ -15,6 +15,7 @@ import org.bukkit.material.MaterialData; import bukkit.tommytony.war.War; +import com.tommytony.war.utils.SignHelper; import com.tommytony.war.volumes.Volume; /** @@ -107,21 +108,12 @@ public class WarHub { // War hub sign Block signBlock = locationBlock.getFace(BlockFace.WEST); - if(signBlock.getType() != Material.SIGN_POST) { - signBlock.setType(Material.SIGN_POST); - } - signBlock.setData((byte)8); - BlockState state = signBlock.getState(); - if(state instanceof Sign) { - Sign sign = (Sign) state; - if(sign.getLines() != null) { - sign.setLine(0, "War hub"); - sign.setLine(1, ""); - sign.setLine(2, "Pick your battle!"); - sign.setLine(3, ""); - sign.update(true); - } - } + String[] lines = new String[4]; + lines[0] = "War hub"; + lines[1] = ""; + lines[2] = "Pick your battle!"; + lines[3] = ""; + SignHelper.setToSign(signBlock, (byte)8, lines); // Warzone signs for(Warzone zone : war.getWarzones()) { @@ -145,22 +137,12 @@ public class WarHub { zonePlayers += t.getPlayers().size(); zoneCap += zone.getTeamCap(); } - - if(block.getType() != Material.SIGN_POST) { - block.setType(Material.SIGN_POST); - } - block.setData((byte)8); - BlockState state = block.getState(); - if(state instanceof Sign) { - Sign sign = (Sign) state; - if(sign.getLines() != null) { - sign.setLine(0, "Warzone"); - sign.setLine(1, zone.getName()); - sign.setLine(2, zonePlayers + "/" + zoneCap + " players"); - sign.setLine(3, zone.getTeams().size() + " teams"); - sign.update(true); - } - } + String[] lines = new String[4]; + lines[0] = "Warzone"; + lines[1] = zone.getName(); + lines[2] = zonePlayers + "/" + zoneCap + " players"; + lines[3] = zone.getTeams().size() + " teams"; + SignHelper.setToSign(block, (byte)8, 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 36d0b36..4a8e259 100644 --- a/war/src/main/java/com/tommytony/war/Warzone.java +++ b/war/src/main/java/com/tommytony/war/Warzone.java @@ -18,6 +18,8 @@ import org.bukkit.inventory.PlayerInventory; import bukkit.tommytony.war.War; +import com.tommytony.war.jobs.ResetCursorJob; +import com.tommytony.war.utils.InventoryStash; import com.tommytony.war.volumes.VerticalVolume; /** diff --git a/war/src/main/java/com/tommytony/war/ZoneLobby.java b/war/src/main/java/com/tommytony/war/ZoneLobby.java index de052f5..c4c47cb 100644 --- a/war/src/main/java/com/tommytony/war/ZoneLobby.java +++ b/war/src/main/java/com/tommytony/war/ZoneLobby.java @@ -11,6 +11,7 @@ import org.bukkit.material.MaterialData; import bukkit.tommytony.war.War; import com.tommytony.war.mappers.VolumeMapper; +import com.tommytony.war.utils.SignHelper; import com.tommytony.war.volumes.VerticalVolume; import com.tommytony.war.volumes.Volume; @@ -181,35 +182,27 @@ public class ZoneLobby { // set zone sign Block zoneSignBlock = lobbyMiddleWallBlock.getFace(wall, 4); - - if(zoneSignBlock.getType() != Material.SIGN_POST) { - zoneSignBlock.setType(Material.SIGN_POST); - } + byte data = 0; if(wall == BlockFace.NORTH) { - zoneSignBlock.setData((byte)4); + data = (byte)4; } else if(wall == BlockFace.EAST) { - zoneSignBlock.setData((byte)8); + data = (byte)8; } else if(wall == BlockFace.SOUTH) { - zoneSignBlock.setData((byte)12); + data = (byte)12; } else if(wall == BlockFace.WEST) { - zoneSignBlock.setData((byte)0); + data = (byte)0; } - BlockState state = zoneSignBlock.getState(); - if(state instanceof Sign) { - Sign sign = (Sign) state; - if(sign.getLines() != null) { - sign.setLine(0, "Warzone"); - sign.setLine(1, warzone.getName()); - if(autoAssignGate != null) { - sign.setLine(2, "Walk in the"); - sign.setLine(3, "auto-assign gate."); - } else { - sign.setLine(2, ""); - sign.setLine(3, "Pick your team."); - } - sign.update(true); - } + String[] lines = new String[4]; + lines[0] = "Warzone"; + lines[1] = warzone.getName(); + if(autoAssignGate != null) { + lines[2] = "Walk in the"; + lines[3] = "auto-assign gate."; + } else { + lines[2] = ""; + lines[3] = "Pick your team."; } + SignHelper.setToSign(zoneSignBlock, data, lines); // lets get some light in here if(wall == BlockFace.NORTH || wall == BlockFace.SOUTH) { @@ -573,39 +566,26 @@ public class ZoneLobby { } else if (wall == BlockFace.WEST) { direction = BlockFace.EAST; } - + byte data = 0; if(wall == BlockFace.NORTH) { block = gate.getFace(direction).getFace(BlockFace.EAST); - if(block.getType() != Material.SIGN_POST) block.setType(Material.SIGN_POST); - if(awayFromWall) block.setData((byte)4); - else block.setData((byte)12); + if(awayFromWall) data = (byte)4; + else data = (byte)12; } else if(wall == BlockFace.EAST) { block = gate.getFace(direction).getFace(BlockFace.SOUTH); - if(block.getType() != Material.SIGN_POST) block.setType(Material.SIGN_POST); - if(awayFromWall) block.setData((byte)8); - else block.setData((byte)0); + if(awayFromWall) data = (byte)8; + else data = (byte)0; } else if(wall == BlockFace.SOUTH) { block = gate.getFace(direction).getFace(BlockFace.WEST); - if(block.getType() != Material.SIGN_POST) block.setType(Material.SIGN_POST); - if(awayFromWall) block.setData((byte)12); - else block.setData((byte)4); + if(awayFromWall) data = (byte)12; + else data = (byte)4; } else if(wall == BlockFace.WEST) { block = gate.getFace(direction).getFace(BlockFace.NORTH); - if(block.getType() != Material.SIGN_POST) block.setType(Material.SIGN_POST); - if(awayFromWall) block.setData((byte)0); - else block.setData((byte)8); + if(awayFromWall) data = (byte)0; + else data = (byte)8; } - BlockState state = block.getState(); - if(state instanceof Sign) { - Sign sign = (Sign) state; - if(sign.getLines() != null) { - sign.setLine(0, lines[0]); - sign.setLine(1, lines[1]); - sign.setLine(2, lines[2]); - sign.setLine(3, lines[3]); - sign.update(true); - } - } + + SignHelper.setToSign(block, data, lines); } public boolean isLeavingZone(Location location) { diff --git a/war/src/main/java/com/tommytony/war/LootDropperTask.java b/war/src/main/java/com/tommytony/war/jobs/LootDropperTask.java similarity index 93% rename from war/src/main/java/com/tommytony/war/LootDropperTask.java rename to war/src/main/java/com/tommytony/war/jobs/LootDropperTask.java index c78521e..e094a76 100644 --- a/war/src/main/java/com/tommytony/war/LootDropperTask.java +++ b/war/src/main/java/com/tommytony/war/jobs/LootDropperTask.java @@ -1,4 +1,4 @@ -package com.tommytony.war; +package com.tommytony.war.jobs; import java.util.List; diff --git a/war/src/main/java/com/tommytony/war/ResetCursorJob.java b/war/src/main/java/com/tommytony/war/jobs/ResetCursorJob.java similarity index 96% rename from war/src/main/java/com/tommytony/war/ResetCursorJob.java rename to war/src/main/java/com/tommytony/war/jobs/ResetCursorJob.java index 4773a5c..a8aebd1 100644 --- a/war/src/main/java/com/tommytony/war/ResetCursorJob.java +++ b/war/src/main/java/com/tommytony/war/jobs/ResetCursorJob.java @@ -1,4 +1,4 @@ -package com.tommytony.war; +package com.tommytony.war.jobs; import org.bukkit.Material; import org.bukkit.block.Block; diff --git a/war/src/main/java/com/tommytony/war/RestoreDeadmanInventoryJob.java b/war/src/main/java/com/tommytony/war/jobs/RestoreDeadmanInventoryJob.java similarity index 85% rename from war/src/main/java/com/tommytony/war/RestoreDeadmanInventoryJob.java rename to war/src/main/java/com/tommytony/war/jobs/RestoreDeadmanInventoryJob.java index a8cabc6..d07e4ec 100644 --- a/war/src/main/java/com/tommytony/war/RestoreDeadmanInventoryJob.java +++ b/war/src/main/java/com/tommytony/war/jobs/RestoreDeadmanInventoryJob.java @@ -1,7 +1,9 @@ -package com.tommytony.war; +package com.tommytony.war.jobs; import org.bukkit.entity.Player; +import com.tommytony.war.Warzone; + public class RestoreDeadmanInventoryJob implements Runnable { private final Player player; diff --git a/war/src/main/java/com/tommytony/war/ScoreCapReachedJob.java b/war/src/main/java/com/tommytony/war/jobs/ScoreCapReachedJob.java similarity index 92% rename from war/src/main/java/com/tommytony/war/ScoreCapReachedJob.java rename to war/src/main/java/com/tommytony/war/jobs/ScoreCapReachedJob.java index 2fbe5c5..0a73dbc 100644 --- a/war/src/main/java/com/tommytony/war/ScoreCapReachedJob.java +++ b/war/src/main/java/com/tommytony/war/jobs/ScoreCapReachedJob.java @@ -1,7 +1,9 @@ -package com.tommytony.war; +package com.tommytony.war.jobs; import org.bukkit.entity.Player; +import com.tommytony.war.Warzone; + public class ScoreCapReachedJob implements Runnable { private final Player player; diff --git a/war/src/main/java/com/tommytony/war/ChatFixUtil.java b/war/src/main/java/com/tommytony/war/utils/ChatFixUtil.java similarity index 99% rename from war/src/main/java/com/tommytony/war/ChatFixUtil.java rename to war/src/main/java/com/tommytony/war/utils/ChatFixUtil.java index 66ecca1..003751e 100644 --- a/war/src/main/java/com/tommytony/war/ChatFixUtil.java +++ b/war/src/main/java/com/tommytony/war/utils/ChatFixUtil.java @@ -1,4 +1,4 @@ -package com.tommytony.war; +package com.tommytony.war.utils; import java.util.*; diff --git a/war/src/main/java/com/tommytony/war/InventoryStash.java b/war/src/main/java/com/tommytony/war/utils/InventoryStash.java similarity index 97% rename from war/src/main/java/com/tommytony/war/InventoryStash.java rename to war/src/main/java/com/tommytony/war/utils/InventoryStash.java index beec46c..448ac82 100644 --- a/war/src/main/java/com/tommytony/war/InventoryStash.java +++ b/war/src/main/java/com/tommytony/war/utils/InventoryStash.java @@ -1,4 +1,4 @@ -package com.tommytony.war; +package com.tommytony.war.utils; import org.bukkit.inventory.ItemStack; diff --git a/war/src/main/java/com/tommytony/war/utils/SignHelper.java b/war/src/main/java/com/tommytony/war/utils/SignHelper.java new file mode 100644 index 0000000..1f4d55e --- /dev/null +++ b/war/src/main/java/com/tommytony/war/utils/SignHelper.java @@ -0,0 +1,34 @@ +package com.tommytony.war.utils; + +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockState; +import org.bukkit.block.Sign; + +import bukkit.tommytony.war.War; + +public class SignHelper { + + public static void setToSign(Block block, byte data, String[] lines) { + if(block.getType() != Material.SIGN_POST) { + block.setType(Material.SIGN_POST); + } + block.setData(data); + BlockState state = block.getState(); + if(state instanceof Sign) { + Sign sign = (Sign) state; + try { + if(sign.getLines() != null) { + sign.setLine(0, lines[0]); + sign.setLine(1, lines[1]); + sign.setLine(2, lines[2]); + sign.setLine(3, lines[3]); + sign.update(true); + } + } catch (Exception e) { + // just can't stand this anymore + } + } + } + +}