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