diff options
Diffstat (limited to 'src/main/kotlin/io/dico/parcels2/defaultimpl/ParcelImpl.kt')
-rw-r--r-- | src/main/kotlin/io/dico/parcels2/defaultimpl/ParcelImpl.kt | 99 |
1 files changed, 67 insertions, 32 deletions
diff --git a/src/main/kotlin/io/dico/parcels2/defaultimpl/ParcelImpl.kt b/src/main/kotlin/io/dico/parcels2/defaultimpl/ParcelImpl.kt index 128705f..d392a8f 100644 --- a/src/main/kotlin/io/dico/parcels2/defaultimpl/ParcelImpl.kt +++ b/src/main/kotlin/io/dico/parcels2/defaultimpl/ParcelImpl.kt @@ -3,21 +3,22 @@ package io.dico.parcels2.defaultimpl import io.dico.dicore.Formatting import io.dico.parcels2.* import io.dico.parcels2.util.Vec2i -import io.dico.parcels2.util.alsoIfTrue -import io.dico.parcels2.util.getPlayerName +import io.dico.parcels2.util.ext.alsoIfTrue +import org.bukkit.Material import org.bukkit.OfflinePlayer import org.joda.time.DateTime -import java.util.UUID -import kotlin.reflect.KProperty +import java.util.concurrent.atomic.AtomicInteger -class ParcelImpl(override val world: ParcelWorld, - override val x: Int, - override val z: Int) : Parcel, ParcelId { +class ParcelImpl( + override val world: ParcelWorld, + override val x: Int, + override val z: Int +) : Parcel, ParcelId { override val id: ParcelId = this override val pos get() = Vec2i(x, z) override var data: ParcelDataHolder = ParcelDataHolder(); private set - override val infoString by ParcelInfoStringComputer - override var hasBlockVisitors: Boolean = false; private set + override val infoString get() = ParcelInfoStringComputer.getInfoString(this) + override val hasBlockVisitors get() = blockVisitors.get() > 0 override val worldId: ParcelWorldId get() = world.id override fun copyDataIgnoringDatabase(data: ParcelData) { @@ -35,7 +36,7 @@ class ParcelImpl(override val world: ParcelWorld, } override val addedMap: AddedDataMap get() = data.addedMap - override fun getAddedStatus(key: StatusKey) = data.getAddedStatus(key) + override fun getStatus(key: StatusKey) = data.getStatus(key) override fun isBanned(key: StatusKey) = data.isBanned(key) override fun isAllowed(key: StatusKey) = data.isAllowed(key) override fun canBuild(player: OfflinePlayer, checkAdmin: Boolean, checkGlobal: Boolean): Boolean { @@ -43,46 +44,77 @@ class ParcelImpl(override val world: ParcelWorld, || checkGlobal && world.globalAddedData[owner ?: return false].isAllowed(player) } - override var addedStatusOfStar: AddedStatus - get() = data.addedStatusOfStar - set(value) = run { setAddedStatus(PlayerProfile.Star, value) } + override var statusOfStar: AddedStatus + get() = data.statusOfStar + set(value) = run { setStatus(PlayerProfile.Star, value) } val globalAddedMap: AddedDataMap? get() = owner?.let { world.globalAddedData[it].addedMap } - override val since: DateTime? get() = data.since + override val lastClaimTime: DateTime? get() = data.lastClaimTime + + override var ownerSignOutdated: Boolean + get() = data.ownerSignOutdated + set(value) { + if (data.ownerSignOutdated != value) { + world.storage.setParcelOwnerSignOutdated(this, value) + data.ownerSignOutdated = value + } + } override var owner: PlayerProfile? get() = data.owner set(value) { if (data.owner != value) { world.storage.setParcelOwner(this, value) + world.blockManager.setOwnerBlock(this, value) data.owner = value } } - override fun setAddedStatus(key: StatusKey, status: AddedStatus): Boolean { - return data.setAddedStatus(key, status).alsoIfTrue { + override fun setStatus(key: StatusKey, status: AddedStatus): Boolean { + return data.setStatus(key, status).alsoIfTrue { world.storage.setParcelPlayerStatus(this, key, status) } } - override var allowInteractInputs: Boolean - get() = data.allowInteractInputs - set(value) { - if (data.allowInteractInputs == value) return - world.storage.setParcelAllowsInteractInputs(this, value) - data.allowInteractInputs = value + private var _interactableConfig: InteractableConfiguration? = null + override var interactableConfig: InteractableConfiguration + get() { + if (_interactableConfig == null) { + _interactableConfig = object : InteractableConfiguration { + override fun isInteractable(material: Material): Boolean = data.interactableConfig.isInteractable(material) + override fun isInteractable(clazz: Interactables): Boolean = data.interactableConfig.isInteractable(clazz) + + override fun setInteractable(clazz: Interactables, interactable: Boolean): Boolean = + data.interactableConfig.setInteractable(clazz, interactable).alsoIfTrue { + // TODO update storage + } + + override fun clear(): Boolean = + data.interactableConfig.clear().alsoIfTrue { + // TODO update storage + } + } + } + return _interactableConfig!! } - - override var allowInteractInventory: Boolean - get() = data.allowInteractInventory set(value) { - if (data.allowInteractInventory == value) return - world.storage.setParcelAllowsInteractInventory(this, value) - data.allowInteractInventory = value + data.interactableConfig.copyFrom(value) + // TODO update storage } + private var blockVisitors = AtomicInteger(0) + override suspend fun withBlockVisitorPermit(block: suspend () -> Unit) { + try { + blockVisitors.getAndIncrement() + block() + } finally { + blockVisitors.getAndDecrement() + } + } + + override fun toString() = toStringExt() } private object ParcelInfoStringComputer { @@ -121,13 +153,15 @@ private object ParcelInfoStringComputer { append(infoStringColor1) append(')') }) { - stringList.joinTo(this, + stringList.joinTo( + this, separator = infoStringColor1.toString() + ", " + infoStringColor2, - limit = 150) + limit = 150 + ) } } - operator fun getValue(parcel: Parcel, property: KProperty<*>): String = buildString { + fun getInfoString(parcel: Parcel): String = buildString { appendField("ID") { append(parcel.x) append(',') @@ -154,6 +188,7 @@ private object ParcelInfoStringComputer { append('\n') appendAddedList(local, global, AddedStatus.BANNED, "Banned") + /* TODO options if (!parcel.allowInteractInputs || !parcel.allowInteractInventory) { appendField("Options") { append("(") @@ -162,7 +197,7 @@ private object ParcelInfoStringComputer { appendField("inventory") { append(parcel.allowInteractInventory) } append(")") } - } + }*/ } }
\ No newline at end of file |