/
CompoundTagBuilder.java
82 lines (63 loc) · 2.26 KB
/
CompoundTagBuilder.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package com.voxelwind.nbt.util;
import com.voxelwind.nbt.tags.*;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import java.util.HashMap;
import java.util.Map;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class CompoundTagBuilder {
private final Map<String, Tag<?>> tagMap = new HashMap<>();
public static CompoundTagBuilder builder() {
return new CompoundTagBuilder();
}
public static CompoundTagBuilder from(CompoundTag tag) {
CompoundTagBuilder builder = new CompoundTagBuilder();
builder.tagMap.putAll(tag.getValue());
return builder;
}
public CompoundTagBuilder tag(Tag<?> tag) {
tagMap.put(tag.getName(), tag);
return this;
}
public CompoundTagBuilder tagByte (String name, byte value) {
return tag(new ByteTag(name, value));
}
public CompoundTagBuilder tagByteArray (String name, byte [] value) {
return tag(new ByteArrayTag(name, value));
}
public CompoundTagBuilder tagDouble (String name, double value) {
return tag(new DoubleTag(name, value));
}
public CompoundTagBuilder tagFloat (String name, float value) {
return tag(new FloatTag(name, value));
}
public CompoundTagBuilder tagIntArray (String name, int[] value) {
return tag(new IntArrayTag(name, value));
}
public CompoundTagBuilder tagInt (String name, int value) {
return tag(new IntTag(name, value));
}
public CompoundTagBuilder tagLong (String name, long value) {
return tag(new LongTag(name, value));
}
public CompoundTagBuilder tagShort (String name, short value) {
return tag(new ShortTag(name, value));
}
public CompoundTagBuilder tagString (String name, String value) {
return tag(new StringTag(name, value));
}
public CompoundTagBuilder tagCompoundTag (String name, CompoundTag value) {
tagMap.put(name, value);
return this;
}
public CompoundTagBuilder tagListTag(String name, ListTag value) {
tagMap.put(name, value);
return this;
}
public CompoundTag buildRootTag() {
return new CompoundTag("", tagMap);
}
public CompoundTag build(String tagName) {
return new CompoundTag(tagName, tagMap);
}
}