From 691d2551cf722b76c1894c814d1f6c2e98fe17d6 Mon Sep 17 00:00:00 2001 From: Thunderblade73 <85900443+Thunderblade73@users.noreply.github.com> Date: Fri, 13 Sep 2024 20:23:40 +0200 Subject: Feature: Carnival QoL (#2498) Co-authored-by: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../java/at/hannibal2/skyhanni/utils/HypixelCommands.kt | 4 ++++ .../at/hannibal2/skyhanni/utils/json/BaseGsonBuilder.kt | 4 +++- .../skyhanni/utils/json/SkyHanniTypeAdapters.kt | 16 +++++++++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/utils') diff --git a/src/main/java/at/hannibal2/skyhanni/utils/HypixelCommands.kt b/src/main/java/at/hannibal2/skyhanni/utils/HypixelCommands.kt index 176afe8c0..c148e93e8 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/HypixelCommands.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/HypixelCommands.kt @@ -32,6 +32,10 @@ object HypixelCommands { send("recipe $itemName") } + fun npcOption(npc: String, answer: String) { + send("selectnpcoption $npc $answer") + } + fun warp(warp: String) { send("warp $warp") } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/json/BaseGsonBuilder.kt b/src/main/java/at/hannibal2/skyhanni/utils/json/BaseGsonBuilder.kt index bc9f706f8..5b3e8c8e1 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/json/BaseGsonBuilder.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/json/BaseGsonBuilder.kt @@ -11,6 +11,7 @@ import at.hannibal2.skyhanni.utils.tracker.SkyHanniTracker import com.google.gson.GsonBuilder import io.github.notenoughupdates.moulconfig.observer.PropertyTypeAdapterFactory import net.minecraft.item.ItemStack +import java.time.LocalDate import java.util.UUID object BaseGsonBuilder { @@ -28,9 +29,10 @@ object BaseGsonBuilder { .registerTypeAdapter(IslandType::class.java, SkyHanniTypeAdapters.ISLAND_TYPE.nullSafe()) .registerTypeAdapter( SkyHanniTracker.DefaultDisplayMode::class.java, - SkyHanniTypeAdapters.TRACKER_DISPLAY_MODE.nullSafe() + SkyHanniTypeAdapters.TRACKER_DISPLAY_MODE.nullSafe(), ) .registerTypeAdapter(SimpleTimeMark::class.java, SkyHanniTypeAdapters.TIME_MARK.nullSafe()) + .registerTypeAdapter(LocalDate::class.java, SkyHanniTypeAdapters.LOCALE_DATE.nullSafe()) .enableComplexMapKeySerialization() fun lenientGson(): GsonBuilder = gson() diff --git a/src/main/java/at/hannibal2/skyhanni/utils/json/SkyHanniTypeAdapters.kt b/src/main/java/at/hannibal2/skyhanni/utils/json/SkyHanniTypeAdapters.kt index 7859853ca..2048be522 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/json/SkyHanniTypeAdapters.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/json/SkyHanniTypeAdapters.kt @@ -18,9 +18,11 @@ import com.google.gson.TypeAdapter import com.google.gson.stream.JsonReader import com.google.gson.stream.JsonWriter import net.minecraft.item.ItemStack +import java.time.LocalDate import java.util.UUID object SkyHanniTypeAdapters { + val NEU_ITEMSTACK: TypeAdapter = SimpleStringTypeAdapter(NEUItems::saveNBTData, NEUItems::loadNBTData) val UUID: TypeAdapter = SimpleStringTypeAdapter( @@ -72,7 +74,19 @@ object SkyHanniTypeAdapters { val ISLAND_TYPE = SimpleStringTypeAdapter.forEnum() val RARITY = SimpleStringTypeAdapter.forEnum() - inline fun GsonBuilder.registerTypeAdapter( + val LOCALE_DATE = object : TypeAdapter() { + override fun write(out: JsonWriter, value: LocalDate) { + out.value(value.toString()) + } + + override fun read(reader: JsonReader): LocalDate { + return LocalDate.parse(reader.nextString()) + } + } + + inline + + fun GsonBuilder.registerTypeAdapter( crossinline write: (JsonWriter, T) -> Unit, crossinline read: (JsonReader) -> T, ): GsonBuilder { -- cgit