Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CollectionSetting backwards compatibility #510

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ object InventoryManager : Module(
private val pauseMovement by setting("Pause Movement", true)
private val delay by setting("Delay Ticks", 1, 0..20, 1, unit = " ticks")
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")
val ejectList = setting(CollectionSetting("Eject List", defaultEjectList, String::class.java))
val ejectList = setting(CollectionSetting("Eject List", defaultEjectList))

enum class State {
IDLE, SAVING_ITEM, HELPING_MEND, REFILLING_BUILDING, REFILLING, EJECTING
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ object Scaffold : Module(
private val thickness by setting("Outline Thickness", 2f, .25f..4f, .25f, { outline && page == Page.RENDER }, description = "Changes thickness of the outline")
private val pendingBlockColor by setting("Pending Color", ColorHolder(0, 0, 255), visibility = { page == Page.RENDER })

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

private enum class Page {
GENERAL, RENDER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ object Search : Module(
private val hideF1 by setting("Hide on F1", true)

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

private val blockRenderer = ESPRenderer()
private val entityRenderer = ESPRenderer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ object Xray : Module(
) {
private val defaultVisibleList = linkedSetOf("minecraft:diamond_ore", "minecraft:iron_ore", "minecraft:gold_ore", "minecraft:portal", "minecraft:cobblestone")

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

@JvmStatic
fun shouldReplace(state: IBlockState): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,25 @@ import com.lambda.client.setting.settings.ImmutableSetting
class CollectionSetting<E : Any, T : MutableCollection<E>>(
name: String,
override val value: T,
entryType: Class<E>,
visibility: () -> Boolean = { true },
description: String = "",
unit: String = ""
) : ImmutableSetting<T>(name, value, visibility, { _, input -> input }, description, unit), MutableCollection<E> by value {

constructor(
name: String,
value: T,
visibility: () -> Boolean = { true },
description: String = "",
unit: String = "",
entryType: Class<E>, // type must be set if the default collection is empty
) : this(name, value, visibility, description, unit) {
this.entryType = entryType
}

private var entryType: Class<E>? = null
override val defaultValue: T = valueClass.newInstance()
private val lockObject = Any()
private val type = TypeToken.getArray(entryType).type
val editListeners = ArrayList<() -> Unit>()

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

override fun read(jsonElement: JsonElement?) {
jsonElement?.asJsonArray?.let {
val cacheArray = gson.fromJson<Array<E>>(it, type)
val cacheArray = gson.fromJson<Array<E>>(it, TypeToken.getArray(entryType ?: value.first().javaClass).type)
synchronized(lockObject) {
value.clear()
value.addAll(cacheArray)
Expand Down