use of com.sk89q.jnbt.NBTInputStream in project PlotSquared by IntellectualSites.
the class WorldUtil method upload.
public void upload(@NonNull final Plot plot, @Nullable final UUID uuid, @Nullable final String file, @NonNull final RunnableVal<URL> whenDone) {
plot.getHome(home -> SchematicHandler.upload(uuid, file, "zip", new RunnableVal<>() {
@Override
public void run(OutputStream output) {
try (final ZipOutputStream zos = new ZipOutputStream(output)) {
File dat = getDat(plot.getWorldName());
Location spawn = getSpawn(plot.getWorldName());
if (dat != null) {
ZipEntry ze = new ZipEntry("world" + File.separator + dat.getName());
zos.putNextEntry(ze);
try (NBTInputStream nis = new NBTInputStream(new GZIPInputStream(new FileInputStream(dat)))) {
Map<String, Tag> tag = ((CompoundTag) nis.readNamedTag().getTag()).getValue();
Map<String, Tag> newMap = new HashMap<>();
for (Map.Entry<String, Tag> entry : tag.entrySet()) {
if (!entry.getKey().equals("Data")) {
newMap.put(entry.getKey(), entry.getValue());
continue;
}
Map<String, Tag> data = new HashMap<>(((CompoundTag) entry.getValue()).getValue());
data.put("SpawnX", new IntTag(home.getX()));
data.put("SpawnY", new IntTag(home.getY()));
data.put("SpawnZ", new IntTag(home.getZ()));
newMap.put("Data", new CompoundTag(data));
}
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
try (NBTOutputStream out = new NBTOutputStream(new GZIPOutputStream(baos, true))) {
// TODO Find what this should be called
out.writeNamedTag("Schematic????", new CompoundTag(newMap));
}
zos.write(baos.toByteArray());
}
}
}
setSpawn(spawn);
byte[] buffer = new byte[1024];
Set<BlockVector2> added = new HashSet<>();
for (Plot current : plot.getConnectedPlots()) {
Location bot = current.getBottomAbs();
Location top = current.getTopAbs();
int brx = bot.getX() >> 9;
int brz = bot.getZ() >> 9;
int trx = top.getX() >> 9;
int trz = top.getZ() >> 9;
Set<BlockVector2> files = getChunkChunks(bot.getWorldName());
for (BlockVector2 mca : files) {
if (mca.getX() >= brx && mca.getX() <= trx && mca.getZ() >= brz && mca.getZ() <= trz && !added.contains(mca)) {
final File file = getMcr(plot.getWorldName(), mca.getX(), mca.getZ());
if (file != null) {
// final String name = "r." + (x - cx) + "." + (z - cz) + ".mca";
String name = file.getName();
final ZipEntry ze = new ZipEntry("world" + File.separator + "region" + File.separator + name);
zos.putNextEntry(ze);
added.add(mca);
try (FileInputStream in = new FileInputStream(file)) {
int len;
while ((len = in.read(buffer)) > 0) {
zos.write(buffer, 0, len);
}
}
zos.closeEntry();
}
}
}
}
zos.closeEntry();
zos.flush();
zos.finish();
} catch (IOException e) {
e.printStackTrace();
}
}
}, whenDone));
}
use of com.sk89q.jnbt.NBTInputStream in project FastAsyncWorldEdit by IntellectualSites.
the class FaweDelegateSchematicHandler method getSchematic.
public Schematic getSchematic(@Nonnull InputStream is) {
try {
FastSchematicReader schematicReader = new FastSchematicReader(new NBTInputStream(new BufferedInputStream(new GZIPInputStream(new BufferedInputStream(is)))));
Clipboard clip = schematicReader.read();
return new Schematic(clip);
} catch (IOException e) {
if (e instanceof EOFException) {
e.printStackTrace();
return null;
}
try {
SpongeSchematicReader schematicReader = new SpongeSchematicReader(new NBTInputStream(new GZIPInputStream(is)));
Clipboard clip = schematicReader.read();
return new Schematic(clip);
} catch (IOException e2) {
if (e2 instanceof EOFException) {
e.printStackTrace();
return null;
}
try {
MCEditSchematicReader schematicReader = new MCEditSchematicReader(new NBTInputStream(new GZIPInputStream(is)));
Clipboard clip = schematicReader.read();
return new Schematic(clip);
} catch (IOException e3) {
LOGGER.warn("{} | {} : {}", is, is.getClass().getCanonicalName(), e.getMessage());
e.printStackTrace();
}
}
}
return null;
}
use of com.sk89q.jnbt.NBTInputStream in project FunnyGuilds by FunnyGuilds.
the class WorldEdit6Hook method pasteSchematic.
@Override
public boolean pasteSchematic(File schematicFile, Location location, boolean withAir) {
try {
Object pasteLocation = vectorConstructor.newInstance(location.getX(), location.getY(), location.getZ());
com.sk89q.worldedit.world.World pasteWorld = new BukkitWorld(location.getWorld());
Object pasteWorldData = getWorldData.invoke(pasteWorld);
NBTInputStream nbtStream = new NBTInputStream(new GZIPInputStream(new FileInputStream(schematicFile)));
Object reader = schematicReaderConstructor.newInstance(nbtStream);
Object clipboard = readSchematic.invoke(reader, pasteWorldData);
EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(pasteWorld, -1);
ClipboardHolder clipboardHolder = (ClipboardHolder) clipboardHolderConstructor.newInstance(clipboard, pasteWorldData);
PasteBuilder builder = ((PasteBuilder) pasteConstructor.newInstance(clipboardHolder, editSession, pasteWorldData));
builder = (PasteBuilder) pasteBuilderSetTo.invoke(builder, pasteLocation);
builder = builder.ignoreAirBlocks(!withAir);
Operations.completeLegacy(builder.build());
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | MaxChangedBlocksException | IOException ex) {
throw new RuntimeException("Could not paste schematic: " + schematicFile.getAbsolutePath(), ex);
}
return true;
}
use of com.sk89q.jnbt.NBTInputStream in project FastAsyncWorldEdit by IntellectualSites.
the class CompressedCompoundTag method decompress.
private void decompress() {
try (NBTInputStream nbtIn = new NBTInputStream(adapt(in))) {
in = null;
CompoundTag tag = (CompoundTag) nbtIn.readTag();
Map<String, Tag> value = tag.getValue();
Map<String, Tag> raw = super.getValue();
raw.putAll(value);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of com.sk89q.jnbt.NBTInputStream in project PlotSquared by IntellectualSites.
the class SchematicHandler method getSchematic.
public Schematic getSchematic(@NonNull InputStream is) {
try {
SpongeSchematicReader schematicReader = new SpongeSchematicReader(new NBTInputStream(new GZIPInputStream(is)));
Clipboard clip = schematicReader.read();
return new Schematic(clip);
} catch (IOException ignored) {
try {
MCEditSchematicReader schematicReader = new MCEditSchematicReader(new NBTInputStream(new GZIPInputStream(is)));
Clipboard clip = schematicReader.read();
return new Schematic(clip);
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
Aggregations