mirror of
https://github.com/taoneill/war.git
synced 2024-11-27 20:59:39 +01:00
Closes gh-3. Signs, chests and dispensers and saved to disk. Everything reloads properly.
This commit is contained in:
parent
0accca079a
commit
23cb281a15
@ -6,9 +6,16 @@ import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Chest;
|
||||
import org.bukkit.block.Dispenser;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.material.MaterialData;
|
||||
|
||||
import bukkit.tommytony.war.War;
|
||||
|
||||
@ -71,29 +78,55 @@ public class VolumeMapper {
|
||||
for(int j = 0; j < volume.getSizeY(); j++) {
|
||||
for(int k = 0; k < volume.getSizeZ(); k++) {
|
||||
String blockLine = in.readLine();
|
||||
String[] blockSplit = blockLine.split(",");
|
||||
if(blockLine != null && !blockLine.equals("")) {
|
||||
String[] blockSplit = blockLine.split(",");
|
||||
if(blockLine != null && !blockLine.equals("") && blockSplit.length > 1) {
|
||||
int typeID = Integer.parseInt(blockSplit[0]);
|
||||
byte data = Byte.parseByte(blockSplit[1]);
|
||||
String[] lines = null;
|
||||
// if(typeID == Material.SIGN.getId() || typeID == Material.SIGN_POST.getId()) {
|
||||
// String signLines = blockSplit[2];
|
||||
// if(blockSplit.length > 3) {
|
||||
// // sign includes commas
|
||||
// for(int splitI = 3; splitI < blockSplit.length; splitI++) {
|
||||
// signLines.concat(blockSplit[splitI]);
|
||||
// }
|
||||
// }
|
||||
// String[] signLinesSplit = signLines.split("[line]");
|
||||
// lines = new String[4];
|
||||
// lines[0] = signLinesSplit[0];
|
||||
// lines[1] = signLinesSplit[1];
|
||||
// lines[2] = signLinesSplit[2];
|
||||
// lines[3] = signLinesSplit[3];
|
||||
// }
|
||||
//volume.getBlockTypes()[i][j][k] = new BlockInfo(typeID, data, lines);
|
||||
|
||||
volume.getBlockTypes()[i][j][k] = typeID;
|
||||
volume.getBlockDatas()[i][j][k] = data;
|
||||
|
||||
if(typeID == Material.SIGN.getId()
|
||||
|| typeID == Material.SIGN_POST.getId()) {
|
||||
// Signs
|
||||
String linesStr = "";
|
||||
if(blockSplit.length > 2) {
|
||||
for(int o = 2; o < blockSplit.length; o++) {
|
||||
linesStr += blockSplit[o];
|
||||
}
|
||||
String[] lines = linesStr.split(";;");
|
||||
volume.getSignLines().put("sign-" + i + "-" + j + "-" + k, lines);
|
||||
}
|
||||
} else if(typeID == Material.CHEST.getId()) {
|
||||
// Chests
|
||||
List<ItemStack> items = new ArrayList<ItemStack>();
|
||||
if(blockSplit.length > 2) {
|
||||
String itemsStr = blockSplit[2];
|
||||
String[] itemsStrSplit = itemsStr.split(";;");
|
||||
for(String itemStr : itemsStrSplit) {
|
||||
String[] itemStrSplit = itemStr.split(";");
|
||||
items.add(new ItemStack(Integer.parseInt(itemStrSplit[0]),
|
||||
Integer.parseInt(itemStrSplit[1])));
|
||||
}
|
||||
}
|
||||
volume.getInvBlockContents().put("chest-" + i + "-" + j + "-" + k, items);
|
||||
} else if(typeID == Material.DISPENSER.getId()) {
|
||||
// Dispensers
|
||||
List<ItemStack> items = new ArrayList<ItemStack>();
|
||||
if(blockSplit.length > 2) {
|
||||
String itemsStr = blockSplit[2];
|
||||
String[] itemsStrSplit = itemsStr.split(";;");
|
||||
for(String itemStr : itemsStrSplit) {
|
||||
String[] itemStrSplit = itemStr.split(";");
|
||||
items.add(new ItemStack(Integer.parseInt(itemStrSplit[0]),
|
||||
Integer.parseInt(itemStrSplit[1])));
|
||||
}
|
||||
}
|
||||
volume.getInvBlockContents().put("dispenser-" + i + "-" + j + "-" + k, items);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(height129Fix && j == volume.getSizeY() - 1) {
|
||||
@ -143,19 +176,38 @@ public class VolumeMapper {
|
||||
int typeId = volume.getBlockTypes()[i][j][k];
|
||||
byte data = volume.getBlockDatas()[i][j][k];
|
||||
out.write(typeId + "," + data + ",");
|
||||
//BlockInfo info = volume.getBlockTypes()[i][j][k];
|
||||
// if(info == null) {
|
||||
// out.write("0,0,");
|
||||
// } else {
|
||||
// if(info.getType() == Material.SIGN || info.getType() == Material.SIGN_POST) {
|
||||
// String[] lines = info.getSignLines();
|
||||
// out.write(info.getTypeId() + "," + info.getData() + "," + lines[0] + "[line]" + lines[1]
|
||||
// + "[line]" + lines[2] + "[line]"+ lines[3]);
|
||||
//
|
||||
// } else {
|
||||
// out.write(info.getTypeId() + "," + info.getData() + ",");
|
||||
//}
|
||||
// }
|
||||
if(typeId == Material.SIGN.getId()
|
||||
|| typeId == Material.SIGN_POST.getId()) {
|
||||
// Signs
|
||||
String extra = "";
|
||||
String[] lines = volume.getSignLines().get("sign-" + i + "-" + j + "-" + k);
|
||||
if(lines != null) {
|
||||
for(String line : lines) {
|
||||
extra += line + ";;";
|
||||
}
|
||||
out.write(extra);
|
||||
}
|
||||
} else if(typeId == Material.CHEST.getId()) {
|
||||
// Chests
|
||||
String extra = "";
|
||||
List<ItemStack> contents = volume.getInvBlockContents().get("chest-" + i + "-" + j + "-" + k);
|
||||
if(contents != null) {
|
||||
for(ItemStack item : contents) {
|
||||
extra += item.getTypeId() + ";" + item.getAmount() + ";;";
|
||||
}
|
||||
out.write(extra);
|
||||
}
|
||||
} else if(typeId == Material.DISPENSER.getId()) {
|
||||
// Dispensers
|
||||
String extra = "";
|
||||
List<ItemStack> contents = volume.getInvBlockContents().get("dispenser-" + i + "-" + j + "-" + k);
|
||||
if(contents != null) {
|
||||
for(ItemStack item : contents) {
|
||||
extra += item.getTypeId() + ";" + item.getAmount() + ";;";
|
||||
}
|
||||
out.write(extra);
|
||||
}
|
||||
}
|
||||
out.newLine();
|
||||
}
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ public class Volume {
|
||||
if(state instanceof Sign) {
|
||||
// Signs
|
||||
Sign sign = (Sign)state;
|
||||
this.getSignLines().put("sign-" + i + "-" + j + "," + k, sign.getLines());
|
||||
this.getSignLines().put("sign-" + i + "-" + j + "-" + k, sign.getLines());
|
||||
} else if(state instanceof Chest) {
|
||||
// Chests
|
||||
Chest chest = (Chest)state;
|
||||
@ -87,7 +87,7 @@ public class Volume {
|
||||
items.add(item);
|
||||
}
|
||||
}
|
||||
this.getInvBlockContents().put("chest-" + i + "-" + j + "," + k, items);
|
||||
this.getInvBlockContents().put("chest-" + i + "-" + j + "-" + k, items);
|
||||
} else if(state instanceof Dispenser) {
|
||||
// Dispensers
|
||||
Dispenser dispenser = (Dispenser)state;
|
||||
@ -100,7 +100,7 @@ public class Volume {
|
||||
items.add(item);
|
||||
}
|
||||
}
|
||||
this.getInvBlockContents().put("dispenser-" + i + "-" + j + "," + k, items);
|
||||
this.getInvBlockContents().put("dispenser-" + i + "-" + j + "-" + k, items);
|
||||
}
|
||||
z++;
|
||||
noOfSavedBlocks++;
|
||||
@ -156,12 +156,14 @@ public class Volume {
|
||||
state.update(true);
|
||||
state = war.refetchStateForBlock(world, state.getBlock());
|
||||
Sign sign = (Sign)state;
|
||||
String[] lines = this.getSignLines().get("sign-" + i + "-" + j + "," + k);
|
||||
String[] lines = this.getSignLines().get("sign-" + i + "-" + j + "-" + k);
|
||||
if(lines != null) {
|
||||
sign.setLine(0, lines[0]);
|
||||
sign.setLine(1, lines[1]);
|
||||
sign.setLine(2, lines[2]);
|
||||
sign.setLine(3, lines[3]);
|
||||
if(lines.length>1)sign.setLine(1, lines[1]);
|
||||
if(lines.length>2)sign.setLine(2, lines[2]);
|
||||
if(lines.length>3)sign.setLine(3, lines[3]);
|
||||
sign.update(true);
|
||||
}
|
||||
} else if(oldBlockType == Material.CHEST.getId()) {
|
||||
// Chests
|
||||
state.setType(Material.getMaterial(oldBlockType));
|
||||
@ -169,7 +171,8 @@ public class Volume {
|
||||
state.update(true);
|
||||
state = war.refetchStateForBlock(world, state.getBlock());
|
||||
Chest chest = (Chest)state;
|
||||
List<ItemStack> contents = this.getInvBlockContents().get("chest-" + i + "-" + j + "," + k);
|
||||
List<ItemStack> contents = this.getInvBlockContents().get("chest-" + i + "-" + j + "-" + k);
|
||||
if(contents != null) {
|
||||
int ii = 0;
|
||||
chest.getInventory().clear();
|
||||
for(ItemStack item : contents) {
|
||||
@ -177,6 +180,7 @@ public class Volume {
|
||||
ii++;
|
||||
}
|
||||
chest.update(true);
|
||||
}
|
||||
} else if(oldBlockType == Material.DISPENSER.getId()) {
|
||||
// Dispensers
|
||||
state.setType(Material.getMaterial(oldBlockType));
|
||||
@ -184,7 +188,8 @@ public class Volume {
|
||||
state.update(true);
|
||||
state = war.refetchStateForBlock(world, state.getBlock());
|
||||
Dispenser dispenser = (Dispenser)state;
|
||||
List<ItemStack> contents = this.getInvBlockContents().get("dispenser-" + i + "-" + j + "," + k);
|
||||
List<ItemStack> contents = this.getInvBlockContents().get("dispenser-" + i + "-" + j + "-" + k);
|
||||
if(contents != null) {
|
||||
int ii = 0;
|
||||
dispenser.getInventory().clear();
|
||||
for(ItemStack item : contents) {
|
||||
@ -192,6 +197,7 @@ public class Volume {
|
||||
ii++;
|
||||
}
|
||||
dispenser.update(true);
|
||||
}
|
||||
} else {
|
||||
// regular block
|
||||
currentBlock.setType(Material.getMaterial(oldBlockType));
|
||||
|
Loading…
Reference in New Issue
Block a user