minor Schematic changes

This commit is contained in:
boy0001 2014-12-28 21:38:11 +11:00
parent 5e5e46eef0
commit 7580b0ea82
3 changed files with 68 additions and 83 deletions

View File

@ -68,7 +68,7 @@ public class PlotMeConverter {
public void runAsync() throws Exception { public void runAsync() throws Exception {
// We have to make it wait a couple of seconds // We have to make it wait a couple of seconds
Bukkit.getScheduler().runTaskLaterAsynchronously(this.plugin, new Runnable() { Bukkit.getScheduler().runTaskLater(this.plugin, new Runnable() {
@Override @Override
public void run() { public void run() {

View File

@ -57,6 +57,9 @@ public class StringWrapper {
return false; return false;
} }
final StringWrapper other = (StringWrapper) obj; final StringWrapper other = (StringWrapper) obj;
if (other.value == null || this.value == null) {
return false;
}
if (Settings.OFFLINE_MODE) { if (Settings.OFFLINE_MODE) {
return other.value.equals(this.value); return other.value.equals(this.value);
} }

View File

@ -114,34 +114,7 @@ public class SchematicHandler {
return true; return true;
} }
/** public static Schematic getSchematic(final CompoundTag tag, File file) {
* Get a schematic
*
* @param name to check
*
* @return schematic if found, else null
*/
public static Schematic getSchematic(final String name) {
{
final File parent = new File(PlotMain.getMain().getDataFolder() + File.separator + "schematics");
if (!parent.exists()) {
if (!parent.mkdir()) {
throw new RuntimeException("Could not create schematic parent directory");
}
}
}
final File file = new File(PlotMain.getMain().getDataFolder() + File.separator + "schematics" + File.separator + name + ".schematic");
if (!file.exists()) {
PlotMain.sendConsoleSenderMessage(file.toString() + " doesn't exist");
return null;
}
Schematic schematic;
try {
final InputStream iStream = new FileInputStream(file);
final NBTInputStream stream = new NBTInputStream(new GZIPInputStream(iStream));
final CompoundTag tag = (CompoundTag) stream.readTag();
stream.close();
final Map<String, Tag> tagMap = tag.getValue(); final Map<String, Tag> tagMap = tag.getValue();
byte[] addId = new byte[0]; byte[] addId = new byte[0];
@ -176,48 +149,42 @@ public class SchematicHandler {
for (int x = 0; x < b.length; x++) { for (int x = 0; x < b.length; x++) {
collection[x] = new DataCollection(blocks[x], d[x]); collection[x] = new DataCollection(blocks[x], d[x]);
} }
// if (PlotMain.worldEdit!=null) { return new Schematic(collection, dimension, file);
// List<Tag> tileEntities = requireTag(tagMap, "TileEntities", }
// ListTag.class).getValue();
// /**
// for (Tag blocktag : tileEntities) { * Get a schematic
// if (!(blocktag instanceof CompoundTag)) continue; *
// CompoundTag t = (CompoundTag) blocktag; * @param name to check
// *
// int x = 0; * @return schematic if found, else null
// int y = 0; */
// int z = 0; public static Schematic getSchematic(final String name) {
// {
// Map<String, Tag> values = new HashMap<String, Tag>(); final File parent = new File(PlotMain.getMain().getDataFolder() + File.separator + "schematics");
// if (!parent.exists()) {
// for (Map.Entry<String, Tag> entry : t.getValue().entrySet()) { if (!parent.mkdir()) {
// if (entry.getKey().equals("x")) { throw new RuntimeException("Could not create schematic parent directory");
// if (entry.getValue() instanceof IntTag) { }
// x = ((IntTag) entry.getValue()).getValue(); }
// } }
// } else if (entry.getKey().equals("y")) { final File file = new File(PlotMain.getMain().getDataFolder() + File.separator + "schematics" + File.separator + name + ".schematic");
// if (entry.getValue() instanceof IntTag) { if (!file.exists()) {
// y = ((IntTag) entry.getValue()).getValue(); PlotMain.sendConsoleSenderMessage(file.toString() + " doesn't exist");
// } return null;
// } else if (entry.getKey().equals("z")) { }
// if (entry.getValue() instanceof IntTag) {
// z = ((IntTag) entry.getValue()).getValue(); try {
// } final InputStream iStream = new FileInputStream(file);
// } final NBTInputStream stream = new NBTInputStream(new GZIPInputStream(iStream));
// final CompoundTag tag = (CompoundTag) stream.readTag();
// values.put(entry.getKey(), entry.getValue()); stream.close();
// } return getSchematic(tag, file);
//
// int index = y * width * length + z * height + x;
// collection[index].tag = new CompoundTag("", values);
// }
// }
schematic = new Schematic(collection, dimension, file);
} catch (final Exception e) { } catch (final Exception e) {
e.printStackTrace(); e.printStackTrace();
return null; return null;
} }
return schematic;
} }
/** /**
@ -229,13 +196,13 @@ public class SchematicHandler {
* @return true if succeeded * @return true if succeeded
*/ */
public static boolean save(final CompoundTag tag, final String path) { public static boolean save(final CompoundTag tag, final String path) {
if (tag == null) { if (tag == null) {
PlotMain.sendConsoleSenderMessage("&cCannot save empty tag"); PlotMain.sendConsoleSenderMessage("&cCannot save empty tag");
return false; return false;
} }
try { try {
File tmp = new File(path);
tmp.getParentFile().mkdirs();
final OutputStream stream = new FileOutputStream(path); final OutputStream stream = new FileOutputStream(path);
final NBTOutputStream output = new NBTOutputStream(new GZIPOutputStream(stream)); final NBTOutputStream output = new NBTOutputStream(new GZIPOutputStream(stream));
output.writeTag(tag); output.writeTag(tag);
@ -256,17 +223,23 @@ public class SchematicHandler {
* *
* @return tag * @return tag
*/ */
@SuppressWarnings("deprecation") public static CompoundTag getCompoundTag(final World world, PlotId id) {
public static CompoundTag getCompoundTag(final World world, final PlotId id) {
if (!PlotMain.getPlots(world).containsKey(id)) { if (!PlotMain.getPlots(world).containsKey(id)) {
return null; return null;
// Plot is empty
} }
// loading chunks
final Location pos1 = PlotHelper.getPlotBottomLoc(world, id).add(1, 0, 1); final Location pos1 = PlotHelper.getPlotBottomLoc(world, id).add(1, 0, 1);
final Location pos2 = PlotHelper.getPlotTopLoc(world, id); final Location pos2 = PlotHelper.getPlotTopLoc(world, id);
return getCompoundTag(world, pos1, pos2);
}
@SuppressWarnings("deprecation")
public static CompoundTag getCompoundTag(final World world, Location pos1, Location pos2) {
// loading chunks
int i = 0; int i = 0;
int j = 0; int j = 0;
try { try {
@ -287,7 +260,7 @@ public class SchematicHandler {
return null; return null;
} }
final int width = (pos2.getBlockX() - pos1.getBlockX()) + 1; final int width = (pos2.getBlockX() - pos1.getBlockX()) + 1;
final int height = 256; final int height = pos2.getBlockY() - pos1.getBlockY() + 1;
final int length = (pos2.getBlockZ() - pos1.getBlockZ()) + 1; final int length = (pos2.getBlockZ() - pos1.getBlockZ()) + 1;
final HashMap<String, Tag> schematic = new HashMap<>(); final HashMap<String, Tag> schematic = new HashMap<>();
@ -305,12 +278,21 @@ public class SchematicHandler {
byte[] addBlocks = null; byte[] addBlocks = null;
final byte[] blockData = new byte[width * height * length]; final byte[] blockData = new byte[width * height * length];
int sx = pos1.getBlockX();
int ex = pos2.getBlockX();
int sz = pos1.getBlockZ();
int ez = pos2.getBlockZ();
int sy = pos1.getBlockY();
int ey = pos2.getBlockY();
for (int x = 0; x < width; x++) { for (int x = 0; x < width; x++) {
for (int z = 0; z < length; z++) { for (int z = 0; z < length; z++) {
for (int y = 0; y < height; y++) { for (int y = 0; y < height; y++) {
final int index = (y * width * length) + (z * width) + x; final int index = (y * width * length) + (z * width) + x;
final Block block = world.getBlockAt(new Location(world, pos1.getBlockX() + x, y, pos1.getBlockZ() + z)); final Block block = world.getBlockAt(new Location(world, sx + x, sy + y, sz + z));
@SuppressWarnings("deprecation") final int id2 = block.getTypeId(); @SuppressWarnings("deprecation") final int id2 = block.getTypeId();