diff --git a/src/main/java/me/zeroeightsix/kami/command/commands/GenerateWebsiteCommand.kt b/src/main/java/me/zeroeightsix/kami/command/commands/GenerateWebsiteCommand.kt
index 45b58cb46..7c0f46001 100644
--- a/src/main/java/me/zeroeightsix/kami/command/commands/GenerateWebsiteCommand.kt
+++ b/src/main/java/me/zeroeightsix/kami/command/commands/GenerateWebsiteCommand.kt
@@ -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>()
+ modulesList.groupByTo(moduleMap) { it.category }
- for (modCategory in modCategories) {
- var totalMods = 0
- var str = ""
- for (module in mods) {
- totalMods++
- str += " " + module.name.value + "" + module.description + "
\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("")
+ it.appendLine(" $category (${modules.size})
")
+ it.appendLine(" ")
+ for (module in modules) {
+ it.appendLine(" - ${module.name.value}
${module.description}
")
+ }
+ it.appendLine("
")
+ it.appendLine("")
+ }
+ }
}
- KamiMod.LOG.info("")
- KamiMod.LOG.info(" $modCategory ($totalMods)
")
- KamiMod.LOG.info(" ")
- KamiMod.LOG.info(str)
- KamiMod.LOG.info("
")
- KamiMod.LOG.info(" ")
- }
- MessageSendHelper.sendChatMessage("Generated website to log file!")
+ MessageSendHelper.sendChatMessage("Generated website to .minecraft/$path!")
+ }
}
}
}
\ No newline at end of file
diff --git a/src/main/java/me/zeroeightsix/kami/module/Module.kt b/src/main/java/me/zeroeightsix/kami/module/Module.kt
index 7c21c2a31..f162e086e 100644
--- a/src/main/java/me/zeroeightsix/kami/module/Module.kt
+++ b/src/main/java/me/zeroeightsix/kami/module/Module.kt
@@ -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"),
diff --git a/src/main/java/me/zeroeightsix/kami/module/ModuleManager.kt b/src/main/java/me/zeroeightsix/kami/module/ModuleManager.kt
index 0480a33bc..5aaa1228e 100644
--- a/src/main/java/me/zeroeightsix/kami/module/ModuleManager.kt
+++ b/src/main/java/me/zeroeightsix/kami/module/ModuleManager.kt
@@ -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)
}
\ No newline at end of file