+ update nbt api
This commit is contained in:
parent
baf2958535
commit
8b05ff6451
@ -122,10 +122,10 @@ public class NBTBase {
|
|||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static NBTBase formNBTBase(Object obj) {
|
public static NBTBase toNBT(Object obj) {
|
||||||
if (obj instanceof String) {
|
if (obj instanceof String) {
|
||||||
if (SHORT_PATTERN.matcher(obj.toString()).matches()) {
|
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);
|
return new NBTBase((String) obj);
|
||||||
} else if (obj instanceof Integer) {
|
} else if (obj instanceof Integer) {
|
||||||
@ -144,11 +144,11 @@ public class NBTBase {
|
|||||||
return translateList(new NBTList(), (List) obj);
|
return translateList(new NBTList(), (List) obj);
|
||||||
} else if (obj instanceof Map) {
|
} else if (obj instanceof Map) {
|
||||||
NBTCompound nbtCompound = new NBTCompound();
|
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;
|
return nbtCompound;
|
||||||
} else if (obj instanceof ConfigurationSection) {
|
} else if (obj instanceof ConfigurationSection) {
|
||||||
NBTCompound nbtCompound = new NBTCompound();
|
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 nbtCompound;
|
||||||
}
|
}
|
||||||
return new NBTBase("error: " + obj);
|
return new NBTBase("error: " + obj);
|
||||||
@ -156,7 +156,7 @@ public class NBTBase {
|
|||||||
|
|
||||||
public static NBTList translateList(NBTList nbtListBase, List list) {
|
public static NBTList translateList(NBTList nbtListBase, List list) {
|
||||||
for (Object obj : list) {
|
for (Object obj : list) {
|
||||||
NBTBase base = formNBTBase(obj);
|
NBTBase base = toNBT(obj);
|
||||||
if (base == null) {
|
if (base == null) {
|
||||||
TabooLib.getLogger().warn("Invalid Type: " + obj + " [" + obj.getClass().getSimpleName() + "]");
|
TabooLib.getLogger().warn("Invalid Type: " + obj + " [" + obj.getClass().getSimpleName() + "]");
|
||||||
continue;
|
continue;
|
||||||
@ -172,7 +172,7 @@ public class NBTBase {
|
|||||||
NBTBase base;
|
NBTBase base;
|
||||||
if (obj instanceof ConfigurationSection) {
|
if (obj instanceof ConfigurationSection) {
|
||||||
base = translateSection(new NBTCompound(), section.getConfigurationSection(key));
|
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() + "]");
|
TabooLib.getLogger().warn("Invalid Type: " + obj + " [" + obj.getClass().getSimpleName() + "]");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -64,6 +64,14 @@ public class NBTCompound extends NBTBase implements Map<String, NBTBase> {
|
|||||||
return this.value.put(key, value);
|
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) {
|
public NBTBase putDeep(String key, NBTBase value) {
|
||||||
NBTBase compound = this, temp;
|
NBTBase compound = this, temp;
|
||||||
String[] keySplit = key.split("\\.");
|
String[] keySplit = key.split("\\.");
|
||||||
@ -112,7 +120,7 @@ public class NBTCompound extends NBTBase implements Map<String, NBTBase> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NBTBase getOrDefault(Object key, NBTBase defaultValue) {
|
public NBTBase getOrDefault(Object key, NBTBase defaultValue) {
|
||||||
return this.value.getOrDefault(key, defaultValue);
|
return this.value.getOrDefault(String.valueOf(key), defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user