From df68687092375883f1fefe502ceb14e74ac430d6 Mon Sep 17 00:00:00 2001 From: taoneill Date: Sun, 20 Mar 2011 20:54:03 -0400 Subject: [PATCH] Closes gh-92. Closes gh-103. Corner markers should reset wool properly and stay a bit longer, but disappear properly. Chest and dispenser item durability and data are now saved to disk (minor change of file format). --- .../main/java/com/tommytony/war/Warzone.java | 22 ++++----- .../tommytony/war/jobs/ResetCursorJob.java | 26 +++++++---- .../tommytony/war/mappers/VolumeMapper.java | 46 ++++++++++++++++--- 3 files changed, 67 insertions(+), 27 deletions(-) diff --git a/war/src/main/java/com/tommytony/war/Warzone.java b/war/src/main/java/com/tommytony/war/Warzone.java index af34c79..76f7a6b 100644 --- a/war/src/main/java/com/tommytony/war/Warzone.java +++ b/war/src/main/java/com/tommytony/war/Warzone.java @@ -8,7 +8,6 @@ import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; -import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.inventory.ItemStack; @@ -20,6 +19,7 @@ import com.tommytony.war.jobs.InitZoneJob; import com.tommytony.war.jobs.ResetCursorJob; import com.tommytony.war.jobs.ScoreCapReachedJob; import com.tommytony.war.utils.InventoryStash; +import com.tommytony.war.volumes.BlockInfo; import com.tommytony.war.volumes.VerticalVolume; /** @@ -124,14 +124,14 @@ public class Warzone { private void addNorthwestCursorBlocks() { Block topNWBlock = this.world.getBlockAt(this.northwest.getBlockX(), this.northwest.getBlockY()-1, this.northwest.getBlockZ()); - Material[] originalNorthwestBlocks = new Material[3]; - originalNorthwestBlocks[0] = topNWBlock.getType(); // save blocks for reset - originalNorthwestBlocks[1] = topNWBlock.getFace(BlockFace.EAST).getType(); - originalNorthwestBlocks[2] = topNWBlock.getFace(BlockFace.SOUTH).getType(); + BlockInfo[] originalNorthwestBlocks = new BlockInfo[3]; + originalNorthwestBlocks[0] = new BlockInfo(topNWBlock); // save blocks for reset + originalNorthwestBlocks[1] = new BlockInfo(topNWBlock.getFace(BlockFace.EAST)); + originalNorthwestBlocks[2] = new BlockInfo(topNWBlock.getFace(BlockFace.SOUTH)); topNWBlock.setType(Material.GLASS); topNWBlock.getFace(BlockFace.EAST).setType(Material.GLASS); topNWBlock.getFace(BlockFace.SOUTH).setType(Material.GLASS); - this.war.getServer().getScheduler().scheduleSyncDelayedTask(this.war, new ResetCursorJob(topNWBlock, originalNorthwestBlocks, false), 40); + this.war.getServer().getScheduler().scheduleSyncDelayedTask(this.war, new ResetCursorJob(topNWBlock, originalNorthwestBlocks, false), 75); } public Location getNorthwest() { @@ -146,14 +146,14 @@ public class Warzone { private void addSoutheastCursorBlocks() { Block topSEBlock = this.world.getBlockAt(this.southeast.getBlockX(), this.southeast.getBlockY()-1, this.southeast.getBlockZ()); - Material[] originalSoutheastBlocks = new Material[3]; - originalSoutheastBlocks[0] = topSEBlock.getType(); // save block for reset - originalSoutheastBlocks[1] = topSEBlock.getFace(BlockFace.WEST).getType(); - originalSoutheastBlocks[2] = topSEBlock.getFace(BlockFace.NORTH).getType(); + BlockInfo[] originalSoutheastBlocks = new BlockInfo[3]; + originalSoutheastBlocks[0] = new BlockInfo(topSEBlock); // save block for reset + originalSoutheastBlocks[1] = new BlockInfo(topSEBlock.getFace(BlockFace.WEST)); + originalSoutheastBlocks[2] = new BlockInfo(topSEBlock.getFace(BlockFace.NORTH)); topSEBlock.setType(Material.GLASS); topSEBlock.getFace(BlockFace.WEST).setType(Material.GLASS); topSEBlock.getFace(BlockFace.NORTH).setType(Material.GLASS); - this.war.getServer().getScheduler().scheduleSyncDelayedTask(this.war, new ResetCursorJob(topSEBlock, originalSoutheastBlocks, true), 40); + this.war.getServer().getScheduler().scheduleSyncDelayedTask(this.war, new ResetCursorJob(topSEBlock, originalSoutheastBlocks, true), 75); } diff --git a/war/src/main/java/com/tommytony/war/jobs/ResetCursorJob.java b/war/src/main/java/com/tommytony/war/jobs/ResetCursorJob.java index a8aebd1..587466d 100644 --- a/war/src/main/java/com/tommytony/war/jobs/ResetCursorJob.java +++ b/war/src/main/java/com/tommytony/war/jobs/ResetCursorJob.java @@ -1,32 +1,38 @@ package com.tommytony.war.jobs; -import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import com.tommytony.war.volumes.BlockInfo; + public class ResetCursorJob implements Runnable { private final Block cornerBlock; - private final Material[] originalCursorBlocks; + private final BlockInfo[] originalCursorBlocks; private final boolean isSoutheast; - public ResetCursorJob(Block cornerBlock, Material[] originalCursorBlocks, boolean isSoutheast) { + public ResetCursorJob(Block cornerBlock, BlockInfo[] originalCursorBlocks, boolean isSoutheast) { this.cornerBlock = cornerBlock; this.originalCursorBlocks = originalCursorBlocks; this.isSoutheast = isSoutheast; - } public void run() { if(isSoutheast) { - cornerBlock.setType(originalCursorBlocks[0]); - cornerBlock.getFace(BlockFace.WEST).setType(originalCursorBlocks[1]); - cornerBlock.getFace(BlockFace.NORTH).setType(originalCursorBlocks[2]); + cornerBlock.setType(originalCursorBlocks[0].getType()); + cornerBlock.setData(originalCursorBlocks[0].getData()); + cornerBlock.getFace(BlockFace.WEST).setType(originalCursorBlocks[1].getType()); + cornerBlock.getFace(BlockFace.WEST).setData(originalCursorBlocks[1].getData()); + cornerBlock.getFace(BlockFace.NORTH).setType(originalCursorBlocks[2].getType()); + cornerBlock.getFace(BlockFace.NORTH).setData(originalCursorBlocks[2].getData()); } else { - cornerBlock.setType(originalCursorBlocks[0]); - cornerBlock.getFace(BlockFace.EAST).setType(originalCursorBlocks[1]); - cornerBlock.getFace(BlockFace.SOUTH).setType(originalCursorBlocks[2]); + cornerBlock.setType(originalCursorBlocks[0].getType()); + cornerBlock.setData(originalCursorBlocks[0].getData()); + cornerBlock.getFace(BlockFace.EAST).setType(originalCursorBlocks[1].getType()); + cornerBlock.getFace(BlockFace.EAST).setData(originalCursorBlocks[1].getData()); + cornerBlock.getFace(BlockFace.SOUTH).setType(originalCursorBlocks[2].getType()); + cornerBlock.getFace(BlockFace.SOUTH).setData(originalCursorBlocks[2].getData()); } } } diff --git a/war/src/main/java/com/tommytony/war/mappers/VolumeMapper.java b/war/src/main/java/com/tommytony/war/mappers/VolumeMapper.java index 4e3ea21..2e5973c 100644 --- a/war/src/main/java/com/tommytony/war/mappers/VolumeMapper.java +++ b/war/src/main/java/com/tommytony/war/mappers/VolumeMapper.java @@ -106,8 +106,23 @@ public class VolumeMapper { String[] itemsStrSplit = itemsStr.split(";;"); for(String itemStr : itemsStrSplit) { String[] itemStrSplit = itemStr.split(";"); - items.add(new ItemStack(Integer.parseInt(itemStrSplit[0]), - Integer.parseInt(itemStrSplit[1]))); + 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]))); + } } } volume.getInvBlockContents().put("chest-" + i + "-" + j + "-" + k, items); @@ -119,12 +134,26 @@ public class VolumeMapper { String[] itemsStrSplit = itemsStr.split(";;"); for(String itemStr : itemsStrSplit) { String[] itemStrSplit = itemStr.split(";"); - items.add(new ItemStack(Integer.parseInt(itemStrSplit[0]), + 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]))); + } } } volume.getInvBlockContents().put("dispenser-" + i + "-" + j + "-" + k, items); - } } } @@ -193,7 +222,12 @@ public class VolumeMapper { List contents = volume.getInvBlockContents().get("chest-" + i + "-" + j + "-" + k); if(contents != null) { for(ItemStack item : contents) { - extra += item.getTypeId() + ";" + item.getAmount() + ";;"; + extra += item.getTypeId() + ";" + + item.getAmount() + ";" + + item.getDurability(); + if(item.getData() != null) + extra += ";" + item.getData().getData() ; + extra += ";;"; } out.write(extra); } @@ -203,7 +237,7 @@ public class VolumeMapper { List contents = volume.getInvBlockContents().get("dispenser-" + i + "-" + j + "-" + k); if(contents != null) { for(ItemStack item : contents) { - extra += item.getTypeId() + ";" + item.getAmount() + ";;"; + extra += item.getTypeId() + ";" + item.getAmount() + ";" + item.getDurability() + ";" + item.getData().getData() + ";;"; } out.write(extra); }