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).

This commit is contained in:
taoneill 2011-03-20 20:54:03 -04:00
parent a5988c242c
commit df68687092
3 changed files with 67 additions and 27 deletions

View File

@ -8,7 +8,6 @@ import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.inventory.ItemStack; 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.ResetCursorJob;
import com.tommytony.war.jobs.ScoreCapReachedJob; import com.tommytony.war.jobs.ScoreCapReachedJob;
import com.tommytony.war.utils.InventoryStash; import com.tommytony.war.utils.InventoryStash;
import com.tommytony.war.volumes.BlockInfo;
import com.tommytony.war.volumes.VerticalVolume; import com.tommytony.war.volumes.VerticalVolume;
/** /**
@ -124,14 +124,14 @@ public class Warzone {
private void addNorthwestCursorBlocks() { private void addNorthwestCursorBlocks() {
Block topNWBlock = this.world.getBlockAt(this.northwest.getBlockX(), this.northwest.getBlockY()-1, this.northwest.getBlockZ()); Block topNWBlock = this.world.getBlockAt(this.northwest.getBlockX(), this.northwest.getBlockY()-1, this.northwest.getBlockZ());
Material[] originalNorthwestBlocks = new Material[3]; BlockInfo[] originalNorthwestBlocks = new BlockInfo[3];
originalNorthwestBlocks[0] = topNWBlock.getType(); // save blocks for reset originalNorthwestBlocks[0] = new BlockInfo(topNWBlock); // save blocks for reset
originalNorthwestBlocks[1] = topNWBlock.getFace(BlockFace.EAST).getType(); originalNorthwestBlocks[1] = new BlockInfo(topNWBlock.getFace(BlockFace.EAST));
originalNorthwestBlocks[2] = topNWBlock.getFace(BlockFace.SOUTH).getType(); originalNorthwestBlocks[2] = new BlockInfo(topNWBlock.getFace(BlockFace.SOUTH));
topNWBlock.setType(Material.GLASS); topNWBlock.setType(Material.GLASS);
topNWBlock.getFace(BlockFace.EAST).setType(Material.GLASS); topNWBlock.getFace(BlockFace.EAST).setType(Material.GLASS);
topNWBlock.getFace(BlockFace.SOUTH).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() { public Location getNorthwest() {
@ -146,14 +146,14 @@ public class Warzone {
private void addSoutheastCursorBlocks() { private void addSoutheastCursorBlocks() {
Block topSEBlock = this.world.getBlockAt(this.southeast.getBlockX(), this.southeast.getBlockY()-1, this.southeast.getBlockZ()); Block topSEBlock = this.world.getBlockAt(this.southeast.getBlockX(), this.southeast.getBlockY()-1, this.southeast.getBlockZ());
Material[] originalSoutheastBlocks = new Material[3]; BlockInfo[] originalSoutheastBlocks = new BlockInfo[3];
originalSoutheastBlocks[0] = topSEBlock.getType(); // save block for reset originalSoutheastBlocks[0] = new BlockInfo(topSEBlock); // save block for reset
originalSoutheastBlocks[1] = topSEBlock.getFace(BlockFace.WEST).getType(); originalSoutheastBlocks[1] = new BlockInfo(topSEBlock.getFace(BlockFace.WEST));
originalSoutheastBlocks[2] = topSEBlock.getFace(BlockFace.NORTH).getType(); originalSoutheastBlocks[2] = new BlockInfo(topSEBlock.getFace(BlockFace.NORTH));
topSEBlock.setType(Material.GLASS); topSEBlock.setType(Material.GLASS);
topSEBlock.getFace(BlockFace.WEST).setType(Material.GLASS); topSEBlock.getFace(BlockFace.WEST).setType(Material.GLASS);
topSEBlock.getFace(BlockFace.NORTH).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);
} }

View File

@ -1,32 +1,38 @@
package com.tommytony.war.jobs; package com.tommytony.war.jobs;
import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import com.tommytony.war.volumes.BlockInfo;
public class ResetCursorJob implements Runnable { public class ResetCursorJob implements Runnable {
private final Block cornerBlock; private final Block cornerBlock;
private final Material[] originalCursorBlocks; private final BlockInfo[] originalCursorBlocks;
private final boolean isSoutheast; private final boolean isSoutheast;
public ResetCursorJob(Block cornerBlock, Material[] originalCursorBlocks, boolean isSoutheast) { public ResetCursorJob(Block cornerBlock, BlockInfo[] originalCursorBlocks, boolean isSoutheast) {
this.cornerBlock = cornerBlock; this.cornerBlock = cornerBlock;
this.originalCursorBlocks = originalCursorBlocks; this.originalCursorBlocks = originalCursorBlocks;
this.isSoutheast = isSoutheast; this.isSoutheast = isSoutheast;
} }
public void run() { public void run() {
if(isSoutheast) { if(isSoutheast) {
cornerBlock.setType(originalCursorBlocks[0]); cornerBlock.setType(originalCursorBlocks[0].getType());
cornerBlock.getFace(BlockFace.WEST).setType(originalCursorBlocks[1]); cornerBlock.setData(originalCursorBlocks[0].getData());
cornerBlock.getFace(BlockFace.NORTH).setType(originalCursorBlocks[2]); 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 { } else {
cornerBlock.setType(originalCursorBlocks[0]); cornerBlock.setType(originalCursorBlocks[0].getType());
cornerBlock.getFace(BlockFace.EAST).setType(originalCursorBlocks[1]); cornerBlock.setData(originalCursorBlocks[0].getData());
cornerBlock.getFace(BlockFace.SOUTH).setType(originalCursorBlocks[2]); 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());
} }
} }
} }

View File

@ -106,8 +106,23 @@ public class VolumeMapper {
String[] itemsStrSplit = itemsStr.split(";;"); String[] itemsStrSplit = itemsStr.split(";;");
for(String itemStr : itemsStrSplit) { for(String itemStr : itemsStrSplit) {
String[] itemStrSplit = itemStr.split(";"); String[] itemStrSplit = itemStr.split(";");
items.add(new ItemStack(Integer.parseInt(itemStrSplit[0]), if(itemStrSplit.length == 4) {
Integer.parseInt(itemStrSplit[1]))); 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); volume.getInvBlockContents().put("chest-" + i + "-" + j + "-" + k, items);
@ -119,12 +134,26 @@ public class VolumeMapper {
String[] itemsStrSplit = itemsStr.split(";;"); String[] itemsStrSplit = itemsStr.split(";;");
for(String itemStr : itemsStrSplit) { for(String itemStr : itemsStrSplit) {
String[] itemStrSplit = itemStr.split(";"); 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]))); Integer.parseInt(itemStrSplit[1])));
}
} }
} }
volume.getInvBlockContents().put("dispenser-" + i + "-" + j + "-" + k, items); volume.getInvBlockContents().put("dispenser-" + i + "-" + j + "-" + k, items);
} }
} }
} }
@ -193,7 +222,12 @@ public class VolumeMapper {
List<ItemStack> contents = volume.getInvBlockContents().get("chest-" + i + "-" + j + "-" + k); List<ItemStack> contents = volume.getInvBlockContents().get("chest-" + i + "-" + j + "-" + k);
if(contents != null) { if(contents != null) {
for(ItemStack item : contents) { 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); out.write(extra);
} }
@ -203,7 +237,7 @@ public class VolumeMapper {
List<ItemStack> contents = volume.getInvBlockContents().get("dispenser-" + i + "-" + j + "-" + k); List<ItemStack> contents = volume.getInvBlockContents().get("dispenser-" + i + "-" + j + "-" + k);
if(contents != null) { if(contents != null) {
for(ItemStack item : contents) { for(ItemStack item : contents) {
extra += item.getTypeId() + ";" + item.getAmount() + ";;"; extra += item.getTypeId() + ";" + item.getAmount() + ";" + item.getDurability() + ";" + item.getData().getData() + ";;";
} }
out.write(extra); out.write(extra);
} }