diff --git a/lands-plugin/src/main/kotlin/net/hareworks/hcu/lands/api/LandsAPI.kt b/lands-plugin/src/main/kotlin/net/hareworks/hcu/lands/api/LandsAPI.kt index db24354..bb56c3a 100644 --- a/lands-plugin/src/main/kotlin/net/hareworks/hcu/lands/api/LandsAPI.kt +++ b/lands-plugin/src/main/kotlin/net/hareworks/hcu/lands/api/LandsAPI.kt @@ -100,5 +100,5 @@ interface LandsAPI { * @param modifier A function that modifies the land's data * @return true if the land was modified successfully, false if the land doesn't exist */ - fun modifyLand(name: String, modifier: (LandData) -> Unit): Boolean + fun modifyLand(name: String, modifier: (LandData) -> LandData): Boolean } diff --git a/lands-plugin/src/main/kotlin/net/hareworks/hcu/lands/api/LandsAPIImpl.kt b/lands-plugin/src/main/kotlin/net/hareworks/hcu/lands/api/LandsAPIImpl.kt index e59f795..90feda1 100644 --- a/lands-plugin/src/main/kotlin/net/hareworks/hcu/lands/api/LandsAPIImpl.kt +++ b/lands-plugin/src/main/kotlin/net/hareworks/hcu/lands/api/LandsAPIImpl.kt @@ -49,7 +49,7 @@ class LandsAPIImpl(private val landService: LandService) : LandsAPI { return landService.deleteLand(land.id) } - override fun modifyLand(name: String, modifier: (LandData) -> Unit): Boolean { + override fun modifyLand(name: String, modifier: (LandData) -> LandData): Boolean { val land = landService.findLandsByName(name).firstOrNull() ?: return false return landService.modifyLand(land.id, modifier) } diff --git a/lands-plugin/src/main/kotlin/net/hareworks/hcu/lands/command/LandsCommand.kt b/lands-plugin/src/main/kotlin/net/hareworks/hcu/lands/command/LandsCommand.kt index 53e768b..2769b67 100644 --- a/lands-plugin/src/main/kotlin/net/hareworks/hcu/lands/command/LandsCommand.kt +++ b/lands-plugin/src/main/kotlin/net/hareworks/hcu/lands/command/LandsCommand.kt @@ -454,8 +454,9 @@ class LandsCommand( } service.modifyLand(land.id) { data -> - @Suppress("UNCHECKED_CAST") - action(data.parts as MutableList) + val mutableParts = data.parts.toMutableList() + action(mutableParts) + data.copy(parts = mutableParts) } } diff --git a/lands-plugin/src/main/kotlin/net/hareworks/hcu/lands/service/LandService.kt b/lands-plugin/src/main/kotlin/net/hareworks/hcu/lands/service/LandService.kt index 31af859..63570e1 100644 --- a/lands-plugin/src/main/kotlin/net/hareworks/hcu/lands/service/LandService.kt +++ b/lands-plugin/src/main/kotlin/net/hareworks/hcu/lands/service/LandService.kt @@ -81,12 +81,10 @@ class LandService(private val database: Database) { } } - fun modifyLand(id: Int, modifier: (LandData) -> Unit): Boolean { + fun modifyLand(id: Int, modifier: (LandData) -> LandData): Boolean { val land = cache[id] ?: return false - val newParts = ArrayList(land.data.parts) - val newData = land.data.copy(parts = newParts) - modifier(newData) + val newData = modifier(land.data) transaction(database) { LandsTable.update({ LandsTable.id eq id }) {