Search in sources :

Example 6 with NbtInputStream

use of net.glowstone.util.nbt.NbtInputStream in project Glowstone by GlowstoneMC.

the class NbtStructureDataService method writeStructuresData.

@Override
public void writeStructuresData(Map<Integer, GlowStructure> structures) {
    for (GlowStructure structure : structures.values()) {
        if (structure.isDirty()) {
            CompoundTag root = new CompoundTag();
            CompoundTag data = new CompoundTag();
            CompoundTag features = new CompoundTag();
            CompoundTag feature = new CompoundTag();
            StructureStore<GlowStructure> store = StructureStorage.saveStructure(structure, feature);
            File structureFile = new File(structureDir, store.getId() + ".dat");
            if (structureFile.exists()) {
                try (NBTInputStream in = new NBTInputStream(new FileInputStream(structureFile))) {
                    data = new CompoundTag();
                    data = in.readCompound();
                    if (data.isCompound("data")) {
                        data = data.getCompound("data");
                        if (data.isCompound("Features")) {
                            features = data.getCompound("Features");
                        }
                    }
                } catch (IOException e) {
                    server.getLogger().log(Level.SEVERE, "Failed to read structure data from " + structureFile, e);
                }
            }
            String key = "[" + structure.getChunkX() + "," + structure.getChunkZ() + "]";
            features.putCompound(key, feature);
            data.putCompound("Features", features);
            root.putCompound("data", data);
            try (NBTOutputStream nbtOut = new NBTOutputStream(new FileOutputStream(structureFile))) {
                nbtOut.writeTag(root);
            } catch (IOException e) {
                server.getLogger().log(Level.SEVERE, "Failed to write structure data to " + structureFile, e);
            }
            structure.setDirty(false);
        }
    }
}
Also used : GlowStructure(net.glowstone.generator.structures.GlowStructure) FileOutputStream(java.io.FileOutputStream) NBTInputStream(net.glowstone.util.nbt.NBTInputStream) IOException(java.io.IOException) File(java.io.File) NBTOutputStream(net.glowstone.util.nbt.NBTOutputStream) CompoundTag(net.glowstone.util.nbt.CompoundTag) FileInputStream(java.io.FileInputStream)

Example 7 with NbtInputStream

use of net.glowstone.util.nbt.NbtInputStream in project Glowstone by GlowstoneMC.

the class GlowBufUtils method readCompound.

private static CompoundTag readCompound(ByteBuf buf, boolean network) {
    int idx = buf.readerIndex();
    if (buf.readByte() == 0) {
        return null;
    }
    buf.readerIndex(idx);
    try (NBTInputStream str = new NBTInputStream(new ByteBufInputStream(buf), false)) {
        return str.readCompound(network ? new NBTReadLimiter(2097152L) : NBTReadLimiter.UNLIMITED);
    } catch (IOException e) {
        return null;
    }
}
Also used : NBTInputStream(net.glowstone.util.nbt.NBTInputStream) NBTReadLimiter(net.glowstone.util.nbt.NBTReadLimiter) ByteBufInputStream(io.netty.buffer.ByteBufInputStream) IOException(java.io.IOException)

Example 8 with NbtInputStream

use of net.glowstone.util.nbt.NbtInputStream in project Glowstone by GlowstoneMC.

the class NbtScoreboardIoReader method readMainScoreboard.

public static GlowScoreboard readMainScoreboard(File path) throws IOException {
    CompoundTag root;
    try (NBTInputStream nbt = new NBTInputStream(getDataInputStream(path), true)) {
        root = nbt.readCompound().getCompound("data");
    }
    GlowScoreboard scoreboard = new GlowScoreboard();
    registerObjectives(root, scoreboard);
    registerScores(root, scoreboard);
    registerTeams(root, scoreboard);
    registerDisplaySlots(root, scoreboard);
    return scoreboard;
}
Also used : NBTInputStream(net.glowstone.util.nbt.NBTInputStream) CompoundTag(net.glowstone.util.nbt.CompoundTag)

Aggregations

NBTInputStream (net.glowstone.util.nbt.NBTInputStream)8 CompoundTag (net.glowstone.util.nbt.CompoundTag)7 IOException (java.io.IOException)5 File (java.io.File)3 FileInputStream (java.io.FileInputStream)3 GlowStructure (net.glowstone.generator.structures.GlowStructure)2 ByteBufInputStream (io.netty.buffer.ByteBufInputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 FileOutputStream (java.io.FileOutputStream)1 HashMap (java.util.HashMap)1 UUID (java.util.UUID)1 GlowBlock (net.glowstone.block.GlowBlock)1 BlockType (net.glowstone.block.blocktype.BlockType)1 BlockEntity (net.glowstone.block.entity.BlockEntity)1 ChunkSection (net.glowstone.chunk.ChunkSection)1 Key (net.glowstone.chunk.GlowChunk.Key)1 NBTOutputStream (net.glowstone.util.nbt.NBTOutputStream)1 NBTReadLimiter (net.glowstone.util.nbt.NBTReadLimiter)1 Location (org.bukkit.Location)1