diff --git a/src/main/kotlin/club/someoneice/ovo/core/CoreRunner.kt b/src/main/kotlin/club/someoneice/ovo/core/CoreRunner.kt index 6ee9cc2..fa9fb52 100644 --- a/src/main/kotlin/club/someoneice/ovo/core/CoreRunner.kt +++ b/src/main/kotlin/club/someoneice/ovo/core/CoreRunner.kt @@ -9,7 +9,6 @@ import com.google.gson.reflect.TypeToken import cpw.mods.fml.common.Loader import java.io.File import java.io.FileNotFoundException -import java.nio.file.Files class CoreRunner { private val basePath: String = "${System.getProperty("user.dir")}\\ovo" @@ -45,17 +44,7 @@ class CoreRunner { private fun init() { fun readWithOriginal(file: File): HashMap? { val type = object: TypeToken>() {}.type - val reader = Files.newInputStream(file.toPath()) - - return try { - val byte = ByteArray(file.length().toInt()) - reader.read(byte) - reader.close() - - gson.fromJson(String(byte), type) as HashMap - } catch (_: Exception) { - null - } + return gson.fromJson(file.readText(), type) as HashMap? } for (i in packagePathList) { diff --git a/src/main/kotlin/club/someoneice/ovo/core/JarRunner.kt b/src/main/kotlin/club/someoneice/ovo/core/JarRunner.kt index cbab357..0ce0e21 100644 --- a/src/main/kotlin/club/someoneice/ovo/core/JarRunner.kt +++ b/src/main/kotlin/club/someoneice/ovo/core/JarRunner.kt @@ -29,11 +29,11 @@ class JarRunner { val infoMappings: HashMap = Maps.newHashMap() fun ArrayList.addElement(e: E): ArrayList { this.add(e) - return this; + return this } for (buffered in JarUtil.getInstance().dataSet) { - val urlName = buffered.fileUrl; + val urlName = buffered.fileUrl if (!urlName.contains("ovo/")) continue val name = urlName.replace("ovo/", "").substring(0, urlName.replace("ovo/", "").indexOf("/")) mappings[name] = mappings.getOrDefault(name, Lists.newArrayList()).addElement(buffered) @@ -48,31 +48,28 @@ class JarRunner { (gson.fromJson(JarUtil.getInstance().readFileFromUrl(infoMappings[key]), type) as HashMap).let { it["modid"] } for (url in mappings[key]!!) { if (url == infoMappings[key]) continue - val fileName = - url.fileUrl.substring(url.fileUrl.lastIndexOf("/") + 1, url.fileUrl.lastIndexOf(".")) - ( - if (set.contains(fileName.lowercase())) fileName - else { - val path = url.fileUrl.replace("ovo/${key}/", "") - val filePath = path.substring(0, path.indexOf("/")) - if (set.contains(filePath.lowercase())) filePath - else null - } - )?.let { - val txt = JarUtil.getInstance().readFileFromUrl(url) ?: return@let - when (it.lowercase()) { - "Item".lowercase() -> CoreRunner.item.init (txt, DataList.dataItem) - "ItemFood".lowercase() -> CoreRunner.food.init (txt, DataList.dataItemFood) - "ItemGift".lowercase() -> CoreRunner.gift.init (txt, DataList.dataItemGift) - "ItemTool".lowercase() -> CoreRunner.tool.init (txt, DataList.dataItemTool) - "ItemWeapons".lowercase() -> CoreRunner.swords.init (txt, DataList.dataItemWeapons) - "Block".lowercase() -> CoreRunner.block.init (txt, DataList.dataBlock) - "Recipe".lowercase() -> CoreRunner.recipes.init (txt, DataList.dataRecipes) - "DeleteRecipe".lowercase() -> CoreRunner.delete_recipes.init (txt, DataList.dataDeleteRecipes) - "Biomes".lowercase() -> CoreRunner.biomes.init (txt, DataList.dataBiomes) - "Group".lowercase() -> CoreRunner.group.init (txt, DataList.dataGroup) - } + val fileName = url.fileUrl.substring(url.fileUrl.lastIndexOf("/") + 1, url.fileUrl.lastIndexOf(".")) + if (set.contains(fileName.lowercase())) fileName + else { + val path = url.fileUrl.replace("ovo/${key}/", "") + val filePath = path.substring(0, path.indexOf("/")) + if (set.contains(filePath.lowercase())) filePath + else null + }?.let { + val txt = JarUtil.getInstance().readFileFromUrl(url) ?: return@let + when (it.lowercase()) { + "Item".lowercase() -> CoreRunner.item.init (txt, DataList.dataItem) + "ItemFood".lowercase() -> CoreRunner.food.init (txt, DataList.dataItemFood) + "ItemGift".lowercase() -> CoreRunner.gift.init (txt, DataList.dataItemGift) + "ItemTool".lowercase() -> CoreRunner.tool.init (txt, DataList.dataItemTool) + "ItemWeapons".lowercase() -> CoreRunner.swords.init (txt, DataList.dataItemWeapons) + "Block".lowercase() -> CoreRunner.block.init (txt, DataList.dataBlock) + "Recipe".lowercase() -> CoreRunner.recipes.init (txt, DataList.dataRecipes) + "DeleteRecipe".lowercase() -> CoreRunner.delete_recipes.init (txt, DataList.dataDeleteRecipes) + "Biomes".lowercase() -> CoreRunner.biomes.init (txt, DataList.dataBiomes) + "Group".lowercase() -> CoreRunner.group.init (txt, DataList.dataGroup) } + } } DataProcessor(modid).init() diff --git a/src/main/kotlin/club/someoneice/ovo/core/object/DataList.kt b/src/main/kotlin/club/someoneice/ovo/core/object/DataList.kt index 252030d..557821b 100644 --- a/src/main/kotlin/club/someoneice/ovo/core/object/DataList.kt +++ b/src/main/kotlin/club/someoneice/ovo/core/object/DataList.kt @@ -7,21 +7,21 @@ import net.minecraft.creativetab.CreativeTabs object DataList { // Retain this map for other package to use. - var getGroup :HashMap = Maps.newHashMap() + val getGroup :HashMap = Maps.newHashMap() - var dataItem :ArrayList = Lists.newArrayList() - var dataItemGift :ArrayList = Lists.newArrayList() - var dataItemFood :ArrayList = Lists.newArrayList() - var dataItemTool :ArrayList = Lists.newArrayList() - var dataItemWeapons :ArrayList = Lists.newArrayList() - var dataBlock :ArrayList = Lists.newArrayList() + val dataItem :ArrayList = Lists.newArrayList() + val dataItemGift :ArrayList = Lists.newArrayList() + val dataItemFood :ArrayList = Lists.newArrayList() + val dataItemTool :ArrayList = Lists.newArrayList() + val dataItemWeapons :ArrayList = Lists.newArrayList() + val dataBlock :ArrayList = Lists.newArrayList() - var dataBiomes :ArrayList = Lists.newArrayList() - var dataGroup :ArrayList = Lists.newArrayList() - var dataRecipes :ArrayList = Lists.newArrayList() - var dataDeleteRecipes :ArrayList = Lists.newArrayList() + val dataBiomes :ArrayList = Lists.newArrayList() + val dataGroup :ArrayList = Lists.newArrayList() + val dataRecipes :ArrayList = Lists.newArrayList() + val dataDeleteRecipes :ArrayList = Lists.newArrayList() - // Clean all of the data list. + // Clean all the data list. fun init() { dataItem.clear() dataBlock.clear() diff --git a/src/main/kotlin/club/someoneice/ovo/json/JsonReaderBean.kt b/src/main/kotlin/club/someoneice/ovo/json/JsonReaderBean.kt index a08037a..329665e 100644 --- a/src/main/kotlin/club/someoneice/ovo/json/JsonReaderBean.kt +++ b/src/main/kotlin/club/someoneice/ovo/json/JsonReaderBean.kt @@ -12,7 +12,7 @@ class JsonReaderBean { * @return Input the originalList, the object for return will put into the originalList. * */ fun init(file: File, originalList: ArrayList) { - this.init(file.reader().readText(), originalList) + this.init(file.readText(), originalList) } fun init(file: String, originalList: ArrayList) {