Search in sources :

Example 1 with NbtOutputStream

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

the class NbtScoreboardIoWriter method writeMainScoreboard.

public static void writeMainScoreboard(File path, GlowScoreboard scoreboard) throws IOException {
    CompoundTag root = new CompoundTag();
    CompoundTag data = new CompoundTag();
    root.putCompound("data", data);
    try (NBTOutputStream nbt = new NBTOutputStream(getDataOutputStream(path), true)) {
        writeObjectives(data, scoreboard);
        writeScores(data, scoreboard);
        writeTeams(data, scoreboard);
        writeDisplaySlots(data, scoreboard);
        nbt.writeTag(root);
        nbt.close();
    }
}
Also used : NBTOutputStream(net.glowstone.util.nbt.NBTOutputStream) CompoundTag(net.glowstone.util.nbt.CompoundTag)

Example 2 with NbtOutputStream

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

the class NbtPlayerDataService method writeData.

@Override
public void writeData(GlowPlayer player) {
    File playerFile = getPlayerFile(player.getUniqueId());
    CompoundTag tag = new CompoundTag();
    EntityStorage.save(player, tag);
    try (NBTOutputStream out = new NBTOutputStream(new FileOutputStream(playerFile))) {
        out.writeTag(tag);
    } catch (IOException e) {
        player.kickPlayer("Failed to save player data!");
        server.getLogger().log(Level.SEVERE, "Failed to write data for " + player.getName() + ": " + playerFile, e);
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File) NBTOutputStream(net.glowstone.util.nbt.NBTOutputStream) CompoundTag(net.glowstone.util.nbt.CompoundTag)

Example 3 with NbtOutputStream

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

the class GlowBufUtils method writeCompound.

/**
     * Write an uncompressed compound NBT tag to the buffer.
     *
     * @param buf  The buffer.
     * @param data The tag to write, or null.
     */
public static void writeCompound(ByteBuf buf, CompoundTag data) {
    if (data == null) {
        buf.writeByte(0);
        return;
    }
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try (NBTOutputStream str = new NBTOutputStream(out, false)) {
        str.writeTag(data);
    } catch (IOException e) {
        GlowServer.logger.log(Level.WARNING, "Error serializing NBT: " + data, e);
        return;
    }
    buf.writeBytes(out.toByteArray());
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) NBTOutputStream(net.glowstone.util.nbt.NBTOutputStream)

Example 4 with NbtOutputStream

use of net.glowstone.util.nbt.NbtOutputStream in project Dragonet-Legacy by DragonetMC.

the class PEInventorySlot method writeSlot.

public static void writeSlot(PEBinaryWriter writer, PEInventorySlot slot) throws IOException {
    if (slot == null || (slot != null && slot.id == 0)) {
        writer.writeShort((short) 0);
        return;
    }
    writer.writeShort(slot.id);
    writer.writeByte(slot.count);
    writer.writeShort(slot.meta);
    if (slot.nbt == null) {
        writer.writeShort((short) 0);
    } else {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        NBTOutputStream nos = new NBTOutputStream(bos);
        nos.writeTag(slot.nbt);
        byte[] nbtdata = bos.toByteArray();
        writer.writeShort((short) (nbtdata.length & 0xFFFF));
        writer.write(nbtdata);
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) NBTOutputStream(net.glowstone.util.nbt.NBTOutputStream)

Example 5 with NbtOutputStream

use of net.glowstone.util.nbt.NbtOutputStream 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)

Aggregations

NBTOutputStream (net.glowstone.util.nbt.NBTOutputStream)7 CompoundTag (net.glowstone.util.nbt.CompoundTag)5 IOException (java.io.IOException)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 Location (org.bukkit.Location)2 FileInputStream (java.io.FileInputStream)1 ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1 BlockEntity (net.glowstone.block.entity.BlockEntity)1 ChunkSection (net.glowstone.chunk.ChunkSection)1 GlowChunkSnapshot (net.glowstone.chunk.GlowChunkSnapshot)1 GlowEntity (net.glowstone.entity.GlowEntity)1 GlowStructure (net.glowstone.generator.structures.GlowStructure)1 NBTInputStream (net.glowstone.util.nbt.NBTInputStream)1