summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDico200 <dico.karssiens@gmail.com>2018-07-21 20:48:03 +0100
committerDico200 <dico.karssiens@gmail.com>2018-07-21 20:48:03 +0100
commit519f3f6b5c39eebace0247b34d56584db463f92b (patch)
treed173644e6f1121fc84476a6e04a2771050116e30
Initial commit
-rw-r--r--.gitignore6
-rw-r--r--build.gradle.kts32
-rw-r--r--settings.gradle.kts2
-rw-r--r--src/main/kotlin/io/dico/parcels2/Parcel.kt38
-rw-r--r--src/main/kotlin/io/dico/parcels2/ParcelWorld.kt4
-rw-r--r--src/main/kotlin/io/dico/parcels2/ParcelsPlugin.kt12
-rw-r--r--src/main/kotlin/io/dico/parcels2/math/Vec2i.kt7
-rw-r--r--src/main/kotlin/io/dico/parcels2/storage/Storage.kt69
-rw-r--r--src/main/kotlin/io/dico/parcels2/storage/backing/Exposed.kt41
-rw-r--r--src/main/kotlin/io/dico/parcels2/util/UUIDUtil.kt23
10 files changed, 234 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..93978c7
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,6 @@
+/.idea/
+/*.iml
+/.gradle/
+/out/
+/debug/
+/target/ \ No newline at end of file
diff --git a/build.gradle.kts b/build.gradle.kts
new file mode 100644
index 0000000..ccb3622
--- /dev/null
+++ b/build.gradle.kts
@@ -0,0 +1,32 @@
+import org.jetbrains.kotlin.gradle.dsl.Coroutines
+
+plugins {
+ kotlin("jvm") version "1.2.51"
+}
+
+group = "io.dico"
+version = "0.1"
+
+repositories {
+ mavenCentral()
+ maven("https://dl.bintray.com/kotlin/exposed")
+}
+
+kotlin.experimental.coroutines = Coroutines.ENABLE
+
+dependencies {
+ compile(files("../res/spigot-1.13-pre7.jar"))
+ compile(kotlin("stdlib-jdk8"))
+ compile("org.jetbrains.exposed:exposed:0.10.3")
+ compile("org.jetbrains.kotlinx:kotlinx-coroutines-core:0.23.4")
+ testCompile("junit:junit:4.12")
+}
+
+val jar by tasks.getting(Jar::class)
+val fatJar by tasks.creating(Jar::class) {
+ baseName = "parcels2-all"
+ manifest.attributes["Main-Class"] = ""
+ destinationDir = file("debug/plugins")
+ from(*configurations.compile.map(::zipTree).toTypedArray())
+ with(jar)
+}
diff --git a/settings.gradle.kts b/settings.gradle.kts
new file mode 100644
index 0000000..25ca636
--- /dev/null
+++ b/settings.gradle.kts
@@ -0,0 +1,2 @@
+rootProject.name = "parcels2"
+
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
diff --git a/src/main/kotlin/io/dico/parcels2/ParcelWorld.kt b/src/main/kotlin/io/dico/parcels2/ParcelWorld.kt
new file mode 100644
index 0000000..9832ce8
--- /dev/null
+++ b/src/main/kotlin/io/dico/parcels2/ParcelWorld.kt
@@ -0,0 +1,4 @@
+package io.dico.parcels2
+
+class ParcelWorld {
+} \ No newline at end of file
diff --git a/src/main/kotlin/io/dico/parcels2/ParcelsPlugin.kt b/src/main/kotlin/io/dico/parcels2/ParcelsPlugin.kt
new file mode 100644
index 0000000..6c1d6e9
--- /dev/null
+++ b/src/main/kotlin/io/dico/parcels2/ParcelsPlugin.kt
@@ -0,0 +1,12 @@
+package io.dico.parcels2
+
+import org.bukkit.plugin.java.JavaPlugin
+
+class ParcelsPlugin : JavaPlugin() {
+
+
+
+
+
+
+} \ No newline at end of file
diff --git a/src/main/kotlin/io/dico/parcels2/math/Vec2i.kt b/src/main/kotlin/io/dico/parcels2/math/Vec2i.kt
new file mode 100644
index 0000000..70ca246
--- /dev/null
+++ b/src/main/kotlin/io/dico/parcels2/math/Vec2i.kt
@@ -0,0 +1,7 @@
+package io.dico.parcels2.math
+
+data class Vec2i(
+ val x: Int,
+ val z: Int
+)
+
diff --git a/src/main/kotlin/io/dico/parcels2/storage/Storage.kt b/src/main/kotlin/io/dico/parcels2/storage/Storage.kt
new file mode 100644
index 0000000..7414b88
--- /dev/null
+++ b/src/main/kotlin/io/dico/parcels2/storage/Storage.kt
@@ -0,0 +1,69 @@
+package io.dico.parcels2.storage
+
+import kotlinx.coroutines.experimental.CoroutineDispatcher
+import kotlinx.coroutines.experimental.CoroutineScope
+import kotlinx.coroutines.experimental.CoroutineStart
+import kotlinx.coroutines.experimental.asCoroutineDispatcher
+import kotlinx.coroutines.experimental.channels.ProducerJob
+import kotlinx.coroutines.experimental.channels.produce
+import java.util.*
+import java.util.concurrent.CompletableFuture
+import java.util.concurrent.Executor
+import java.util.concurrent.Executors
+
+/*
+interface Storage {
+
+ val name: String
+
+ val syncDispatcher: CoroutineDispatcher
+
+ val asyncDispatcher: CoroutineDispatcher
+
+ fun init(): CompletableFuture<Unit>
+
+ fun shutdown(): CompletableFuture<Unit>
+
+ fun readPlotData(plotFor: Plot): CompletableFuture<PlotData?>
+
+ fun readPlotData(plotsFor: Sequence<Plot>, channelCapacity: Int): ProducerJob<Pair<Plot, PlotData?>>
+
+ fun getOwnedPlots(user: PlotOwner): CompletableFuture<List<SerializablePlot>>
+
+ fun setPlotOwner(plotFor: Plot, owner: PlotOwner?): CompletableFuture<Unit>
+
+ fun setPlotPlayerState(plotFor: Plot, player: UUID, state: Boolean?): CompletableFuture<Unit>
+
+ fun setPlotAllowsInteractInventory(plot: Plot, value: Boolean): CompletableFuture<Unit>
+
+ fun setPlotAllowsInteractInputs(plot: Plot, value: Boolean): CompletableFuture<Unit>
+
+}
+
+class StorageWithBacking internal constructor(val backing: Backing) : Storage {
+ override val name get() = backing.name
+ override val syncDispatcher = Executor { it.run() }.asCoroutineDispatcher()
+ override val asyncDispatcher = Executors.newFixedThreadPool(4) { Thread(it, "AbstractStorageThread") }.asCoroutineDispatcher()
+
+ private fun <T> future(block: suspend CoroutineScope.() -> T) = kotlinx.coroutines.experimental.future.future(asyncDispatcher, CoroutineStart.ATOMIC, block)
+
+ override fun init(): CompletableFuture<Unit> = future { backing.init() }
+
+ override fun shutdown(): CompletableFuture<Unit> = future { backing.shutdown() }
+
+ override fun readPlotData(plotFor: Plot) = future { backing.readPlotData(plotFor) }
+
+ override fun readPlotData(plotsFor: Sequence<Plot>, channelCapacity: Int) =
+ produce<Pair<Plot, PlotData?>>(asyncDispatcher, capacity = channelCapacity) { backing.producePlotData(this, plotsFor) }
+
+ override fun getOwnedPlots(user: PlotOwner) = future { backing.getOwnedPlots(user) }
+
+ override fun setPlotOwner(plotFor: Plot, owner: PlotOwner?) = future { backing.setPlotOwner(plotFor, owner) }
+
+ override fun setPlotPlayerState(plotFor: Plot, player: UUID, state: Boolean?) = future { backing.setPlotPlayerState(plotFor, player, state) }
+
+ override fun setPlotAllowsInteractInventory(plot: Plot, value: Boolean) = future { backing.setPlotAllowsInteractInventory(plot, value) }
+
+ override fun setPlotAllowsInteractInputs(plot: Plot, value: Boolean) = future { backing.setPlotAllowsInteractInputs(plot, value) }
+}
+ */ \ No newline at end of file
diff --git a/src/main/kotlin/io/dico/parcels2/storage/backing/Exposed.kt b/src/main/kotlin/io/dico/parcels2/storage/backing/Exposed.kt
new file mode 100644
index 0000000..404e48c
--- /dev/null
+++ b/src/main/kotlin/io/dico/parcels2/storage/backing/Exposed.kt
@@ -0,0 +1,41 @@
+package io.dico.parcels2.storage.backing
+
+import org.jetbrains.exposed.sql.ReferenceOption
+import org.jetbrains.exposed.sql.Table
+
+object ParcelsTable : Table() {
+ val id = integer("id").autoIncrement().primaryKey()
+ val px = integer("px")
+ val pz = integer("pz")
+ val world_uuid = binary("world_uuid", 16).also { uniqueIndex("location", it, px, pz) }
+ val world = varchar("world", 32).nullable()
+ val owner_uuid = binary("owner_uuid", 16).nullable()
+ val owner = varchar("owner", 16).nullable()
+}
+
+object ParcelsAddedTable : Table() {
+ val id = integer("id").references(ParcelsTable.id, ReferenceOption.CASCADE)
+ val player_uuid = binary("player_uuid", 16).also { uniqueIndex("pair", id, it) }
+ val allowed_flag = bool("allowed_flag")
+}
+
+object PlayerAddedTable : Table() {
+ val owner_uuid = binary("owner_uuid", 16)
+ val player_uuid = binary("player_uuid", 16).also { uniqueIndex("pair", owner_uuid, it) }
+ val allowed_flag = bool("allowed_flag")
+}
+
+class AbstractParcelsDatabase {
+
+
+
+
+
+}
+
+
+
+
+
+
+
diff --git a/src/main/kotlin/io/dico/parcels2/util/UUIDUtil.kt b/src/main/kotlin/io/dico/parcels2/util/UUIDUtil.kt
new file mode 100644
index 0000000..5bd7f92
--- /dev/null
+++ b/src/main/kotlin/io/dico/parcels2/util/UUIDUtil.kt
@@ -0,0 +1,23 @@
+package io.dico.parcels2.util
+
+import org.bukkit.Bukkit
+import java.nio.ByteBuffer
+import java.util.*
+
+@Suppress("UsePropertyAccessSyntax")
+fun getPlayerName(uuid: UUID?, ifUnknown: String? = null): String {
+ return uuid?.let { Bukkit.getOfflinePlayer(uuid)?.takeIf { it.isOnline() || it.hasPlayedBefore() }?.name }
+ ?: ifUnknown
+ ?: ":unknown_name:"
+}
+
+fun UUID?.toByteArray(): ByteArray? = this?.let {
+ ByteBuffer.allocate(16).apply {
+ putLong(mostSignificantBits)
+ putLong(leastSignificantBits)
+ }.array()
+}
+
+fun ByteArray?.toUUID(): UUID? = this?.let {
+ ByteBuffer.wrap(it).run { UUID(long, long) }
+} \ No newline at end of file