4
0
Fork 0
mirror of https://github.com/Anvilcraft/modpacktools synced 2024-11-17 23:41:55 +01:00

commands can (and should) now be KT objects instead of classes

This commit is contained in:
LordMZTE 2020-07-26 13:50:07 +02:00
parent b21b276563
commit 897bc9b918
6 changed files with 11 additions and 8 deletions

View file

@ -17,9 +17,9 @@ repositories {
dependencies {
//Kotlin
implementation "org.jetbrains.kotlin:kotlin-reflect:1.3.72"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.3.8"
compile 'org.jetbrains.kotlin:kotlin-reflect:1.3.72'
compile 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
compile 'org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.3.8'
//Other
compile 'com.squareup.okhttp3:okhttp:4.8.0'

View file

@ -26,6 +26,7 @@ class CommandLoader(private val pkg: String) {
loadCommands()
}
@Suppress("UNCHECKED_CAST")
private fun loadCommands() {
//Get ICommands in package
val refs = Reflections(pkg, SubTypesScanner(false))
@ -33,7 +34,9 @@ class CommandLoader(private val pkg: String) {
refs.getSubTypesOf(ICommand::class.java).stream()
//Only annotated classes
.filter {it.isAnnotationPresent(LoadCommand::class.java)}
.forEach {addClass(it)}
//can be object
.map {it.kotlin.objectInstance?: it}
.forEach {if(it is ICommand) addCommand(it) else addClass(it as Class<out ICommand>)}
}
/**

View file

@ -14,7 +14,7 @@ import java.io.File
import java.io.FileWriter
@LoadCommand
class CreateModlist : ICommand {
object CreateModlist : ICommand {
override val name: String = "createmodlist"
override val helpMessage: String = "This creates a modlist either as html or csv file. Syntax: <html/csv> outFile"

View file

@ -16,7 +16,7 @@ import java.nio.file.Paths
import java.util.stream.Collectors.toMap
@LoadCommand
class DownloadMods : ICommand {
object DownloadMods : ICommand {
override val name: String = "downloadmods"
override val helpMessage: String = "Downloads all mods. force always downloads files even if they are already present Syntax: <OutDir> [force]"

View file

@ -14,7 +14,7 @@ import java.io.FileReader
import java.io.FileWriter
@LoadCommand
class Import : ICommand {
object Import : ICommand {
override val name: String = "import"
override val helpMessage: String = "Converts a given manifest file to a modpackjson file"

View file

@ -8,7 +8,7 @@ import ley.anvil.modpacktools.command.ICommand
import ley.anvil.modpacktools.command.LoadCommand
@LoadCommand
class Init : ICommand {
object Init : ICommand {
override val name: String = "init"
override val helpMessage: String = "initializes the MPT dev environment (currently only creates config file)"
override val needsConfig: Boolean = false