blob: 2c566278962f96c75ca135ebb60d2c6986a4edc4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
package io.dico.parcels2
import io.dico.parcels2.util.Vec2i
import io.dico.parcels2.util.ext.hasBuildAnywhere
import org.bukkit.Location
import org.bukkit.OfflinePlayer
import org.bukkit.entity.Player
import org.joda.time.DateTime
import java.util.UUID
/**
* Parcel implementation of ParcelData will update the database when changes are made.
* To change the data without updating the database, defer to the data delegate instance.
*
* This should be used for example in database query callbacks.
* However, this implementation is intentionally not thread-safe.
* Therefore, database query callbacks should schedule their updates using the bukkit scheduler.
*/
interface Parcel : ParcelData {
val id: ParcelId
val world: ParcelWorld
val pos: Vec2i
val x: Int
val z: Int
val data: ParcelData
val infoString: String
val hasBlockVisitors: Boolean
fun copyDataIgnoringDatabase(data: ParcelData)
fun copyData(data: ParcelData)
fun dispose()
suspend fun withBlockVisitorPermit(block: suspend () -> Unit)
val homeLocation: Location get() = world.blockManager.getHomeLocation(id)
}
interface ParcelData : AddedData {
var owner: PlayerProfile?
val lastClaimTime: DateTime?
var ownerSignOutdated: Boolean
var interactableConfig: InteractableConfiguration
fun canBuild(player: OfflinePlayer, checkAdmin: Boolean = true, checkGlobal: Boolean = true): Boolean
fun isOwner(uuid: UUID): Boolean {
return owner?.uuid == uuid
}
fun isOwner(profile: PlayerProfile?): Boolean {
return owner == profile
}
}
class ParcelDataHolder(addedMap: MutableAddedDataMap = mutableMapOf())
: ParcelData, AddedDataHolder(addedMap) {
override var owner: PlayerProfile? = null
override var lastClaimTime: DateTime? = null
override var ownerSignOutdated = false
override fun canBuild(player: OfflinePlayer, checkAdmin: Boolean, checkGlobal: Boolean) = isAllowed(player.statusKey)
|| owner.let { it != null && it.matches(player, allowNameMatch = false) }
|| (checkAdmin && player is Player && player.hasBuildAnywhere)
override var interactableConfig: InteractableConfiguration = BitmaskInteractableConfiguration()
}
|