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 {
// 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
public void run() {

View File

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

View File

@ -114,34 +114,7 @@ public class SchematicHandler {
return true;
}
/**
* 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();
public static Schematic getSchematic(final CompoundTag tag, File file) {
final Map<String, Tag> tagMap = tag.getValue();
byte[] addId = new byte[0];
@ -176,48 +149,42 @@ public class SchematicHandler {
for (int x = 0; x < b.length; x++) {
collection[x] = new DataCollection(blocks[x], d[x]);
}
// if (PlotMain.worldEdit!=null) {
// List<Tag> tileEntities = requireTag(tagMap, "TileEntities",
// ListTag.class).getValue();
//
// for (Tag blocktag : tileEntities) {
// if (!(blocktag instanceof CompoundTag)) continue;
// CompoundTag t = (CompoundTag) blocktag;
//
// int x = 0;
// int y = 0;
// int z = 0;
//
// Map<String, Tag> values = new HashMap<String, Tag>();
//
// for (Map.Entry<String, Tag> entry : t.getValue().entrySet()) {
// if (entry.getKey().equals("x")) {
// if (entry.getValue() instanceof IntTag) {
// x = ((IntTag) entry.getValue()).getValue();
// }
// } else if (entry.getKey().equals("y")) {
// if (entry.getValue() instanceof IntTag) {
// y = ((IntTag) entry.getValue()).getValue();
// }
// } else if (entry.getKey().equals("z")) {
// if (entry.getValue() instanceof IntTag) {
// z = ((IntTag) entry.getValue()).getValue();
// }
// }
//
// values.put(entry.getKey(), entry.getValue());
// }
//
// int index = y * width * length + z * height + x;
// collection[index].tag = new CompoundTag("", values);
// }
// }
schematic = new Schematic(collection, dimension, file);
return new Schematic(collection, dimension, 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;
}
try {
final InputStream iStream = new FileInputStream(file);
final NBTInputStream stream = new NBTInputStream(new GZIPInputStream(iStream));
final CompoundTag tag = (CompoundTag) stream.readTag();
stream.close();
return getSchematic(tag, file);
} catch (final Exception e) {
e.printStackTrace();
return null;
}
return schematic;
}
/**
@ -229,13 +196,13 @@ public class SchematicHandler {
* @return true if succeeded
*/
public static boolean save(final CompoundTag tag, final String path) {
if (tag == null) {
PlotMain.sendConsoleSenderMessage("&cCannot save empty tag");
return false;
}
try {
File tmp = new File(path);
tmp.getParentFile().mkdirs();
final OutputStream stream = new FileOutputStream(path);
final NBTOutputStream output = new NBTOutputStream(new GZIPOutputStream(stream));
output.writeTag(tag);
@ -256,17 +223,23 @@ public class SchematicHandler {
*
* @return tag
*/
@SuppressWarnings("deprecation")
public static CompoundTag getCompoundTag(final World world, final PlotId id) {
public static CompoundTag getCompoundTag(final World world, PlotId id) {
if (!PlotMain.getPlots(world).containsKey(id)) {
return null;
// Plot is empty
}
// loading chunks
final Location pos1 = PlotHelper.getPlotBottomLoc(world, id).add(1, 0, 1);
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 j = 0;
try {
@ -287,7 +260,7 @@ public class SchematicHandler {
return null;
}
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 HashMap<String, Tag> schematic = new HashMap<>();
@ -305,12 +278,21 @@ public class SchematicHandler {
byte[] addBlocks = null;
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 z = 0; z < length; z++) {
for (int y = 0; y < height; y++) {
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();