2014-11-16 10:48:18 +01:00
|
|
|
package com.intellectualcrafters.plot.util;
|
2014-09-22 13:02:14 +02:00
|
|
|
|
2015-07-06 01:44:10 +10:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.io.OutputStream;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.zip.GZIPInputStream;
|
|
|
|
import java.util.zip.GZIPOutputStream;
|
|
|
|
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
|
|
|
|
import com.intellectualcrafters.jnbt.ByteArrayTag;
|
|
|
|
import com.intellectualcrafters.jnbt.CompoundTag;
|
|
|
|
import com.intellectualcrafters.jnbt.IntTag;
|
|
|
|
import com.intellectualcrafters.jnbt.ListTag;
|
|
|
|
import com.intellectualcrafters.jnbt.NBTInputStream;
|
|
|
|
import com.intellectualcrafters.jnbt.NBTOutputStream;
|
|
|
|
import com.intellectualcrafters.jnbt.ShortTag;
|
|
|
|
import com.intellectualcrafters.jnbt.Tag;
|
2015-07-03 22:15:20 +10:00
|
|
|
import com.intellectualcrafters.plot.PS;
|
2015-04-16 14:04:11 +10:00
|
|
|
import com.intellectualcrafters.plot.config.Settings;
|
2015-02-19 21:47:05 +11:00
|
|
|
import com.intellectualcrafters.plot.object.Location;
|
2015-01-14 03:38:15 +11:00
|
|
|
import com.intellectualcrafters.plot.object.Plot;
|
|
|
|
import com.intellectualcrafters.plot.object.PlotId;
|
2015-02-26 15:16:52 +11:00
|
|
|
import com.intellectualcrafters.plot.object.schematic.PlotItem;
|
|
|
|
import com.intellectualcrafters.plot.object.schematic.StateWrapper;
|
2015-02-19 22:06:27 +11:00
|
|
|
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
|
2015-04-16 14:04:11 +10:00
|
|
|
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
2015-01-14 03:38:15 +11:00
|
|
|
|
2015-02-25 23:25:28 +11:00
|
|
|
public abstract class SchematicHandler {
|
|
|
|
public static SchematicHandler manager = new BukkitSchematicHandler();
|
|
|
|
|
2015-04-16 14:04:11 +10:00
|
|
|
private boolean exportAll = false;
|
|
|
|
|
2015-05-18 02:18:27 +10:00
|
|
|
public boolean exportAll(final Collection<Plot> collection, final File outputDir, final String namingScheme, final Runnable ifSuccess) {
|
2015-04-16 14:04:11 +10:00
|
|
|
if (exportAll) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-05-18 02:18:27 +10:00
|
|
|
if (collection.size() == 0) {
|
2015-04-16 14:04:11 +10:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
exportAll = true;
|
2015-05-18 02:18:27 +10:00
|
|
|
final ArrayList<Plot> plots = new ArrayList<Plot>(collection);
|
2015-04-16 14:04:11 +10:00
|
|
|
TaskManager.index.increment();
|
|
|
|
final Integer currentIndex = TaskManager.index.toInteger();
|
|
|
|
final int task = TaskManager.runTaskRepeat(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (plots.size() == 0) {
|
2015-05-18 02:18:27 +10:00
|
|
|
exportAll = false;
|
2015-04-16 14:04:11 +10:00
|
|
|
Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex));
|
|
|
|
TaskManager.tasks.remove(currentIndex);
|
|
|
|
TaskManager.runTask(ifSuccess);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Iterator<Plot> i = plots.iterator();
|
|
|
|
final Plot plot = i.next();
|
|
|
|
i.remove();
|
|
|
|
String o = UUIDHandler.getName(plot.owner);
|
|
|
|
if (o == null) {
|
|
|
|
o = "unknown";
|
|
|
|
}
|
|
|
|
final String name;
|
|
|
|
if (namingScheme == null) {
|
|
|
|
name = plot.id.x + ";" + plot.id.y + "," + plot.world + "," + o;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
name = namingScheme.replaceAll("%owner%", o).replaceAll("%id%", plot.id.toString()).replaceAll("%idx%", plot.id.x + "").replaceAll("%idy%", plot.id.y + "").replaceAll("%world%", plot.world);
|
|
|
|
}
|
|
|
|
final String directory;
|
|
|
|
if (outputDir == null) {
|
|
|
|
directory = Settings.SCHEMATIC_SAVE_PATH;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
directory = outputDir.getPath();
|
|
|
|
}
|
2015-07-03 22:15:20 +10:00
|
|
|
if (PS.get().worldEdit != null) {
|
2015-05-16 03:48:26 +10:00
|
|
|
new WorldEditSchematic().saveSchematic(directory + File.separator + name + ".schematic", plot.world, plot.id);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
final CompoundTag sch = SchematicHandler.manager.getCompoundTag(plot.world, plot.id);
|
|
|
|
if (sch == null) {
|
|
|
|
MainUtil.sendMessage(null, "&7 - Skipped plot &c" + plot.id);
|
|
|
|
} else {
|
|
|
|
TaskManager.runTaskAsync(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
MainUtil.sendMessage(null, "&6ID: " + plot.id);
|
|
|
|
final boolean result = SchematicHandler.manager.save(sch, directory + File.separator + name + ".schematic");
|
|
|
|
if (!result) {
|
|
|
|
MainUtil.sendMessage(null, "&7 - Failed to save &c" + plot.id);
|
|
|
|
} else {
|
|
|
|
MainUtil.sendMessage(null, "&7 - &a success: " + plot.id);
|
|
|
|
}
|
2015-04-16 14:04:11 +10:00
|
|
|
}
|
2015-05-16 03:48:26 +10:00
|
|
|
});
|
|
|
|
}
|
2015-04-16 14:04:11 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}, 20);
|
|
|
|
TaskManager.tasks.put(currentIndex, task);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-10-28 01:57:14 +01:00
|
|
|
/**
|
|
|
|
* Paste a schematic
|
2014-11-05 14:42:08 +11:00
|
|
|
*
|
2015-03-13 18:02:48 +11:00
|
|
|
* @param schematic the schematic object to paste
|
2014-12-17 20:15:11 -06:00
|
|
|
* @param plot plot to paste in
|
2015-03-13 18:02:48 +11:00
|
|
|
* @param x_offset offset x to paste it from plot origin
|
|
|
|
* @param z_offset offset z to paste it from plot origin
|
2014-12-17 20:15:11 -06:00
|
|
|
*
|
2015-03-13 18:02:48 +11:00
|
|
|
* @return boolean true if succeeded
|
2014-10-28 01:57:14 +01:00
|
|
|
*/
|
2015-02-26 15:16:52 +11:00
|
|
|
public boolean paste(final Schematic schematic, final Plot plot, final int x_offset, final int z_offset) {
|
2014-11-05 14:42:08 +11:00
|
|
|
if (schematic == null) {
|
2015-07-03 22:15:20 +10:00
|
|
|
PS.log("Schematic == null :|");
|
2014-11-05 14:42:08 +11:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
final Dimension demensions = schematic.getSchematicDimension();
|
|
|
|
final int WIDTH = demensions.getX();
|
|
|
|
final int LENGTH = demensions.getZ();
|
|
|
|
final int HEIGHT = demensions.getY();
|
|
|
|
final DataCollection[] blocks = schematic.getBlockCollection();
|
2015-02-20 22:23:48 +11:00
|
|
|
Location l1 = MainUtil.getPlotBottomLoc(plot.world, plot.getId());
|
2015-02-26 15:16:52 +11:00
|
|
|
final int sy = BukkitUtil.getHeighestBlock(plot.world, l1.getX() + 1, l1.getZ() + 1);
|
|
|
|
if (!(HEIGHT == BukkitUtil.getMaxHeight(plot.world))) {
|
|
|
|
l1 = l1.add(1, sy - 1, 1);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
l1 = l1.add(1, 0, 1);
|
2014-11-05 14:42:08 +11:00
|
|
|
}
|
2015-02-26 15:16:52 +11:00
|
|
|
int X = l1.getX();
|
|
|
|
int Y = l1.getY();
|
|
|
|
int Z = l1.getZ();
|
2015-02-20 17:34:19 +11:00
|
|
|
final int[] xl = new int[blocks.length];
|
|
|
|
final int[] yl = new int[blocks.length];
|
|
|
|
final int[] zl = new int[blocks.length];
|
|
|
|
final int[] ids = new int[blocks.length];
|
|
|
|
final byte[] data = new byte[blocks.length];
|
2014-11-05 14:42:08 +11:00
|
|
|
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 DataCollection block = blocks[index];
|
2015-02-26 15:16:52 +11:00
|
|
|
xl[index] = x + X;
|
|
|
|
yl[index] = y + Y;
|
|
|
|
zl[index] = z + Z;
|
2015-02-19 22:06:27 +11:00
|
|
|
ids[index] = block.block;
|
|
|
|
data[index] = block.data;
|
2014-11-05 14:42:08 +11:00
|
|
|
}
|
|
|
|
}
|
2014-10-15 20:43:20 +11:00
|
|
|
}
|
2015-02-19 22:06:27 +11:00
|
|
|
BlockManager.setBlocks(plot.world, xl, yl, zl, ids, data);
|
2015-02-26 15:16:52 +11:00
|
|
|
pasteStates(schematic, plot, x_offset, z_offset);
|
2014-12-17 20:15:11 -06:00
|
|
|
} catch (final Exception e) {
|
2014-11-05 14:42:08 +11:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2015-02-26 15:16:52 +11:00
|
|
|
|
|
|
|
public boolean pasteStates(final Schematic schematic, final Plot plot, final int x_offset, final int z_offset) {
|
|
|
|
if (schematic == null) {
|
2015-07-03 22:15:20 +10:00
|
|
|
PS.log("Schematic == null :|");
|
2015-02-26 15:16:52 +11:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
HashSet<PlotItem> items = schematic.getItems();
|
|
|
|
if (items == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Location l1 = MainUtil.getPlotBottomLoc(plot.world, plot.getId());
|
|
|
|
final int sy = BukkitUtil.getHeighestBlock(plot.world, l1.getX() + 1, l1.getZ() + 1);
|
|
|
|
final Dimension demensions = schematic.getSchematicDimension();
|
|
|
|
final int HEIGHT = demensions.getY();
|
|
|
|
if (!(HEIGHT == BukkitUtil.getMaxHeight(plot.world))) {
|
|
|
|
l1 = l1.add(1, sy - 1, 1);
|
|
|
|
} else {
|
|
|
|
l1 = l1.add(1, 0, 1);
|
|
|
|
}
|
|
|
|
int X = l1.getX() + x_offset;
|
|
|
|
int Y = l1.getY();
|
|
|
|
int Z = l1.getZ() + z_offset;
|
|
|
|
for (PlotItem item : items) {
|
|
|
|
item.x += X;
|
|
|
|
item.y += Y;
|
|
|
|
item.z += Z;
|
|
|
|
BlockManager.manager.addItems(plot.world, item);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-02-25 23:25:28 +11:00
|
|
|
public Schematic getSchematic(final CompoundTag tag, final File file) {
|
2014-12-28 21:38:11 +11:00
|
|
|
final Map<String, Tag> tagMap = tag.getValue();
|
|
|
|
byte[] addId = new byte[0];
|
|
|
|
if (tagMap.containsKey("AddBlocks")) {
|
|
|
|
addId = ByteArrayTag.class.cast(tagMap.get("AddBlocks")).getValue();
|
|
|
|
}
|
|
|
|
final short width = ShortTag.class.cast(tagMap.get("Width")).getValue();
|
|
|
|
final short length = ShortTag.class.cast(tagMap.get("Length")).getValue();
|
|
|
|
final short height = ShortTag.class.cast(tagMap.get("Height")).getValue();
|
|
|
|
final byte[] b = ByteArrayTag.class.cast(tagMap.get("Blocks")).getValue();
|
|
|
|
final byte[] d = ByteArrayTag.class.cast(tagMap.get("Data")).getValue();
|
|
|
|
final short[] blocks = new short[b.length];
|
|
|
|
final Dimension dimension = new Dimension(width, height, length);
|
|
|
|
for (int index = 0; index < b.length; index++) {
|
|
|
|
if ((index >> 1) >= addId.length) { // No corresponding
|
|
|
|
// AddBlocks index
|
|
|
|
blocks[index] = (short) (b[index] & 0xFF);
|
|
|
|
} else {
|
|
|
|
if ((index & 1) == 0) {
|
|
|
|
blocks[index] = (short) (((addId[index >> 1] & 0x0F) << 8) + (b[index] & 0xFF));
|
|
|
|
} else {
|
|
|
|
blocks[index] = (short) (((addId[index >> 1] & 0xF0) << 4) + (b[index] & 0xFF));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
final DataCollection[] collection = new DataCollection[b.length];
|
|
|
|
for (int x = 0; x < b.length; x++) {
|
|
|
|
collection[x] = new DataCollection(blocks[x], d[x]);
|
|
|
|
}
|
2015-02-26 15:16:52 +11:00
|
|
|
Schematic schem = new Schematic(collection, dimension, file);
|
|
|
|
try {
|
|
|
|
List<Tag> blockStates = ListTag.class.cast(tagMap.get("TileEntities")).getValue();
|
|
|
|
for (Tag stateTag : blockStates) {
|
|
|
|
CompoundTag ct = ((CompoundTag) stateTag);
|
|
|
|
Map<String, Tag> state = ct.getValue();
|
|
|
|
short x = IntTag.class.cast(state.get("x")).getValue().shortValue();
|
|
|
|
short y = IntTag.class.cast(state.get("y")).getValue().shortValue();
|
|
|
|
short z = IntTag.class.cast(state.get("z")).getValue().shortValue();
|
|
|
|
new StateWrapper(ct).restoreTag(x, y, z, schem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
return schem;
|
2014-12-28 21:38:11 +11:00
|
|
|
}
|
2015-02-25 23:25:28 +11:00
|
|
|
|
2014-10-28 01:57:14 +01:00
|
|
|
/**
|
|
|
|
* Get a schematic
|
2014-11-05 14:42:08 +11:00
|
|
|
*
|
2014-12-17 20:15:11 -06:00
|
|
|
* @param name to check
|
|
|
|
*
|
2014-10-28 01:57:14 +01:00
|
|
|
* @return schematic if found, else null
|
|
|
|
*/
|
2015-02-25 23:25:28 +11:00
|
|
|
public Schematic getSchematic(final String name) {
|
2014-11-05 14:42:08 +11:00
|
|
|
{
|
2015-07-03 22:15:20 +10:00
|
|
|
final File parent = new File(PS.get().IMP.getDirectory() + File.separator + "schematics");
|
2014-11-05 14:42:08 +11:00
|
|
|
if (!parent.exists()) {
|
2014-11-20 00:00:38 +01:00
|
|
|
if (!parent.mkdir()) {
|
|
|
|
throw new RuntimeException("Could not create schematic parent directory");
|
|
|
|
}
|
2014-11-05 14:42:08 +11:00
|
|
|
}
|
|
|
|
}
|
2015-07-03 22:15:20 +10:00
|
|
|
final File file = new File(PS.get().IMP.getDirectory() + File.separator + "schematics" + File.separator + name + ".schematic");
|
2015-04-14 23:55:00 +10:00
|
|
|
return getSchematic(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a schematic
|
|
|
|
*
|
|
|
|
* @param name to check
|
|
|
|
*
|
|
|
|
* @return schematic if found, else null
|
|
|
|
*/
|
|
|
|
public Schematic getSchematic(File file) {
|
2014-11-05 14:42:08 +11:00
|
|
|
if (!file.exists()) {
|
2015-07-03 22:15:20 +10:00
|
|
|
PS.log(file.toString() + " doesn't exist");
|
2014-11-05 14:42:08 +11:00
|
|
|
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();
|
2014-12-28 21:38:11 +11:00
|
|
|
return getSchematic(tag, file);
|
2014-12-17 20:15:11 -06:00
|
|
|
} catch (final Exception e) {
|
2015-07-03 22:15:20 +10:00
|
|
|
PS.log(file.toString() + " is not in GZIP format");
|
2014-11-05 14:42:08 +11:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2015-02-25 23:25:28 +11:00
|
|
|
|
2014-11-05 14:42:08 +11:00
|
|
|
/**
|
|
|
|
* Saves a schematic to a file path
|
|
|
|
*
|
2014-12-17 20:15:11 -06:00
|
|
|
* @param tag to save
|
|
|
|
* @param path to save in
|
|
|
|
*
|
2014-11-05 14:42:08 +11:00
|
|
|
* @return true if succeeded
|
|
|
|
*/
|
2015-02-25 23:25:28 +11:00
|
|
|
public boolean save(final CompoundTag tag, final String path) {
|
2014-11-05 14:42:08 +11:00
|
|
|
if (tag == null) {
|
2015-07-03 22:15:20 +10:00
|
|
|
PS.log("&cCannot save empty tag");
|
2014-11-05 14:42:08 +11:00
|
|
|
return false;
|
|
|
|
}
|
2014-10-22 19:46:41 +11:00
|
|
|
try {
|
2015-02-20 17:34:19 +11:00
|
|
|
final File tmp = new File(path);
|
2014-12-28 21:38:11 +11:00
|
|
|
tmp.getParentFile().mkdirs();
|
2014-11-05 14:42:08 +11:00
|
|
|
final OutputStream stream = new FileOutputStream(path);
|
|
|
|
final NBTOutputStream output = new NBTOutputStream(new GZIPOutputStream(stream));
|
2014-10-22 19:46:41 +11:00
|
|
|
output.writeTag(tag);
|
|
|
|
output.close();
|
|
|
|
stream.close();
|
2014-12-17 20:15:11 -06:00
|
|
|
} catch (final IOException e) {
|
2014-10-22 19:46:41 +11:00
|
|
|
e.printStackTrace();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2014-11-05 14:42:08 +11:00
|
|
|
}
|
2015-02-25 23:25:28 +11:00
|
|
|
|
2014-11-05 14:42:08 +11:00
|
|
|
/**
|
|
|
|
* Gets the schematic of a plot
|
|
|
|
*
|
2014-12-17 20:15:11 -06:00
|
|
|
* @param world to check
|
|
|
|
* @param id plot
|
|
|
|
*
|
2014-11-05 14:42:08 +11:00
|
|
|
* @return tag
|
|
|
|
*/
|
2015-02-25 23:25:28 +11:00
|
|
|
public CompoundTag getCompoundTag(final String world, final PlotId id) {
|
2015-07-03 22:15:20 +10:00
|
|
|
if (!PS.get().getPlots(world).containsKey(id)) {
|
2014-11-05 14:42:08 +11:00
|
|
|
return null;
|
|
|
|
}
|
2015-02-20 22:23:48 +11:00
|
|
|
final Location pos1 = MainUtil.getPlotBottomLoc(world, id).add(1, 0, 1);
|
|
|
|
final Location pos2 = MainUtil.getPlotTopLoc(world, id);
|
2014-12-28 21:38:11 +11:00
|
|
|
return getCompoundTag(world, pos1, pos2);
|
|
|
|
}
|
2015-02-25 23:25:28 +11:00
|
|
|
|
|
|
|
public abstract CompoundTag getCompoundTag(final String world, final Location pos1, final Location pos2);
|
|
|
|
|
|
|
|
public boolean pastePart(final String world, final DataCollection[] blocks, final Location l1, final int x_offset, final int z_offset, final int i1, final int i2, final int WIDTH, final int LENGTH) {
|
2015-02-19 22:06:27 +11:00
|
|
|
int length = 0;
|
|
|
|
for (int i = i1; i <= i2; i++) {
|
|
|
|
if (blocks[i].block == 0) {
|
|
|
|
length++;
|
|
|
|
}
|
|
|
|
}
|
2015-02-26 15:16:52 +11:00
|
|
|
length = i2 - i1 - length + 1;
|
|
|
|
|
|
|
|
int X = l1.getX();
|
|
|
|
int Y = l1.getY();
|
|
|
|
int Z = l1.getZ();
|
|
|
|
|
2015-02-20 17:34:19 +11:00
|
|
|
final int[] xl = new int[length];
|
|
|
|
final int[] yl = new int[length];
|
|
|
|
final int[] zl = new int[length];
|
|
|
|
final int[] ids = new int[length];
|
|
|
|
final byte[] data = new byte[length];
|
2015-02-19 22:06:27 +11:00
|
|
|
int count = 0;
|
2014-11-05 14:42:08 +11:00
|
|
|
for (int i = i1; i <= i2; i++) {
|
2015-02-19 21:47:05 +11:00
|
|
|
final short id = blocks[i].block;
|
2014-11-05 14:42:08 +11:00
|
|
|
if (id == 0) {
|
2015-02-26 15:16:52 +11:00
|
|
|
continue; //
|
2014-11-05 14:42:08 +11:00
|
|
|
}
|
|
|
|
final int area = WIDTH * LENGTH;
|
|
|
|
final int r = i % (area);
|
|
|
|
final int x = r % WIDTH;
|
|
|
|
final int y = i / area;
|
|
|
|
final int z = r / WIDTH;
|
2015-02-26 15:16:52 +11:00
|
|
|
xl[count] = x + X;
|
|
|
|
yl[count] = y + Y;
|
|
|
|
zl[count] = z + Z;
|
2015-02-19 22:06:27 +11:00
|
|
|
ids[count] = id;
|
|
|
|
data[count] = blocks[i].data;
|
2015-02-26 15:16:52 +11:00
|
|
|
count++;
|
2014-11-05 14:42:08 +11:00
|
|
|
if (y > 256) {
|
2014-10-30 17:24:58 +11:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-02-19 21:47:05 +11:00
|
|
|
BlockManager.setBlocks(world, xl, yl, zl, ids, data);
|
|
|
|
return true;
|
2014-10-30 17:24:58 +11:00
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2014-11-16 10:48:18 +01:00
|
|
|
/**
|
|
|
|
* Schematic Class
|
|
|
|
*
|
|
|
|
* @author Citymonstret
|
|
|
|
*/
|
2015-02-25 23:25:28 +11:00
|
|
|
public class Schematic {
|
2014-11-16 10:48:18 +01:00
|
|
|
private final DataCollection[] blockCollection;
|
2014-12-17 20:15:11 -06:00
|
|
|
private final Dimension schematicDimension;
|
|
|
|
private final File file;
|
2015-02-26 15:16:52 +11:00
|
|
|
private HashSet<PlotItem> items;
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-07-03 13:21:21 +02:00
|
|
|
public Schematic(final DataCollection[] blockCollection, final Dimension schematicDimension, final File file) {
|
|
|
|
this.blockCollection = blockCollection;
|
|
|
|
this.schematicDimension = schematicDimension;
|
|
|
|
this.file = file;
|
|
|
|
}
|
|
|
|
|
2015-02-26 15:16:52 +11:00
|
|
|
public void addItem(PlotItem item) {
|
|
|
|
if (this.items == null) {
|
|
|
|
this.items = new HashSet<>();
|
|
|
|
}
|
|
|
|
items.add(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
public HashSet<PlotItem> getItems() {
|
|
|
|
return this.items;
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2014-11-16 10:48:18 +01:00
|
|
|
public File getFile() {
|
|
|
|
return this.file;
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2014-11-16 10:48:18 +01:00
|
|
|
public Dimension getSchematicDimension() {
|
|
|
|
return this.schematicDimension;
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2014-11-16 10:48:18 +01:00
|
|
|
public DataCollection[] getBlockCollection() {
|
|
|
|
return this.blockCollection;
|
|
|
|
}
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2014-11-16 10:48:18 +01:00
|
|
|
/**
|
|
|
|
* Schematic Dimensions
|
|
|
|
*
|
|
|
|
* @author Citymonstret
|
|
|
|
*/
|
2015-02-25 23:25:28 +11:00
|
|
|
public class Dimension {
|
2014-11-16 10:48:18 +01:00
|
|
|
private final int x;
|
|
|
|
private final int y;
|
|
|
|
private final int z;
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2014-11-16 10:48:18 +01:00
|
|
|
public Dimension(final int x, final int y, final int z) {
|
|
|
|
this.x = x;
|
|
|
|
this.y = y;
|
|
|
|
this.z = z;
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2014-11-16 10:48:18 +01:00
|
|
|
public int getX() {
|
|
|
|
return this.x;
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2014-11-16 10:48:18 +01:00
|
|
|
public int getY() {
|
|
|
|
return this.y;
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2014-11-16 10:48:18 +01:00
|
|
|
public int getZ() {
|
|
|
|
return this.z;
|
|
|
|
}
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2014-11-16 10:48:18 +01:00
|
|
|
/**
|
|
|
|
* Schematic Data Collection
|
|
|
|
*
|
|
|
|
* @author Citymonstret
|
|
|
|
*/
|
2015-02-25 23:25:28 +11:00
|
|
|
public class DataCollection {
|
2014-11-16 10:48:18 +01:00
|
|
|
private final short block;
|
2014-12-17 20:15:11 -06:00
|
|
|
private final byte data;
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2014-11-16 10:48:18 +01:00
|
|
|
// public CompoundTag tag;
|
|
|
|
public DataCollection(final short block, final byte data) {
|
|
|
|
this.block = block;
|
|
|
|
this.data = data;
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2014-11-16 10:48:18 +01:00
|
|
|
public short getBlock() {
|
|
|
|
return this.block;
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2014-11-16 10:48:18 +01:00
|
|
|
public byte getData() {
|
|
|
|
return this.data;
|
|
|
|
}
|
|
|
|
}
|
2014-09-22 13:02:14 +02:00
|
|
|
}
|