Permalink
Browse files

Add type-related tag methods to CompoundTag

  • Loading branch information...
fromgate committed Feb 16, 2017
1 parent 1310837 commit 7adb3668e43ffa97163cb6cfd4d0e062bf5f4767
Showing with 62 additions and 0 deletions.
  1. +62 −0 nbt/src/main/java/com/voxelwind/nbt/tags/CompoundTag.java
@@ -8,11 +8,73 @@
private final String name;
private final Map<String, Tag<?>> value;

public CompoundTag(String name) {
this.name = name;
this.value = Collections.unmodifiableMap(new HashMap<>());
}

public CompoundTag(String name, Map<String, Tag<?>> value) {
this.name = name;
this.value = Collections.unmodifiableMap(new HashMap<>(value));
}

public void remove(String name) {
if (value.containsKey(name)) {
value.remove(name);
}
}

public CompoundTag tag(Tag<?> tag) {
value.put(tag.getName(), tag);
return this;
}

public CompoundTag tagByte(String name, byte value) {
return tag(new ByteTag(name, value));
}

public CompoundTag tagByteArray(String name, byte[] value) {
return tag(new ByteArrayTag(name, value));
}

public CompoundTag tagDouble(String name, double value) {
return tag(new DoubleTag(name, value));
}

public CompoundTag tagFloat(String name, float value) {
return tag(new FloatTag(name, value));
}

public CompoundTag tagIntArray(String name, int[] value) {
return tag(new IntArrayTag(name, value));
}

public CompoundTag tagInt(String name, int value) {
return tag(new IntTag(name, value));
}

public CompoundTag tagLong(String name, long value) {
return tag(new LongTag(name, value));
}

public CompoundTag tagShort(String name, short value) {
return tag(new ShortTag(name, value));
}

public CompoundTag tagString(String name, String value) {
return tag(new StringTag(name, value));
}

public CompoundTag tagCompoundTag(String name, CompoundTag value) {
this.value.put(name, value);
return this;
}

public CompoundTag tagListTag(String name, ListTag value) {
this.value.put(name, value);
return this;
}

@Override
public String getName() {
return name;

0 comments on commit 7adb366

Please sign in to comment.