public Tag<?> getValue(String name, T value) { return new CompoundTag(name, value.save()); } }
public CompoundTag clone() { CompoundMap map = new CompoundMap(value); return new CompoundTag(getName(), map); } }
public void saveServers(ServerInfo[] servers) throws IOException { if(file.exists()) if(!file.delete()) throw new IOException("Could not overwrite '".concat(file.getAbsolutePath()).concat("'")); final FileOutputStream fos = new FileOutputStream(file); NBTOutputStream nbtOutputStream = new NBTOutputStream(fos, false); ArrayList<CompoundTag> serversList = new ArrayList<CompoundTag>(); for(ServerInfo server : servers){ serversList.add(new CompoundTag("", createCompoundFromServer(server))); } ListTag<CompoundTag> listTag = new ListTag<CompoundTag>("servers", CompoundTag.class, serversList); CompoundTag root = new CompoundTag("", new CompoundMap()); root.getValue().put("servers", listTag); nbtOutputStream.writeTag(root); nbtOutputStream.flush(); fos.flush(); nbtOutputStream.close(); fos.close(); } }
/** * Get this field from a CompoundTag * * @param tag The tag to get this field from * @return The value */ public T load(CompoundTag tag) { Tag subTag = tag.getValue().get(key); if (subTag == null) { return (value = defaultValue); } return (value = field.getValue(subTag)); }
@Override public String toString() { String name = getName(); String append = ""; if (name != null && !name.equals("")) { append = "(\"" + this.getName() + "\")"; } StringBuilder bldr = new StringBuilder(); bldr.append("TAG_Compound").append(append).append(": ").append(value.size()).append(" entries\r\n{\r\n"); for (Tag entry : value.values()) { bldr.append(" ").append(entry.toString().replaceAll("\r\n", "\r\n ")).append("\r\n"); } bldr.append("}"); return bldr.toString(); }
public CompoundTag clone() { CompoundMap map = new CompoundMap(value); return new CompoundTag(getName(), map); } }
/** * Get this field from a CompoundTag * * @param tag The tag to get this field from * @return The value */ public T load(CompoundTag tag) { Tag subTag = tag.getValue().get(key); if (subTag == null) { return (value = defaultValue); } return (value = field.getValue(subTag)); }
@Override public String toString() { String name = getName(); String append = ""; if (name != null && !name.equals("")) { append = "(\"" + this.getName() + "\")"; } StringBuilder bldr = new StringBuilder(); bldr.append("TAG_Compound").append(append).append(": ").append(value.size()).append(" entries\r\n{\r\n"); for (Tag entry : value.values()) { bldr.append(" ").append(entry.toString().replaceAll("\r\n", "\r\n ")).append("\r\n"); } bldr.append("}"); return bldr.toString(); }
public Tag<?> getValue(String name, T value) { return new CompoundTag(name, value.save()); } }
public CompoundTag clone() { CompoundMap map = new CompoundMap(value); return new CompoundTag(getName(), map); } }
/** * Get this field from a CompoundTag * * @param tag The tag to get this field from * @return The value */ public T load(CompoundTag tag) { Tag subTag = tag.getValue().get(key); if (subTag == null) { return (value = defaultValue); } return (value = field.getValue(subTag)); }
@Override public String toString() { String name = getName(); String append = ""; if (name != null && !name.equals("")) { append = "(\"" + this.getName() + "\")"; } StringBuilder bldr = new StringBuilder(); bldr.append("TAG_Compound").append(append).append(": ").append(value.size()).append(" entries\r\n{\r\n"); for (Tag entry : value.values()) { bldr.append(" ").append(entry.toString().replaceAll("\r\n", "\r\n ")).append("\r\n"); } bldr.append("}"); return bldr.toString(); }
public Tag<?> getValue(String name, T value) { return new CompoundTag(name, value.save()); } }
public ServerInfo[] loadServers() throws Exception{ final FileInputStream fis = new FileInputStream(file); NBTInputStream nbtIs = new NBTInputStream(fis, false); // the cast should be safe, because compound tag is also a root container of contents in the file... final CompoundTag root = (CompoundTag) nbtIs.readTag(); nbtIs.close(); ListTag serversListTag = (ListTag) root.getValue().get("servers"); if(serversListTag.getElementType() != CompoundTag.class) { throw new Exception("Type of list value in servers file is not tag_compound!"); } List<CompoundTag> serversList = serversListTag.getValue(); ServerInfo[] result = new ServerInfo[serversList.size()]; for(int i = 0; i < serversList.size(); ++i){ result[i] = createServerFromTag(serversList.get(i).getValue()); } return result; }
public void save(OutputStream stream, boolean compressed) throws IOException { NBTOutputStream os = new NBTOutputStream(stream, compressed); os.writeTag(new CompoundTag("", save())); }
/** * Writes a {@code TAG_Compound} tag. * * @param tag The tag. * @throws java.io.IOException if an I/O error occurs. */ private void writeCompoundTagPayload(CompoundTag tag) throws IOException { for (Tag<?> childTag : tag.getValue().values()) { writeTag(childTag); } os.writeByte(TagType.TAG_END.getId()); // end tag - better way? }
public void save(OutputStream stream, boolean compressed) throws IOException { NBTOutputStream os = new NBTOutputStream(stream, compressed); os.writeTag(new CompoundTag("", save())); }