[enhancement] Rewrote GenerateWebsiteCommand

This commit is contained in:
Xiaro 2020-12-26 18:51:57 -05:00
parent df62eb804b
commit 642fd4d7c8
No known key found for this signature in database
GPG Key ID: 996D265D6E155377
3 changed files with 39 additions and 38 deletions

View File

@ -1,42 +1,55 @@
package me.zeroeightsix.kami.command.commands
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import me.zeroeightsix.kami.KamiMod
import me.zeroeightsix.kami.command.ClientCommand
import me.zeroeightsix.kami.module.Module
import me.zeroeightsix.kami.module.ModuleManager
import me.zeroeightsix.kami.util.text.MessageSendHelper
import java.io.File
import java.util.*
object GenerateWebsiteCommand : ClientCommand(
name = "generatewebsite",
description = "Generates the website modules to the log"
description = "Generates the website modules to the file"
) {
private const val path = "${KamiMod.DIRECTORY}modules.md"
init {
execute {
val mods = ModuleManager.getModules()
val modCategories = arrayOf("Chat", "Combat", "Client", "Misc", "Movement", "Player", "Render")
KamiMod.LOG.info("\n"
+ "---\n"
+ "layout: default\n"
+ "title: Modules\n"
+ "description: A list of modules and commands this mod has\n"
+ "---"
+ "\n## Modules (${mods.size})\n")
commandScope.launch {
val modulesList = ModuleManager.getModules()
val moduleMap = TreeMap<Module.Category, MutableList<Module>>()
modulesList.groupByTo(moduleMap) { it.category }
for (modCategory in modCategories) {
var totalMods = 0
var str = ""
for (module in mods) {
totalMods++
str += " <li>" + module.name.value + "<p><i>" + module.description + "</i></p></li>\n"
launch(Dispatchers.IO) {
val file = File(path)
if (!file.exists()) file.createNewFile()
file.bufferedWriter().use {
it.appendLine("---")
it.appendLine("layout: default")
it.appendLine("title: Modules")
it.appendLine("description: A list of modules and commands this mod has")
it.appendLine("---")
it.appendLine("## Modules (${modulesList.size})")
it.newLine()
for ((category, modules) in moduleMap) {
it.appendLine("<details>")
it.appendLine(" <summary>$category (${modules.size})</summary>")
it.appendLine(" <p><ul>")
for (module in modules) {
it.appendLine(" <li>${module.name.value}<p><i>${module.description}</i></p></li>")
}
it.appendLine(" </ul></p>")
it.appendLine("</details>")
}
}
}
KamiMod.LOG.info("<details>")
KamiMod.LOG.info(" <summary>$modCategory ($totalMods)</summary>")
KamiMod.LOG.info(" <p><ul>")
KamiMod.LOG.info(str)
KamiMod.LOG.info(" </ul></p>")
KamiMod.LOG.info("</details>")
}
MessageSendHelper.sendChatMessage("Generated website to log file!")
MessageSendHelper.sendChatMessage("Generated website to .minecraft/$path!")
}
}
}
}

View File

@ -58,8 +58,8 @@ open class Module {
*/
enum class Category(override val displayName: String): DisplayEnum {
CHAT("Chat"),
COMBAT("Combat"),
CLIENT("Client"),
COMBAT("Combat"),
MISC("Misc"),
MOVEMENT("Movement"),
PLAYER("Player"),

View File

@ -59,18 +59,7 @@ object ModuleManager {
}
@JvmStatic
fun getModules() = moduleMap.values
@JvmStatic
fun getModule(moduleName: String?): Module {
return moduleName?.replace(" ", "").let { name ->
getModules().firstOrNull { module ->
module.name.value.replace(" ", "").equals(name, true)
|| module.alias.any { it.replace(" ", "").equals(name, true) }
}
}
?: throw ModuleNotFoundException("Error: Module not found. Check the spelling of the module. (getModuleByName(String) failed)")
}
fun getModules() = moduleMap.values.toList()
fun getModuleOrNull(moduleName: String?): Module? {
return moduleName?.replace(" ", "").let { name ->
@ -81,5 +70,4 @@ object ModuleManager {
}
}
class ModuleNotFoundException(s: String?) : IllegalArgumentException(s)
}