private static DefaultMutableTreeNode getNode(CompoundTag tag) { CompoundMap map = tag.getValue(); DefaultMutableTreeNode root = new DefaultMutableTreeNode(tag.getName() + " [Map]"); for (Tag<?> t : map.values()) { DefaultMutableTreeNode child = getNode(t); root.add(child); } return root; }
/** * 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)); }
/** * 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)); }
private static DefaultMutableTreeNode getNode(CompoundTag tag) { CompoundMap map = tag.getValue(); DefaultMutableTreeNode root = new DefaultMutableTreeNode(tag.getName() + " [Map]"); for (Tag<?> t : map.values()) { DefaultMutableTreeNode child = getNode(t); root.add(child); } return root; }
private static DefaultMutableTreeNode getNode(CompoundTag tag) { CompoundMap map = tag.getValue(); DefaultMutableTreeNode root = new DefaultMutableTreeNode(tag.getName() + " [Map]"); for (Tag<?> t : map.values()) { DefaultMutableTreeNode child = getNode(t); root.add(child); } return root; }
/** * 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)); }
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 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(); } }
/** * 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? }
/** * 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? }
/** * 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? }