/** * Clones a Map<String, Tag> * * @param map the map * @return a clone of the map */ public static Map<String, Tag<?>> cloneMap(Map<String, Tag<?>> map) { if (map == null) { return null; } Map<String, Tag<?>> newMap = new HashMap<String, Tag<?>>(); for (Entry<String, Tag<?>> entry : map.entrySet()) { newMap.put(entry.getKey(), entry.getValue().clone()); } return newMap; }
/** * Writes a tag. * * @param tag The tag to write. * @throws java.io.IOException if an I/O error occurs. */ public void writeTag(Tag<?> tag) throws IOException { String name = tag.getName(); byte[] nameBytes = name.getBytes(NBTConstants.CHARSET.name()); os.writeByte(tag.getType().getId()); os.writeShort(nameBytes.length); os.write(nameBytes); if (tag.getType() == TagType.TAG_END) { throw new IOException("Named TAG_End not permitted."); } writeTagPayload(tag); }
/** * Takes in an NBT tag, sanely checks null status, and then returns its value. * * @param t Tag to get value from * @return tag value as an object or null if no value */ public static Object toTagValue(Tag<?> t) { if (t == null) { return null; } else { return t.getValue(); } }
/** * Puts a tag in this map, getting the string from the tag * * @param tag to add * @return the previous value */ public Tag<?> put(Tag<?> tag) { return map.put(tag.getName(), tag); }
@Override public boolean equals(Object o) { if (o instanceof CompoundMap) { CompoundMap other = (CompoundMap) o; Iterator<Tag<?>> iThis = iterator(); Iterator<Tag<?>> iOther = other.iterator(); while (iThis.hasNext() && iOther.hasNext()) { Tag tThis = iThis.next(); Tag tOther = iOther.next(); if (!tThis.equals(tOther)) { return false; } } if (iThis.hasNext() || iOther.hasNext()) { return false; } return true; } else { return false; } } }
/** * Writes a tag. * * @param tag The tag to write. * @throws java.io.IOException if an I/O error occurs. */ public void writeTag(Tag<?> tag) throws IOException { String name = tag.getName(); byte[] nameBytes = name.getBytes(NBTConstants.CHARSET.name()); os.writeByte(tag.getType().getId()); os.writeShort(nameBytes.length); os.write(nameBytes); if (tag.getType() == TagType.TAG_END) { throw new IOException("Named TAG_End not permitted."); } writeTagPayload(tag); }
/** * Takes in an NBT tag, sanely checks null status, and then returns its value. * * @param t Tag to get value from * @return tag value as an object or null if no value */ public static Object toTagValue(Tag<?> t) { if (t == null) { return null; } else { return t.getValue(); } }
/** * Puts a tag in this map, getting the string from the tag * * @param tag to add * @return the previous value */ public Tag<?> put(Tag<?> tag) { return map.put(tag.getName(), tag); }
@Override public boolean equals(Object o) { if (o instanceof CompoundMap) { CompoundMap other = (CompoundMap) o; Iterator<Tag<?>> iThis = iterator(); Iterator<Tag<?>> iOther = other.iterator(); while (iThis.hasNext() && iOther.hasNext()) { Tag tThis = iThis.next(); Tag tOther = iOther.next(); if (!tThis.equals(tOther)) { return false; } } if (iThis.hasNext() || iOther.hasNext()) { return false; } return true; } else { return false; } } }
/** * Writes a tag. * * @param tag The tag to write. * @throws java.io.IOException if an I/O error occurs. */ public void writeTag(Tag<?> tag) throws IOException { String name = tag.getName(); byte[] nameBytes = name.getBytes(NBTConstants.CHARSET.name()); os.writeByte(tag.getType().getId()); os.writeShort(nameBytes.length); os.write(nameBytes); if (tag.getType() == TagType.TAG_END) { throw new IOException("Named TAG_End not permitted."); } writeTagPayload(tag); }
/** * Takes in an NBT tag, sanely checks null status, and then returns its value. * * @param t Tag to get value from * @return tag value as an object or null if no value */ public static Object toTagValue(Tag<?> t) { if (t == null) { return null; } else { return t.getValue(); } }
/** * Puts a tag in this map, getting the string from the tag * * @param tag to add * @return the previous value */ public Tag<?> put(Tag<?> tag) { return map.put(tag.getName(), tag); }
@Override public boolean equals(Object o) { if (o instanceof CompoundMap) { CompoundMap other = (CompoundMap) o; Iterator<Tag<?>> iThis = iterator(); Iterator<Tag<?>> iOther = other.iterator(); while (iThis.hasNext() && iOther.hasNext()) { Tag tThis = iThis.next(); Tag tOther = iOther.next(); if (!tThis.equals(tOther)) { return false; } } if (iThis.hasNext() || iOther.hasNext()) { return false; } return true; } else { return false; } } }
/** * Clones a Map<String, Tag> * * @param map the map * @return a clone of the map */ public static Map<String, Tag<?>> cloneMap(Map<String, Tag<?>> map) { if (map == null) { return null; } Map<String, Tag<?>> newMap = new HashMap<String, Tag<?>>(); for (Entry<String, Tag<?>> entry : map.entrySet()) { newMap.put(entry.getKey(), entry.getValue().clone()); } return newMap; }