();
234 | for(Tag value : this.value) {
235 | newList.add(value.clone());
236 | }
237 |
238 | return new ListTag(this.getName(), newList);
239 | }
240 | }
241 |
--------------------------------------------------------------------------------
/src/main/java/com/github/steveice10/opennbt/tag/builtin/LongArrayTag.java:
--------------------------------------------------------------------------------
1 | package com.github.steveice10.opennbt.tag.builtin;
2 |
3 | import java.io.DataInput;
4 | import java.io.DataOutput;
5 | import java.io.IOException;
6 |
7 | import com.github.steveice10.opennbt.SNBTIO.StringifiedNBTReader;
8 | import com.github.steveice10.opennbt.SNBTIO.StringifiedNBTWriter;
9 |
10 | /**
11 | * A tag containing a long array.
12 | */
13 | public class LongArrayTag extends Tag {
14 | private long[] value;
15 |
16 | /**
17 | * Creates a tag with the specified name.
18 | *
19 | * @param name The name of the tag.
20 | */
21 | public LongArrayTag(String name) {
22 | this(name, new long[0]);
23 | }
24 |
25 | /**
26 | * Creates a tag with the specified name.
27 | *
28 | * @param name The name of the tag.
29 | * @param value The value of the tag.
30 | */
31 | public LongArrayTag(String name, long[] value) {
32 | super(name);
33 | this.value = value;
34 | }
35 |
36 | @Override
37 | public long[] getValue() {
38 | return this.value.clone();
39 | }
40 |
41 | /**
42 | * Sets the value of this tag.
43 | *
44 | * @param value New value of this tag.
45 | */
46 | public void setValue(long[] value) {
47 | if(value == null) {
48 | return;
49 | }
50 |
51 | this.value = value.clone();
52 | }
53 |
54 | /**
55 | * Gets a value in this tag's array.
56 | *
57 | * @param index Index of the value.
58 | * @return The value at the given index.
59 | */
60 | public long getValue(int index) {
61 | return this.value[index];
62 | }
63 |
64 | /**
65 | * Sets a value in this tag's array.
66 | *
67 | * @param index Index of the value.
68 | * @param value Value to set.
69 | */
70 | public void setValue(int index, long value) {
71 | this.value[index] = value;
72 | }
73 |
74 | /**
75 | * Gets the length of this tag's array.
76 | *
77 | * @return This tag's array length.
78 | */
79 | public int length() {
80 | return this.value.length;
81 | }
82 |
83 | @Override
84 | public void read(DataInput in) throws IOException {
85 | this.value = new long[in.readInt()];
86 | for(int index = 0; index < this.value.length; index++) {
87 | this.value[index] = in.readLong();
88 | }
89 | }
90 |
91 | @Override
92 | public void write(DataOutput out) throws IOException {
93 | out.writeInt(this.value.length);
94 | for(int index = 0; index < this.value.length; index++) {
95 | out.writeLong(this.value[index]);
96 | }
97 | }
98 |
99 | @Override
100 | public void destringify(StringifiedNBTReader in) throws IOException {
101 | String s = in.readUntil(true, ']');
102 | String[] valueStrings = s.substring(s.indexOf(';') + 1, s.length() - 1).replaceAll(" ", "").split(",");
103 | value = new long[valueStrings.length];
104 | for(int i = 0; i < value.length; i++) {
105 | value[i] = Long.parseLong(valueStrings[i]);
106 | }
107 | }
108 |
109 | @Override
110 | public void stringify(StringifiedNBTWriter out, boolean linebreak, int depth) throws IOException {
111 | StringBuilder sb = new StringBuilder("[L; ");
112 | for(long b : value) {
113 | sb.append(b);
114 | sb.append(',');
115 | sb.append(' ');
116 | }
117 | sb.setLength(sb.length() - 2);
118 | sb.append(']');
119 | out.append(sb.toString());
120 | }
121 |
122 | @Override
123 | public LongArrayTag clone() {
124 | return new LongArrayTag(this.getName(), this.getValue());
125 | }
126 | }
127 |
--------------------------------------------------------------------------------
/src/main/java/com/github/steveice10/opennbt/tag/builtin/LongTag.java:
--------------------------------------------------------------------------------
1 | package com.github.steveice10.opennbt.tag.builtin;
2 |
3 | import java.io.DataInput;
4 | import java.io.DataOutput;
5 | import java.io.IOException;
6 |
7 | import com.github.steveice10.opennbt.SNBTIO.StringifiedNBTReader;
8 | import com.github.steveice10.opennbt.SNBTIO.StringifiedNBTWriter;
9 |
10 | /**
11 | * A tag containing a long.
12 | */
13 | public class LongTag extends Tag {
14 | private long value;
15 |
16 | /**
17 | * Creates a tag with the specified name.
18 | *
19 | * @param name The name of the tag.
20 | */
21 | public LongTag(String name) {
22 | this(name, 0);
23 | }
24 |
25 | /**
26 | * Creates a tag with the specified name.
27 | *
28 | * @param name The name of the tag.
29 | * @param value The value of the tag.
30 | */
31 | public LongTag(String name, long value) {
32 | super(name);
33 | this.value = value;
34 | }
35 |
36 | @Override
37 | public Long getValue() {
38 | return this.value;
39 | }
40 |
41 | /**
42 | * Sets the value of this tag.
43 | *
44 | * @param value New value of this tag.
45 | */
46 | public void setValue(long value) {
47 | this.value = value;
48 | }
49 |
50 | @Override
51 | public void read(DataInput in) throws IOException {
52 | this.value = in.readLong();
53 | }
54 |
55 | @Override
56 | public void write(DataOutput out) throws IOException {
57 | out.writeLong(this.value);
58 | }
59 |
60 | @Override
61 | public void destringify(StringifiedNBTReader in) throws IOException {
62 | String s = in.readNextSingleValueString();
63 | s = s.toLowerCase().substring(0, s.length() - 1);
64 | value = Long.parseLong(s);
65 | }
66 |
67 | @Override
68 | public void stringify(StringifiedNBTWriter out, boolean linebreak, int depth) throws IOException {
69 | StringBuilder sb = new StringBuilder();
70 | sb.append(value);
71 | sb.append('l');
72 | out.append(sb.toString());
73 | }
74 |
75 | @Override
76 | public LongTag clone() {
77 | return new LongTag(this.getName(), this.getValue());
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/src/main/java/com/github/steveice10/opennbt/tag/builtin/ShortTag.java:
--------------------------------------------------------------------------------
1 | package com.github.steveice10.opennbt.tag.builtin;
2 |
3 | import java.io.DataInput;
4 | import java.io.DataOutput;
5 | import java.io.IOException;
6 |
7 | import com.github.steveice10.opennbt.SNBTIO.StringifiedNBTReader;
8 | import com.github.steveice10.opennbt.SNBTIO.StringifiedNBTWriter;
9 |
10 | /**
11 | * A tag containing a short.
12 | */
13 | public class ShortTag extends Tag {
14 | private short value;
15 |
16 | /**
17 | * Creates a tag with the specified name.
18 | *
19 | * @param name The name of the tag.
20 | */
21 | public ShortTag(String name) {
22 | this(name, (short) 0);
23 | }
24 |
25 | /**
26 | * Creates a tag with the specified name.
27 | *
28 | * @param name The name of the tag.
29 | * @param value The value of the tag.
30 | */
31 | public ShortTag(String name, short value) {
32 | super(name);
33 | this.value = value;
34 | }
35 |
36 | @Override
37 | public Short getValue() {
38 | return this.value;
39 | }
40 |
41 | /**
42 | * Sets the value of this tag.
43 | *
44 | * @param value New value of this tag.
45 | */
46 | public void setValue(short value) {
47 | this.value = value;
48 | }
49 |
50 | @Override
51 | public void read(DataInput in) throws IOException {
52 | this.value = in.readShort();
53 | }
54 |
55 | @Override
56 | public void write(DataOutput out) throws IOException {
57 | out.writeShort(this.value);
58 | }
59 |
60 | @Override
61 | public void destringify(StringifiedNBTReader in) throws IOException {
62 | String s = in.readNextSingleValueString();
63 | s = s.toLowerCase().substring(0, s.length() - 1);
64 | value = Short.parseShort(s);
65 | }
66 |
67 | @Override
68 | public void stringify(StringifiedNBTWriter out, boolean linebreak, int depth) throws IOException {
69 | StringBuilder sb = new StringBuilder();
70 | sb.append(value);
71 | sb.append('s');
72 | out.append(sb.toString());
73 | }
74 |
75 | @Override
76 | public ShortTag clone() {
77 | return new ShortTag(this.getName(), this.getValue());
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/src/main/java/com/github/steveice10/opennbt/tag/builtin/StringTag.java:
--------------------------------------------------------------------------------
1 | package com.github.steveice10.opennbt.tag.builtin;
2 |
3 | import java.io.DataInput;
4 | import java.io.DataOutput;
5 | import java.io.IOException;
6 |
7 | import com.github.steveice10.opennbt.SNBTIO.StringifiedNBTReader;
8 | import com.github.steveice10.opennbt.SNBTIO.StringifiedNBTWriter;
9 |
10 | /**
11 | * A tag containing a string.
12 | */
13 | public class StringTag extends Tag {
14 | private String value;
15 |
16 | /**
17 | * Creates a tag with the specified name.
18 | *
19 | * @param name The name of the tag.
20 | */
21 | public StringTag(String name) {
22 | this(name, "");
23 | }
24 |
25 | /**
26 | * Creates a tag with the specified name.
27 | *
28 | * @param name The name of the tag.
29 | * @param value The value of the tag.
30 | */
31 | public StringTag(String name, String value) {
32 | super(name);
33 | this.value = value;
34 | }
35 |
36 | @Override
37 | public String getValue() {
38 | return this.value;
39 | }
40 |
41 | /**
42 | * Sets the value of this tag.
43 | *
44 | * @param value New value of this tag.
45 | */
46 | public void setValue(String value) {
47 | this.value = value;
48 | }
49 |
50 | @Override
51 | public void read(DataInput in) throws IOException {
52 | this.value = in.readUTF();
53 | }
54 |
55 | @Override
56 | public void write(DataOutput out) throws IOException {
57 | out.writeUTF(this.value);
58 | }
59 |
60 | @Override
61 | public void destringify(StringifiedNBTReader in) throws IOException {
62 | String s = in.readNextSingleValueString();
63 | if(s.charAt(0) == '"') {
64 | value = s.substring(1, s.length() - 1).replaceAll("\\\\\"", "\"");
65 | } else if(s.charAt(0) == '\'') {
66 | value = s.substring(1, s.length() - 1).replaceAll("\\\\\'", "'");
67 | } else {
68 | value = s;
69 | }
70 | }
71 |
72 | @Override
73 | public void stringify(StringifiedNBTWriter out, boolean linebreak, int depth) throws IOException {
74 | if(value.matches("(?!\\d+)[\\w\\d]*")) {
75 | out.append(value);
76 | return;
77 | }
78 | if(value.contains("\"")) {
79 | if(value.contains("'")) {
80 | StringBuilder sb = new StringBuilder("\"");
81 | sb.append(value.replaceAll("\"", "\\\\\""));
82 | sb.append("\"");
83 | out.append(sb.toString());
84 | return;
85 | }
86 | StringBuilder sb = new StringBuilder("'");
87 | sb.append(value);
88 | sb.append("'");
89 | out.append(sb.toString());
90 | return;
91 | }
92 | StringBuilder sb = new StringBuilder("\"");
93 | sb.append(value);
94 | sb.append("\"");
95 | out.append(sb.toString());
96 | }
97 |
98 | @Override
99 | public StringTag clone() {
100 | return new StringTag(this.getName(), this.getValue());
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/src/main/java/com/github/steveice10/opennbt/tag/builtin/Tag.java:
--------------------------------------------------------------------------------
1 | package com.github.steveice10.opennbt.tag.builtin;
2 |
3 | import java.io.DataInput;
4 | import java.io.DataOutput;
5 | import java.io.IOException;
6 | import java.io.OutputStreamWriter;
7 | import java.lang.reflect.Array;
8 |
9 | import com.github.steveice10.opennbt.SNBTIO.StringifiedNBTReader;
10 | import com.github.steveice10.opennbt.SNBTIO.StringifiedNBTWriter;
11 |
12 | /**
13 | * Represents an NBT tag.
14 | *
15 | * All tags must have a constructor with a single string parameter for reading tags (can be any visibility).
16 | * Tags should also have setter methods specific to their value types.
17 | */
18 | public abstract class Tag implements Cloneable {
19 | private String name;
20 |
21 | /**
22 | * Creates a tag with the specified name.
23 | *
24 | * @param name The name.
25 | */
26 | public Tag(String name) {
27 | this.name = name;
28 | }
29 |
30 | /**
31 | * Gets the name of this tag.
32 | *
33 | * @return The name of this tag.
34 | */
35 | public final String getName() {
36 | return this.name;
37 | }
38 |
39 | /**
40 | * Gets the value of this tag.
41 | *
42 | * @return The value of this tag.
43 | */
44 | public abstract Object getValue();
45 |
46 | /**
47 | * Reads this tag from an input stream.
48 | *
49 | * @param in Stream to read from.
50 | * @throws java.io.IOException If an I/O error occurs.
51 | */
52 | public abstract void read(DataInput in) throws IOException;
53 |
54 | /**
55 | * Writes this tag to an output stream.
56 | *
57 | * @param out Stream to write to.
58 | * @throws java.io.IOException If an I/O error occurs.
59 | */
60 | public abstract void write(DataOutput out) throws IOException;
61 |
62 | /**
63 | * Parses this tag from stringified NBT.
64 | *
65 | * @param in String to parse.
66 | */
67 | public abstract void destringify(StringifiedNBTReader in) throws IOException;
68 |
69 | /**
70 | * Write this tag as stringified NBT.
71 | */
72 | public abstract void stringify(StringifiedNBTWriter out, boolean linebreak, int depth) throws IOException;
73 |
74 | @Override
75 | public abstract Tag clone();
76 |
77 | @Override
78 | public boolean equals(Object obj) {
79 | if(!(obj instanceof Tag)) {
80 | return false;
81 | }
82 |
83 | Tag tag = (Tag) obj;
84 | if(!this.getName().equals(tag.getName())) {
85 | return false;
86 | }
87 |
88 | if(this.getValue() == null) {
89 | return tag.getValue() == null;
90 | } else if(tag.getValue() == null) {
91 | return false;
92 | }
93 |
94 | if(this.getValue().getClass().isArray() && tag.getValue().getClass().isArray()) {
95 | int length = Array.getLength(this.getValue());
96 | if(Array.getLength(tag.getValue()) != length) {
97 | return false;
98 | }
99 |
100 | for(int index = 0; index < length; index++) {
101 | Object o = Array.get(this.getValue(), index);
102 | Object other = Array.get(tag.getValue(), index);
103 | if(o == null && other != null || o != null && !o.equals(other)) {
104 | return false;
105 | }
106 | }
107 |
108 | return true;
109 | }
110 |
111 | return this.getValue().equals(tag.getValue());
112 | }
113 |
114 | @Override
115 | public String toString() {
116 | String name = this.getName() != null && !this.getName().equals("") ? "(" + this.getName() + ")" : "";
117 | String value = "";
118 | if(this.getValue() != null) {
119 | value = this.getValue().toString();
120 | if(this.getValue().getClass().isArray()) {
121 | StringBuilder build = new StringBuilder();
122 | build.append("[");
123 | for(int index = 0; index < Array.getLength(this.getValue()); index++) {
124 | if(index > 0) {
125 | build.append(", ");
126 | }
127 |
128 | build.append(Array.get(this.getValue(), index));
129 | }
130 |
131 | build.append("]");
132 | value = build.toString();
133 | }
134 | }
135 |
136 | return this.getClass().getSimpleName() + name + " { " + value + " }";
137 | }
138 | }
139 |
--------------------------------------------------------------------------------
/src/main/java/com/github/steveice10/opennbt/tag/builtin/custom/DoubleArrayTag.java:
--------------------------------------------------------------------------------
1 | package com.github.steveice10.opennbt.tag.builtin.custom;
2 |
3 | import java.io.DataInput;
4 | import java.io.DataOutput;
5 | import java.io.IOException;
6 |
7 | import com.github.steveice10.opennbt.SNBTIO.StringifiedNBTReader;
8 | import com.github.steveice10.opennbt.SNBTIO.StringifiedNBTWriter;
9 | import com.github.steveice10.opennbt.tag.builtin.Tag;
10 |
11 | /**
12 | * A tag containing a double array.
13 | */
14 | public class DoubleArrayTag extends Tag {
15 | private double[] value;
16 |
17 | /**
18 | * Creates a tag with the specified name.
19 | *
20 | * @param name The name of the tag.
21 | */
22 | public DoubleArrayTag(String name) {
23 | this(name, new double[0]);
24 | }
25 |
26 | /**
27 | * Creates a tag with the specified name.
28 | *
29 | * @param name The name of the tag.
30 | * @param value The value of the tag.
31 | */
32 | public DoubleArrayTag(String name, double[] value) {
33 | super(name);
34 | this.value = value;
35 | }
36 |
37 | @Override
38 | public double[] getValue() {
39 | return this.value.clone();
40 | }
41 |
42 | /**
43 | * Sets the value of this tag.
44 | *
45 | * @param value New value of this tag.
46 | */
47 | public void setValue(double[] value) {
48 | if(value == null) {
49 | return;
50 | }
51 |
52 | this.value = value.clone();
53 | }
54 |
55 | /**
56 | * Gets a value in this tag's array.
57 | *
58 | * @param index Index of the value.
59 | * @return The value at the given index.
60 | */
61 | public double getValue(int index) {
62 | return this.value[index];
63 | }
64 |
65 | /**
66 | * Sets a value in this tag's array.
67 | *
68 | * @param index Index of the value.
69 | * @param value Value to set.
70 | */
71 | public void setValue(int index, double value) {
72 | this.value[index] = value;
73 | }
74 |
75 | /**
76 | * Gets the length of this tag's array.
77 | *
78 | * @return This tag's array length.
79 | */
80 | public int length() {
81 | return this.value.length;
82 | }
83 |
84 | @Override
85 | public void read(DataInput in) throws IOException {
86 | this.value = new double[in.readInt()];
87 | for(int index = 0; index < this.value.length; index++) {
88 | this.value[index] = in.readDouble();
89 | }
90 | }
91 |
92 | @Override
93 | public void write(DataOutput out) throws IOException {
94 | out.writeInt(this.value.length);
95 | for(int index = 0; index < this.value.length; index++) {
96 | out.writeDouble(this.value[index]);
97 | }
98 | }
99 |
100 | @Override
101 | public void destringify(StringifiedNBTReader in) throws IOException {
102 | String s = in.readUntil(true, ']');
103 | String[] valueStrings = s.substring(s.indexOf(';') + 1, s.length() - 1).replaceAll(" ", "").split(",");
104 | value = new double[valueStrings.length];
105 | for(int i = 0; i < value.length; i++) {
106 | value[i] = Double.parseDouble(valueStrings[i]);
107 | }
108 | }
109 |
110 | @Override
111 | public void stringify(StringifiedNBTWriter out, boolean linebreak, int depth) throws IOException {
112 | StringBuilder sb = new StringBuilder("[D; ");
113 | for(double b : value) {
114 | sb.append(b);
115 | sb.append(',');
116 | sb.append(' ');
117 | }
118 | sb.setLength(sb.length() - 2);
119 | sb.append(']');
120 | out.append(sb.toString());
121 | }
122 |
123 | @Override
124 | public DoubleArrayTag clone() {
125 | return new DoubleArrayTag(this.getName(), this.getValue());
126 | }
127 | }
128 |
--------------------------------------------------------------------------------
/src/main/java/com/github/steveice10/opennbt/tag/builtin/custom/FloatArrayTag.java:
--------------------------------------------------------------------------------
1 | package com.github.steveice10.opennbt.tag.builtin.custom;
2 |
3 | import java.io.DataInput;
4 | import java.io.DataOutput;
5 | import java.io.IOException;
6 |
7 | import com.github.steveice10.opennbt.SNBTIO.StringifiedNBTReader;
8 | import com.github.steveice10.opennbt.SNBTIO.StringifiedNBTWriter;
9 | import com.github.steveice10.opennbt.tag.builtin.Tag;
10 |
11 | /**
12 | * A tag containing a float array.
13 | */
14 | public class FloatArrayTag extends Tag {
15 | private float[] value;
16 |
17 | /**
18 | * Creates a tag with the specified name.
19 | *
20 | * @param name The name of the tag.
21 | */
22 | public FloatArrayTag(String name) {
23 | this(name, new float[0]);
24 | }
25 |
26 | /**
27 | * Creates a tag with the specified name.
28 | *
29 | * @param name The name of the tag.
30 | * @param value The value of the tag.
31 | */
32 | public FloatArrayTag(String name, float[] value) {
33 | super(name);
34 | this.value = value;
35 | }
36 |
37 | @Override
38 | public float[] getValue() {
39 | return this.value.clone();
40 | }
41 |
42 | /**
43 | * Sets the value of this tag.
44 | *
45 | * @param value New value of this tag.
46 | */
47 | public void setValue(float[] value) {
48 | if(value == null) {
49 | return;
50 | }
51 |
52 | this.value = value.clone();
53 | }
54 |
55 | /**
56 | * Gets a value in this tag's array.
57 | *
58 | * @param index Index of the value.
59 | * @return The value at the given index.
60 | */
61 | public float getValue(int index) {
62 | return this.value[index];
63 | }
64 |
65 | /**
66 | * Sets a value in this tag's array.
67 | *
68 | * @param index Index of the value.
69 | * @param value Value to set.
70 | */
71 | public void setValue(int index, float value) {
72 | this.value[index] = value;
73 | }
74 |
75 | /**
76 | * Gets the length of this tag's array.
77 | *
78 | * @return This tag's array length.
79 | */
80 | public int length() {
81 | return this.value.length;
82 | }
83 |
84 | @Override
85 | public void read(DataInput in) throws IOException {
86 | this.value = new float[in.readInt()];
87 | for(int index = 0; index < this.value.length; index++) {
88 | this.value[index] = in.readFloat();
89 | }
90 | }
91 |
92 | @Override
93 | public void write(DataOutput out) throws IOException {
94 | out.writeInt(this.value.length);
95 | for(int index = 0; index < this.value.length; index++) {
96 | out.writeFloat(this.value[index]);
97 | }
98 | }
99 |
100 | @Override
101 | public void destringify(StringifiedNBTReader in) throws IOException {
102 | String s = in.readUntil(true, ']');
103 | String[] valueStrings = s.substring(s.indexOf(';') + 1, s.length() - 1).replaceAll(" ", "").split(",");
104 | value = new float[valueStrings.length];
105 | for(int i = 0; i < value.length; i++) {
106 | value[i] = Float.parseFloat(valueStrings[i]);
107 | }
108 | }
109 |
110 | @Override
111 | public void stringify(StringifiedNBTWriter out, boolean linebreak, int depth) throws IOException {
112 | StringBuilder sb = new StringBuilder("[F; ");
113 | for(float b : value) {
114 | sb.append(b);
115 | sb.append(',');
116 | sb.append(' ');
117 | }
118 | sb.setLength(sb.length() - 2);
119 | sb.append(']');
120 | out.append(sb.toString());
121 | }
122 |
123 | @Override
124 | public FloatArrayTag clone() {
125 | return new FloatArrayTag(this.getName(), this.getValue());
126 | }
127 | }
128 |
--------------------------------------------------------------------------------
/src/main/java/com/github/steveice10/opennbt/tag/builtin/custom/ShortArrayTag.java:
--------------------------------------------------------------------------------
1 | package com.github.steveice10.opennbt.tag.builtin.custom;
2 |
3 | import java.io.DataInput;
4 | import java.io.DataOutput;
5 | import java.io.IOException;
6 |
7 | import com.github.steveice10.opennbt.SNBTIO.StringifiedNBTReader;
8 | import com.github.steveice10.opennbt.SNBTIO.StringifiedNBTWriter;
9 | import com.github.steveice10.opennbt.tag.builtin.Tag;
10 |
11 | /**
12 | * A tag containing a short array.
13 | */
14 | public class ShortArrayTag extends Tag {
15 | private short[] value;
16 |
17 | /**
18 | * Creates a tag with the specified name.
19 | *
20 | * @param name The name of the tag.
21 | */
22 | public ShortArrayTag(String name) {
23 | this(name, new short[0]);
24 | }
25 |
26 | /**
27 | * Creates a tag with the specified name.
28 | *
29 | * @param name The name of the tag.
30 | * @param value The value of the tag.
31 | */
32 | public ShortArrayTag(String name, short[] value) {
33 | super(name);
34 | this.value = value;
35 | }
36 |
37 | @Override
38 | public short[] getValue() {
39 | return this.value.clone();
40 | }
41 |
42 | /**
43 | * Sets the value of this tag.
44 | *
45 | * @param value New value of this tag.
46 | */
47 | public void setValue(short[] value) {
48 | if(value == null) {
49 | return;
50 | }
51 |
52 | this.value = value.clone();
53 | }
54 |
55 | /**
56 | * Gets a value in this tag's array.
57 | *
58 | * @param index Index of the value.
59 | * @return The value at the given index.
60 | */
61 | public short getValue(int index) {
62 | return this.value[index];
63 | }
64 |
65 | /**
66 | * Sets a value in this tag's array.
67 | *
68 | * @param index Index of the value.
69 | * @param value Value to set.
70 | */
71 | public void setValue(int index, short value) {
72 | this.value[index] = value;
73 | }
74 |
75 | /**
76 | * Gets the length of this tag's array.
77 | *
78 | * @return This tag's array length.
79 | */
80 | public int length() {
81 | return this.value.length;
82 | }
83 |
84 | @Override
85 | public void read(DataInput in) throws IOException {
86 | this.value = new short[in.readInt()];
87 | for(int index = 0; index < this.value.length; index++) {
88 | this.value[index] = in.readShort();
89 | }
90 | }
91 |
92 | @Override
93 | public void write(DataOutput out) throws IOException {
94 | out.writeInt(this.value.length);
95 | for(int index = 0; index < this.value.length; index++) {
96 | out.writeShort(this.value[index]);
97 | }
98 | }
99 |
100 | @Override
101 | public void destringify(StringifiedNBTReader in) throws IOException {
102 | String s = in.readUntil(true, ']');
103 | String[] valueStrings = s.substring(s.indexOf(';') + 1, s.length() - 1).replaceAll(" ", "").split(",");
104 | value = new short[valueStrings.length];
105 | for(int i = 0; i < value.length; i++) {
106 | value[i] = Short.parseShort(valueStrings[i]);
107 | }
108 | }
109 |
110 | @Override
111 | public void stringify(StringifiedNBTWriter out, boolean linebreak, int depth) throws IOException {
112 | StringBuilder sb = new StringBuilder("[S; ");
113 | for(short b : value) {
114 | sb.append(b);
115 | sb.append(',');
116 | sb.append(' ');
117 | }
118 | sb.setLength(sb.length() - 2);
119 | sb.append(']');
120 | out.append(sb.toString());
121 | }
122 |
123 | @Override
124 | public ShortArrayTag clone() {
125 | return new ShortArrayTag(this.getName(), this.getValue());
126 | }
127 | }
128 |
--------------------------------------------------------------------------------