File tree 3 files changed +58
-0
lines changed
src/main/kotlin/br/com/devsrsouza/exposed
3 files changed +58
-0
lines changed Original file line number Diff line number Diff line change @@ -46,6 +46,12 @@ subprojects {
46
46
compileOnly(" org.spigotmc:spigot-api:1.8.8-R0.1-SNAPSHOT" )
47
47
}
48
48
49
+ kotlin {
50
+ sourceSets.all {
51
+ languageSettings.useExperimentalAnnotation(" kotlin.contracts.ExperimentalContracts" )
52
+ }
53
+ }
54
+
49
55
tasks {
50
56
" shadowJar" (ShadowJar ::class ) {
51
57
baseName = " KotlinBukkitAPI-${project.name} "
Original file line number Diff line number Diff line change
1
+ repositories {
2
+ maven {
3
+ name = " perfectdreams"
4
+ url = uri(" https://repo.perfectdreams.net/" )
5
+ }
6
+ }
7
+
8
+
9
+ dependencies {
10
+ compileOnly(project(" :core" ))
11
+ compileOnly(project(" :attributestorage" ))
12
+ compileOnly(" org.jetbrains.exposed:exposed:0.11.2" )
13
+ }
Original file line number Diff line number Diff line change
1
+ package br.com.devsrsouza.exposed
2
+
3
+ import br.com.devsrsouza.kotlinbukkitapi.attributestorage.fromByteArrayItem
4
+ import br.com.devsrsouza.kotlinbukkitapi.attributestorage.toByteArray
5
+ import org.bukkit.inventory.ItemStack
6
+ import org.jetbrains.exposed.sql.ColumnType
7
+ import org.jetbrains.exposed.sql.Table
8
+ import org.jetbrains.exposed.sql.transactions.TransactionManager
9
+ import java.io.InputStream
10
+ import java.sql.Blob
11
+
12
+ fun Table.itemStack (name : String ) = registerColumn<ItemStack >(name, ItemStackColumn ())
13
+
14
+ class ItemStackColumn : ColumnType () { // from BlobColumnType
15
+
16
+ private val currentDialect get() = TransactionManager .current().db.dialect
17
+
18
+ override fun sqlType (): String = currentDialect.dataTypeProvider.blobType()
19
+
20
+ override fun nonNullValueToString (value : Any ): String = when (value) {
21
+ is ItemStack -> value.toString()
22
+ else -> " ?"
23
+ }
24
+
25
+ override fun valueFromDB (value : Any ): Any = when (value) {
26
+ is ItemStack -> value
27
+ is ByteArray -> fromByteArrayItem(value)
28
+ is Blob -> fromByteArrayItem(value.getBytes(1 , value.length().toInt()))
29
+ is InputStream -> fromByteArrayItem(value.readBytes())
30
+ else -> error(" Unknown type for blob (ItemStack) column: ${value.javaClass} " )
31
+ }
32
+
33
+ override fun notNullValueToDB (value : Any ): Any {
34
+ return when (value) {
35
+ is ItemStack -> value.toByteArray()
36
+ else -> error(" Unexpected value of type ItemStack: ${value.javaClass.canonicalName} " )
37
+ }
38
+ }
39
+ }
You can’t perform that action at this time.
0 commit comments