diff --git a/src/main/scala/io/izzel/taboolib/module/nms/nbt/NBTBase.java b/src/main/scala/io/izzel/taboolib/module/nms/nbt/NBTBase.java index 7e3de18..75345b4 100644 --- a/src/main/scala/io/izzel/taboolib/module/nms/nbt/NBTBase.java +++ b/src/main/scala/io/izzel/taboolib/module/nms/nbt/NBTBase.java @@ -122,10 +122,10 @@ public class NBTBase { return type; } - public static NBTBase formNBTBase(Object obj) { + public static NBTBase toNBT(Object obj) { if (obj instanceof String) { if (SHORT_PATTERN.matcher(obj.toString()).matches()) { - return formNBTBase(Short.valueOf(obj.toString().substring(0, obj.toString().length() - 1))); + return toNBT(Short.valueOf(obj.toString().substring(0, obj.toString().length() - 1))); } return new NBTBase((String) obj); } else if (obj instanceof Integer) { @@ -144,11 +144,11 @@ public class NBTBase { return translateList(new NBTList(), (List) obj); } else if (obj instanceof Map) { NBTCompound nbtCompound = new NBTCompound(); - ((Map) obj).forEach((key, value) -> nbtCompound.put(key.toString(), formNBTBase(value))); + ((Map) obj).forEach((key, value) -> nbtCompound.put(key.toString(), toNBT(value))); return nbtCompound; } else if (obj instanceof ConfigurationSection) { NBTCompound nbtCompound = new NBTCompound(); - ((ConfigurationSection) obj).getValues(false).forEach((key, value) -> nbtCompound.put(key, formNBTBase(value))); + ((ConfigurationSection) obj).getValues(false).forEach((key, value) -> nbtCompound.put(key, toNBT(value))); return nbtCompound; } return new NBTBase("error: " + obj); @@ -156,7 +156,7 @@ public class NBTBase { public static NBTList translateList(NBTList nbtListBase, List list) { for (Object obj : list) { - NBTBase base = formNBTBase(obj); + NBTBase base = toNBT(obj); if (base == null) { TabooLib.getLogger().warn("Invalid Type: " + obj + " [" + obj.getClass().getSimpleName() + "]"); continue; @@ -172,7 +172,7 @@ public class NBTBase { NBTBase base; if (obj instanceof ConfigurationSection) { base = translateSection(new NBTCompound(), section.getConfigurationSection(key)); - } else if ((base = formNBTBase(obj)) == null) { + } else if ((base = toNBT(obj)) == null) { TabooLib.getLogger().warn("Invalid Type: " + obj + " [" + obj.getClass().getSimpleName() + "]"); continue; } diff --git a/src/main/scala/io/izzel/taboolib/module/nms/nbt/NBTCompound.java b/src/main/scala/io/izzel/taboolib/module/nms/nbt/NBTCompound.java index b94d4cb..8d3adbc 100644 --- a/src/main/scala/io/izzel/taboolib/module/nms/nbt/NBTCompound.java +++ b/src/main/scala/io/izzel/taboolib/module/nms/nbt/NBTCompound.java @@ -64,6 +64,14 @@ public class NBTCompound extends NBTBase implements Map { return this.value.put(key, value); } + public NBTBase put(String key, Object value) { + return this.value.put(key, NBTBase.toNBT(value)); + } + + public NBTBase putDeep(String key, Object value) { + return putDeep(key, NBTBase.toNBT(value)); + } + public NBTBase putDeep(String key, NBTBase value) { NBTBase compound = this, temp; String[] keySplit = key.split("\\."); @@ -112,7 +120,7 @@ public class NBTCompound extends NBTBase implements Map { @Override public NBTBase getOrDefault(Object key, NBTBase defaultValue) { - return this.value.getOrDefault(key, defaultValue); + return this.value.getOrDefault(String.valueOf(key), defaultValue); } @Override