Modernize Java code (#997)

Co-authored-by: slprime <[email protected]>
This commit is contained in:
Nikolay S.andslprime authored and GitHub committed 2026-08-10 14:55:40 +03:00
1 parent 6c3db443d7
commit d70a47a3a4
36 files changed
+108 -141

No files matched your search

@@ -39,13 +39,12 @@ public class NBTJson {
@SuppressWarnings("unchecked")
public static JsonElement toJsonObject(NBTBase nbt) {
if (nbt instanceof NBTTagCompound) {
if (nbt instanceof NBTTagCompound nbtTagCompound) {
// NBTTagCompound
final NBTTagCompound nbtTagCompound = (NBTTagCompound) nbt;
final Map<String, NBTBase> tagMap = (Map<String, NBTBase>) nbtTagCompound.tagMap;
final JsonObject root = new JsonObject();
tagMap.entrySet().stream().sorted(Map.Entry.<String, NBTBase>comparingByKey())
tagMap.entrySet().stream().sorted(Map.Entry.comparingByKey())
.forEach(nbtEntry -> { root.add(nbtEntry.getKey(), toJsonObject(nbtEntry.getValue())); });
return root;
@@ -73,9 +72,8 @@ public class NBTJson {
} else if (nbt instanceof NBTTagString) {
// String
return new JsonPrimitive(((NBTTagString) nbt).func_150285_a_());
} else if (nbt instanceof NBTTagList) {
} else if (nbt instanceof NBTTagList list) {
// Tag List
final NBTTagList list = (NBTTagList) nbt;
if (list.tagList.isEmpty()) {
return createEmptyList(list);
@@ -85,9 +83,8 @@ public class NBTJson {
return arr;
}
} else if (nbt instanceof NBTTagIntArray) {
} else if (nbt instanceof NBTTagIntArray list) {
// Int Array
final NBTTagIntArray list = (NBTTagIntArray) nbt;
if (list.func_150302_c().length == 0) {
return createEmptyList(list);
@@ -101,9 +98,8 @@ public class NBTJson {
return arr;
}
} else if (nbt instanceof NBTTagByteArray) {
} else if (nbt instanceof NBTTagByteArray list) {
// Byte Array
final NBTTagByteArray list = (NBTTagByteArray) nbt;
if (list.func_150292_c().length == 0) {
return createEmptyList(list);
@@ -123,9 +119,8 @@ public class NBTJson {
}
public static NBTBase toNbt(JsonElement jsonElement) {
if (jsonElement instanceof JsonPrimitive) {
if (jsonElement instanceof JsonPrimitive jsonPrimitive) {
// Number or String
final JsonPrimitive jsonPrimitive = (JsonPrimitive) jsonElement;
final String jsonString = jsonPrimitive.getAsString();
final Matcher m = numberPattern.matcher(jsonString);
if (m.find()) {
@@ -158,9 +153,8 @@ public class NBTJson {
// String
return new NBTTagString(jsonString);
}
} else if (jsonElement instanceof JsonArray) {
} else if (jsonElement instanceof JsonArray jsonArray) {
// NBTTagIntArray or NBTTagList
final JsonArray jsonArray = (JsonArray) jsonElement;
final List<NBTBase> nbtList = new ArrayList<>();
for (JsonElement element : jsonArray) {
@@ -183,9 +177,8 @@ public class NBTJson {
return nbtTagList;
}
} else if (jsonElement instanceof JsonObject) {
} else if (jsonElement instanceof JsonObject jsonObject) {
// NBTTagCompound
final JsonObject jsonObject = (JsonObject) jsonElement;
final NBTBase custom = restoreEmptyList(jsonObject);
if (custom == null) {