-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
49 changed files
with
235 additions
and
833 deletions.
There are no files selected for viewing
193 changes: 42 additions & 151 deletions
193
src/main/kotlin/club/someoneice/ovo/core/CoreRunner.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,187 +1,78 @@ | ||
package club.someoneice.ovo.core | ||
|
||
import club.someoneice.ovo.OVOMain | ||
import club.someoneice.ovo.core.`object`.DataList | ||
import club.someoneice.ovo.data.* | ||
import club.someoneice.ovo.json.JsonReaderBean | ||
import club.someoneice.ovo.json.Sandman | ||
import club.someoneice.ovo.json.helper.JsonProcessor | ||
import club.someoneice.ovo.json.reader.Group | ||
import club.someoneice.ovo.json.reader.Item | ||
import club.someoneice.ovo.json.reader.* | ||
import com.google.common.reflect.TypeToken | ||
import com.google.gson.Gson | ||
import java.io.BufferedReader | ||
import java.io.File | ||
import java.io.FileNotFoundException | ||
import java.io.FileReader | ||
import java.util.* | ||
import kotlin.collections.List | ||
|
||
class CoreRunner { | ||
private val gson: Gson = Gson() | ||
private val basePath: String = "${System.getProperty("user.dir")}\\ovo" | ||
private val packageInfoFilePath: File = File("$basePath\\ovo_package.json") | ||
private var packagePathList = ArrayList<String>() | ||
|
||
private val group = Group() | ||
private val item = Item() | ||
private val food = ItemFoods() | ||
private val gift = ItemGifts() | ||
private val tool = ItemTools() | ||
private val swords = ItemSwords() | ||
private val block = ItemBlocks() | ||
private val recipes = Recipes() | ||
|
||
private val JsonProcessor = JsonProcessor(group, item, block, food, gift, swords, tool) | ||
private val group = JsonReaderBean<Group>() | ||
private val item = JsonReaderBean<ItemData>() | ||
private val food = JsonReaderBean<ItemFood>() | ||
private val gift = JsonReaderBean<ItemGift>() | ||
private val tool = JsonReaderBean<ItemTool>() | ||
private val swords = JsonReaderBean<ItemWeapon>() | ||
private val block = JsonReaderBean<BlockData>() | ||
|
||
init { | ||
try { | ||
if (!packageInfoFilePath.isFile) { | ||
OVOMain.Logger.info("ovo_package.json is not find!") | ||
Sandman.nullSandman() | ||
} else { | ||
readerPackage() | ||
if (packageInfoFilePath.isFile) { | ||
JsonReaderBean<String>().init(packageInfoFilePath, packagePathList) | ||
init() | ||
} | ||
} else OVOMain.Logger.info("ovo_package.json is not find!") | ||
} catch (_: FileNotFoundException) { | ||
throw FileNotFoundException("package.json is not find!") | ||
Sandman.nullSandman() | ||
} | ||
} | ||
|
||
private fun init() { | ||
if (packagePathList.size < 1) return | ||
for (i in packagePathList){ | ||
if (!File("${basePath}\\${i}").isDirectory || !File("${basePath}\\${i}\\info.json").isFile) { | ||
continue | ||
} else { | ||
OVOMain.Logger.info("Such package: ${basePath}\\${i}") | ||
val modid: String? = readInfo(File("${basePath}\\${i}\\info.json")) | ||
getFile("${basePath}\\${i}") | ||
|
||
DataProcessor(modid) | ||
|
||
// Finish read this package, and now clear the DataList. | ||
DataClearer() | ||
} | ||
} | ||
} | ||
|
||
private fun getFile(baseFile: String) { | ||
if (File("${baseFile}\\Group.json").isFile) { | ||
group.init(File("${baseFile}\\Group.json")) | ||
} | ||
for (i in packagePathList) { | ||
if (File("${basePath}\\${i}").isDirectory || !File("${basePath}\\${i}\\info.json").isFile) { | ||
OVOMain.Logger.info("Such pockage: ${basePath}\\${i}") | ||
val modid: String? = | ||
(JsonReaderBean<HashMap<String, String>>().readWithOriginal(File("${basePath}\\${i}\\info.json")) as HashMap<String, String>)["modid"] | ||
|
||
if (File("${baseFile}\\Item.json").isFile) { | ||
item.getToolType(JsonProcessor, File("${baseFile}\\Item.json")) | ||
} else if (File("${baseFile}\\Item").isDirectory) { | ||
val fileList: Array<File> = File("${baseFile}\\Item").listFiles() as Array<File> | ||
for (i in fileList) { | ||
item.getToolType(JsonProcessor, i) | ||
} | ||
} | ||
// Scanning the OVOPackage! And add all we want! | ||
scanning("${basePath}\\${i}") | ||
|
||
if (File("${baseFile}\\ItemFood.json").isFile) { | ||
food.getToolType(JsonProcessor, File("${baseFile}\\ItemFood.json")) | ||
} else if (File("${baseFile}\\ItemFood").isDirectory) { | ||
val fileList: Array<File> = File("${baseFile}\\ItemFood").listFiles() as Array<File> | ||
for (i in fileList) { | ||
food.getToolType(JsonProcessor, i) | ||
} | ||
} | ||
|
||
if (File("${baseFile}\\ItemGift.json").isFile) { | ||
gift.getToolType(JsonProcessor, File("${baseFile}\\ItemGift.json")) | ||
} else if (File("${baseFile}\\ItemGift").isDirectory) { | ||
val fileList: Array<File> = File("${baseFile}\\ItemGift").listFiles() as Array<File> | ||
for (i in fileList) { | ||
gift.getToolType(JsonProcessor, i) | ||
} | ||
} | ||
|
||
if (File("${baseFile}\\ItemTool.json").isFile) { | ||
tool.getToolType(JsonProcessor, File("${baseFile}\\ItemTool.json")) | ||
} else if (File("${baseFile}\\ItemTool").isDirectory) { | ||
val fileList: Array<File> = File("${baseFile}\\ItemTool").listFiles() as Array<File> | ||
for (i in fileList) { | ||
tool.getToolType(JsonProcessor, i) | ||
} | ||
} | ||
|
||
if (File("${baseFile}\\ItemWeapons.json").isFile) { | ||
swords.getToolType(JsonProcessor, File("${baseFile}\\ItemWeapons.json")) | ||
} else if (File("${baseFile}\\ItemWeapons").isDirectory) { | ||
val fileList: Array<File> = File("${baseFile}\\ItemWeapons").listFiles() as Array<File> | ||
for (i in fileList) { | ||
swords.getToolType(JsonProcessor, i) | ||
} | ||
} | ||
|
||
if (File("${baseFile}\\Block.json").isFile) { | ||
block.getToolType(JsonProcessor, File("${baseFile}\\Block.json")) | ||
} else if (File("${baseFile}\\Block").isDirectory) { | ||
val fileList: Array<File> = File("${baseFile}\\Block").listFiles() as Array<File> | ||
for (i in fileList) { | ||
block.getToolType(JsonProcessor, i) | ||
} | ||
} | ||
|
||
if (!Info.dataMode) return | ||
|
||
if (File("${baseFile}\\Recipes.json").isFile) { | ||
recipes.init(File("${baseFile}\\Recipes.json")) | ||
} else if (File("${baseFile}\\Recipes").isDirectory) { | ||
val fileList: Array<File> = File("${baseFile}\\Recipes").listFiles() as Array<File> | ||
for (i in fileList) { | ||
recipes.init(i) | ||
DataProcessor(modid) | ||
DataList.init() | ||
} | ||
} | ||
} | ||
|
||
private fun readerPackage() { | ||
val text = StringBuffer() | ||
val buffreader = BufferedReader(FileReader(packageInfoFilePath)) | ||
|
||
try { | ||
while (true) { | ||
val str = buffreader.readLine() | ||
if (str == null) break else text.append(str.toString()) | ||
@OptIn(ExperimentalStdlibApi::class) | ||
private fun scanning(baseFile: String) { | ||
val initPath = File(baseFile) | ||
if (!initPath.exists() || !initPath.isDirectory) return | ||
for (file in initPath.listFiles()!!) { | ||
val name: String = if (file.isDirectory) file.name else file.nameWithoutExtension | ||
when (name.lowercase()) { | ||
"Item".lowercase() -> handle(file, item, DataList.dataItem) | ||
"ItemFood".lowercase() -> handle(file, food, DataList.dataItemFood) | ||
"ItemGift".lowercase() -> handle(file, gift, DataList.dataItemGift) | ||
"ItemTool".lowercase() -> handle(file, tool, DataList.dataItemTool) | ||
"ItemWeapons".lowercase() -> handle(file, swords, DataList.dataItemWeapons) | ||
"Block".lowercase() -> handle(file, block, DataList.dataBlock) | ||
"Group".lowercase() -> { | ||
if (file.isDirectory) continue | ||
group.init(file, DataList.dataGroup) | ||
} | ||
} | ||
|
||
buffreader.close() | ||
val output: String = text.toString() | ||
packagePathList = gson.fromJson(output, (object: TypeToken<List<String>> () {} .type) ) | ||
|
||
} catch (_: Exception) { | ||
Sandman.nullSandman() | ||
} | ||
} | ||
|
||
private fun readInfo(infoPath: File): String? { | ||
val text = StringBuffer() | ||
val buffreader = BufferedReader(FileReader(infoPath)) | ||
|
||
try { | ||
while (true) { | ||
val str = buffreader.readLine() | ||
if (str == null) break else text.append(str.toString()) | ||
} | ||
|
||
buffreader.close() | ||
val output: String = text.toString() | ||
val infoList: Map<String, String> = gson.fromJson(output, (object: TypeToken<HashMap<String, String>> () {} .type) ) | ||
if (infoList.containsKey("data") && infoList["data"] == "true") { | ||
OVOMain.Logger.info("Now will output Data!") | ||
Info.dataMode = true | ||
} | ||
|
||
if (infoList.containsKey("modid")) { | ||
OVOMain.Logger.info("Find modid ${infoList["modid"]}") | ||
return infoList["modid"] | ||
} | ||
|
||
} catch (_: Exception) { | ||
Sandman.nullSandman() | ||
} | ||
|
||
return Sandman.missingNo() as String? | ||
private fun <T> handle(file: File, json: JsonReaderBean<T>, list: ArrayList<T>) { | ||
if (file.isDirectory) for(f in file.listFiles()!!) json.init(f, list) | ||
else json.init(file, list) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 15 additions & 4 deletions
19
...tlin/club/someoneice/ovo/core/DataList.kt → ...ub/someoneice/ovo/core/object/DataList.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,32 @@ | ||
package club.someoneice.ovo.core | ||
package club.someoneice.ovo.core.`object` | ||
|
||
import club.someoneice.ovo.data.* | ||
import net.minecraft.item.ItemGroup | ||
import java.util.* | ||
|
||
object DataList { | ||
var getGroup: HashMap<String, ItemGroup> = HashMap<String, ItemGroup>() | ||
|
||
var dataItem = ArrayList<ItemData>() | ||
var dataItemGift = ArrayList<ItemGift>() | ||
var dataItemFood = ArrayList<ItemFoods>() | ||
var dataItemFood = ArrayList<ItemFood>() | ||
var dataItemTool = ArrayList<ItemTool>() | ||
var dataItemWeapons = ArrayList<ItemKnife>() | ||
var dataItemWeapons = ArrayList<ItemWeapon>() | ||
|
||
var dataBlock = ArrayList<BlockData>() | ||
|
||
var dataGroup = ArrayList<Group>() | ||
|
||
var dataRecipe = ArrayList<Recipes>() | ||
|
||
fun init() { | ||
dataItem.clear() | ||
dataBlock.clear() | ||
dataGroup.clear() | ||
dataItemFood.clear() | ||
dataItemTool.clear() | ||
dataItemWeapons.clear() | ||
dataItemGift.clear() | ||
|
||
dataRecipe.clear() | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...n/kotlin/club/someoneice/ovo/core/Info.kt → ...n/club/someoneice/ovo/core/object/Info.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package club.someoneice.ovo.core | ||
package club.someoneice.ovo.core.`object` | ||
|
||
object Info { | ||
var modid: String = "" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package club.someoneice.ovo.data | ||
|
||
import club.someoneice.ovo.IDataGem | ||
|
||
data class ItemFood( | ||
val name: String, | ||
val max_size: Int = 64, | ||
val hunger: Int, | ||
val saturation: Float, | ||
val wolf: Boolean = false, | ||
val always_eat: Boolean = false, | ||
val fast_food: Boolean = false, | ||
val isDrink: Boolean = false, | ||
val return_item: String = "null", | ||
val group: String = "null" | ||
): IDataGem |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.