diff --git a/src/com/evilco/mc/nbt/EVILCO NBT LIBRARY LICENSE b/src/com/evilco/mc/nbt/EVILCO NBT LIBRARY LICENSE deleted file mode 100644 index 9b5e401..0000000 --- a/src/com/evilco/mc/nbt/EVILCO NBT LIBRARY LICENSE +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. \ No newline at end of file diff --git a/src/com/evilco/mc/nbt/error/TagNotFoundException.java b/src/com/evilco/mc/nbt/error/TagNotFoundException.java deleted file mode 100644 index 9cbe16b..0000000 --- a/src/com/evilco/mc/nbt/error/TagNotFoundException.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.evilco.mc.nbt.error; - -import java.io.IOException; - -/** - * An exception that is thrown when trying to access a component of a CompoundTag that does not exist - */ -public class TagNotFoundException extends IOException { - private static final long serialVersionUID = -4631008535746749103L; - - /** - * Constructs a TagNotFoundException with a default message - */ - public TagNotFoundException() { - super("The tag does not exist"); - } - - /** - * Constructs a TagNotFoundException with the given message - * @param message the exception message - */ - public TagNotFoundException(String message) { - super(message); - } - - /** - * Constructs a TagNotFoundException with a cause - * @param cause the cause exception - */ - public TagNotFoundException(Throwable cause) { - super(cause); - } - - /** - * Constructs a TagNotFoundException with the given message and a cause - * @param message the exception message - * @param cause the cause exception - */ - public TagNotFoundException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/src/com/evilco/mc/nbt/error/UnexpectedTagTypeException.java b/src/com/evilco/mc/nbt/error/UnexpectedTagTypeException.java deleted file mode 100644 index 7a32e5c..0000000 --- a/src/com/evilco/mc/nbt/error/UnexpectedTagTypeException.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.evilco.mc.nbt.error; - -import java.io.IOException; - -/** - * An exception that is thrown when an entry of a TagCompound or TagList - * is not of the expected tag type - */ -public class UnexpectedTagTypeException extends IOException { - private static final long serialVersionUID = -6604963428978583800L; - - /** - * Constructs an UnexpectedTagTypeException with a default message - */ - public UnexpectedTagTypeException() { - super("The tag is not of the expected type"); - } - - /** - * Constructs an UnexpectedTagTypeException with the given message - * @param message the exception message - */ - public UnexpectedTagTypeException(String message) { - super(message); - } - - /** - * Constructs an UnexpectedTagTypeException with a cause - * @param cause the cause exception - */ - public UnexpectedTagTypeException(Throwable cause) { - super(cause); - } - - /** - * Constructs an UnexpectedTagTypeException with the given message and a cause - * @param message the exception message - * @param cause the cause exception - */ - public UnexpectedTagTypeException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/src/com/evilco/mc/nbt/stream/NbtInputStream.java b/src/com/evilco/mc/nbt/stream/NbtInputStream.java deleted file mode 100644 index d61d936..0000000 --- a/src/com/evilco/mc/nbt/stream/NbtInputStream.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.evilco.mc.nbt.stream; - -import com.evilco.mc.nbt.tag.ITag; -import com.evilco.mc.nbt.tag.TagType; - -import java.io.DataInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.lang.reflect.Constructor; - -/** - * @auhtor Johannes Donath - * @copyright Copyright (C) 2014 Evil-Co - */ -public class NbtInputStream extends DataInputStream { - - /** - * Constructs a new NbtInputStream. - * @param in - */ - public NbtInputStream (InputStream in) { - super (in); - } - - /** - * Reads a single tag. - * @return - * @throws IOException - */ - public ITag readTag () throws IOException { - // remove first byte - byte type = this.readByte (); - - // find type - TagType tagType = TagType.valueOf (type); - - // verify - if (tagType == null) throw new IOException ("Invalid NBT tag: Found unknown tag type " + type + "."); - - // END? - if (tagType == TagType.END) return null; - - // read tag - return this.readTag (tagType, false); - } - - /** - * Reads a single tag. - * @param type - * @param anonymous - * @return - * @throws IOException - */ - public ITag readTag (TagType type, boolean anonymous) throws IOException { - // find constructor - Constructor constructor = null; - - try { - constructor = type.tagType.getConstructor (NbtInputStream.class, boolean.class); - } catch (NoSuchMethodException ex) { - throw new IOException ("Invalid NBT implementation state: Type " + type.tagType.getName () + " has no de-serialization constructor."); - } - - // create a new instance - try { - return constructor.newInstance (this, anonymous); - } catch (Exception ex) { - throw new IOException ("Invalid NBT implementation state: Type " + type.tagType.getName () + " in (" + this.getClass ().getName () + ") has no valid constructor: " + ex.getMessage (), ex); - } - } -} \ No newline at end of file diff --git a/src/com/evilco/mc/nbt/stream/NbtOutputStream.java b/src/com/evilco/mc/nbt/stream/NbtOutputStream.java deleted file mode 100644 index 0d93307..0000000 --- a/src/com/evilco/mc/nbt/stream/NbtOutputStream.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.evilco.mc.nbt.stream; - -import com.evilco.mc.nbt.tag.ITag; - -import java.io.DataOutputStream; -import java.io.IOException; -import java.io.OutputStream; - -/** - * @auhtor Johannes Donath - * @copyright Copyright (C) 2014 Evil-Co - */ -public class NbtOutputStream extends DataOutputStream { - - /** - * Constructs a new NbtOutputStream. - * @param out - */ - public NbtOutputStream (OutputStream out) { - super (out); - } - - /** - * Writes a tag into the stream. - * @param tag - * @throws IOException - */ - public void write (ITag tag) throws IOException { - // write tag information - this.writeByte (tag.getTagID ()); - - // write tag - tag.write (this, false); - } -} \ No newline at end of file diff --git a/src/com/evilco/mc/nbt/tag/AbstractTag.java b/src/com/evilco/mc/nbt/tag/AbstractTag.java deleted file mode 100644 index e9b2d48..0000000 --- a/src/com/evilco/mc/nbt/tag/AbstractTag.java +++ /dev/null @@ -1,138 +0,0 @@ -package com.evilco.mc.nbt.tag; - -import java.io.IOException; - -import com.evilco.mc.nbt.stream.NbtInputStream; -import com.evilco.mc.nbt.stream.NbtOutputStream; -import com.google.common.base.Preconditions; - - -/** - * @auhtor Johannes Donath - * @copyright Copyright (C) 2014 Evil-Co - */ -public abstract class AbstractTag implements ITag { - - /** - * Stores the tag name. - */ - protected String name; - - /** - * Stores the parent tag. - */ - protected ITagContainer parent = null; - - /** - * Constructs a new AbstractTag. - * @param name The tag name. - */ - public AbstractTag ( String name) { - this.setName (name); - } - - /** - * Constructs a new AbstractTag. - * @param inputStream - * @param anonymous - * @throws java.io.IOException - */ - public AbstractTag ( NbtInputStream inputStream, boolean anonymous) throws IOException { - // validate arguments - Preconditions.checkNotNull (inputStream, "inputStream"); - - // read name - if (!anonymous) { - // read name size - int nameSize = inputStream.readShort (); - byte[] nameBytes = new byte[nameSize]; - - // read name - inputStream.readFully (nameBytes); - this.setName (new String (nameBytes, STRING_CHARSET)); - } - } - - /** - * {@inheritDoc} - */ - @Override - public String getName () { - return this.name; - } - - /** - * {@inheritDoc} - */ - @Override - public byte[] getNameBytes () { - return this.name.getBytes (STRING_CHARSET); - } - - /** - * {@inheritDoc} - */ - @Override - public ITagContainer getParent () { - return this.parent; - } - - /** - * {@inheritDoc} - */ - @Override - public abstract byte getTagID (); - - /** - * {@inheritDoc} - */ - @Override - public void setName ( String name) { - // check arguments - Preconditions.checkNotNull (name, "name"); - - // remove previous tag - if (this.getParent () != null) this.getParent ().removeTag (this); - - // update name - this.name = name; - - // add new tag - if (this.getParent () != null) { - if (this.getParent () instanceof IAnonymousTagContainer) - ((IAnonymousTagContainer) this.getParent ()).addTag (this); - else - ((INamedTagContainer) this.getParent ()).setTag (this); - } - } - - /** - * {@inheritDoc} - */ - @Override - public void setParent ( ITagContainer parent) { - // remove from old parent - if (this.getParent () != null) this.getParent ().removeTag (this); - - // set new parent - this.parent = parent; - } - - /** - * {@inheritDoc} - */ - @Override - public void write (NbtOutputStream outputStream, boolean anonymous) throws IOException { - // write name - if (!anonymous) { - // get name - byte[] name = this.getNameBytes (); - - // write size - outputStream.writeShort (name.length); - - // write bytes - outputStream.write (name); - } - }; -} \ No newline at end of file diff --git a/src/com/evilco/mc/nbt/tag/IAnonymousTagContainer.java b/src/com/evilco/mc/nbt/tag/IAnonymousTagContainer.java deleted file mode 100644 index d905498..0000000 --- a/src/com/evilco/mc/nbt/tag/IAnonymousTagContainer.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.evilco.mc.nbt.tag; - -import com.evilco.mc.nbt.error.UnexpectedTagTypeException; - -import java.util.List; - -/** - * @auhtor Johannes Donath - * @copyright Copyright (C) 2014 Evil-Co - */ -public interface IAnonymousTagContainer extends ITagContainer { - - /** - * Adds a new tag. - * @param tag - */ - public void addTag ( ITag tag); - - /** - * Returns a list of all tags. - * @return - */ - public List getTags (); - - /** - * Gets all tags in this container, ensuring their type is as expected - * @param tagClass the expected tag type of the contents - * @return the tags in this container - * @throws com.evilco.mc.nbt.error.UnexpectedTagTypeException at least one tag in this container is not of the expected type - */ - public List getTags(Class tagClass) throws UnexpectedTagTypeException; - - /** - * Sets a tag. - * @param i - * @param tag - */ - public void setTag (int i, ITag tag); -} \ No newline at end of file diff --git a/src/com/evilco/mc/nbt/tag/INamedTagContainer.java b/src/com/evilco/mc/nbt/tag/INamedTagContainer.java deleted file mode 100644 index eb0d603..0000000 --- a/src/com/evilco/mc/nbt/tag/INamedTagContainer.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.evilco.mc.nbt.tag; - -import com.evilco.mc.nbt.error.TagNotFoundException; -import com.evilco.mc.nbt.error.UnexpectedTagTypeException; - - -import java.util.Map; - -/** - * @auhtor Johannes Donath - * @copyright Copyright (C) 2014 Evil-Co - */ -public interface INamedTagContainer extends ITagContainer { - - /** - * Returns the tag associated with the given name. - * @param name The tag name. - */ - public ITag getTag ( String name); - - /** - * Returns the tag associated with the given name, ensuring its type is as expected - * @param name The tag name - * @param tagClass The expected tag type - * @return the tag - * @throws com.evilco.mc.nbt.error.UnexpectedTagTypeException The tag is found, but of different type than expected - * @throws com.evilco.mc.nbt.error.TagNotFoundException There is no tag with the given name in this container - */ - public T getTag(String name, Class tagClass) - throws UnexpectedTagTypeException, TagNotFoundException; - - /** - * Returns a named map of all tags. - * @return - */ - public Map getTags (); - - /** - * Removes a tag from the container. - * @param tag The tag name. - */ - public void removeTag ( String tag); - - /** - * Sets a new tag. - * @param tag The tag. - */ - public void setTag ( ITag tag); -} \ No newline at end of file diff --git a/src/com/evilco/mc/nbt/tag/ITag.java b/src/com/evilco/mc/nbt/tag/ITag.java deleted file mode 100644 index 378969f..0000000 --- a/src/com/evilco/mc/nbt/tag/ITag.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.evilco.mc.nbt.tag; - -import com.evilco.mc.nbt.stream.NbtOutputStream; - -import java.io.IOException; -import java.nio.charset.Charset; - -/** - * @auhtor Johannes Donath - * @copyright Copyright (C) 2014 Evil-Co - */ -public interface ITag { - - /** - * Defines the string charset. - */ - public static final Charset STRING_CHARSET = Charset.forName ("UTF-8"); - - /** - * Returns the tag name. - * @return The tag identifier. - */ - public String getName (); - - /** - * Returns the name bytes. - * @return Name string in UTF-8 bytes. - */ - public byte[] getNameBytes (); - - /** - * Returns the parent tag. - * @return The parent tag container (if any). - */ - public ITagContainer getParent (); - - /** - * Returns the tag ID. - * @return The tag numerical identifier. - */ - public byte getTagID (); - - /** - * Sets a new name. - * @param name The new name. - */ - public void setName ( String name); - - /** - * Sets a new parent. - * @param parent The new parent tag container. - */ - public void setParent ( ITagContainer parent); - - /** - * Writes a tag into a byte buffer. - * @param outputStream - * @param anonymous - */ - public void write (NbtOutputStream outputStream, boolean anonymous) throws IOException; -} \ No newline at end of file diff --git a/src/com/evilco/mc/nbt/tag/ITagContainer.java b/src/com/evilco/mc/nbt/tag/ITagContainer.java deleted file mode 100644 index 7827bd4..0000000 --- a/src/com/evilco/mc/nbt/tag/ITagContainer.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.evilco.mc.nbt.tag; - - -/** - * @auhtor Johannes Donath - * @copyright Copyright (C) 2014 Evil-Co - */ -public interface ITagContainer extends ITag { - - /** - * Removes a tag from the container. - * @param tag The tag. - * @return - */ - public void removeTag ( ITag tag); -} \ No newline at end of file diff --git a/src/com/evilco/mc/nbt/tag/TagByte.java b/src/com/evilco/mc/nbt/tag/TagByte.java deleted file mode 100644 index fcd1c4e..0000000 --- a/src/com/evilco/mc/nbt/tag/TagByte.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.evilco.mc.nbt.tag; - -import com.evilco.mc.nbt.stream.NbtInputStream; -import com.evilco.mc.nbt.stream.NbtOutputStream; - -import java.io.IOException; - -/** - * @auhtor Johannes Donath - * @copyright Copyright (C) 2014 Evil-Co - */ -public class TagByte extends AbstractTag { - - /** - * Stores the byte value. - */ - protected byte value; - - /** - * Constructs a new TagByte. - * @param name - * @param value - */ - public TagByte ( String name, byte value) { - super (name); - this.setValue (value); - } - - /** - * Constructs a new TagByte. - * @param inputStream - * @param anonymous - * @throws IOException - */ - public TagByte ( NbtInputStream inputStream, boolean anonymous) throws IOException { - super (inputStream, anonymous); - - // read value - this.setValue (inputStream.readByte ()); - } - - /** - * {@inheritDoc} - */ - @Override - public byte getTagID () { - return TagType.BYTE.typeID; - } - - /** - * Returns the current tag value. - * @return - */ - public byte getValue () { - return this.value; - } - - /** - * Sets a new byte value. - * @param b - */ - public void setValue (byte b) { - this.value = b; - } - - /** - * {@inheritDoc} - */ - @Override - public void write (NbtOutputStream outputStream, boolean anonymous) throws IOException { - super.write (outputStream, anonymous); - - // write value - outputStream.write (this.getValue ()); - } -} \ No newline at end of file diff --git a/src/com/evilco/mc/nbt/tag/TagByteArray.java b/src/com/evilco/mc/nbt/tag/TagByteArray.java deleted file mode 100644 index cac8b5f..0000000 --- a/src/com/evilco/mc/nbt/tag/TagByteArray.java +++ /dev/null @@ -1,91 +0,0 @@ -package com.evilco.mc.nbt.tag; - -import com.evilco.mc.nbt.stream.NbtInputStream; -import com.evilco.mc.nbt.stream.NbtOutputStream; -import com.google.common.base.Preconditions; - -import java.io.IOException; - -/** - * @auhtor Johannes Donath - * @copyright Copyright (C) 2014 Evil-Co - */ -public class TagByteArray extends AbstractTag { - - /** - * Stores the tag value. - */ - protected byte[] value; - - /** - * Constructs a new TagByteArray. - * @param name - * @param value - */ - public TagByteArray ( String name, byte[] value) { - super (name); - this.setValue (value); - } - - /** - * Constructs a new TagByteArray. - * @param inputStream - * @param anonymous - * @throws IOException - */ - public TagByteArray ( NbtInputStream inputStream, boolean anonymous) throws IOException { - super (inputStream, anonymous); - - // read size - int size = inputStream.readInt (); - - // read data - byte[] data = new byte[size]; - inputStream.readFully (data); - - // store data - this.setValue (data); - } - - /** - * {@inheritDoc} - */ - @Override - public byte getTagID () { - return TagType.BYTE_ARRAY.typeID; - } - - /** - * Returns the tag value. - * @return - */ - public byte[] getValue () { - return this.value; - } - - /** - * Sets a new tag value. - * @param b - */ - public void setValue ( byte[] b) { - // check arguments - Preconditions.checkNotNull (b, "b"); - - // save value - this.value = b; - } - - /** - * {@inheritDoc} - */ - @Override - public void write (NbtOutputStream outputStream, boolean anonymous) throws IOException { - super.write (outputStream, anonymous); - - // write size - outputStream.writeInt (this.value.length); - - // write data - outputStream.write (this.value); - } -} \ No newline at end of file diff --git a/src/com/evilco/mc/nbt/tag/TagCompound.java b/src/com/evilco/mc/nbt/tag/TagCompound.java deleted file mode 100644 index 54e5967..0000000 --- a/src/com/evilco/mc/nbt/tag/TagCompound.java +++ /dev/null @@ -1,352 +0,0 @@ -package com.evilco.mc.nbt.tag; - -import com.evilco.mc.nbt.error.TagNotFoundException; -import com.evilco.mc.nbt.error.UnexpectedTagTypeException; -import com.evilco.mc.nbt.stream.NbtInputStream; -import com.evilco.mc.nbt.stream.NbtOutputStream; -import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableMap; - -import java.io.IOException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * @auhtor Johannes Donath - * @copyright Copyright (C) 2014 Evil-Co - */ -public class TagCompound extends AbstractTag implements INamedTagContainer { - - /** - * Stores all child tags. - */ - protected Map tags; - - /** - * Constructs a new TagCompound. - * @param name The tag name. - */ - public TagCompound (String name) { - super (name); - - this.tags = new HashMap<> (); - } - - /** - * Constructs a new TagCompound. - * @param inputStream - * @param anonymous - */ - public TagCompound ( NbtInputStream inputStream, boolean anonymous) throws IOException { - super (inputStream, anonymous); - - // create map - this.tags = new HashMap<> (); - - // attempt to read all elements - do { - // read type - byte type = inputStream.readByte (); - - // get type - TagType tagType = TagType.valueOf (type); - - // error! - if (tagType == null) throw new IOException ("Could not find a tag for type ID " + type + "."); - - // reached end - if (tagType == TagType.END) break; - - // read tag - this.setTag (inputStream.readTag (tagType, false)); - } while (true); - } - - /** - * {@inheritDoc} - */ - @Override - public ITag getTag ( String name) { - // check arguments - Preconditions.checkNotNull (name, "name"); - - // return tag - return this.tags.get (name); - } - - /** - * {@inheritDoc} - */ - @SuppressWarnings("unchecked") - public T getTag(String name, Class tagClass) - throws UnexpectedTagTypeException, TagNotFoundException { - ITag tag = getTag(name); - - if (tag == null) - throw new TagNotFoundException( - "The compound tag is missing a " + name + " entry"); - if (!tagClass.isInstance(tag)) - throw new UnexpectedTagTypeException("The compound entry " + name - + " should be of type " + tagClass.getSimpleName() - + ", but is of type " + tag.getClass().getSimpleName()); - - return (T) tag; - } - - /** - * Gets the tag of the given name and verifies that it is a compound tag - * @param name the tag's name - * @return the compound tag - * @throws UnexpectedTagTypeException the tag exists, but is not a compound tag - * @throws TagNotFoundException the tag does not exist - */ - public TagCompound getCompound(String name) throws UnexpectedTagTypeException, TagNotFoundException { - return getTag(name, TagCompound.class); - } - - /** - * Verifies that the tag of the given name is an integer tag and gets its value - * @param name the tag's name - * @return the tag's value - * @throws UnexpectedTagTypeException the tag exists, but is not an integer tag - * @throws TagNotFoundException the tag does not exist - */ - public int getInteger(String name) throws UnexpectedTagTypeException, TagNotFoundException { - return getTag(name, TagInteger.class).getValue(); - } - - /** - * Verifies that the tag of the given name is an short tag and gets its value - * @param name the tag's name - * @return the tag's value - * @throws UnexpectedTagTypeException the tag exists, but is not an short tag - * @throws TagNotFoundException the tag does not exist - */ - public short getShort(String name) throws UnexpectedTagTypeException, TagNotFoundException { - return getTag(name, TagShort.class).getValue(); - } - - /** - * Verifies that the tag of the given name is an byte tag and gets its value - * @param name the tag's name - * @return the tag's value - * @throws UnexpectedTagTypeException the tag exists, but is not an byte tag - * @throws TagNotFoundException the tag does not exist - */ - public byte getByte(String name) throws UnexpectedTagTypeException, TagNotFoundException { - return getTag(name, TagByte.class).getValue(); - } - - /** - * Verifies that the tag of the given name is an long tag and gets its value - * @param name the tag's name - * @return the tag's value - * @throws UnexpectedTagTypeException the tag exists, but is not an long tag - * @throws TagNotFoundException the tag does not exist - */ - public long getLong(String name) throws UnexpectedTagTypeException, TagNotFoundException { - return getTag(name, TagLong.class).getValue(); - } - - /** - * Verifies that the tag of the given name is an double tag and gets its value - * @param name the tag's name - * @return the tag's value - * @throws UnexpectedTagTypeException the tag exists, but is not an double tag - * @throws TagNotFoundException the tag does not exist - */ - public double getDouble(String name) throws UnexpectedTagTypeException, TagNotFoundException { - return getTag(name, TagDouble.class).getValue(); - } - - /** - * Verifies that the tag of the given name is an float tag and gets its value - * @param name the tag's name - * @return the tag's value - * @throws UnexpectedTagTypeException the tag exists, but is not an float tag - * @throws TagNotFoundException the tag does not exist - */ - public float getFloat(String name) throws UnexpectedTagTypeException, TagNotFoundException { - return getTag(name, TagFloat.class).getValue(); - } - - /** - * Verifies that the tag of the given name is an string tag and gets its value - * @param name the tag's name - * @return the tag's value - * @throws UnexpectedTagTypeException the tag exists, but is not an string tag - * @throws TagNotFoundException the tag does not exist - */ - public String getString(String name) throws UnexpectedTagTypeException, TagNotFoundException { - return getTag(name, TagString.class).getValue(); - } - - /** - * Gets the contents of the list tag and checks its item types - * @param name the tag's name - * @param itemClass the type the list items are expected to be of - * @return the contents of the list tag - * @throws UnexpectedTagTypeException the tag exists, but is not a list tag - or - - * the contents of the list tag are not of the expected type - * @throws TagNotFoundException the list tag does not exist - */ - public List getList(String name, Class itemClass) - throws UnexpectedTagTypeException, TagNotFoundException { - return getTag(name, TagList.class).getTags(itemClass); - } - - /** - * Verifies that the tag of the given name is an integer array tag and gets its value - * @param name the tag's name - * @return the tag's value - * @throws UnexpectedTagTypeException the tag exists, but is not an integer array tag - * @throws TagNotFoundException the tag does not exist - */ - public int[] getIntegerArray(String name) throws UnexpectedTagTypeException, TagNotFoundException { - return getTag(name, TagIntegerArray.class).getValues(); - } - - /** - * Verifies that the tag of the given name is an byte array tag and gets its value - * @param name the tag's name - * @return the tag's value - * @throws UnexpectedTagTypeException the tag exists, but is not an byte array tag - * @throws TagNotFoundException the tag does not exist - */ - public byte[] getByteArray(String name) throws UnexpectedTagTypeException, TagNotFoundException { - return getTag(name, TagByteArray.class).getValue(); - } - - /** - * Gets the contents of the list tag and verifies that its items are string tags - * @param name the tag's name - * @return the values of the list tag's item tags - * @throws UnexpectedTagTypeException the tag exists, but is not a list tag - or - - * the contents of the list tag are not string tags - * @throws TagNotFoundException the list tag does not exist - */ - public String[] getStringArray(String name) - throws UnexpectedTagTypeException, TagNotFoundException { - List tags = getList(name, TagString.class); - String[] array = new String[tags.size()]; - for (int i = 0; i < tags.size(); i++) { - array[i] = tags.get(i).getValue(); - } - return array; - } - - /** - * Gets the contents of the list tag and verifies that its items are double tags - * @param name the tag's name - * @return the values of the list tag's item tags - * @throws UnexpectedTagTypeException the tag exists, but is not a list tag - or - - * the contents of the list tag are not double tags - * @throws TagNotFoundException the list tag does not exist - */ - public double[] getDoubleArray(String name) - throws UnexpectedTagTypeException, TagNotFoundException { - List tags = getList(name, TagDouble.class); - double[] array = new double[tags.size()]; - for (int i = 0; i < tags.size(); i++) { - array[i] = tags.get(i).getValue(); - } - return array; - } - - /** - * Gets the contents of the list tag and verifies that its items are float tags - * @param name the tag's name - * @return the values of the list tag's item tags - * @throws UnexpectedTagTypeException the tag exists, but is not a list tag - or - - * the contents of the list tag are not float tags - * @throws TagNotFoundException the list tag does not exist - */ - public float[] getFloatArray(String name) - throws UnexpectedTagTypeException, TagNotFoundException { - List tags = getList(name, TagFloat.class); - float[] array = new float[tags.size()]; - for (int i = 0; i < tags.size(); i++) { - array[i] = tags.get(i).getValue(); - } - return array; - } - - /** - * {@inheritDoc} - */ - @Override - public Map getTags () { - return (new ImmutableMap.Builder ().putAll (this.tags)).build (); - } - - /** - * {@inheritDoc} - */ - @Override - public void removeTag ( ITag tag) { - // check arguments - Preconditions.checkNotNull (tag, "tag"); - - // delete tag - this.tags.remove (tag.getName ()); - } - - /** - * {@inheritDoc} - */ - @Override - public void removeTag ( String tag) { - // check arguments - Preconditions.checkNotNull (tag, "tag"); - - // delete tag - this.tags.remove (tag); - } - - /** - * {@inheritDoc} - */ - @Override - public void setTag ( ITag tag) { - // check arguments - Preconditions.checkNotNull (tag, "tag"); - - // delete previous - if (this.tags.containsKey (tag)) this.tags.get (tag.getName ()).setParent (null); - - // store tag - this.tags.put (tag.getName (), tag); - - // update parent - tag.setParent (this); - } - - /** - * {@inheritDoc} - */ - @Override - public byte getTagID () { - return TagType.COMPOUND.typeID; - } - - /** - * {@inheritDoc} - */ - @Override - public void write (NbtOutputStream outputStream, boolean anonymous) throws IOException { - super.write (outputStream, anonymous); - - // write tags - for (Map.Entry tagEntry : this.tags.entrySet ()) { - // write tag ID - outputStream.writeByte (tagEntry.getValue ().getTagID ()); - - // write tag - tagEntry.getValue ().write (outputStream, false); - } - - // write end tag - outputStream.writeByte (TagType.END.typeID); - } -} \ No newline at end of file diff --git a/src/com/evilco/mc/nbt/tag/TagDouble.java b/src/com/evilco/mc/nbt/tag/TagDouble.java deleted file mode 100644 index 9eba6f7..0000000 --- a/src/com/evilco/mc/nbt/tag/TagDouble.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.evilco.mc.nbt.tag; - -import com.evilco.mc.nbt.stream.NbtInputStream; -import com.evilco.mc.nbt.stream.NbtOutputStream; - -import java.io.IOException; - -/** - * @auhtor Johannes Donath - * @copyright Copyright (C) 2014 Evil-Co - */ -public class TagDouble extends AbstractTag { - - /** - * Stores the tag value. - */ - protected double value; - - /** - * Constructs a new TagDouble. - * @param name - * @param value - */ - public TagDouble ( String name, double value) { - super (name); - this.setValue (value); - } - - /** - * Constructs a new TagDouble. - * @param inputStream - * @param anonymous - * @throws IOException - */ - public TagDouble ( NbtInputStream inputStream, boolean anonymous) throws IOException { - super (inputStream, anonymous); - - this.setValue (inputStream.readDouble ()); - } - - /** - * {@inheritDoc} - */ - @Override - public byte getTagID () { - return TagType.DOUBLE.typeID; - } - - /** - * Returns the tag value. - * @return - */ - public double getValue () { - return this.value; - } - - /** - * Sets a new tag value. - * @param d - */ - public void setValue (double d) { - this.value = d; - } - - /** - * {@inheritDoc} - */ - @Override - public void write (NbtOutputStream outputStream, boolean anonymous) throws IOException { - super.write (outputStream, anonymous); - - // write double - outputStream.writeDouble (this.value); - } -} \ No newline at end of file diff --git a/src/com/evilco/mc/nbt/tag/TagFloat.java b/src/com/evilco/mc/nbt/tag/TagFloat.java deleted file mode 100644 index 8c5a628..0000000 --- a/src/com/evilco/mc/nbt/tag/TagFloat.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.evilco.mc.nbt.tag; - -import com.evilco.mc.nbt.stream.NbtInputStream; -import com.evilco.mc.nbt.stream.NbtOutputStream; - -import java.io.IOException; - -/** - * @auhtor Johannes Donath - * @copyright Copyright (C) 2014 Evil-Co - */ -public class TagFloat extends AbstractTag { - - /** - * Stores the tag value. - */ - protected float value; - - /** - * Constructs a new TagFloat. - * @param name - * @param value - */ - public TagFloat ( String name, float value) { - super (name); - this.setValue (value); - } - - /** - * Constructs a new TagFloat. - * @param inputStream - * @param anonymous - * @throws IOException - */ - public TagFloat ( NbtInputStream inputStream, boolean anonymous) throws IOException { - super (inputStream, anonymous); - - this.setValue (inputStream.readFloat ()); - } - - /** - * {@inheritDoc} - */ - @Override - public byte getTagID () { - return TagType.FLOAT.typeID; - } - - /** - * Returns the tag value. - * @return - */ - public float getValue () { - return this.value; - } - - /** - * Sets a new tag value. - * @param f - */ - public void setValue (float f) { - this.value = f; - } - - /** - * {@inheritDoc} - */ - @Override - public void write (NbtOutputStream outputStream, boolean anonymous) throws IOException { - super.write (outputStream, anonymous); - - // write value - outputStream.writeFloat (this.value); - } -} \ No newline at end of file diff --git a/src/com/evilco/mc/nbt/tag/TagInteger.java b/src/com/evilco/mc/nbt/tag/TagInteger.java deleted file mode 100644 index 06e65f4..0000000 --- a/src/com/evilco/mc/nbt/tag/TagInteger.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.evilco.mc.nbt.tag; - -import com.evilco.mc.nbt.stream.NbtInputStream; -import com.evilco.mc.nbt.stream.NbtOutputStream; - -import java.io.IOException; - -/** - * @auhtor Johannes Donath - * @copyright Copyright (C) 2014 Evil-Co - */ -public class TagInteger extends AbstractTag { - - /** - * Stores the tag value. - */ - protected int value; - - /** - * Constructs a new TagInteger. - * @param name - * @param value - */ - public TagInteger ( String name, int value) { - super (name); - this.setValue (value); - } - - /** - * Constructs a new TagInteger. - * @param inputStream - * @param anonymous - * @throws IOException - */ - public TagInteger ( NbtInputStream inputStream, boolean anonymous) throws IOException { - super (inputStream, anonymous); - - this.setValue (inputStream.readInt ()); - } - - /** - * {@inheritDoc} - */ - @Override - public byte getTagID () { - return TagType.INTEGER.typeID; - } - - /** - * Returns the tag value. - * @return - */ - public int getValue () { - return this.value; - } - - /** - * Sets a new tag value. - * @param i - */ - public void setValue (int i) { - this.value = i; - } - - /** - * {@inheritDoc} - */ - @Override - public void write (NbtOutputStream outputStream, boolean anonymous) throws IOException { - super.write (outputStream, anonymous); - - // write value - outputStream.writeInt (this.value); - } -} \ No newline at end of file diff --git a/src/com/evilco/mc/nbt/tag/TagIntegerArray.java b/src/com/evilco/mc/nbt/tag/TagIntegerArray.java deleted file mode 100644 index afbb244..0000000 --- a/src/com/evilco/mc/nbt/tag/TagIntegerArray.java +++ /dev/null @@ -1,97 +0,0 @@ -package com.evilco.mc.nbt.tag; - -import com.evilco.mc.nbt.stream.NbtInputStream; -import com.evilco.mc.nbt.stream.NbtOutputStream; -import com.google.common.base.Preconditions; - -import java.io.IOException; - -/** - * @auhtor Johannes Donath - * @copyright Copyright (C) 2014 Evil-Co - */ -public class TagIntegerArray extends AbstractTag { - - /** - * Stores the tag values. - */ - protected int[] values; - - /** - * Constructs a new TagIntegerArray. - * @param name - * @param values - */ - public TagIntegerArray ( String name, int[] values) { - super (name); - this.setValues (values); - } - - /** - * Constructs a new TagIntegerArray. - * @param inputStream - * @param anonymous - * @throws IOException - */ - public TagIntegerArray ( NbtInputStream inputStream, boolean anonymous) throws IOException { - super (inputStream, anonymous); - - // get size - int size = inputStream.readInt (); - - // create array - int[] data = new int[size]; - - // read data - for (int i = 0; i < size; i++) { - data[i] = inputStream.readInt (); - } - - // - this.values = data; - } - - /** - * {@inheritDoc} - */ - @Override - public byte getTagID () { - return TagType.INTEGER_ARRAY.typeID; - } - - /** - * Returns the tag values. - * @return - */ - public int[] getValues () { - return this.values; - } - - /** - * Sets new tag values. - * @param i - */ - public void setValues ( int[] i) { - // check arguments - Preconditions.checkNotNull (i, "i"); - - // save value - this.values = i; - } - - /** - * {@inheritDoc} - */ - @Override - public void write (NbtOutputStream outputStream, boolean anonymous) throws IOException { - super.write (outputStream, anonymous); - - // write size - outputStream.writeInt (this.values.length); - - // write data - for (int i : this.values) { - outputStream.writeInt (i); - } - } -} \ No newline at end of file diff --git a/src/com/evilco/mc/nbt/tag/TagList.java b/src/com/evilco/mc/nbt/tag/TagList.java deleted file mode 100644 index e4361a2..0000000 --- a/src/com/evilco/mc/nbt/tag/TagList.java +++ /dev/null @@ -1,154 +0,0 @@ -package com.evilco.mc.nbt.tag; - -import com.evilco.mc.nbt.error.UnexpectedTagTypeException; -import com.evilco.mc.nbt.stream.NbtInputStream; -import com.evilco.mc.nbt.stream.NbtOutputStream; -import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableList; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -/** - * @auhtor Johannes Donath - * @copyright Copyright (C) 2014 Evil-Co - */ -public class TagList extends AbstractTag implements IAnonymousTagContainer { - - /** - * Stores the tag values. - */ - protected List tagList; - - /** - * Constructs a new TagList. - */ - public TagList ( String name) { - super (name); - this.tagList = new ArrayList<> (); - } - - /** - * Constructs a new TagList. - * @param name - * @param tagList - */ - public TagList ( String name, List tagList) { - super (name); - - // verify arguments - Preconditions.checkNotNull (tagList, "tagList"); - - // save tagList - this.tagList = tagList; - } - - /** - * Constructs a new TagList. - * @param inputStream - * @param anonymous - * @throws IOException - */ - public TagList ( NbtInputStream inputStream, boolean anonymous) throws IOException { - super (inputStream, anonymous); - - // create tagList - this.tagList = new ArrayList<> (); - - // get type ID - byte type = inputStream.readByte (); - - // get type - TagType tagType = TagType.valueOf (type); - - // read size - int size = inputStream.readInt (); - - // (no data, skip) - if (tagType == TagType.END) return; - - // load all elements - for (int i = 0; i < size; i++) { - this.addTag (inputStream.readTag (tagType, true)); - } - } - - /** - * {@inheritDoc} - */ - @Override - public void addTag ( ITag tag) { - this.tagList.add (tag); - } - - /** - * {@inheritDoc} - */ - @Override - public List getTags () { - return (new ImmutableList.Builder ().addAll (this.tagList)).build (); - } - - /** - * {@inheritDoc} - */ - @SuppressWarnings("unchecked") - public List getTags(Class tagClass) throws UnexpectedTagTypeException { - ImmutableList.Builder builder = new ImmutableList.Builder(); - for (ITag tag : tagList) { - if (!tagClass.isInstance(tag)) - throw new UnexpectedTagTypeException( - "The list entry should be of type " - + tagClass.getSimpleName() - + ", but is of type " - + tag.getClass().getSimpleName()); - builder.add((T) tag); - } - return builder.build (); - } - - /** - * {@inheritDoc} - */ - @Override - public byte getTagID () { - return TagType.LIST.typeID; - } - - /** - * {@inheritDoc} - */ - @Override - public void removeTag ( ITag tag) { - this.tagList.remove (tag); - } - - /** - * {@inheritDoc} - */ - @Override - public void setTag (int i, ITag tag) { - this.tagList.set (i, tag); - } - - /** - * {@inheritDoc} - */ - @Override - public void write (NbtOutputStream outputStream, boolean anonymous) throws IOException { - super.write (outputStream, anonymous); - - // write type - outputStream.writeByte ((this.tagList.size () > 0 ? this.tagList.get (0).getTagID () : TagType.END.typeID)); - - // write size - outputStream.writeInt (this.tagList.size ()); - - // write tags - for (ITag tag : this.tagList) { - // write data - tag.write (outputStream, true); - } - } -} \ No newline at end of file diff --git a/src/com/evilco/mc/nbt/tag/TagLong.java b/src/com/evilco/mc/nbt/tag/TagLong.java deleted file mode 100644 index 00ad384..0000000 --- a/src/com/evilco/mc/nbt/tag/TagLong.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.evilco.mc.nbt.tag; - -import com.evilco.mc.nbt.stream.NbtInputStream; -import com.evilco.mc.nbt.stream.NbtOutputStream; - -import java.io.IOException; - -/** - * @auhtor Johannes Donath - * @copyright Copyright (C) 2014 Evil-Co - */ -public class TagLong extends AbstractTag { - - /** - * Stores the tag value. - */ - protected long value; - - /** - * Constructs a new TagLong. - * @param name - * @param value - */ - public TagLong ( String name, long value) { - super (name); - this.setValue (value); - } - - /** - * Constructs a new TagLong. - * @param inputStream - * @param anonymous - * @throws IOException - */ - public TagLong ( NbtInputStream inputStream, boolean anonymous) throws IOException { - super (inputStream, anonymous); - - // read value - this.setValue (inputStream.readLong ()); - } - - /** - * {@inheritDoc} - */ - @Override - public byte getTagID () { - return TagType.LONG.typeID; - } - - /** - * Returns the tag value. - * @return - */ - public long getValue () { - return this.value; - } - - /** - * Sets a new tag value. - * @param l - * @return - */ - public void setValue (long l) { - this.value = l; - } - - /** - * {@inheritDoc} - */ - @Override - public void write (NbtOutputStream outputStream, boolean anonymous) throws IOException { - super.write (outputStream, anonymous); - - // write value - outputStream.writeLong (this.value); - } -} \ No newline at end of file diff --git a/src/com/evilco/mc/nbt/tag/TagShort.java b/src/com/evilco/mc/nbt/tag/TagShort.java deleted file mode 100644 index 398df94..0000000 --- a/src/com/evilco/mc/nbt/tag/TagShort.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.evilco.mc.nbt.tag; - -import com.evilco.mc.nbt.stream.NbtInputStream; -import com.evilco.mc.nbt.stream.NbtOutputStream; - -import java.io.IOException; - -/** - * @auhtor Johannes Donath - * @copyright Copyright (C) 2014 Evil-Co - */ -public class TagShort extends AbstractTag { - - /** - * Stores the tag value. - */ - protected short value; - - /** - * Constructs a new TagShort. - * @param name - * @param value - */ - public TagShort ( String name, short value) { - super (name); - this.setValue (value); - } - - /** - * Constructs a new TagShort. - * @param inputStream - * @param anonymous - * @throws IOException - */ - public TagShort ( NbtInputStream inputStream, boolean anonymous) throws IOException { - super (inputStream, anonymous); - - // read value - this.setValue (inputStream.readShort ()); - } - - /** - * {@inheritDoc} - */ - @Override - public byte getTagID () { - return TagType.SHORT.typeID; - } - - /** - * Returns the tag value. - * @return - */ - public short getValue () { - return this.value; - } - - /** - * Sets a new tag value. - * @param s - */ - public void setValue (short s) { - this.value = s; - } - - /** - * {@inheritDoc} - */ - @Override - public void write (NbtOutputStream outputStream, boolean anonymous) throws IOException { - super.write (outputStream, anonymous); - - // write value - outputStream.writeShort (this.value); - } -} \ No newline at end of file diff --git a/src/com/evilco/mc/nbt/tag/TagString.java b/src/com/evilco/mc/nbt/tag/TagString.java deleted file mode 100644 index aa506ca..0000000 --- a/src/com/evilco/mc/nbt/tag/TagString.java +++ /dev/null @@ -1,89 +0,0 @@ -package com.evilco.mc.nbt.tag; - -import com.evilco.mc.nbt.stream.NbtInputStream; -import com.evilco.mc.nbt.stream.NbtOutputStream; - - -import java.io.IOException; - -/** - * @auhtor Johannes Donath - * @copyright Copyright (C) 2014 Evil-Co - */ -public class TagString extends AbstractTag { - - /** - * Stores the tag value. - */ - protected String value; - - /** - * Constructs a new TagString. - * @param name - * @param value - */ - public TagString ( String name, String value) { - super (name); - this.setValue (value); - } - - /** - * Constructs a new TagString. - * @param inputStream - * @param anonymous - * @throws IOException - */ - public TagString ( NbtInputStream inputStream, boolean anonymous) throws IOException { - super (inputStream, anonymous); - - // read size - int size = inputStream.readShort (); - - // read bytes - byte[] data = new byte[size]; - inputStream.readFully (data); - - // store value - this.setValue (new String (data, ITag.STRING_CHARSET)); - } - - /** - * {@inheritDoc} - */ - @Override - public byte getTagID () { - return TagType.STRING.typeID; - } - - /** - * Returns the tag value. - * @return - */ - public String getValue () { - return this.value; - } - - /** - * Sets a new tag value. - * @param s - */ - public void setValue ( String s) { - this.value = s; - } - - /** - * {@inheritDoc} - */ - @Override - public void write (NbtOutputStream outputStream, boolean anonymous) throws IOException { - super.write (outputStream, anonymous); - - // write length - since getBytes can produce an array of a different length than the original string - // the length of the output array is the one to write - byte[] outputBytes = this.value.getBytes (ITag.STRING_CHARSET); - outputStream.writeShort (outputBytes.length); - - // write string - outputStream.write (outputBytes); - } -} \ No newline at end of file diff --git a/src/com/evilco/mc/nbt/tag/TagType.java b/src/com/evilco/mc/nbt/tag/TagType.java deleted file mode 100644 index 723ca5a..0000000 --- a/src/com/evilco/mc/nbt/tag/TagType.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.evilco.mc.nbt.tag; - -import com.google.common.collect.ImmutableMap; - -import java.util.Map; - -/** - * @auhtor Johannes Donath - * @copyright Copyright (C) 2014 Evil-Co - */ -public enum TagType { - BYTE (1, TagByte.class), - BYTE_ARRAY (7, TagByteArray.class), - COMPOUND (10, TagCompound.class), - DOUBLE (6, TagDouble.class), - END (0, null), - FLOAT (5, TagFloat.class), - INTEGER (3, TagInteger.class), - INTEGER_ARRAY (11, TagIntegerArray.class), - LIST (9, TagList.class), - LONG (4, TagLong.class), - SHORT (2, TagShort.class), - STRING (8, TagString.class); - - /** - * Static Initialization. - */ - static { - // create map builder - ImmutableMap.Builder mapBuilder = new ImmutableMap.Builder<> (); - - // add all types - for (TagType type : values ()) { - mapBuilder.put (type.typeID, type); - } - - // build map - typeMap = mapBuilder.build (); - } - - /** - * Stores an internal mapping between IDs and types. - */ - protected static final Map typeMap; - - /** - * Defines the tag representation type. - */ - public final Class tagType; - - /** - * Stores the tag identifier. - */ - public final byte typeID; - - /** - * Constructs a new TagType. - * @param typeID - * @param type - */ - private TagType (int typeID, Class type) { - this.typeID = ((byte) typeID); - this.tagType = type; - } - - /** - * Returns the correct type associated with the specified type ID. - * @param typeID - * @return - */ - public static TagType valueOf (byte typeID) { - return typeMap.get (typeID); - } -} \ No newline at end of file