TAG_Byte_Array
tag.
- * @author Graham Edgecombe
- *
+ * The {@code TAG_Byte_Array} tag.
*/
public final class ByteArrayTag extends Tag {
-
- /**
- * The value.
- */
- private final byte[] value;
-
- /**
- * Creates the tag.
- * @param name The name.
- * @param value The value.
- */
- public ByteArrayTag(String name, byte[] value) {
- super(name);
- this.value = value;
- }
-
- @Override
- public byte[] getValue() {
- return value;
- }
-
- @Override
- public String toString() {
- StringBuilder hex = new StringBuilder();
- for(byte b : value) {
- String hexDigits = Integer.toHexString(b).toUpperCase();
- if(hexDigits.length() == 1) {
- hex.append("0");
- }
- hex.append(hexDigits).append(" ");
- }
- String name = getName();
- String append = "";
- if(name != null && !name.equals("")) {
- append = "(\"" + this.getName() + "\")";
- }
- return "TAG_Byte_Array" + append + ": " + hex.toString();
- }
+
+ private final byte[] value;
+
+ /**
+ * Creates the tag with an empty name.
+ *
+ * @param value the value of the tag
+ */
+ public ByteArrayTag(byte[] value) {
+ super();
+ this.value = value;
+ }
+
+ /**
+ * Creates the tag.
+ *
+ * @param name the name of the tag
+ * @param value the value of the tag
+ */
+ public ByteArrayTag(String name, byte[] value) {
+ super(name);
+ this.value = value;
+ }
+
+ @Override
+ public byte[] getValue() {
+ return value;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder hex = new StringBuilder();
+ for (byte b : value) {
+ String hexDigits = Integer.toHexString(b).toUpperCase();
+ if (hexDigits.length() == 1) {
+ hex.append("0");
+ }
+ hex.append(hexDigits).append(" ");
+ }
+ String name = getName();
+ String append = "";
+ if (name != null && !name.equals("")) {
+ append = "(\"" + this.getName() + "\")";
+ }
+ return "TAG_Byte_Array" + append + ": " + hex;
+ }
}
diff --git a/PlotSquared/src/com/intellectualcrafters/jnbt/ByteTag.java b/PlotSquared/src/com/intellectualcrafters/jnbt/ByteTag.java
index eea13796f..65e86ec84 100644
--- a/PlotSquared/src/com/intellectualcrafters/jnbt/ByteTag.java
+++ b/PlotSquared/src/com/intellectualcrafters/jnbt/ByteTag.java
@@ -1,73 +1,65 @@
-package com.intellectualcrafters.jnbt;
-
/*
- * JNBT License
- *
- * Copyright (c) 2010 Graham Edgecombe
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * * Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of the JNBT team nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
+ * WorldEdit, a Minecraft world manipulation toolkit
+ * Copyright (C) sk89q TAG_Byte
tag.
- * @author Graham Edgecombe
- *
+ * The {@code TAG_Byte} tag.
*/
public final class ByteTag extends Tag {
- /**
- * The value.
- */
- private final byte value;
-
- /**
- * Creates the tag.
- * @param name The name.
- * @param value The value.
- */
- public ByteTag(String name, byte value) {
- super(name);
- this.value = value;
- }
+ private final byte value;
+
+ /**
+ * Creates the tag with an empty name.
+ *
+ * @param value the value of the tag
+ */
+ public ByteTag(byte value) {
+ super();
+ this.value = value;
+ }
+
+ /**
+ * Creates the tag.
+ *
+ * @param name the name of the tag
+ * @param value the value of the tag
+ */
+ public ByteTag(String name, byte value) {
+ super(name);
+ this.value = value;
+ }
+
+ @Override
+ public Byte getValue() {
+ return value;
+ }
+
+ @Override
+ public String toString() {
+ String name = getName();
+ String append = "";
+ if (name != null && !name.equals("")) {
+ append = "(\"" + this.getName() + "\")";
+ }
+ return "TAG_Byte" + append + ": " + value;
+ }
- @Override
- public Byte getValue() {
- return value;
- }
-
- @Override
- public String toString() {
- String name = getName();
- String append = "";
- if(name != null && !name.equals("")) {
- append = "(\"" + this.getName() + "\")";
- }
- return "TAG_Byte" + append + ": " + value;
- }
-
}
diff --git a/PlotSquared/src/com/intellectualcrafters/jnbt/CompoundTag.java b/PlotSquared/src/com/intellectualcrafters/jnbt/CompoundTag.java
index 6d8e586ea..13dad7121 100644
--- a/PlotSquared/src/com/intellectualcrafters/jnbt/CompoundTag.java
+++ b/PlotSquared/src/com/intellectualcrafters/jnbt/CompoundTag.java
@@ -1,82 +1,436 @@
-package com.intellectualcrafters.jnbt;
-
/*
- * JNBT License
- *
- * Copyright (c) 2010 Graham Edgecombe
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * * Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of the JNBT team nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
+ * WorldEdit, a Minecraft world manipulation toolkit
+ * Copyright (C) sk89q TAG_Compound
tag.
- * @author Graham Edgecombe
- *
+ * The {@code TAG_Compound} tag.
*/
public final class CompoundTag extends Tag {
-
- /**
- * The value.
- */
- private final MapIf the key does not exist or its value is not a byte array tag, + * then an empty byte array will be returned.
+ * + * @param key the key + * @return a byte array + */ + public byte[] getByteArray(String key) { + Tag tag = value.get(key); + if (tag instanceof ByteArrayTag) { + return ((ByteArrayTag) tag).getValue(); + } else { + return new byte[0]; + } + } + + /** + * Get a byte named with the given key. + * + *If the key does not exist or its value is not a byte tag, + * then {@code 0} will be returned.
+ * + * @param key the key + * @return a byte + */ + public byte getByte(String key) { + Tag tag = value.get(key); + if (tag instanceof ByteTag) { + return ((ByteTag) tag).getValue(); + } else { + return (byte) 0; + } + } + + /** + * Get a double named with the given key. + * + *If the key does not exist or its value is not a double tag, + * then {@code 0} will be returned.
+ * + * @param key the key + * @return a double + */ + public double getDouble(String key) { + Tag tag = value.get(key); + if (tag instanceof DoubleTag) { + return ((DoubleTag) tag).getValue(); + } else { + return 0; + } + } + + /** + * Get a double named with the given key, even if it's another + * type of number. + * + *If the key does not exist or its value is not a number, + * then {@code 0} will be returned.
+ * + * @param key the key + * @return a double + */ + public double asDouble(String key) { + Tag tag = value.get(key); + if (tag instanceof ByteTag) { + return ((ByteTag) tag).getValue(); + + } else if (tag instanceof ShortTag) { + return ((ShortTag) tag).getValue(); + + } else if (tag instanceof IntTag) { + return ((IntTag) tag).getValue(); + + } else if (tag instanceof LongTag) { + return ((LongTag) tag).getValue(); + + } else if (tag instanceof FloatTag) { + return ((FloatTag) tag).getValue(); + + } else if (tag instanceof DoubleTag) { + return ((DoubleTag) tag).getValue(); + + } else { + return 0; + } + } + + /** + * Get a float named with the given key. + * + *If the key does not exist or its value is not a float tag, + * then {@code 0} will be returned.
+ * + * @param key the key + * @return a float + */ + public float getFloat(String key) { + Tag tag = value.get(key); + if (tag instanceof FloatTag) { + return ((FloatTag) tag).getValue(); + } else { + return 0; + } + } + + /** + * Get a {@code int[]} named with the given key. + * + *If the key does not exist or its value is not an int array tag, + * then an empty array will be returned.
+ * + * @param key the key + * @return an int array + */ + public int[] getIntArray(String key) { + Tag tag = value.get(key); + if (tag instanceof IntArrayTag) { + return ((IntArrayTag) tag).getValue(); + } else { + return new int[0]; + } + } + + /** + * Get an int named with the given key. + * + *If the key does not exist or its value is not an int tag, + * then {@code 0} will be returned.
+ * + * @param key the key + * @return an int + */ + public int getInt(String key) { + Tag tag = value.get(key); + if (tag instanceof IntTag) { + return ((IntTag) tag).getValue(); + } else { + return 0; + } + } + + /** + * Get an int named with the given key, even if it's another + * type of number. + * + *If the key does not exist or its value is not a number, + * then {@code 0} will be returned.
+ * + * @param key the key + * @return an int + */ + public int asInt(String key) { + Tag tag = value.get(key); + if (tag instanceof ByteTag) { + return ((ByteTag) tag).getValue(); + + } else if (tag instanceof ShortTag) { + return ((ShortTag) tag).getValue(); + + } else if (tag instanceof IntTag) { + return ((IntTag) tag).getValue(); + + } else if (tag instanceof LongTag) { + return ((LongTag) tag).getValue().intValue(); + + } else if (tag instanceof FloatTag) { + return ((FloatTag) tag).getValue().intValue(); + + } else if (tag instanceof DoubleTag) { + return ((DoubleTag) tag).getValue().intValue(); + + } else { + return 0; + } + } + + /** + * Get a list of tags named with the given key. + * + *If the key does not exist or its value is not a list tag, + * then an empty list will be returned.
+ * + * @param key the key + * @return a list of tags + */ + public ListIf the key does not exist or its value is not a list tag, + * then an empty tag list will be returned.
+ * + * @param key the key + * @return a tag list instance + */ + public ListTag getListTag(String key) { + Tag tag = value.get(key); + if (tag instanceof ListTag) { + return (ListTag) tag; + } else { + return new ListTag(key, StringTag.class, Collections.If the key does not exist or its value is not a list tag, + * then an empty list will be returned. If the given key references + * a list but the list of of a different type, then an empty + * list will also be returned.
+ * + * @param key the key + * @param listType the class of the contained type + * @return a list of tags + * @paramIf the key does not exist or its value is not a long tag, + * then {@code 0} will be returned.
+ * + * @param key the key + * @return a long + */ + public long getLong(String key) { + Tag tag = value.get(key); + if (tag instanceof LongTag) { + return ((LongTag) tag).getValue(); + } else { + return 0L; + } + } + + /** + * Get a long named with the given key, even if it's another + * type of number. + * + *If the key does not exist or its value is not a number, + * then {@code 0} will be returned.
+ * + * @param key the key + * @return a long + */ + public long asLong(String key) { + Tag tag = value.get(key); + if (tag instanceof ByteTag) { + return ((ByteTag) tag).getValue(); + + } else if (tag instanceof ShortTag) { + return ((ShortTag) tag).getValue(); + + } else if (tag instanceof IntTag) { + return ((IntTag) tag).getValue(); + + } else if (tag instanceof LongTag) { + return ((LongTag) tag).getValue(); + + } else if (tag instanceof FloatTag) { + return ((FloatTag) tag).getValue().longValue(); + + } else if (tag instanceof DoubleTag) { + return ((DoubleTag) tag).getValue().longValue(); + + } else { + return 0L; + } + } + + /** + * Get a short named with the given key. + * + *If the key does not exist or its value is not a short tag, + * then {@code 0} will be returned.
+ * + * @param key the key + * @return a short + */ + public short getShort(String key) { + Tag tag = value.get(key); + if (tag instanceof ShortTag) { + return ((ShortTag) tag).getValue(); + } else { + return 0; + } + } + + /** + * Get a string named with the given key. + * + *If the key does not exist or its value is not a string tag, + * then {@code ""} will be returned.
+ * + * @param key the key + * @return a string + */ + public String getString(String key) { + Tag tag = value.get(key); + if (tag instanceof StringTag) { + return ((StringTag) tag).getValue(); + } else { + return ""; + } + } + + @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 (Map.EntryTAG_Double
tag.
- * @author Graham Edgecombe
- *
+ * The {@code TAG_Double} tag.
+ *
*/
public final class DoubleTag extends Tag {
-
- /**
- * The value.
- */
- private final double value;
- /**
- * Creates the tag.
- * @param name The name.
- * @param value The value.
- */
- public DoubleTag(String name, double value) {
- super(name);
- this.value = value;
- }
-
- @Override
- public Double getValue() {
- return value;
- }
-
- @Override
- public String toString() {
- String name = getName();
- String append = "";
- if(name != null && !name.equals("")) {
- append = "(\"" + this.getName() + "\")";
- }
- return "TAG_Double" + append + ": " + value;
- }
+ private final double value;
+
+ /**
+ * Creates the tag with an empty name.
+ *
+ * @param value the value of the tag
+ */
+ public DoubleTag(double value) {
+ super();
+ this.value = value;
+ }
+
+ /**
+ * Creates the tag.
+ *
+ * @param name the name of the tag
+ * @param value the value of the tag
+ */
+ public DoubleTag(String name, double value) {
+ super(name);
+ this.value = value;
+ }
+
+ @Override
+ public Double getValue() {
+ return value;
+ }
+
+ @Override
+ public String toString() {
+ String name = getName();
+ String append = "";
+ if (name != null && !name.equals("")) {
+ append = "(\"" + this.getName() + "\")";
+ }
+ return "TAG_Double" + append + ": " + value;
+ }
}
diff --git a/PlotSquared/src/com/intellectualcrafters/jnbt/EndTag.java b/PlotSquared/src/com/intellectualcrafters/jnbt/EndTag.java
index 8072216f5..f4a6b49e4 100644
--- a/PlotSquared/src/com/intellectualcrafters/jnbt/EndTag.java
+++ b/PlotSquared/src/com/intellectualcrafters/jnbt/EndTag.java
@@ -1,60 +1,44 @@
-package com.intellectualcrafters.jnbt;
-
/*
- * JNBT License
- *
- * Copyright (c) 2010 Graham Edgecombe
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * * Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of the JNBT team nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
+ * WorldEdit, a Minecraft world manipulation toolkit
+ * Copyright (C) sk89q TAG_End
tag.
- * @author Graham Edgecombe
- *
+ * The {@code TAG_End} tag.
*/
public final class EndTag extends Tag {
- /**
- * Creates the tag.
- */
- public EndTag() {
- super("");
- }
+ /**
+ * Creates the tag.
+ */
+ public EndTag() {
+ super();
+ }
- @Override
- public Object getValue() {
- return null;
- }
-
- @Override
- public String toString() {
- return "TAG_End";
- }
+ @Override
+ public Object getValue() {
+ return null;
+ }
+
+ @Override
+ public String toString() {
+ return "TAG_End";
+ }
}
diff --git a/PlotSquared/src/com/intellectualcrafters/jnbt/FloatTag.java b/PlotSquared/src/com/intellectualcrafters/jnbt/FloatTag.java
index 37b78d823..9d75964c0 100644
--- a/PlotSquared/src/com/intellectualcrafters/jnbt/FloatTag.java
+++ b/PlotSquared/src/com/intellectualcrafters/jnbt/FloatTag.java
@@ -1,73 +1,65 @@
-package com.intellectualcrafters.jnbt;
-
/*
- * JNBT License
- *
- * Copyright (c) 2010 Graham Edgecombe
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * * Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of the JNBT team nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
+ * WorldEdit, a Minecraft world manipulation toolkit
+ * Copyright (C) sk89q TAG_Float
tag.
- * @author Graham Edgecombe
- *
+ * The {@code TAG_Float} tag.
*/
public final class FloatTag extends Tag {
- /**
- * The value.
- */
- private final float value;
-
- /**
- * Creates the tag.
- * @param name The name.
- * @param value The value.
- */
- public FloatTag(String name, float value) {
- super(name);
- this.value = value;
- }
-
- @Override
- public Float getValue() {
- return value;
- }
-
- @Override
- public String toString() {
- String name = getName();
- String append = "";
- if(name != null && !name.equals("")) {
- append = "(\"" + this.getName() + "\")";
- }
- return "TAG_Float" + append + ": " + value;
- }
+ private final float value;
+
+ /**
+ * Creates the tag with an empty name.
+ *
+ * @param value the value of the tag
+ */
+ public FloatTag(float value) {
+ super();
+ this.value = value;
+ }
+
+ /**
+ * Creates the tag.
+ *
+ * @param name the name of the tag
+ * @param value the value of the tag
+ */
+ public FloatTag(String name, float value) {
+ super(name);
+ this.value = value;
+ }
+
+ @Override
+ public Float getValue() {
+ return value;
+ }
+
+ @Override
+ public String toString() {
+ String name = getName();
+ String append = "";
+ if (name != null && !name.equals("")) {
+ append = "(\"" + this.getName() + "\")";
+ }
+ return "TAG_Float" + append + ": " + value;
+ }
}
diff --git a/PlotSquared/src/com/intellectualcrafters/jnbt/IntArrayTag.java b/PlotSquared/src/com/intellectualcrafters/jnbt/IntArrayTag.java
new file mode 100644
index 000000000..3359b393a
--- /dev/null
+++ b/PlotSquared/src/com/intellectualcrafters/jnbt/IntArrayTag.java
@@ -0,0 +1,77 @@
+/*
+ * WorldEdit, a Minecraft world manipulation toolkit
+ * Copyright (C) sk89q TAG_Int
tag.
- * @author Graham Edgecombe
- *
+ * The {@code TAG_Int} tag.
*/
public final class IntTag extends Tag {
- /**
- * The value.
- */
- private final int value;
-
- /**
- * Creates the tag.
- * @param name The name.
- * @param value The value.
- */
- public IntTag(String name, int value) {
- super(name);
- this.value = value;
- }
+ private final int value;
- @Override
- public Integer getValue() {
- return value;
- }
-
- @Override
- public String toString() {
- String name = getName();
- String append = "";
- if(name != null && !name.equals("")) {
- append = "(\"" + this.getName() + "\")";
- }
- return "TAG_Int" + append + ": " + value;
- }
+ /**
+ * Creates the tag with an empty name.
+ *
+ * @param value the value of the tag
+ */
+ public IntTag(int value) {
+ super();
+ this.value = value;
+ }
+
+ /**
+ * Creates the tag.
+ *
+ * @param name the name of the tag
+ * @param value the value of the tag
+ */
+ public IntTag(String name, int value) {
+ super(name);
+ this.value = value;
+ }
+
+ @Override
+ public Integer getValue() {
+ return value;
+ }
+
+ @Override
+ public String toString() {
+ String name = getName();
+ String append = "";
+ if (name != null && !name.equals("")) {
+ append = "(\"" + this.getName() + "\")";
+ }
+ return "TAG_Int" + append + ": " + value;
+ }
}
diff --git a/PlotSquared/src/com/intellectualcrafters/jnbt/ListTag.java b/PlotSquared/src/com/intellectualcrafters/jnbt/ListTag.java
index 124602b09..8d36aea43 100644
--- a/PlotSquared/src/com/intellectualcrafters/jnbt/ListTag.java
+++ b/PlotSquared/src/com/intellectualcrafters/jnbt/ListTag.java
@@ -1,97 +1,450 @@
-package com.intellectualcrafters.jnbt;
-
/*
- * JNBT License
- *
- * Copyright (c) 2010 Graham Edgecombe
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * * Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of the JNBT team nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
+ * WorldEdit, a Minecraft world manipulation toolkit
+ * Copyright (C) sk89q TAG_List
tag.
- * @author Graham Edgecombe
- *
+ * The {@code TAG_List} tag.
*/
public final class ListTag extends Tag {
- /**
- * The type.
- */
- private final Class extends Tag> type;
-
- /**
- * The value.
- */
- private final ListIf the index does not exist or its value is not a byte array tag, + * then an empty byte array will be returned.
+ * + * @param index the index + * @return a byte array + */ + public byte[] getByteArray(int index) { + Tag tag = getIfExists(index); + if (tag instanceof ByteArrayTag) { + return ((ByteArrayTag) tag).getValue(); + } else { + return new byte[0]; + } + } + + /** + * Get a byte named with the given index. + * + *If the index does not exist or its value is not a byte tag, + * then {@code 0} will be returned.
+ * + * @param index the index + * @return a byte + */ + public byte getByte(int index) { + Tag tag = getIfExists(index); + if (tag instanceof ByteTag) { + return ((ByteTag) tag).getValue(); + } else { + return (byte) 0; + } + } + + /** + * Get a double named with the given index. + * + *If the index does not exist or its value is not a double tag, + * then {@code 0} will be returned.
+ * + * @param index the index + * @return a double + */ + public double getDouble(int index) { + Tag tag = getIfExists(index); + if (tag instanceof DoubleTag) { + return ((DoubleTag) tag).getValue(); + } else { + return 0; + } + } + + /** + * Get a double named with the given index, even if it's another + * type of number. + * + *If the index does not exist or its value is not a number, + * then {@code 0} will be returned.
+ * + * @param index the index + * @return a double + */ + public double asDouble(int index) { + Tag tag = getIfExists(index); + if (tag instanceof ByteTag) { + return ((ByteTag) tag).getValue(); + + } else if (tag instanceof ShortTag) { + return ((ShortTag) tag).getValue(); + + } else if (tag instanceof IntTag) { + return ((IntTag) tag).getValue(); + + } else if (tag instanceof LongTag) { + return ((LongTag) tag).getValue(); + + } else if (tag instanceof FloatTag) { + return ((FloatTag) tag).getValue(); + + } else if (tag instanceof DoubleTag) { + return ((DoubleTag) tag).getValue(); + + } else { + return 0; + } + } + + /** + * Get a float named with the given index. + * + *If the index does not exist or its value is not a float tag, + * then {@code 0} will be returned.
+ * + * @param index the index + * @return a float + */ + public float getFloat(int index) { + Tag tag = getIfExists(index); + if (tag instanceof FloatTag) { + return ((FloatTag) tag).getValue(); + } else { + return 0; + } + } + + /** + * Get a {@code int[]} named with the given index. + * + *If the index does not exist or its value is not an int array tag, + * then an empty array will be returned.
+ * + * @param index the index + * @return an int array + */ + public int[] getIntArray(int index) { + Tag tag = getIfExists(index); + if (tag instanceof IntArrayTag) { + return ((IntArrayTag) tag).getValue(); + } else { + return new int[0]; + } + } + + /** + * Get an int named with the given index. + * + *If the index does not exist or its value is not an int tag, + * then {@code 0} will be returned.
+ * + * @param index the index + * @return an int + */ + public int getInt(int index) { + Tag tag = getIfExists(index); + if (tag instanceof IntTag) { + return ((IntTag) tag).getValue(); + } else { + return 0; + } + } + + /** + * Get an int named with the given index, even if it's another + * type of number. + * + *If the index does not exist or its value is not a number, + * then {@code 0} will be returned.
+ * + * @param index the index + * @return an int + */ + public int asInt(int index) { + Tag tag = getIfExists(index); + if (tag instanceof ByteTag) { + return ((ByteTag) tag).getValue(); + + } else if (tag instanceof ShortTag) { + return ((ShortTag) tag).getValue(); + + } else if (tag instanceof IntTag) { + return ((IntTag) tag).getValue(); + + } else if (tag instanceof LongTag) { + return ((LongTag) tag).getValue().intValue(); + + } else if (tag instanceof FloatTag) { + return ((FloatTag) tag).getValue().intValue(); + + } else if (tag instanceof DoubleTag) { + return ((DoubleTag) tag).getValue().intValue(); + + } else { + return 0; + } + } + + /** + * Get a list of tags named with the given index. + * + *If the index does not exist or its value is not a list tag, + * then an empty list will be returned.
+ * + * @param index the index + * @return a list of tags + */ + public ListIf the index does not exist or its value is not a list tag, + * then an empty tag list will be returned.
+ * + * @param index the index + * @return a tag list instance + */ + public ListTag getListTag(int index) { + Tag tag = getIfExists(index); + if (tag instanceof ListTag) { + return (ListTag) tag; + } else { + return new ListTag(StringTag.class, Collections.If the index does not exist or its value is not a list tag, + * then an empty list will be returned. If the given index references + * a list but the list of of a different type, then an empty + * list will also be returned.
+ * + * @param index the index + * @param listType the class of the contained type + * @return a list of tags + * @paramIf the index does not exist or its value is not a long tag, + * then {@code 0} will be returned.
+ * + * @param index the index + * @return a long + */ + public long getLong(int index) { + Tag tag = getIfExists(index); + if (tag instanceof LongTag) { + return ((LongTag) tag).getValue(); + } else { + return 0L; + } + } + + /** + * Get a long named with the given index, even if it's another + * type of number. + * + *If the index does not exist or its value is not a number, + * then {@code 0} will be returned.
+ * + * @param index the index + * @return a long + */ + public long asLong(int index) { + Tag tag = getIfExists(index); + if (tag instanceof ByteTag) { + return ((ByteTag) tag).getValue(); + + } else if (tag instanceof ShortTag) { + return ((ShortTag) tag).getValue(); + + } else if (tag instanceof IntTag) { + return ((IntTag) tag).getValue(); + + } else if (tag instanceof LongTag) { + return ((LongTag) tag).getValue(); + + } else if (tag instanceof FloatTag) { + return ((FloatTag) tag).getValue().longValue(); + + } else if (tag instanceof DoubleTag) { + return ((DoubleTag) tag).getValue().longValue(); + + } else { + return 0; + } + } + + /** + * Get a short named with the given index. + * + *If the index does not exist or its value is not a short tag, + * then {@code 0} will be returned.
+ * + * @param index the index + * @return a short + */ + public short getShort(int index) { + Tag tag = getIfExists(index); + if (tag instanceof ShortTag) { + return ((ShortTag) tag).getValue(); + } else { + return 0; + } + } + + /** + * Get a string named with the given index. + * + *If the index does not exist or its value is not a string tag, + * then {@code ""} will be returned.
+ * + * @param index the index + * @return a string + */ + public String getString(int index) { + Tag tag = getIfExists(index); + if (tag instanceof StringTag) { + return ((StringTag) tag).getValue(); + } else { + return ""; + } + } + + @Override + public String toString() { + String name = getName(); + String append = ""; + if (name != null && !name.equals("")) { + append = "(\"" + this.getName() + "\")"; + } + StringBuilder bldr = new StringBuilder(); + bldr.append("TAG_List").append(append).append(": ").append(value.size()).append(" entries of type ").append(NBTUtils.getTypeName(type)).append("\r\n{\r\n"); + for (Tag t : value) { + bldr.append(" ").append(t.toString().replaceAll("\r\n", "\r\n ")).append("\r\n"); + } + bldr.append("}"); + return bldr.toString(); + } } diff --git a/PlotSquared/src/com/intellectualcrafters/jnbt/ListTagBuilder.java b/PlotSquared/src/com/intellectualcrafters/jnbt/ListTagBuilder.java new file mode 100644 index 000000000..711e5629e --- /dev/null +++ b/PlotSquared/src/com/intellectualcrafters/jnbt/ListTagBuilder.java @@ -0,0 +1,129 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89qTAG_Long
tag.
- * @author Graham Edgecombe
- *
+ * The {@code TAG_Long} tag.
+ *
*/
public final class LongTag extends Tag {
- /**
- * The value.
- */
- private final long value;
-
- /**
- * Creates the tag.
- * @param name The name.
- * @param value The value.
- */
- public LongTag(String name, long value) {
- super(name);
- this.value = value;
- }
-
- @Override
- public Long getValue() {
- return value;
- }
-
- @Override
- public String toString() {
- String name = getName();
- String append = "";
- if(name != null && !name.equals("")) {
- append = "(\"" + this.getName() + "\")";
- }
- return "TAG_Long" + append + ": " + value;
- }
+ private final long value;
+
+ /**
+ * Creates the tag with an empty name.
+ *
+ * @param value the value of the tag
+ */
+ public LongTag(long value) {
+ super();
+ this.value = value;
+ }
+
+ /**
+ * Creates the tag.
+ *
+ * @param name the name of the tag
+ * @param value the value of the tag
+ */
+ public LongTag(String name, long value) {
+ super(name);
+ this.value = value;
+ }
+
+ @Override
+ public Long getValue() {
+ return value;
+ }
+
+ @Override
+ public String toString() {
+ String name = getName();
+ String append = "";
+ if (name != null && !name.equals("")) {
+ append = "(\"" + this.getName() + "\")";
+ }
+ return "TAG_Long" + append + ": " + value;
+ }
}
diff --git a/PlotSquared/src/com/intellectualcrafters/jnbt/NBTConstants.java b/PlotSquared/src/com/intellectualcrafters/jnbt/NBTConstants.java
index 6298fd90e..d8b5544f9 100644
--- a/PlotSquared/src/com/intellectualcrafters/jnbt/NBTConstants.java
+++ b/PlotSquared/src/com/intellectualcrafters/jnbt/NBTConstants.java
@@ -1,72 +1,81 @@
+/*
+ * WorldEdit, a Minecraft world manipulation toolkit
+ * Copyright (C) sk89q This class reads NBT, or
- * Named Binary Tag streams, and produces an object graph of
- * subclasses of the Tag
object.
The NBT format was created by Markus Persson, and the specification may
- * be found at
+ * The NBT format was created by Markus Persson, and the specification may be
+ * found at
* http://www.minecraft.net/docs/NBT.txt. This class writes NBT, or
- * Named Binary Tag The NBT format was created by Markus Persson, and the specification may
- * be found at
+ * The NBT format was created by Markus Persson, and the specification may be
+ * found at
* http://www.minecraft.net/docs/NBT.txt.NBTInputStream
, which will source its data
- * from the specified input stream.
- * @param is The input stream.
- * @throws IOException if an I/O error occurs.
- */
- public NBTInputStream(InputStream is) throws IOException {
- this.is = new DataInputStream(new GZIPInputStream(is));
- }
-
- /**
- * Reads an NBT tag from the stream.
- * @return The tag that was read.
- * @throws IOException if an I/O error occurs.
- */
- public Tag readTag() throws IOException {
- return readTag(0);
- }
-
- /**
- * Reads an NBT from the stream.
- * @param depth The depth of this tag.
- * @return The tag that was read.
- * @throws IOException if an I/O error occurs.
- */
- private Tag readTag(int depth) throws IOException {
- int type = is.readByte() & 0xFF;
-
- String name;
- if(type != NBTConstants.TYPE_END) {
- int nameLength = is.readShort() & 0xFFFF;
- byte[] nameBytes = new byte[nameLength];
- is.readFully(nameBytes);
- name = new String(nameBytes, NBTConstants.CHARSET);
- } else {
- name = "";
- }
-
- return readTagPayload(type, name, depth);
- }
- /**
- * Reads the payload of a tag, given the name and type.
- * @param type The type.
- * @param name The name.
- * @param depth The depth.
- * @return The tag.
- * @throws IOException if an I/O error occurs.
- */
- private Tag readTagPayload(int type, String name, int depth) throws IOException {
- switch(type) {
- case NBTConstants.TYPE_END:
- if(depth == 0) {
- throw new IOException("TAG_End found without a TAG_Compound/TAG_List tag preceding it.");
- } else {
- return new EndTag();
- }
- case NBTConstants.TYPE_BYTE:
- return new ByteTag(name, is.readByte());
- case NBTConstants.TYPE_SHORT:
- return new ShortTag(name, is.readShort());
- case NBTConstants.TYPE_INT:
- return new IntTag(name, is.readInt());
- case NBTConstants.TYPE_LONG:
- return new LongTag(name, is.readLong());
- case NBTConstants.TYPE_FLOAT:
- return new FloatTag(name, is.readFloat());
- case NBTConstants.TYPE_DOUBLE:
- return new DoubleTag(name, is.readDouble());
- case NBTConstants.TYPE_BYTE_ARRAY:
- int length = is.readInt();
- byte[] bytes = new byte[length];
- is.readFully(bytes);
- return new ByteArrayTag(name, bytes);
- case NBTConstants.TYPE_STRING:
- length = is.readShort();
- bytes = new byte[length];
- is.readFully(bytes);
- return new StringTag(name, new String(bytes, NBTConstants.CHARSET));
- case NBTConstants.TYPE_LIST:
- int childType = is.readByte();
- length = is.readInt();
-
- ListTag
objects to an underlying
- * OutputStream
.NBTOutputStream
, which will write data to the
- * specified underlying output stream.
- * @param os The output stream.
- * @throws IOException if an I/O error occurs.
- */
- public NBTOutputStream(OutputStream os) throws IOException {
- this.os = new DataOutputStream(new GZIPOutputStream(os));
- }
-
- /**
- * Writes a tag.
- * @param tag The tag to write.
- * @throws IOException if an I/O error occurs.
- */
- public void writeTag(Tag tag) throws IOException {
- int type = NBTUtils.getTypeCode(tag.getClass());
- String name = tag.getName();
- byte[] nameBytes = name.getBytes(NBTConstants.CHARSET);
-
- os.writeByte(type);
- os.writeShort(nameBytes.length);
- os.write(nameBytes);
-
- if(type == NBTConstants.TYPE_END) {
- throw new IOException("Named TAG_End not permitted.");
- }
-
- writeTagPayload(tag);
- }
- /**
- * Writes tag payload.
- * @param tag The tag.
- * @throws IOException if an I/O error occurs.
- */
- private void writeTagPayload(Tag tag) throws IOException {
- int type = NBTUtils.getTypeCode(tag.getClass());
- switch(type) {
- case NBTConstants.TYPE_END:
- writeEndTagPayload((EndTag) tag);
- break;
- case NBTConstants.TYPE_BYTE:
- writeByteTagPayload((ByteTag) tag);
- break;
- case NBTConstants.TYPE_SHORT:
- writeShortTagPayload((ShortTag) tag);
- break;
- case NBTConstants.TYPE_INT:
- writeIntTagPayload((IntTag) tag);
- break;
- case NBTConstants.TYPE_LONG:
- writeLongTagPayload((LongTag) tag);
- break;
- case NBTConstants.TYPE_FLOAT:
- writeFloatTagPayload((FloatTag) tag);
- break;
- case NBTConstants.TYPE_DOUBLE:
- writeDoubleTagPayload((DoubleTag) tag);
- break;
- case NBTConstants.TYPE_BYTE_ARRAY:
- writeByteArrayTagPayload((ByteArrayTag) tag);
- break;
- case NBTConstants.TYPE_STRING:
- writeStringTagPayload((StringTag) tag);
- break;
- case NBTConstants.TYPE_LIST:
- writeListTagPayload((ListTag) tag);
- break;
- case NBTConstants.TYPE_COMPOUND:
- writeCompoundTagPayload((CompoundTag) tag);
- break;
- default:
- throw new IOException("Invalid tag type: " + type + ".");
- }
- }
+ /**
+ * The output stream.
+ */
+ private final DataOutputStream os;
- /**
- * Writes a TAG_Byte
tag.
- * @param tag The tag.
- * @throws IOException if an I/O error occurs.
- */
- private void writeByteTagPayload(ByteTag tag) throws IOException {
- os.writeByte(tag.getValue());
- }
+ /**
+ * Creates a new {@code NBTOutputStream}, which will write data to the
+ * specified underlying output stream.
+ *
+ * @param os
+ * The output stream.
+ * @throws IOException
+ * if an I/O error occurs.
+ */
+ public NBTOutputStream(OutputStream os) throws IOException {
+ this.os = new DataOutputStream(os);
+ }
- /**
- * Writes a TAG_Byte_Array
tag.
- * @param tag The tag.
- * @throws IOException if an I/O error occurs.
- */
- private void writeByteArrayTagPayload(ByteArrayTag tag) throws IOException {
- byte[] bytes = tag.getValue();
- os.writeInt(bytes.length);
- os.write(bytes);
- }
+ /**
+ * Writes a tag.
+ *
+ * @param tag
+ * The tag to write.
+ * @throws IOException
+ * if an I/O error occurs.
+ */
+ public void writeTag(Tag tag) throws IOException {
+ int type = NBTUtils.getTypeCode(tag.getClass());
+ String name = tag.getName();
+ byte[] nameBytes = name.getBytes(NBTConstants.CHARSET);
- /**
- * Writes a TAG_Compound
tag.
- * @param tag The tag.
- * @throws IOException if an I/O error occurs.
- */
- private void writeCompoundTagPayload(CompoundTag tag) throws IOException {
- for(Tag childTag : tag.getValue().values()) {
- writeTag(childTag);
- }
- os.writeByte((byte) 0); // end tag - better way?
- }
+ os.writeByte(type);
+ os.writeShort(nameBytes.length);
+ os.write(nameBytes);
- /**
- * Writes a TAG_List
tag.
- * @param tag The tag.
- * @throws IOException if an I/O error occurs.
- */
- private void writeListTagPayload(ListTag tag) throws IOException {
- Class extends Tag> clazz = tag.getType();
- ListTAG_String
tag.
- * @param tag The tag.
- * @throws IOException if an I/O error occurs.
- */
- private void writeStringTagPayload(StringTag tag) throws IOException {
- byte[] bytes = tag.getValue().getBytes(NBTConstants.CHARSET);
- os.writeShort(bytes.length);
- os.write(bytes);
- }
+ writeTagPayload(tag);
+ }
- /**
- * Writes a TAG_Double
tag.
- * @param tag The tag.
- * @throws IOException if an I/O error occurs.
- */
- private void writeDoubleTagPayload(DoubleTag tag) throws IOException {
- os.writeDouble(tag.getValue());
- }
+ /**
+ * Writes tag payload.
+ *
+ * @param tag
+ * The tag.
+ * @throws IOException
+ * if an I/O error occurs.
+ */
+ private void writeTagPayload(Tag tag) throws IOException {
+ int type = NBTUtils.getTypeCode(tag.getClass());
+ switch (type) {
+ case NBTConstants.TYPE_END:
+ writeEndTagPayload((EndTag) tag);
+ break;
+ case NBTConstants.TYPE_BYTE:
+ writeByteTagPayload((ByteTag) tag);
+ break;
+ case NBTConstants.TYPE_SHORT:
+ writeShortTagPayload((ShortTag) tag);
+ break;
+ case NBTConstants.TYPE_INT:
+ writeIntTagPayload((IntTag) tag);
+ break;
+ case NBTConstants.TYPE_LONG:
+ writeLongTagPayload((LongTag) tag);
+ break;
+ case NBTConstants.TYPE_FLOAT:
+ writeFloatTagPayload((FloatTag) tag);
+ break;
+ case NBTConstants.TYPE_DOUBLE:
+ writeDoubleTagPayload((DoubleTag) tag);
+ break;
+ case NBTConstants.TYPE_BYTE_ARRAY:
+ writeByteArrayTagPayload((ByteArrayTag) tag);
+ break;
+ case NBTConstants.TYPE_STRING:
+ writeStringTagPayload((StringTag) tag);
+ break;
+ case NBTConstants.TYPE_LIST:
+ writeListTagPayload((ListTag) tag);
+ break;
+ case NBTConstants.TYPE_COMPOUND:
+ writeCompoundTagPayload((CompoundTag) tag);
+ break;
+ case NBTConstants.TYPE_INT_ARRAY:
+ writeIntArrayTagPayload((IntArrayTag) tag);
+ break;
+ default:
+ throw new IOException("Invalid tag type: " + type + ".");
+ }
+ }
- /**
- * Writes a TAG_Float
tag.
- * @param tag The tag.
- * @throws IOException if an I/O error occurs.
- */
- private void writeFloatTagPayload(FloatTag tag) throws IOException {
- os.writeFloat(tag.getValue());
- }
+ /**
+ * Writes a {@code TAG_Byte} tag.
+ *
+ * @param tag
+ * The tag.
+ * @throws IOException
+ * if an I/O error occurs.
+ */
+ private void writeByteTagPayload(ByteTag tag) throws IOException {
+ os.writeByte(tag.getValue());
+ }
- /**
- * Writes a TAG_Long
tag.
- * @param tag The tag.
- * @throws IOException if an I/O error occurs.
- */
- private void writeLongTagPayload(LongTag tag) throws IOException {
- os.writeLong(tag.getValue());
- }
+ /**
+ * Writes a {@code TAG_Byte_Array} tag.
+ *
+ * @param tag
+ * The tag.
+ * @throws IOException
+ * if an I/O error occurs.
+ */
+ private void writeByteArrayTagPayload(ByteArrayTag tag) throws IOException {
+ byte[] bytes = tag.getValue();
+ os.writeInt(bytes.length);
+ os.write(bytes);
+ }
- /**
- * Writes a TAG_Int
tag.
- * @param tag The tag.
- * @throws IOException if an I/O error occurs.
- */
- private void writeIntTagPayload(IntTag tag) throws IOException {
- os.writeInt(tag.getValue());
- }
+ /**
+ * Writes a {@code TAG_Compound} tag.
+ *
+ * @param tag
+ * The tag.
+ * @throws IOException
+ * if an I/O error occurs.
+ */
+ private void writeCompoundTagPayload(CompoundTag tag) throws IOException {
+ for (Tag childTag : tag.getValue().values()) {
+ writeTag(childTag);
+ }
+ os.writeByte((byte) 0); // end tag - better way?
+ }
- /**
- * Writes a TAG_Short
tag.
- * @param tag The tag.
- * @throws IOException if an I/O error occurs.
- */
- private void writeShortTagPayload(ShortTag tag) throws IOException {
- os.writeShort(tag.getValue());
- }
+ /**
+ * Writes a {@code TAG_List} tag.
+ *
+ * @param tag
+ * The tag.
+ * @throws IOException
+ * if an I/O error occurs.
+ */
+ private void writeListTagPayload(ListTag tag) throws IOException {
+ Class extends Tag> clazz = tag.getType();
+ ListTAG_Empty
tag.
- * @param tag The tag.
- * @throws IOException if an I/O error occurs.
- */
- private void writeEndTagPayload(EndTag tag) {
- /* empty */
- }
+ os.writeByte(NBTUtils.getTypeCode(clazz));
+ os.writeInt(size);
+ for (Tag tag1 : tags) {
+ writeTagPayload(tag1);
+ }
+ }
- @Override
- public void close() throws IOException {
- os.close();
- }
+ /**
+ * Writes a {@code TAG_String} tag.
+ *
+ * @param tag
+ * The tag.
+ * @throws IOException
+ * if an I/O error occurs.
+ */
+ private void writeStringTagPayload(StringTag tag) throws IOException {
+ byte[] bytes = tag.getValue().getBytes(NBTConstants.CHARSET);
+ os.writeShort(bytes.length);
+ os.write(bytes);
+ }
+
+ /**
+ * Writes a {@code TAG_Double} tag.
+ *
+ * @param tag
+ * The tag.
+ * @throws IOException
+ * if an I/O error occurs.
+ */
+ private void writeDoubleTagPayload(DoubleTag tag) throws IOException {
+ os.writeDouble(tag.getValue());
+ }
+
+ /**
+ * Writes a {@code TAG_Float} tag.
+ *
+ * @param tag
+ * The tag.
+ * @throws IOException
+ * if an I/O error occurs.
+ */
+ private void writeFloatTagPayload(FloatTag tag) throws IOException {
+ os.writeFloat(tag.getValue());
+ }
+
+ /**
+ * Writes a {@code TAG_Long} tag.
+ *
+ * @param tag
+ * The tag.
+ * @throws IOException
+ * if an I/O error occurs.
+ */
+ private void writeLongTagPayload(LongTag tag) throws IOException {
+ os.writeLong(tag.getValue());
+ }
+
+ /**
+ * Writes a {@code TAG_Int} tag.
+ *
+ * @param tag
+ * The tag.
+ * @throws IOException
+ * if an I/O error occurs.
+ */
+ private void writeIntTagPayload(IntTag tag) throws IOException {
+ os.writeInt(tag.getValue());
+ }
+
+ /**
+ * Writes a {@code TAG_Short} tag.
+ *
+ * @param tag
+ * The tag.
+ * @throws IOException
+ * if an I/O error occurs.
+ */
+ private void writeShortTagPayload(ShortTag tag) throws IOException {
+ os.writeShort(tag.getValue());
+ }
+
+ /**
+ * Writes a {@code TAG_Empty} tag.
+ *
+ * @param tag the tag
+ */
+ private void writeEndTagPayload(EndTag tag) {
+ /* empty */
+ }
+
+ private void writeIntArrayTagPayload(IntArrayTag tag) throws IOException {
+ int[] data = tag.getValue();
+ os.writeInt(data.length);
+ for (int aData : data) {
+ os.writeInt(aData);
+ }
+ }
+
+ @Override
+ public void close() throws IOException {
+ os.close();
+ }
}
diff --git a/PlotSquared/src/com/intellectualcrafters/jnbt/NBTUtils.java b/PlotSquared/src/com/intellectualcrafters/jnbt/NBTUtils.java
index 36c6d0aa3..19a62bfb6 100644
--- a/PlotSquared/src/com/intellectualcrafters/jnbt/NBTUtils.java
+++ b/PlotSquared/src/com/intellectualcrafters/jnbt/NBTUtils.java
@@ -1,152 +1,174 @@
+/*
+ * WorldEdit, a Minecraft world manipulation toolkit
+ * Copyright (C) sk89q TAG_Short
tag.
- * @author Graham Edgecombe
- *
+ * The {@code TAG_Short} tag.
*/
public final class ShortTag extends Tag {
- /**
- * The value.
- */
- private final short value;
-
- /**
- * Creates the tag.
- * @param name The name.
- * @param value The value.
- */
- public ShortTag(String name, short value) {
- super(name);
- this.value = value;
- }
-
- @Override
- public Short getValue() {
- return value;
- }
-
- @Override
- public String toString() {
- String name = getName();
- String append = "";
- if(name != null && !name.equals("")) {
- append = "(\"" + this.getName() + "\")";
- }
- return "TAG_Short" + append + ": " + value;
- }
+ private final short value;
+
+ /**
+ * Creates the tag with an empty name.
+ *
+ * @param value the value of the tag
+ */
+ public ShortTag(short value) {
+ super();
+ this.value = value;
+ }
+
+ /**
+ * Creates the tag.
+ *
+ * @param name the name of the tag
+ * @param value the value of the tag
+ */
+ public ShortTag(String name, short value) {
+ super(name);
+ this.value = value;
+ }
+
+ @Override
+ public Short getValue() {
+ return value;
+ }
+
+ @Override
+ public String toString() {
+ String name = getName();
+ String append = "";
+ if (name != null && !name.equals("")) {
+ append = "(\"" + this.getName() + "\")";
+ }
+ return "TAG_Short" + append + ": " + value;
+ }
}
diff --git a/PlotSquared/src/com/intellectualcrafters/jnbt/StringTag.java b/PlotSquared/src/com/intellectualcrafters/jnbt/StringTag.java
index d84b70f55..1e5c06a98 100644
--- a/PlotSquared/src/com/intellectualcrafters/jnbt/StringTag.java
+++ b/PlotSquared/src/com/intellectualcrafters/jnbt/StringTag.java
@@ -1,73 +1,69 @@
-package com.intellectualcrafters.jnbt;
-
/*
- * JNBT License
- *
- * Copyright (c) 2010 Graham Edgecombe
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * * Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of the JNBT team nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
+ * WorldEdit, a Minecraft world manipulation toolkit
+ * Copyright (C) sk89q TAG_String
tag.
- * @author Graham Edgecombe
- *
+ * The {@code TAG_String} tag.
*/
public final class StringTag extends Tag {
- /**
- * The value.
- */
- private final String value;
-
- /**
- * Creates the tag.
- * @param name The name.
- * @param value The value.
- */
- public StringTag(String name, String value) {
- super(name);
- this.value = value;
- }
-
- @Override
- public String getValue() {
- return value;
- }
-
- @Override
- public String toString() {
- String name = getName();
- String append = "";
- if(name != null && !name.equals("")) {
- append = "(\"" + this.getName() + "\")";
- }
- return "TAG_String" + append + ": " + value;
- }
+ private final String value;
+
+ /**
+ * Creates the tag with an empty name.
+ *
+ * @param value the value of the tag
+ */
+ public StringTag(String value) {
+ super();
+ checkNotNull(value);
+ this.value = value;
+ }
+
+ /**
+ * Creates the tag.
+ *
+ * @param name the name of the tag
+ * @param value the value of the tag
+ */
+ public StringTag(String name, String value) {
+ super(name);
+ checkNotNull(value);
+ this.value = value;
+ }
+
+ @Override
+ public String getValue() {
+ return value;
+ }
+
+ @Override
+ public String toString() {
+ String name = getName();
+ String append = "";
+ if (name != null && !name.equals("")) {
+ append = "(\"" + this.getName() + "\")";
+ }
+ return "TAG_String" + append + ": " + value;
+ }
}
diff --git a/PlotSquared/src/com/intellectualcrafters/jnbt/Tag.java b/PlotSquared/src/com/intellectualcrafters/jnbt/Tag.java
index 1c2694f5b..a1ea70e83 100644
--- a/PlotSquared/src/com/intellectualcrafters/jnbt/Tag.java
+++ b/PlotSquared/src/com/intellectualcrafters/jnbt/Tag.java
@@ -1,70 +1,64 @@
+/*
+ * WorldEdit, a Minecraft world manipulation toolkit
+ * Copyright (C) sk89q