diff --git a/build.gradle.kts b/build.gradle.kts index 4eaa630..5c14d3c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -7,7 +7,7 @@ plugins { allprojects { group = "net.minevn" - version = "1.1.0" + version = "1.1.3" apply(plugin = "java") apply(plugin = "org.jetbrains.kotlin.jvm") diff --git a/minevnlib-bukkit/src/main/java/net/minevn/libs/bukkit/Utils.kt b/minevnlib-bukkit/src/main/java/net/minevn/libs/bukkit/Utils.kt index a975fb9..3d44c64 100644 --- a/minevnlib-bukkit/src/main/java/net/minevn/libs/bukkit/Utils.kt +++ b/minevnlib-bukkit/src/main/java/net/minevn/libs/bukkit/Utils.kt @@ -1,7 +1,5 @@ package net.minevn.libs.bukkit -import com.google.gson.JsonElement -import com.google.gson.JsonParser import org.bukkit.Bukkit import org.bukkit.ChatColor import org.bukkit.Location @@ -19,10 +17,6 @@ fun runSync(action: Runnable) { } } -fun String.parseJson() = JsonParser.parseString(this)!! - -fun JsonElement.getOrNull() = if (isJsonNull) null else this - fun Player.sendMessages(messages: List) = messages.forEach { sendMessage(it) } fun Player.sendMessages(messages: Array) = messages.forEach { sendMessage(it) } diff --git a/minevnlib-master/src/main/java/net/minevn/libs/MineVNUtils.kt b/minevnlib-master/src/main/java/net/minevn/libs/MineVNUtils.kt index 9700bb1..dc58415 100644 --- a/minevnlib-master/src/main/java/net/minevn/libs/MineVNUtils.kt +++ b/minevnlib-master/src/main/java/net/minevn/libs/MineVNUtils.kt @@ -1,5 +1,8 @@ package net.minevn.libs +import com.google.gson.Gson +import com.google.gson.JsonElement +import com.google.gson.JsonParser import java.time.YearMonth import java.time.ZoneId import java.time.format.DateTimeFormatter @@ -69,4 +72,17 @@ fun minMaxEpochTimestamp(monthYear: String): Pair { .atZone(ZoneId.systemDefault()).toInstant().toEpochMilli() return Pair(startOfMonth, endOfMonth) -} \ No newline at end of file +} + +private val gson: Gson = Gson() +fun Any.toJson() = gson.toJson(this)!! +fun String.parseJson() = JsonParser.parseString(this)!! +fun JsonElement?.getOrNull() = if (this == null || this.isJsonNull) null else this +fun JsonElement?.asBooleanOrNull() = this?.getOrNull()?.asBoolean +fun JsonElement?.asIntOrNull() = this?.getOrNull()?.asInt +fun JsonElement?.asLongOrNull() = this?.getOrNull()?.asLong +fun JsonElement?.asDoubleOrNull() = this?.getOrNull()?.asDouble +fun JsonElement?.asFloatOrNull() = this?.getOrNull()?.asFloat +fun JsonElement?.asShortOrNull() = this?.getOrNull()?.asShort +fun JsonElement?.asStringOrNull() = this?.getOrNull()?.asString +fun JsonElement?.asArrayOrNull() = this?.getOrNull()?.asJsonArray