From 4e69a56e0e9f0403f38ee21cc6603892eb446fc0 Mon Sep 17 00:00:00 2001 From: Intel <102398177+kotlinsyntax@users.noreply.github.com> Date: Tue, 13 Feb 2024 15:13:02 +0000 Subject: [PATCH 1/5] Cleaned up some stuff --- .../flyte/twilight/inventory/GUIListener.kt | 1 - .../kotlin/gg/flyte/twilight/time/Time.kt | 24 +++++++++---------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/main/kotlin/gg/flyte/twilight/inventory/GUIListener.kt b/src/main/kotlin/gg/flyte/twilight/inventory/GUIListener.kt index c545e17..7752af4 100644 --- a/src/main/kotlin/gg/flyte/twilight/inventory/GUIListener.kt +++ b/src/main/kotlin/gg/flyte/twilight/inventory/GUIListener.kt @@ -22,7 +22,6 @@ object GUIListener : CustomTwilightListener() { events += event(EventPriority.NORMAL, ignoreCancelled = true) { if (inventory.isNotCustom() || view.topInventory != inventory) return@event - println("clicked") (inventory.holder as CustomGUI).onClick(this) } diff --git a/src/main/kotlin/gg/flyte/twilight/time/Time.kt b/src/main/kotlin/gg/flyte/twilight/time/Time.kt index bcf3c74..fe85230 100644 --- a/src/main/kotlin/gg/flyte/twilight/time/Time.kt +++ b/src/main/kotlin/gg/flyte/twilight/time/Time.kt @@ -3,18 +3,16 @@ package gg.flyte.twilight.time /** * Returns the English suffix for a given day of the month. * - * @param day The day of the month for which to retrieve the suffix. Should be a value between 1 and 31. - * @return The English suffix for the given day of the month. - * @throws ArrayIndexOutOfBoundsException if the provided day is not within the valid range (1 to 31). + * @param day The day of the month for which to retrieve the suffix. + * @return The English suffix for the given day. */ fun getDaySuffix(day: Int): String { - return arrayOf( - // 0 1 2 3 4 5 6 7 8 9 - "th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th", - // 10 11 12 13 14 15 16 17 18 19 - "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", - // 20 21 22 23 24 25 26 27 28 29 - "th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th", - // 30 31 - "th", "st")[day] -} \ No newline at end of file + if (day in 11..13) return "th" + val last = day.toString().last() + return when (last) { + '1' -> "st" + '2' -> "nd" + '3' -> "rd" + else -> "th" + } +} From 0dd21c1dbc6ef9c509f12890af68bf8e7f367e51 Mon Sep 17 00:00:00 2001 From: Intel <102398177+kotlinsyntax@users.noreply.github.com> Date: Tue, 13 Feb 2024 15:15:14 +0000 Subject: [PATCH 2/5] Added more symbols --- src/main/kotlin/gg/flyte/twilight/string/Symbol.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/kotlin/gg/flyte/twilight/string/Symbol.kt b/src/main/kotlin/gg/flyte/twilight/string/Symbol.kt index 807d93b..a9afefe 100644 --- a/src/main/kotlin/gg/flyte/twilight/string/Symbol.kt +++ b/src/main/kotlin/gg/flyte/twilight/string/Symbol.kt @@ -62,4 +62,8 @@ object Symbol { const val GIFT = "🎁" const val JAPANESE_CASTLE = "\uD83C\uDFEF" const val BELL = "🔔" + const val COFFEE = "☕" + const val PENCIL = "✎" + const val TICK = "✓" + const val CROSS = "✖" } \ No newline at end of file From 0a598980b119420d2175e54d60f9b228d4506a82 Mon Sep 17 00:00:00 2001 From: Intel <102398177+kotlinsyntax@users.noreply.github.com> Date: Tue, 13 Feb 2024 17:11:04 +0000 Subject: [PATCH 3/5] Added ItemStack Json Adapter --- .../flyte/twilight/gson/ItemStackAdapter.kt | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 src/main/kotlin/gg/flyte/twilight/gson/ItemStackAdapter.kt diff --git a/src/main/kotlin/gg/flyte/twilight/gson/ItemStackAdapter.kt b/src/main/kotlin/gg/flyte/twilight/gson/ItemStackAdapter.kt new file mode 100644 index 0000000..52c903f --- /dev/null +++ b/src/main/kotlin/gg/flyte/twilight/gson/ItemStackAdapter.kt @@ -0,0 +1,93 @@ +package gg.flyte.twilight.gson + +import com.google.gson.* +import org.bukkit.Material +import org.bukkit.inventory.ItemStack +import org.bukkit.inventory.meta.MapMeta +import org.bukkit.inventory.meta.SkullMeta +import java.lang.reflect.Type +import gg.flyte.twilight.extension.enumValue; +import gg.flyte.twilight.itembuilder.ItemBuilder +import net.kyori.adventure.text.Component +import org.bukkit.enchantments.Enchantment + +object ItemStackAdapter: JsonDeserializer, JsonSerializer { + override fun deserialize(json: JsonElement?, type: Type?, context: JsonDeserializationContext?): ItemStack { + if (json == null) throw JsonParseException("JSON cannot be null.") + if (json !is JsonObject) throw JsonParseException("Not a valid JSON Object.") + + val materialType = json.get("type") + val amount = json.get("amount").asInt + val meta = json.getAsJsonObject("meta") + + if(materialType == null) throw JsonParseException("Invalid JSON format, some required values are null.") + + + if (!materialType.isJsonPrimitive && !(materialType as JsonPrimitive).isString) throw JsonParseException("\"type\" not of type string.") + val material = enumValue(materialType.asString) ?: throw JsonParseException("Invalid JSON, Invalid Material Provided."); + val builder = ItemBuilder(material, amount) + + + // Meta stuff + if(meta != null) { + val displayName = meta.get("displayName") + val lore = meta.getAsJsonArray("lore") + val enchants = meta.getAsJsonObject("enchants") + val flags = meta.getAsJsonArray("flags") + val unbreakable = meta.get("unbreakable") + + if(unbreakable != null && unbreakable.isJsonPrimitive && (unbreakable as JsonPrimitive).isBoolean) { + builder.unbreakable = unbreakable.asBoolean; + } + + if(displayName != null && displayName.isJsonPrimitive && (displayName as JsonPrimitive).isString) { + builder.name = Component.text(displayName.asString); + } + + if(lore != null) { + builder.lore = lore.map { Component.text(it.asString) }.toMutableList(); + } + + if(enchants != null && !enchants.isEmpty) { + enchants.asMap().forEach{(enchant, level) -> + builder.enchantments[Enchantment.getByName(enchant)!!] = level.asInt + } + } + + if(flags != null) { + // ... + } + } + + return builder.build() + } + + override fun serialize(itemStack: ItemStack?,type: Type?, context: JsonSerializationContext?): JsonElement { + if(itemStack == null) throw JsonParseException("ItemStack cannot be null") + return JsonObject().apply { + addProperty("type", itemStack.type.name) + addProperty("amount", itemStack.amount) + // Meta + if(itemStack.hasItemMeta()) { + add("meta", JsonObject().apply { + val meta = itemStack.itemMeta + addProperty("displayName", meta.displayName) + addProperty("unbreakable", meta.isUnbreakable) + add("lore", GSON.toJsonTree(meta.lore()) as JsonArray) + add("enchants", JsonObject().apply { + meta.enchants.forEach { enchant -> + addProperty(enchant.key.key.key, enchant.value) + } + }) + add("flags", GSON.toJsonTree(meta.itemFlags) as JsonArray) + if(meta is SkullMeta) { + add("skullData", JsonObject().apply { + addProperty("owner", meta.owner) + }) + } + }) + + } + } + } +} \ No newline at end of file From 787799a80e5e959e39d06d50a56d334391791b0d Mon Sep 17 00:00:00 2001 From: Intel <102398177+kotlinsyntax@users.noreply.github.com> Date: Tue, 13 Feb 2024 19:07:20 +0000 Subject: [PATCH 4/5] Made getDaySuffix() faster --- .../kotlin/gg/flyte/twilight/time/Time.kt | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/gg/flyte/twilight/time/Time.kt b/src/main/kotlin/gg/flyte/twilight/time/Time.kt index fe85230..4d101d0 100644 --- a/src/main/kotlin/gg/flyte/twilight/time/Time.kt +++ b/src/main/kotlin/gg/flyte/twilight/time/Time.kt @@ -8,11 +8,20 @@ package gg.flyte.twilight.time */ fun getDaySuffix(day: Int): String { if (day in 11..13) return "th" - val last = day.toString().last() - return when (last) { - '1' -> "st" - '2' -> "nd" - '3' -> "rd" - else -> "th" + + val lastTwoDigits = day % 100 + val suffix = when (lastTwoDigits) { + 11, 12, 13 -> "th" + else -> { + val lastDigit = day % 10 + when (lastDigit) { + 1 -> "st" + 2 -> "nd" + 3 -> "rd" + else -> "th" + } + } } + + return suffix } From 0d3f8a162786103c32ff3f979df756894a176c14 Mon Sep 17 00:00:00 2001 From: Josh <43449531+joshbker@users.noreply.github.com> Date: Tue, 13 Feb 2024 19:11:01 +0000 Subject: [PATCH 5/5] chore: bump ver to 1.1.2 --- README.md | 6 +++--- build.gradle.kts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b5b08e7..49cceb1 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Maven gg.flyte twilight -1.1.1 +1.1.2 ``` @@ -30,14 +30,14 @@ maven { url "https://repo.flyte.gg/releases" } -implementation "gg.flyte:twilight:1.1.1" +implementation "gg.flyte:twilight:1.1.2" ``` Gradle (Kotlin DSL) ```kotlin maven("https://repo.flyte.gg/releases") -implementation("gg.flyte:twilight:1.1.1") +implementation("gg.flyte:twilight:1.1.2") ``` Certain features of Twilight require configuration, which can be done via the Twilight class. To setup a Twilight class instance, you can use the `twilight` function as shown below: diff --git a/build.gradle.kts b/build.gradle.kts index 2aef6ff..4fed3e6 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,7 +5,7 @@ plugins { } group = "gg.flyte" -version = "1.1.1" +version = "1.1.2" repositories { mavenLocal()