Skip to content

Commit

Permalink
refactor/fix: Gson APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
opZywl committed Dec 21, 2024
1 parent c418adc commit c0ac3c4
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ object SettingsUtils {
} else (moduleValue as FloatRangeValue).changeValue(min..max)
}
}

else -> {}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
package net.ccbluex.liquidbounce.file.configs

import com.google.gson.*
import com.google.gson.reflect.TypeToken
import net.ccbluex.liquidbounce.file.FileConfig
import net.ccbluex.liquidbounce.file.FileManager.PRETTY_GSON
import net.ccbluex.liquidbounce.utils.io.decode
import net.ccbluex.liquidbounce.utils.io.readJson
import net.ccbluex.liquidbounce.utils.io.writeJson
import java.io.*

class FriendsConfig(file: File) : FileConfig(file) {
Expand All @@ -22,8 +23,7 @@ class FriendsConfig(file: File) : FileConfig(file) {
@Throws(IOException::class)
override fun loadConfig() {
clearFriends()

friends.addAll(PRETTY_GSON.fromJson(file.bufferedReader(), object : TypeToken<List<Friend>>() {}.type))
file.readJson().decode<Array<Friend>>().toCollection(friends)
}

/**
Expand All @@ -32,7 +32,7 @@ class FriendsConfig(file: File) : FileConfig(file) {
* @throws IOException
*/
@Throws(IOException::class)
override fun saveConfig() = file.writeText(PRETTY_GSON.toJson(friends))
override fun saveConfig() = file.writeJson(friends)

/**
* Add friend to config
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/ccbluex/liquidbounce/ui/font/Fonts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ object Fonts : MinecraftInstance {
LOGGER.info("Downloading additional fonts...")
download("${FONTS}/Font.zip", fontZipFile)
LOGGER.info("Extracting additional fonts...")
outputFile.extractZipTo(fontsDir)
fontZipFile.extractZipTo(fontsDir)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,7 @@ fun BlockPos.canBeClicked(): Boolean {
val Block.id: Int
get() = Block.getIdFromBlock(this)
val Int.blockById: Block
get() = Block.getBlockById(this)
get() = Block.getBlockById(this)

val String.blockByName: Block?
get() = Block.getBlockFromName(this)
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ inline fun jsonArray(builderAction: JsonArrayBuilder.() -> Unit): JsonArray {
return JsonArrayBuilder().apply(builderAction).build()
}

inline fun <reified T> JsonElement.decode(gson: Gson = PRETTY_GSON): T = gson.fromJson<T>(this, object : TypeToken<T>() {}.type)
inline fun <reified T> JsonElement.decode(gson: Gson = PRETTY_GSON): T = gson.fromJson<T>(this, object : TypeToken<T>() {}.type)

0 comments on commit c0ac3c4

Please sign in to comment.