io.github.freya022.botcommands.internal.commands.application.NamedCommandMap.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of BotCommands Show documentation
Show all versions of BotCommands Show documentation
A Kotlin-first (and Java) framework that makes creating Discord bots a piece of cake, using the JDA library.
package io.github.freya022.botcommands.internal.commands.application
import io.github.freya022.botcommands.api.commands.INamedCommand
import io.github.freya022.botcommands.api.core.IDeclarationSiteHolder
import io.github.freya022.botcommands.internal.utils.putIfAbsentOrThrow
import java.util.*
internal class NamedCommandMap internal constructor() where T : INamedCommand, T : IDeclarationSiteHolder {
private val mutableMap: MutableMap = hashMapOf()
internal val map: Map = Collections.unmodifiableMap(mutableMap)
internal val values: Collection = Collections.unmodifiableCollection(mutableMap.values)
internal fun putNewCommand(newCommand: T) {
mutableMap.putIfAbsentOrThrow(newCommand.name, newCommand) { oldCommand ->
"""
Command '${newCommand.path.fullPath}' is already defined
Existing command declared at: ${oldCommand.declarationSite?.string ?: ""}
Current command declared at: ${newCommand.declarationSite?.string ?: ""}
""".trimIndent()
}
}
internal fun isEmpty(): Boolean = mutableMap.isEmpty()
}