List & Set

typealias WhenPlayerQuitCollectionCallback = Player.() -> Unit

interface OnlinePlayerCollection : MutableCollection<Player>, KListener<Plugin> {
    /**
     * Adds a new Player to the collection with a callback for when the player quits the server.
     */
    fun add(player: Player, whenPlayerQuit: WhenPlayerQuitCollectionCallback): Boolean {
        return add(player).also {
            if(it) checkRegistration()
        }
    }

    /**
     * Removes the player from the collection, calling the [WhenPlayerQuitCollectionCallback] provided.
     */
    fun quit(player: Player): Boolean {
        return remove(player).also {
            if(it) checkRegistration()
        }
    }

    /**
     * Clear the collection calling all [WhenPlayerQuitCollectionCallback] from the Players.
     */
    fun clearQuiting() {
        toMutableList().forEach {
            quit(it)
        }
    }
}

Creating new one

  • onlinePlayerListOf() & onlinePlayerSetOf(): Creates a new empty online player list or set.

  • onlinePlayerListOf(vararg players: Player) & onlinePlayerSetOf(vararg players: Player): Create a new online player list or set with a list of players.

  • onlinePlayerListOf(vararg pair: Pair<Player, WhenPlayerQuitCollectionCallback>) & onlinePlayerSetOf(vararg pair: Pair<Player, WhenPlayerQuitCollectionCallback>): Create a new online player list or set with a player list in a Pair with the callback for when the Player disconnects from the Server.

Last updated