-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
64 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
...in/me/gabytm/minecraft/arcanevouchers/io/serializers/adventure/TextComponentSerializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package me.gabytm.minecraft.arcanevouchers.io.serializers.adventure | ||
|
||
import com.google.gson.* | ||
import net.kyori.adventure.text.TextComponent | ||
import net.kyori.adventure.text.minimessage.MiniMessage | ||
import java.lang.reflect.Type | ||
|
||
class TextComponentSerializer : JsonSerializer<TextComponent> { | ||
|
||
override fun serialize(src: TextComponent?, typeOfSrc: Type?, context: JsonSerializationContext?): JsonElement { | ||
return if (src == null) JsonNull.INSTANCE else JsonPrimitive(MiniMessage.miniMessage().serialize(src)) | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
...ain/kotlin/me/gabytm/minecraft/arcanevouchers/io/serializers/bukkit/LocationSerializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package me.gabytm.minecraft.arcanevouchers.io.serializers.bukkit | ||
|
||
import com.google.gson.* | ||
import org.bukkit.Location | ||
import java.lang.reflect.Type | ||
|
||
class LocationSerializer : JsonSerializer<Location> { | ||
|
||
override fun serialize(src: Location?, typeOfSrc: Type?, context: JsonSerializationContext?): JsonElement { | ||
if (src == null) { | ||
return JsonNull.INSTANCE | ||
} | ||
|
||
val element = JsonObject() | ||
element.addProperty("world", src.world?.name) | ||
element.addProperty("x", src.x) | ||
element.addProperty("y", src.y) | ||
element.addProperty("z", src.z) | ||
return element | ||
} | ||
|
||
companion object { | ||
|
||
val INSTANCE = LocationSerializer() | ||
|
||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
...c/main/kotlin/me/gabytm/minecraft/arcanevouchers/io/serializers/java/PatternSerializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package me.gabytm.minecraft.arcanevouchers.io.serializers.java | ||
|
||
import com.google.gson.JsonElement | ||
import com.google.gson.JsonPrimitive | ||
import com.google.gson.JsonSerializationContext | ||
import com.google.gson.JsonSerializer | ||
import java.lang.reflect.Type | ||
import java.util.regex.Pattern | ||
|
||
class PatternSerializer : JsonSerializer<Pattern> { | ||
|
||
override fun serialize(src: Pattern?, typeOfSrc: Type?, context: JsonSerializationContext?): JsonElement { | ||
return JsonPrimitive(src?.pattern()) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters