Search in sources :

Example 1 with CompressedSchematicTag

use of com.fastasyncworldedit.core.jnbt.CompressedSchematicTag in project FastAsyncWorldEdit by IntellectualSites.

the class FaweDelegateSchematicHandler method save.

public boolean save(CompoundTag tag, String path) {
    if (tag == null) {
        LOGGER.warn("Cannot save empty tag");
        return false;
    }
    try {
        File tmp = FileUtils.getFile(PlotSquared.platform().getDirectory(), path);
        tmp.getParentFile().mkdirs();
        if (tag instanceof CompressedCompoundTag) {
            CompressedCompoundTag cTag = (CompressedCompoundTag) tag;
            if (cTag instanceof CompressedSchematicTag) {
                Clipboard clipboard = (Clipboard) cTag.getSource();
                try (OutputStream stream = new FileOutputStream(tmp);
                    NBTOutputStream output = new NBTOutputStream(new BufferedOutputStream(new ParallelGZIPOutputStream(stream)))) {
                    new FastSchematicWriter(output).write(clipboard);
                }
            } else {
                try (OutputStream stream = new FileOutputStream(tmp);
                    BufferedOutputStream output = new BufferedOutputStream(new ParallelGZIPOutputStream(stream))) {
                    LZ4BlockInputStream is = cTag.adapt(cTag.getSource());
                    IOUtil.copy(is, output);
                }
            }
        } else {
            try (OutputStream stream = new FileOutputStream(tmp);
                NBTOutputStream output = new NBTOutputStream(new ParallelGZIPOutputStream(stream))) {
                Map<String, Tag> map = tag.getValue();
                output.writeNamedTag("Schematic", map.getOrDefault("Schematic", tag));
            }
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    }
    return true;
}
Also used : FastSchematicWriter(com.fastasyncworldedit.core.extent.clipboard.io.FastSchematicWriter) CompressedSchematicTag(com.fastasyncworldedit.core.jnbt.CompressedSchematicTag) NBTOutputStream(com.sk89q.jnbt.NBTOutputStream) ParallelGZIPOutputStream(org.anarres.parallelgzip.ParallelGZIPOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) NBTOutputStream(com.sk89q.jnbt.NBTOutputStream) LZ4BlockInputStream(net.jpountz.lz4.LZ4BlockInputStream) CompressedCompoundTag(com.fastasyncworldedit.core.jnbt.CompressedCompoundTag) ParallelGZIPOutputStream(org.anarres.parallelgzip.ParallelGZIPOutputStream) FileOutputStream(java.io.FileOutputStream) Clipboard(com.sk89q.worldedit.extent.clipboard.Clipboard) CompressedSchematicTag(com.fastasyncworldedit.core.jnbt.CompressedSchematicTag) CompressedCompoundTag(com.fastasyncworldedit.core.jnbt.CompressedCompoundTag) CompoundTag(com.sk89q.jnbt.CompoundTag) Tag(com.sk89q.jnbt.Tag) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Example 2 with CompressedSchematicTag

use of com.fastasyncworldedit.core.jnbt.CompressedSchematicTag in project FastAsyncWorldEdit by IntellectualSites.

the class FaweDelegateSchematicHandler method upload.

public void upload(final CompoundTag tag, final UUID uuid, final String file, final RunnableVal<URL> whenDone) {
    if (tag == null) {
        LOGGER.warn("Cannot save empty tag");
        if (whenDone != null) {
            TaskManager.runTask(whenDone);
        }
        return;
    }
    final CompoundTag weTag = (CompoundTag) FaweCache.INSTANCE.asTag(tag);
    SchematicHandler.upload(uuid, file, "schem", new RunnableVal<>() {

        @Override
        public void run(OutputStream output) {
            if (weTag instanceof CompressedSchematicTag) {
                Clipboard clipboard = ((CompressedSchematicTag) weTag).getSource();
                BuiltInClipboardFormat.FAST.write(output, clipboard);
            }
            try {
                try (ParallelGZIPOutputStream gzip = new ParallelGZIPOutputStream(output)) {
                    try (NBTOutputStream nos = new NBTOutputStream(gzip)) {
                        Map<String, Tag> map = weTag.getValue();
                        nos.writeNamedTag("Schematic", map.getOrDefault("Schematic", weTag));
                    }
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }, whenDone);
}
Also used : CompressedSchematicTag(com.fastasyncworldedit.core.jnbt.CompressedSchematicTag) ParallelGZIPOutputStream(org.anarres.parallelgzip.ParallelGZIPOutputStream) NBTOutputStream(com.sk89q.jnbt.NBTOutputStream) ParallelGZIPOutputStream(org.anarres.parallelgzip.ParallelGZIPOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) Clipboard(com.sk89q.worldedit.extent.clipboard.Clipboard) IOException(java.io.IOException) NBTOutputStream(com.sk89q.jnbt.NBTOutputStream) Map(java.util.Map) CompressedCompoundTag(com.fastasyncworldedit.core.jnbt.CompressedCompoundTag) CompoundTag(com.sk89q.jnbt.CompoundTag)

Aggregations

CompressedCompoundTag (com.fastasyncworldedit.core.jnbt.CompressedCompoundTag)2 CompressedSchematicTag (com.fastasyncworldedit.core.jnbt.CompressedSchematicTag)2 CompoundTag (com.sk89q.jnbt.CompoundTag)2 NBTOutputStream (com.sk89q.jnbt.NBTOutputStream)2 Clipboard (com.sk89q.worldedit.extent.clipboard.Clipboard)2 BufferedOutputStream (java.io.BufferedOutputStream)2 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 OutputStream (java.io.OutputStream)2 ParallelGZIPOutputStream (org.anarres.parallelgzip.ParallelGZIPOutputStream)2 FastSchematicWriter (com.fastasyncworldedit.core.extent.clipboard.io.FastSchematicWriter)1 Tag (com.sk89q.jnbt.Tag)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 Map (java.util.Map)1 LZ4BlockInputStream (net.jpountz.lz4.LZ4BlockInputStream)1