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();
}
}
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);
}
}
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());
}
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);
}
}
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);
}
}
}
Aggregations