From 45857218e010eba71ac3b27897c09ed56fc60dd1 Mon Sep 17 00:00:00 2001 From: mworzala Date: Fri, 26 Apr 2024 00:27:51 -0400 Subject: [PATCH] fix: make NBTListType and NBTMapType properly mutable --- .../dataconverter/types/nbt/NBTListType.java | 136 ++++++++------ .../dataconverter/types/nbt/NBTMapType.java | 176 +++++++++++------- 2 files changed, 189 insertions(+), 123 deletions(-) diff --git a/src/main/java/ca/spottedleaf/dataconverter/types/nbt/NBTListType.java b/src/main/java/ca/spottedleaf/dataconverter/types/nbt/NBTListType.java index 1fe5b44..1cd815d 100644 --- a/src/main/java/ca/spottedleaf/dataconverter/types/nbt/NBTListType.java +++ b/src/main/java/ca/spottedleaf/dataconverter/types/nbt/NBTListType.java @@ -3,16 +3,23 @@ import ca.spottedleaf.dataconverter.types.*; import net.kyori.adventure.nbt.*; +import java.util.ArrayList; +import java.util.List; + public final class NBTListType implements ListType { - private ListBinaryTag list; + private List list; // Can contain BinaryTags, NBTListType, NBTMapType public NBTListType() { - this.list = ListBinaryTag.empty(); + this.list = new ArrayList<>(); } public NBTListType(final ListBinaryTag tag) { - this.list = tag; + this.list = new ArrayList<>(tag.stream().toList()); + } + + public NBTListType(final List entries) { + this.list = new ArrayList<>(entries); } @Override @@ -45,7 +52,19 @@ public String toString() { } public ListBinaryTag getTag() { - return this.list; + final ListBinaryTag.Builder builder = ListBinaryTag.builder(); + for (Object entry : this.list) { + if (entry instanceof BinaryTag tag) { + builder.add(tag); + } else if (entry instanceof NBTListType list) { + builder.add((BinaryTag) list.getTag()); + } else if (entry instanceof NBTMapType map) { + builder.add(map.getTag()); + } else { + throw new IllegalStateException("Unknown type: " + entry); + } + } + return builder.build(); } @Override @@ -88,7 +107,14 @@ protected static ObjectType getType(final byte id) { @Override public ObjectType getType() { - return getType(this.list.elementType().id()); + if (this.list.isEmpty()) + return ObjectType.NONE; + return switch (this.list.getFirst()) { + case BinaryTag tag -> getType(tag.type().id()); + case NBTListType l -> ObjectType.LIST; + case NBTMapType m -> ObjectType.MAP; + default -> ObjectType.NONE; + }; } @Override @@ -98,12 +124,12 @@ public int size() { @Override public void remove(final int index) { - this.list = this.list.remove(index, null); + this.list.remove(index); } @Override public Number getNumber(final int index) { - final BinaryTag tag = this.list.get(index); // does bound checking for us + final Object tag = this.list.get(index); if (!(tag instanceof NumberBinaryTag)) { throw new IllegalStateException(); } @@ -127,7 +153,7 @@ public Number getNumber(final int index) { @Override public byte getByte(final int index) { - final BinaryTag tag = this.list.get(index); // does bound checking for us + final Object tag = this.list.get(index); if (!(tag instanceof NumberBinaryTag)) { throw new IllegalStateException(); } @@ -136,12 +162,12 @@ public byte getByte(final int index) { @Override public void setByte(final int index, final byte to) { - this.list = this.list.set(index, ByteBinaryTag.byteBinaryTag(to), null); + this.list.set(index, ByteBinaryTag.byteBinaryTag(to)); } @Override public short getShort(final int index) { - final BinaryTag tag = this.list.get(index); // does bound checking for us + final Object tag = this.list.get(index); if (!(tag instanceof NumberBinaryTag)) { throw new IllegalStateException(); } @@ -150,12 +176,12 @@ public short getShort(final int index) { @Override public void setShort(final int index, final short to) { - this.list = this.list.set(index, ShortBinaryTag.shortBinaryTag(to), null); + this.list.set(index, ShortBinaryTag.shortBinaryTag(to)); } @Override public int getInt(final int index) { - final BinaryTag tag = this.list.get(index); // does bound checking for us + final Object tag = this.list.get(index); if (!(tag instanceof NumberBinaryTag)) { throw new IllegalStateException(); } @@ -164,12 +190,12 @@ public int getInt(final int index) { @Override public void setInt(final int index, final int to) { - this.list = this.list.set(index, IntBinaryTag.intBinaryTag(to), null); + this.list.set(index, IntBinaryTag.intBinaryTag(to)); } @Override public long getLong(final int index) { - final BinaryTag tag = this.list.get(index); // does bound checking for us + final Object tag = this.list.get(index); // does bound checking for us if (!(tag instanceof NumberBinaryTag)) { throw new IllegalStateException(); } @@ -178,12 +204,12 @@ public long getLong(final int index) { @Override public void setLong(final int index, final long to) { - this.list = this.list.set(index, LongBinaryTag.longBinaryTag(to), null); + this.list.set(index, LongBinaryTag.longBinaryTag(to)); } @Override public float getFloat(final int index) { - final BinaryTag tag = this.list.get(index); // does bound checking for us + final Object tag = this.list.get(index); // does bound checking for us if (!(tag instanceof NumberBinaryTag)) { throw new IllegalStateException(); } @@ -192,12 +218,12 @@ public float getFloat(final int index) { @Override public void setFloat(final int index, final float to) { - this.list = this.list.set(index, FloatBinaryTag.floatBinaryTag(to), null); + this.list.set(index, FloatBinaryTag.floatBinaryTag(to)); } @Override public double getDouble(final int index) { - final BinaryTag tag = this.list.get(index); // does bound checking for us + final Object tag = this.list.get(index); // does bound checking for us if (!(tag instanceof NumberBinaryTag)) { throw new IllegalStateException(); } @@ -206,12 +232,12 @@ public double getDouble(final int index) { @Override public void setDouble(final int index, final double to) { - this.list = this.list.set(index, DoubleBinaryTag.doubleBinaryTag(to), null); + this.list.set(index, DoubleBinaryTag.doubleBinaryTag(to)); } @Override public byte[] getBytes(final int index) { - final BinaryTag tag = this.list.get(index); // does bound checking for us + final Object tag = this.list.get(index); // does bound checking for us if (!(tag instanceof ByteArrayBinaryTag)) { throw new IllegalStateException(); } @@ -220,7 +246,7 @@ public byte[] getBytes(final int index) { @Override public void setBytes(final int index, final byte[] to) { - this.list = this.list.set(index, ByteArrayBinaryTag.byteArrayBinaryTag(to), null); + this.list.set(index, ByteArrayBinaryTag.byteArrayBinaryTag(to)); } @Override @@ -236,7 +262,7 @@ public void setShorts(final int index, final short[] to) { @Override public int[] getInts(final int index) { - final BinaryTag tag = this.list.get(index); // does bound checking for us + final Object tag = this.list.get(index); // does bound checking for us if (!(tag instanceof IntArrayBinaryTag)) { throw new IllegalStateException(); } @@ -245,12 +271,12 @@ public int[] getInts(final int index) { @Override public void setInts(final int index, final int[] to) { - this.list = this.list.set(index, IntArrayBinaryTag.intArrayBinaryTag(to), null); + this.list.set(index, IntArrayBinaryTag.intArrayBinaryTag(to)); } @Override public long[] getLongs(final int index) { - final BinaryTag tag = this.list.get(index); // does bound checking for us + final Object tag = this.list.get(index); // does bound checking for us if (!(tag instanceof LongArrayBinaryTag)) { throw new IllegalStateException(); } @@ -259,12 +285,12 @@ public long[] getLongs(final int index) { @Override public void setLongs(final int index, final long[] to) { - this.list = this.list.set(index, LongArrayBinaryTag.longArrayBinaryTag(to), null); + this.list.set(index, LongArrayBinaryTag.longArrayBinaryTag(to)); } @Override public ListType getList(final int index) { - final BinaryTag tag = this.list.get(index); // does bound checking for us + final Object tag = this.list.get(index); // does bound checking for us if (!(tag instanceof ListBinaryTag)) { throw new IllegalStateException(); } @@ -273,12 +299,12 @@ public ListType getList(final int index) { @Override public void setList(final int index, final ListType list) { - this.list = this.list.set(index, ((NBTListType) list).getTag(), null); + this.list.set(index, ((NBTListType) list).getTag()); } @Override public MapType getMap(final int index) { - final BinaryTag tag = this.list.get(index); // does bound checking for us + final Object tag = this.list.get(index); // does bound checking for us if (!(tag instanceof CompoundBinaryTag)) { throw new IllegalStateException(); } @@ -287,12 +313,12 @@ public MapType getMap(final int index) { @Override public void setMap(final int index, final MapType to) { - this.list = this.list.set(index, ((NBTMapType) to).getTag(), null); + this.list.set(index, ((NBTMapType) to).getTag()); } @Override public String getString(final int index) { - final BinaryTag tag = this.list.get(index); // does bound checking for us + final Object tag = this.list.get(index); // does bound checking for us if (!(tag instanceof StringBinaryTag)) { throw new IllegalStateException(); } @@ -301,77 +327,77 @@ public String getString(final int index) { @Override public void setString(final int index, final String to) { - this.list = this.list.set(index, StringBinaryTag.stringBinaryTag(to), null); + this.list.set(index, StringBinaryTag.stringBinaryTag(to)); } @Override public void addByte(final byte b) { - this.list = this.list.add(ByteBinaryTag.byteBinaryTag(b)); + this.list.add(ByteBinaryTag.byteBinaryTag(b)); } @Override public void addByte(final int index, final byte b) { - this.list = this.list.set(index, ByteBinaryTag.byteBinaryTag(b), null); + this.list.set(index, ByteBinaryTag.byteBinaryTag(b)); } @Override public void addShort(final short s) { - this.list = this.list.add(ShortBinaryTag.shortBinaryTag(s)); + this.list.add(ShortBinaryTag.shortBinaryTag(s)); } @Override public void addShort(final int index, final short s) { - this.list = this.list.set(index, ShortBinaryTag.shortBinaryTag(s), null); + this.list.set(index, ShortBinaryTag.shortBinaryTag(s)); } @Override public void addInt(final int i) { - this.list = this.list.add(IntBinaryTag.intBinaryTag(i)); + this.list.add(IntBinaryTag.intBinaryTag(i)); } @Override public void addInt(final int index, final int i) { - this.list = this.list.set(index, IntBinaryTag.intBinaryTag(i), null); + this.list.set(index, IntBinaryTag.intBinaryTag(i)); } @Override public void addLong(final long l) { - this.list = this.list.add(LongBinaryTag.longBinaryTag(l)); + this.list.add(LongBinaryTag.longBinaryTag(l)); } @Override public void addLong(final int index, final long l) { - this.list = this.list.set(index, LongBinaryTag.longBinaryTag(l), null); + this.list.set(index, LongBinaryTag.longBinaryTag(l)); } @Override public void addFloat(final float f) { - this.list = this.list.add(FloatBinaryTag.floatBinaryTag(f)); + this.list.add(FloatBinaryTag.floatBinaryTag(f)); } @Override public void addFloat(final int index, final float f) { - this.list = this.list.set(index, FloatBinaryTag.floatBinaryTag(f), null); + this.list.set(index, FloatBinaryTag.floatBinaryTag(f)); } @Override public void addDouble(final double d) { - this.list = this.list.add(DoubleBinaryTag.doubleBinaryTag(d)); + this.list.add(DoubleBinaryTag.doubleBinaryTag(d)); } @Override public void addDouble(final int index, final double d) { - this.list = this.list.set(index, DoubleBinaryTag.doubleBinaryTag(d), null); + this.list.set(index, DoubleBinaryTag.doubleBinaryTag(d)); } @Override public void addByteArray(final byte[] arr) { - this.list = this.list.add(ByteArrayBinaryTag.byteArrayBinaryTag(arr)); + this.list.add(ByteArrayBinaryTag.byteArrayBinaryTag(arr)); } @Override public void addByteArray(final int index, final byte[] arr) { - this.list = this.list.set(index, ByteArrayBinaryTag.byteArrayBinaryTag(arr), null); + this.list.set(index, ByteArrayBinaryTag.byteArrayBinaryTag(arr)); } @Override @@ -388,51 +414,51 @@ public void addShortArray(final int index, final short[] arr) { @Override public void addIntArray(final int[] arr) { - this.list = this.list.add(IntArrayBinaryTag.intArrayBinaryTag(arr)); + this.list.add(IntArrayBinaryTag.intArrayBinaryTag(arr)); } @Override public void addIntArray(final int index, final int[] arr) { - this.list = this.list.set(index, IntArrayBinaryTag.intArrayBinaryTag(arr), null); + this.list.set(index, IntArrayBinaryTag.intArrayBinaryTag(arr)); } @Override public void addLongArray(final long[] arr) { - this.list = this.list.add(LongArrayBinaryTag.longArrayBinaryTag(arr)); + this.list.add(LongArrayBinaryTag.longArrayBinaryTag(arr)); } @Override public void addLongArray(final int index, final long[] arr) { - this.list = this.list.set(index, LongArrayBinaryTag.longArrayBinaryTag(arr), null); + this.list.set(index, LongArrayBinaryTag.longArrayBinaryTag(arr)); } @Override public void addList(final ListType list) { - this.list = this.list.add((BinaryTag) ((NBTListType) list).getTag()); + this.list.add(list); } @Override public void addList(final int index, final ListType list) { - this.list = this.list.set(index, ((NBTListType) list).getTag(), null); + this.list.set(index, list); } @Override public void addMap(final MapType map) { - this.list = this.list.add(((NBTMapType) map).getTag()); + this.list.add(map); } @Override public void addMap(final int index, final MapType map) { - this.list = this.list.set(index, ((NBTMapType) map).getTag(), null); + this.list.set(index, map); } @Override public void addString(final String string) { - this.list = this.list.add(StringBinaryTag.stringBinaryTag(string)); + this.list.add(StringBinaryTag.stringBinaryTag(string)); } @Override public void addString(final int index, final String string) { - this.list = this.list.set(index, StringBinaryTag.stringBinaryTag(string), null); + this.list.set(index, StringBinaryTag.stringBinaryTag(string)); } } diff --git a/src/main/java/ca/spottedleaf/dataconverter/types/nbt/NBTMapType.java b/src/main/java/ca/spottedleaf/dataconverter/types/nbt/NBTMapType.java index a8881ec..70e9708 100644 --- a/src/main/java/ca/spottedleaf/dataconverter/types/nbt/NBTMapType.java +++ b/src/main/java/ca/spottedleaf/dataconverter/types/nbt/NBTMapType.java @@ -4,18 +4,34 @@ import net.kyori.adventure.nbt.*; import org.jetbrains.annotations.NotNull; +import java.util.HashMap; +import java.util.Map; import java.util.Set; public final class NBTMapType implements MapType { - private CompoundBinaryTag map; + private Map map; // Can contain BinaryTag, NBTMapType, NBTListType public NBTMapType() { - this.map = CompoundBinaryTag.empty(); + this.map = new HashMap<>(); } public NBTMapType(final CompoundBinaryTag tag) { - this.map = tag; + this.map = new HashMap<>(); + for (var entry : tag) { + this.map.put(entry.getKey(), entry.getValue()); + } + } + + public NBTMapType(@NotNull Map copy) { + this.map = new HashMap<>(copy.size()); + for (var entry : copy.entrySet()) { + this.map.put(entry.getKey(), switch (entry.getValue()) { + case NBTListType l -> l.copy(); + case NBTMapType m -> m.copy(); + default -> entry.getValue(); + }); + } } @Override @@ -54,12 +70,12 @@ public int size() { @Override public boolean isEmpty() { - return this.map.size() == 0; + return this.map.isEmpty(); } @Override public void clear() { - this.map = CompoundBinaryTag.empty(); + this.map.clear(); } @Override @@ -68,7 +84,16 @@ public Set keys() { } public BinaryTag getTag() { - return this.map; + CompoundBinaryTag.Builder builder = CompoundBinaryTag.builder(); + for (var entry : this.map.entrySet()) { + builder.put(entry.getKey(), switch (entry.getValue()) { + case BinaryTag t -> t; + case NBTListType l -> l.getTag(); + case NBTMapType m -> m.getTag(); + default -> throw new IllegalStateException("Unrecognized type " + entry.getValue()); + }); + } + return builder.build(); } @Override @@ -83,49 +108,62 @@ public boolean hasKey(final String key) { @Override public boolean hasKey(final String key, final ObjectType type) { - final BinaryTag tag = this.map.get(key); + final Object tag = this.map.get(key); if (tag == null) { return false; } - final ObjectType valueType = NBTListType.getType(tag.type().id()); + if (tag instanceof BinaryTag t) { + final ObjectType valueType = NBTListType.getType(t.type().id()); + return valueType == type || (type == ObjectType.NUMBER && valueType.isNumber()); + } else if (tag instanceof NBTListType) { + return type == ObjectType.LIST; + } else if (tag instanceof NBTMapType) { + return type == ObjectType.MAP; + } - return valueType == type || (type == ObjectType.NUMBER && valueType.isNumber()); + return false; } @Override public void remove(final String key) { - this.map = this.map.remove(key); + this.map.remove(key); } @Override public Object getGeneric(final String key) { - final BinaryTag tag = this.map.get(key); + final Object tag = this.map.get(key); if (tag == null) { return null; } - switch (NBTListType.getType(tag.type().id())) { - case BYTE: - case SHORT: - case INT: - case LONG: - case FLOAT: - case DOUBLE: - return numberValue((NumberBinaryTag) tag); - case MAP: - return new NBTMapType((CompoundBinaryTag) tag); - case LIST: - return new NBTListType((ListBinaryTag) tag); - case STRING: - return ((StringBinaryTag) tag).value(); - case BYTE_ARRAY: - return ((ByteArrayBinaryTag) tag).value(); - // Note: No short array tag! - case INT_ARRAY: - return ((IntArrayBinaryTag) tag).value(); - case LONG_ARRAY: - return ((LongArrayBinaryTag) tag).value(); + if (tag instanceof BinaryTag t) { + switch (NBTListType.getType(t.type().id())) { + case BYTE: + case SHORT: + case INT: + case LONG: + case FLOAT: + case DOUBLE: + return numberValue((NumberBinaryTag) tag); + case MAP: + return new NBTMapType((CompoundBinaryTag) tag); + case LIST: + return new NBTListType((ListBinaryTag) tag); + case STRING: + return ((StringBinaryTag) tag).value(); + case BYTE_ARRAY: + return ((ByteArrayBinaryTag) tag).value(); + // Note: No short array tag! + case INT_ARRAY: + return ((IntArrayBinaryTag) tag).value(); + case LONG_ARRAY: + return ((LongArrayBinaryTag) tag).value(); + } + } else if (tag instanceof NBTListType l) { + return l; + } else if (tag instanceof NBTMapType m) { + return m; } throw new IllegalStateException("Unrecognized type " + tag); @@ -138,7 +176,7 @@ public Number getNumber(final String key) { @Override public Number getNumber(final String key, final Number dfl) { - final BinaryTag tag = this.map.get(key); + final Object tag = this.map.get(key); if (tag instanceof NumberBinaryTag) { return numberValue((NumberBinaryTag) tag); } @@ -162,7 +200,7 @@ public void setBoolean(final String key, final boolean val) { @Override public byte getByte(final String key) { - final BinaryTag tag = this.map.get(key); + final Object tag = this.map.get(key); if (tag instanceof NumberBinaryTag) { return ((NumberBinaryTag) tag).byteValue(); } @@ -171,7 +209,7 @@ public byte getByte(final String key) { @Override public byte getByte(final String key, final byte dfl) { - final BinaryTag tag = this.map.get(key); + final Object tag = this.map.get(key); if (tag instanceof NumberBinaryTag) { return ((NumberBinaryTag) tag).byteValue(); } @@ -180,12 +218,12 @@ public byte getByte(final String key, final byte dfl) { @Override public void setByte(final String key, final byte val) { - this.map = this.map.putByte(key, val); + this.map.put(key, ByteBinaryTag.byteBinaryTag(val)); } @Override public short getShort(final String key) { - final BinaryTag tag = this.map.get(key); + final Object tag = this.map.get(key); if (tag instanceof NumberBinaryTag) { return ((NumberBinaryTag) tag).shortValue(); } @@ -194,7 +232,7 @@ public short getShort(final String key) { @Override public short getShort(final String key, final short dfl) { - final BinaryTag tag = this.map.get(key); + final Object tag = this.map.get(key); if (tag instanceof NumberBinaryTag) { return ((NumberBinaryTag) tag).shortValue(); } @@ -203,12 +241,12 @@ public short getShort(final String key, final short dfl) { @Override public void setShort(final String key, final short val) { - this.map = this.map.putShort(key, val); + this.map.put(key, ShortBinaryTag.shortBinaryTag(val)); } @Override public int getInt(final String key) { - final BinaryTag tag = this.map.get(key); + final Object tag = this.map.get(key); if (tag instanceof NumberBinaryTag) { return ((NumberBinaryTag) tag).intValue(); } @@ -217,7 +255,7 @@ public int getInt(final String key) { @Override public int getInt(final String key, final int dfl) { - final BinaryTag tag = this.map.get(key); + final Object tag = this.map.get(key); if (tag instanceof NumberBinaryTag) { return ((NumberBinaryTag) tag).intValue(); } @@ -226,12 +264,12 @@ public int getInt(final String key, final int dfl) { @Override public void setInt(final String key, final int val) { - this.map = this.map.putInt(key, val); + this.map.put(key, IntBinaryTag.intBinaryTag(val)); } @Override public long getLong(final String key) { - final BinaryTag tag = this.map.get(key); + final Object tag = this.map.get(key); if (tag instanceof NumberBinaryTag) { return ((NumberBinaryTag) tag).longValue(); } @@ -240,7 +278,7 @@ public long getLong(final String key) { @Override public long getLong(final String key, final long dfl) { - final BinaryTag tag = this.map.get(key); + final Object tag = this.map.get(key); if (tag instanceof NumberBinaryTag) { return ((NumberBinaryTag) tag).longValue(); } @@ -249,12 +287,12 @@ public long getLong(final String key, final long dfl) { @Override public void setLong(final String key, final long val) { - this.map = this.map.putLong(key, val); + this.map.put(key, LongBinaryTag.longBinaryTag(val)); } @Override public float getFloat(final String key) { - final BinaryTag tag = this.map.get(key); + final Object tag = this.map.get(key); if (tag instanceof NumberBinaryTag) { return ((NumberBinaryTag) tag).floatValue(); } @@ -263,7 +301,7 @@ public float getFloat(final String key) { @Override public float getFloat(final String key, final float dfl) { - final BinaryTag tag = this.map.get(key); + final Object tag = this.map.get(key); if (tag instanceof NumberBinaryTag) { return ((NumberBinaryTag) tag).floatValue(); } @@ -272,12 +310,12 @@ public float getFloat(final String key, final float dfl) { @Override public void setFloat(final String key, final float val) { - this.map = this.map.putFloat(key, val); + this.map.put(key, FloatBinaryTag.floatBinaryTag(val)); } @Override public double getDouble(final String key) { - final BinaryTag tag = this.map.get(key); + final Object tag = this.map.get(key); if (tag instanceof NumberBinaryTag) { return ((NumberBinaryTag) tag).doubleValue(); } @@ -286,7 +324,7 @@ public double getDouble(final String key) { @Override public double getDouble(final String key, final double dfl) { - final BinaryTag tag = this.map.get(key); + final Object tag = this.map.get(key); if (tag instanceof NumberBinaryTag) { return ((NumberBinaryTag) tag).doubleValue(); } @@ -295,7 +333,7 @@ public double getDouble(final String key, final double dfl) { @Override public void setDouble(final String key, final double val) { - this.map = this.map.putDouble(key, val); + this.map.put(key, DoubleBinaryTag.doubleBinaryTag(val)); } @Override @@ -305,7 +343,7 @@ public byte[] getBytes(final String key) { @Override public byte[] getBytes(final String key, final byte[] dfl) { - final BinaryTag tag = this.map.get(key); + final Object tag = this.map.get(key); if (tag instanceof ByteArrayBinaryTag) { return ((ByteArrayBinaryTag) tag).value(); } @@ -314,7 +352,7 @@ public byte[] getBytes(final String key, final byte[] dfl) { @Override public void setBytes(final String key, final byte[] val) { - this.map = this.map.putByteArray(key, val); + this.map.put(key, ByteArrayBinaryTag.byteArrayBinaryTag(val)); } @Override @@ -340,7 +378,7 @@ public int[] getInts(final String key) { @Override public int[] getInts(final String key, final int[] dfl) { - final BinaryTag tag = this.map.get(key); + final Object tag = this.map.get(key); if (tag instanceof IntArrayBinaryTag) { return ((IntArrayBinaryTag) tag).value(); } @@ -349,7 +387,7 @@ public int[] getInts(final String key, final int[] dfl) { @Override public void setInts(final String key, final int[] val) { - this.map = this.map.putIntArray(key, val); + this.map.put(key, IntArrayBinaryTag.intArrayBinaryTag(val)); } @Override @@ -359,7 +397,7 @@ public long[] getLongs(final String key) { @Override public long[] getLongs(final String key, final long[] dfl) { - final BinaryTag tag = this.map.get(key); + final Object tag = this.map.get(key); if (tag instanceof LongArrayBinaryTag) { return ((LongArrayBinaryTag) tag).value(); } @@ -368,7 +406,7 @@ public long[] getLongs(final String key, final long[] dfl) { @Override public void setLongs(final String key, final long[] val) { - this.map = this.map.putLongArray(key, val); + this.map.put(key, LongArrayBinaryTag.longArrayBinaryTag(val)); } @Override @@ -378,16 +416,17 @@ public ListType getListUnchecked(final String key) { @Override public ListType getListUnchecked(final String key, final ListType dfl) { - final BinaryTag tag = this.map.get(key); - if (tag instanceof ListBinaryTag) { + final Object tag = this.map.get(key); + if (tag instanceof NBTListType l) + return l; + if (tag instanceof ListBinaryTag) return new NBTListType((ListBinaryTag) tag); - } return dfl; } @Override public void setList(final String key, final ListType val) { - this.map = this.map.put(key, ((NBTListType) val).getTag()); + this.map.put(key, val); } @Override @@ -397,16 +436,17 @@ public MapType getMap(final String key) { @Override public MapType getMap(final String key, final MapType dfl) { - final BinaryTag tag = this.map.get(key); - if (tag instanceof CompoundBinaryTag) { + final Object tag = this.map.get(key); + if (tag instanceof NBTMapType m) + return m; + if (tag instanceof CompoundBinaryTag) return new NBTMapType((CompoundBinaryTag) tag); - } return dfl; } @Override public void setMap(final String key, final MapType val) { - this.map = this.map.put(key, ((NBTMapType) val).getTag()); + this.map.put(key, val); } @Override @@ -416,7 +456,7 @@ public String getString(final String key) { @Override public String getString(final String key, final String dfl) { - final BinaryTag tag = this.map.get(key); + final Object tag = this.map.get(key); if (tag instanceof StringBinaryTag) { return ((StringBinaryTag) tag).value(); } @@ -430,7 +470,7 @@ public String getForcedString(final String key) { @Override public String getForcedString(final String key, final String dfl) { - final BinaryTag tag = this.map.get(key); + final Object tag = this.map.get(key); if (tag != null) { return ((StringBinaryTag) tag).value(); } @@ -439,7 +479,7 @@ public String getForcedString(final String key, final String dfl) { @Override public void setString(final String key, final String val) { - this.map = this.map.putString(key, val); + this.map.put(key, StringBinaryTag.stringBinaryTag(val)); } private Number numberValue(@NotNull NumberBinaryTag tag) {