Skip to content

Commit

Permalink
fix: remove classes that go through CMDPasses
Browse files Browse the repository at this point in the history
  • Loading branch information
LupusVirtute committed Aug 8, 2023
1 parent e3df589 commit 28686ad
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/main/java/org/lupus/commands/core/data/CommandBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ open class CommandBuilder(
val subCommands: MutableList<CommandBuilder> = mutableListOf()
val optionals = hashMapOf<Int, Array<String>>()
val wildCards = mutableListOf<Int>()

val cmdPasses = mutableListOf<Class<*>>()


var supCommand: CommandBuilder? = null
Expand Down Expand Up @@ -161,6 +161,7 @@ open class CommandBuilder(
subCommand.injectableDependencies.putAll(this.injectableDependencies)
subCommand.namedInjectableDependencies.putAll(this.namedInjectableDependencies)
subCommands.addAll(subCommand.build(nameSpace))
cmdPasses.addAll(subCommand.cmdPasses)
}

if (hasFlag(CommandFlag.CONTINUOUS))
Expand Down Expand Up @@ -219,6 +220,7 @@ open class CommandBuilder(
val cmd = ClazzScanner(plugin, packageName).scan(subCommand,true) ?: return
cmd.supCommand = this
this.subCommands.add(cmd)
this.cmdPasses.add(cmd.declaringClazz)
}

fun addConditions(conditions: MutableList<ConditionFun>) {
Expand Down
22 changes: 20 additions & 2 deletions src/main/java/org/lupus/commands/core/scanner/Scanner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ class Scanner(
) {

private var threadsRunning: AtomicInteger = AtomicInteger(0)
val pluginClazzLoader: ClassLoader = plugin::class.java.classLoader
private var packageName: String = ""
val commands: MutableList<CommandLupi> = Collections.synchronizedList(mutableListOf())
private val commands: MutableList<CommandLupi> = Collections.synchronizedList(mutableListOf())
private val cmdPasses: MutableList<Class<*>> = mutableListOf()


/**
Expand Down Expand Up @@ -112,6 +112,7 @@ class Scanner(

synchronized(commands) {
commands.addAll(built)
cmdPasses.addAll(command.cmdPasses)
}
}
}
Expand All @@ -136,6 +137,12 @@ class Scanner(
if(exportResults)
exportResults(results)

cmdPasses.forEach { cmdPass ->
commands.removeAll { command ->
command.declaringClazz.isAssignableFrom(cmdPass)
}
}

registerBuiltCommands(plugin, commands)
cancel()
}
Expand Down Expand Up @@ -207,9 +214,19 @@ class Scanner(
*/
fun registerCommands(plugin: JavaPlugin, commands: List<CommandBuilder>) {
val builtCommands = mutableListOf<CommandLupi>()
val cmdPasses = mutableListOf<Class<*>>()

for (command in commands) {
builtCommands.addAll(command.build())
cmdPasses.addAll(command.cmdPasses)
}

cmdPasses.forEach { cmdPass ->
builtCommands.removeAll { command ->
command.declaringClazz.isAssignableFrom(cmdPass)
}
}

registerBuiltCommands(plugin, builtCommands)
}
/**
Expand All @@ -221,6 +238,7 @@ class Scanner(

val commandsToRegister = mutableListOf<CommandLupi>()


for (command in commands) {
val lowerCaseName = command.name.lowercase()
MainCMDs[lowerCaseName] = command
Expand Down

0 comments on commit 28686ad

Please sign in to comment.