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()
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
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/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
diff --git a/src/main/kotlin/gg/flyte/twilight/time/Time.kt b/src/main/kotlin/gg/flyte/twilight/time/Time.kt
index bcf3c74..4d101d0 100644
--- a/src/main/kotlin/gg/flyte/twilight/time/Time.kt
+++ b/src/main/kotlin/gg/flyte/twilight/time/Time.kt
@@ -3,18 +3,25 @@ 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 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
+}