Skip to content

Commit d80b180

Browse files
committed
feat: add WorldLocation
1 parent a5e5516 commit d80b180

File tree

5 files changed

+39
-7
lines changed

5 files changed

+39
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ repositories {
1111
}
1212
1313
dependencies {
14-
implementation('io.typst:bukkit-kotlin-serialization:1.0.0')
14+
implementation('io.typst:bukkit-kotlin-serialization:1.3.0')
1515
}
1616
```
1717

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
plugins {
2-
id 'org.jetbrains.kotlin.jvm' version '1.9.22'
2+
id 'org.jetbrains.kotlin.jvm' version '1.9.23'
33
id 'kr.entree.spigradle' version '2.4.3'
4-
id 'org.jetbrains.kotlin.plugin.serialization' version '1.9.22'
4+
id 'org.jetbrains.kotlin.plugin.serialization' version '1.9.23'
55
id 'com.github.johnrengelman.shadow' version '8.1.1'
66
id 'maven-publish'
77
id 'signing'
88
}
99

1010
group = 'io.typst'
11-
version = '1.2.0'
11+
version = '1.3.0'
1212

1313
repositories {
1414
mavenCentral()

src/main/kotlin/io/typst/bukkit/kotlin/serialization/LocationSerializer.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import kotlinx.serialization.encoding.Decoder
77
import kotlinx.serialization.encoding.Encoder
88
import org.bukkit.Location
99

10-
@Deprecated("Use BukkitLocation instead, this might causes issue with world manager plugins.")
10+
@Deprecated("Use WorldLocation instead, this might causes issue with world manager plugins.")
1111
typealias LocationSerializable = @Serializable(LocationSerializer::class) Location
1212

13-
@Deprecated("Use BukkitLocation instead, this might causes issue with world manager plugins.")
13+
@Deprecated("Use WorldLocation instead, this might causes issue with world manager plugins.")
1414
class LocationSerializer : KSerializer<Location> {
1515
override val descriptor: SerialDescriptor
1616
get() = ConfigSerializableSerializer.descriptor
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package io.typst.bukkit.kotlin.serialization.location
2+
3+
import kotlinx.serialization.Serializable
4+
import org.bukkit.Bukkit
5+
import org.bukkit.Location
6+
import org.bukkit.entity.Entity
7+
8+
@Serializable
9+
data class WorldLocation(
10+
val world: String,
11+
val x: Double,
12+
val y: Double,
13+
val z: Double,
14+
val yaw: Float = 0f,
15+
val pitch: Float = 0f,
16+
) {
17+
fun toBukkitLocation(entity: Entity? = null): Location {
18+
val yaw = entity?.location?.yaw ?: this.yaw
19+
val pitch = entity?.location?.pitch ?: this.pitch
20+
return Location(Bukkit.getWorld(world), x, y, z, yaw, pitch)
21+
}
22+
23+
companion object {
24+
@JvmStatic
25+
fun fromBukkit(loc: Location): WorldLocation =
26+
WorldLocation(
27+
loc.world?.name ?: "",
28+
loc.x, loc.y, loc.z,
29+
loc.yaw, loc.pitch
30+
)
31+
}
32+
}

src/main/kotlin/io/typst/bukkit/kotlin/serialization/time/DurationSerializer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import java.time.Duration
1212
typealias DurationAsString = @Serializable(DurationSerializer::class) Duration
1313

1414
object DurationSerializer : KSerializer<Duration> {
15-
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("Duration", PrimitiveKind.STRING)
15+
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("JavaDuration", PrimitiveKind.STRING)
1616

1717
override fun deserialize(decoder: Decoder): Duration {
1818
return Duration.parse(decoder.decodeString())

0 commit comments

Comments
 (0)