All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.freya022.botcommands.internal.commands.application.NamedCommandMap.kt Maven / Gradle / Ivy

Go to download

A Kotlin-first (and Java) framework that makes creating Discord bots a piece of cake, using the JDA library.

There is a newer version: 3.0.0-alpha.18
Show newest version
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()
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy