diff options
author | Dico200 <dico.karssiens@gmail.com> | 2018-07-21 20:48:03 +0100 |
---|---|---|
committer | Dico200 <dico.karssiens@gmail.com> | 2018-07-21 20:48:03 +0100 |
commit | 519f3f6b5c39eebace0247b34d56584db463f92b (patch) | |
tree | d173644e6f1121fc84476a6e04a2771050116e30 /src/main/kotlin/io/dico/parcels2/Parcel.kt |
Initial commit
Diffstat (limited to 'src/main/kotlin/io/dico/parcels2/Parcel.kt')
-rw-r--r-- | src/main/kotlin/io/dico/parcels2/Parcel.kt | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/main/kotlin/io/dico/parcels2/Parcel.kt b/src/main/kotlin/io/dico/parcels2/Parcel.kt new file mode 100644 index 0000000..27b9268 --- /dev/null +++ b/src/main/kotlin/io/dico/parcels2/Parcel.kt @@ -0,0 +1,38 @@ +package io.dico.parcels2 + +import io.dico.parcels2.math.Vec2i +import io.dico.parcels2.util.getPlayerName +import org.bukkit.Bukkit +import org.bukkit.entity.Player +import java.util.* + +class Parcel(val world: ParcelWorld, + val pos: Vec2i, + val data: ParcelData = ParcelData()) { + + +} + +class ParcelData { + val owner: ParcelOwner? = null + val added = mutableMapOf<UUID, Boolean>() +} + +data class ParcelOwner(val uuid: UUID? = null, + val name: String? = null) { + + init { + uuid ?: name ?: throw IllegalArgumentException("uuid and/or name must be present") + } + + val playerName get() = getPlayerName(uuid, name) + + @Suppress("DEPRECATION") + val offlinePlayer get() = (uuid?.let { Bukkit.getOfflinePlayer(it) } ?: Bukkit.getOfflinePlayer(name)) + ?.takeIf { it.isOnline() || it.hasPlayedBefore() } + + fun matches(player: Player, allowNameMatch: Boolean = false): Boolean { + return player.uniqueId == uuid || (allowNameMatch && player.name == name) + } + +}
\ No newline at end of file |