Skip to content

Commit 879fbaf

Browse files
authored
CollectionSetting backwards compatibility (#510)
2 parents b60e697 + 804c197 commit 879fbaf

File tree

5 files changed

+21
-11
lines changed

5 files changed

+21
-11
lines changed

src/main/kotlin/com/lambda/client/module/modules/player/InventoryManager.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ object InventoryManager : Module(
4747
private val pauseMovement by setting("Pause Movement", true)
4848
private val delay by setting("Delay Ticks", 1, 0..20, 1, unit = " ticks")
4949
private val helpMend by setting("Help Mend", false, description = "Helps mending items by replacing the offhand item with low HP items of the same type")
50-
val ejectList = setting(CollectionSetting("Eject List", defaultEjectList, String::class.java))
50+
val ejectList = setting(CollectionSetting("Eject List", defaultEjectList))
5151

5252
enum class State {
5353
IDLE, SAVING_ITEM, HELPING_MEND, REFILLING_BUILDING, REFILLING, EJECTING

src/main/kotlin/com/lambda/client/module/modules/player/Scaffold.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ object Scaffold : Module(
6767
private val thickness by setting("Outline Thickness", 2f, .25f..4f, .25f, { outline && page == Page.RENDER }, description = "Changes thickness of the outline")
6868
private val pendingBlockColor by setting("Pending Color", ColorHolder(0, 0, 255), visibility = { page == Page.RENDER })
6969

70-
val blockSelectionWhitelist = setting(CollectionSetting("BlockWhitelist", linkedSetOf("minecraft:obsidian"), String::class.java, { false }))
71-
val blockSelectionBlacklist = setting(CollectionSetting("BlockBlacklist", blockBlacklist.map { it.registryName.toString() }.toMutableSet(), String::class.java, { false }))
70+
val blockSelectionWhitelist = setting(CollectionSetting("BlockWhitelist", linkedSetOf("minecraft:obsidian"), { false }))
71+
val blockSelectionBlacklist = setting(CollectionSetting("BlockBlacklist", blockBlacklist.map { it.registryName.toString() }.toMutableSet(), { false }))
7272

7373
private enum class Page {
7474
GENERAL, RENDER

src/main/kotlin/com/lambda/client/module/modules/render/Search.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ object Search : Module(
7070
private val hideF1 by setting("Hide on F1", true)
7171

7272
var overrideWarning by setting("Override Warning", false, { false })
73-
val blockSearchList = setting(CollectionSetting("Search List", defaultSearchList, String::class.java, { false }))
74-
val entitySearchList = setting(CollectionSetting("Entity Search List", linkedSetOf(EntityList.getKey((EntityItemFrame::class.java))!!.path), String::class.java, { false }))
75-
val blockSearchDimensionFilter = setting(CollectionSetting("Block Dimension Filter", linkedSetOf(), DimensionFilter::class.java, { false }))
76-
val entitySearchDimensionFilter = setting(CollectionSetting("Entity Dimension Filter", linkedSetOf(), DimensionFilter::class.java, { false }))
73+
val blockSearchList = setting(CollectionSetting("Search List", defaultSearchList, { false }))
74+
val entitySearchList = setting(CollectionSetting("Entity Search List", linkedSetOf(EntityList.getKey((EntityItemFrame::class.java))!!.path), { false }))
75+
val blockSearchDimensionFilter = setting(CollectionSetting("Block Dimension Filter", linkedSetOf(), entryType = DimensionFilter::class.java, visibility = { false }))
76+
val entitySearchDimensionFilter = setting(CollectionSetting("Entity Dimension Filter", linkedSetOf(), entryType = DimensionFilter::class.java, visibility = { false }))
7777

7878
private val blockRenderer = ESPRenderer()
7979
private val entityRenderer = ESPRenderer()

src/main/kotlin/com/lambda/client/module/modules/render/Xray.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ object Xray : Module(
1414
) {
1515
private val defaultVisibleList = linkedSetOf("minecraft:diamond_ore", "minecraft:iron_ore", "minecraft:gold_ore", "minecraft:portal", "minecraft:cobblestone")
1616

17-
val visibleList = setting(CollectionSetting("Visible List", defaultVisibleList, String::class.java, { false }))
17+
val visibleList = setting(CollectionSetting("Visible List", defaultVisibleList, { false }))
1818

1919
@JvmStatic
2020
fun shouldReplace(state: IBlockState): Boolean {

src/main/kotlin/com/lambda/client/setting/settings/impl/collection/CollectionSetting.kt

+13-3
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,25 @@ import com.lambda.client.setting.settings.ImmutableSetting
77
class CollectionSetting<E : Any, T : MutableCollection<E>>(
88
name: String,
99
override val value: T,
10-
entryType: Class<E>,
1110
visibility: () -> Boolean = { true },
1211
description: String = "",
1312
unit: String = ""
1413
) : ImmutableSetting<T>(name, value, visibility, { _, input -> input }, description, unit), MutableCollection<E> by value {
1514

15+
constructor(
16+
name: String,
17+
value: T,
18+
visibility: () -> Boolean = { true },
19+
description: String = "",
20+
unit: String = "",
21+
entryType: Class<E>, // type must be set if the default collection is empty
22+
) : this(name, value, visibility, description, unit) {
23+
this.entryType = entryType
24+
}
25+
26+
private var entryType: Class<E>? = null
1627
override val defaultValue: T = valueClass.newInstance()
1728
private val lockObject = Any()
18-
private val type = TypeToken.getArray(entryType).type
1929
val editListeners = ArrayList<() -> Unit>()
2030

2131
init {
@@ -41,7 +51,7 @@ class CollectionSetting<E : Any, T : MutableCollection<E>>(
4151

4252
override fun read(jsonElement: JsonElement?) {
4353
jsonElement?.asJsonArray?.let {
44-
val cacheArray = gson.fromJson<Array<E>>(it, type)
54+
val cacheArray = gson.fromJson<Array<E>>(it, TypeToken.getArray(entryType ?: value.first().javaClass).type)
4555
synchronized(lockObject) {
4656
value.clear()
4757
value.addAll(cacheArray)

0 commit comments

Comments
 (0)