<commit_before>package com.masahirosaito.spigot.homes.datas

import com.masahirosaito.spigot.homes.exceptions.NoDefaultHomeException
import com.masahirosaito.spigot.homes.exceptions.NoNamedHomeException
import com.masahirosaito.spigot.homes.homedata.PlayerHome
import com.masahirosaito.spigot.homes.nms.HomesEntity
import org.bukkit.Chunk
import org.bukkit.OfflinePlayer

data class PlayerData(
        val offlinePlayer: OfflinePlayer,
        var defaultHome: HomesEntity? = null,
        val namedHomes: MutableList<HomesEntity> = mutableListOf()
) {
    fun tearDown() {
        defaultHome?.despawnEntities()
        namedHomes.forEach { it.despawnEntities() }
    }

    fun toPlayerHome(): PlayerHome = PlayerHome().apply {
        defaultHome?.let { defaultHomeData = it.toHomeData() }
        namedHomes.forEach { namedHomeData.add(it.toHomeData()) }
    }

    fun getHomesEntitiesIn(chunk: Chunk): List<HomesEntity> {
        return mutableListOf<HomesEntity>().apply {
            defaultHome?.let { if (it.inChunk(chunk)) add(it) }
            namedHomes.forEach { if (it.inChunk(chunk)) add(it) }
        }
    }

    fun load(): PlayerData = this.apply {
        defaultHome?.let { if (it.location.chunk.isLoaded) it.spawnEntities() }
        namedHomes.forEach { if (it.location.chunk.isLoaded) it.spawnEntities() }
    }

    fun hasNamedHome(homeName: String): Boolean {
        return namedHomes.any { it.homeName == homeName }
    }

    fun getNamedHome(homeName: String): HomesEntity {
        return namedHomes.find { it.homeName == homeName } ?:
                throw NoNamedHomeException(offlinePlayer, homeName)
    }

    fun removeDefaultHome() {
        if (defaultHome != null) {
            defaultHome!!.despawnEntities()
            defaultHome = null
        }
    }

    fun removeNamedHome(homeName: String) {
        if (hasNamedHome(homeName)) {
            getNamedHome(homeName).despawnEntities()
            namedHomes.removeIf { it.homeName == homeName }
        }
    }
}<commit_msg>Add home delete fialed exception message<commit_after>package com.masahirosaito.spigot.homes.datas

import com.masahirosaito.spigot.homes.exceptions.NoDefaultHomeException
import com.masahirosaito.spigot.homes.exceptions.NoNamedHomeException
import com.masahirosaito.spigot.homes.homedata.PlayerHome
import com.masahirosaito.spigot.homes.nms.HomesEntity
import org.bukkit.Chunk
import org.bukkit.OfflinePlayer

data class PlayerData(
        val offlinePlayer: OfflinePlayer,
        var defaultHome: HomesEntity? = null,
        val namedHomes: MutableList<HomesEntity> = mutableListOf()
) {
    fun tearDown() {
        defaultHome?.despawnEntities()
        namedHomes.forEach { it.despawnEntities() }
    }

    fun toPlayerHome(): PlayerHome = PlayerHome().apply {
        defaultHome?.let { defaultHomeData = it.toHomeData() }
        namedHomes.forEach { namedHomeData.add(it.toHomeData()) }
    }

    fun getHomesEntitiesIn(chunk: Chunk): List<HomesEntity> {
        return mutableListOf<HomesEntity>().apply {
            defaultHome?.let { if (it.inChunk(chunk)) add(it) }
            namedHomes.forEach { if (it.inChunk(chunk)) add(it) }
        }
    }

    fun load(): PlayerData = this.apply {
        defaultHome?.let { if (it.location.chunk.isLoaded) it.spawnEntities() }
        namedHomes.forEach { if (it.location.chunk.isLoaded) it.spawnEntities() }
    }

    fun hasNamedHome(homeName: String): Boolean {
        return namedHomes.any { it.homeName == homeName }
    }

    fun getNamedHome(homeName: String): HomesEntity {
        return namedHomes.find { it.homeName == homeName } ?:
                throw NoNamedHomeException(offlinePlayer, homeName)
    }

    fun removeDefaultHome() {
        if (defaultHome != null) {
            defaultHome!!.despawnEntities()
            defaultHome = null
        } else {
            throw NoDefaultHomeException(offlinePlayer)
        }
    }

    fun removeNamedHome(homeName: String) {
        if (hasNamedHome(homeName)) {
            getNamedHome(homeName).despawnEntities()
            namedHomes.removeIf { it.homeName == homeName }
        } else {
            throw NoNamedHomeException(offlinePlayer, homeName)
        }
    }
}
{'fraction_non_alphanumeric': 0.10607134420033074, 'fraction_numerical': 0.0, 'mean_word_length': 2.8808432630614114, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7059752', 'n_tokens_mistral': 1317, 'n_tokens_neox': 1309, 'n_words': 220}