Skip to content

Commit 96867ea

Browse files
committed
Fix: Settings (don't touch it bites)
1 parent 58095ea commit 96867ea

File tree

10 files changed

+46
-38
lines changed

10 files changed

+46
-38
lines changed

common/src/main/kotlin/com/lambda/config/Configurable.kt

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,9 @@ abstract class Configurable(
159159
* The type parameter [T] must either be a primitive type or a type with a registered type adapter in [Lambda.gson].
160160
*
161161
* @param name The unique identifier for the setting.
162-
* @param defaultValue The default [ArrayList] value of type [T] for the setting.
162+
* @param defaultValue The default [List] value of type [T] for the setting.
163163
* @param description A brief explanation of the setting's purpose and behavior.
164+
* @param hackDelegates A flag that determines whether the setting should be serialized with the default value.
164165
* @param visibility A lambda expression that determines the visibility status of the setting.
165166
*
166167
* ```kotlin
@@ -175,12 +176,14 @@ abstract class Configurable(
175176
defaultValue: List<T>,
176177
description: String = "",
177178
noinline visibility: () -> Boolean = { true },
179+
hackDelegates: Boolean = false,
178180
) = ListSetting(
179181
name,
180182
defaultValue.toMutableList(),
181183
TypeToken.getParameterized(MutableList::class.java, T::class.java).type,
182184
description,
183-
visibility
185+
hackDelegates,
186+
visibility,
184187
).also {
185188
settings.add(it)
186189
}
@@ -193,6 +196,7 @@ abstract class Configurable(
193196
* @param name The unique identifier for the setting.
194197
* @param defaultValue The default [Map] value of type [K] and [V] for the setting.
195198
* @param description A brief explanation of the setting's purpose and behavior.
199+
* @param hackDelegates A flag that determines whether the setting should be serialized with the default value.
196200
* @param visibility A lambda expression that determines the visibility status of the setting.
197201
*
198202
* ```kotlin
@@ -206,12 +210,14 @@ abstract class Configurable(
206210
name: String,
207211
defaultValue: Map<K, V>,
208212
description: String = "",
213+
hackDelegates: Boolean,
209214
noinline visibility: () -> Boolean = { true },
210215
) = MapSetting(
211216
name,
212217
defaultValue.toMutableMap(),
213-
TypeToken.getParameterized(Map::class.java, K::class.java, V::class.java).type,
218+
TypeToken.getParameterized(MutableMap::class.java, K::class.java, V::class.java).type,
214219
description,
220+
hackDelegates,
215221
visibility
216222
).also {
217223
settings.add(it)
@@ -225,6 +231,7 @@ abstract class Configurable(
225231
* @param name The unique identifier for the setting.
226232
* @param defaultValue The default [Set] value of type [T] for the setting.
227233
* @param description A brief explanation of the setting's purpose and behavior.
234+
* @param hackDelegates A flag that determines whether the setting should be serialized with the default value.
228235
* @param visibility A lambda expression that determines the visibility status of the setting.
229236
*
230237
* ```kotlin
@@ -238,13 +245,15 @@ abstract class Configurable(
238245
name: String,
239246
defaultValue: Set<T>,
240247
description: String = "",
248+
hackDelegates: Boolean = false,
241249
noinline visibility: () -> Boolean = { true },
242250
) = SetSetting(
243251
name,
244252
defaultValue.toMutableSet(),
245-
TypeToken.getParameterized(Set::class.java, T::class.java).type,
253+
TypeToken.getParameterized(MutableSet::class.java, T::class.java).type,
246254
description,
247-
visibility
255+
hackDelegates,
256+
visibility,
248257
).also {
249258
settings.add(it)
250259
}

common/src/main/kotlin/com/lambda/config/Configuration.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,15 @@ abstract class Configuration : Jsonable {
7979

8080
private fun save() {
8181
with(primary) {
82-
if (exists()) {
83-
copyTo(backup, true)
84-
}
82+
if (exists()) copyTo(backup, true)
83+
8584
parentFile.mkdirs()
8685
writeText(gson.toJson(toJson()))
8786
}
8887
}
8988

9089
private fun load(file: File) {
91-
check(file.exists()) {
92-
"No configuration file found for ${configName.capitalize()}"
93-
}
90+
check(file.exists()) { "No configuration file found for ${configName.capitalize()}" }
9491

9592
loadFromJson(JsonParser.parseReader(file.reader()).asJsonObject)
9693
}
Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,24 @@
11
package com.lambda.config.settings.collections
22

33
import com.google.gson.JsonElement
4-
import com.google.gson.reflect.TypeToken
5-
import com.lambda.Lambda.gson
64
import com.lambda.config.AbstractSetting
75
import java.lang.reflect.Type
86

97
class ListSetting<T : Any>(
108
override val name: String,
119
private val defaultValue: MutableList<T>,
12-
private val type: Type,
10+
type: Type,
1311
description: String,
12+
private val hackDelegates: Boolean,
1413
visibility: () -> Boolean,
1514
) : AbstractSetting<MutableList<T>>(
1615
defaultValue,
1716
type,
1817
description,
1918
visibility
2019
) {
21-
override fun loadFromJson(serialized: JsonElement) {
22-
value = gson.fromJson(serialized, type)
23-
}
24-
2520
override fun toJson(): JsonElement {
26-
return gson.toJsonTree(value)
21+
if (hackDelegates) value = defaultValue
22+
return super.toJson()
2723
}
2824
}
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
package com.lambda.config.settings.collections
22

3+
import com.google.gson.JsonElement
34
import com.lambda.config.AbstractSetting
45
import java.lang.reflect.Type
56

67
class MapSetting<K, V>(
78
override val name: String,
8-
defaultValue: MutableMap<K, V>,
9+
private val defaultValue: Map<K, V>,
910
type: Type,
1011
description: String,
12+
private val hackDelegates: Boolean,
1113
visibility: () -> Boolean,
12-
) : AbstractSetting<MutableMap<K, V>>(
14+
) : AbstractSetting<Map<K, V>>(
1315
defaultValue,
1416
type,
1517
description,
1618
visibility
17-
)
19+
) {
20+
override fun toJson(): JsonElement {
21+
if (hackDelegates) value = defaultValue
22+
return super.toJson()
23+
}
24+
}
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
package com.lambda.config.settings.collections
22

3+
import com.google.gson.JsonElement
34
import com.lambda.config.AbstractSetting
45
import java.lang.reflect.Type
56

67
class SetSetting<T : Any>(
78
override val name: String,
8-
defaultValue: MutableSet<T>,
9+
private val defaultValue: MutableSet<T>,
910
type: Type,
1011
description: String,
12+
private val hackDelegates: Boolean,
1113
visibility: () -> Boolean,
1214
) : AbstractSetting<MutableSet<T>>(
1315
defaultValue,
1416
type,
1517
description,
1618
visibility
17-
)
19+
) {
20+
override fun toJson(): JsonElement {
21+
if (hackDelegates) value = defaultValue
22+
return super.toJson()
23+
}
24+
}

common/src/main/kotlin/com/lambda/friend/FriendRegistry.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import com.mojang.authlib.GameProfile
88
object FriendRegistry : Configurable(FriendConfig), Loadable {
99
override val name = "friends"
1010

11-
val friends by setting("friends", listOf<GameProfile>()) // Todo: Fix the fucking delegates
11+
val friends by setting("friends", listOf<GameProfile>(), hackDelegates = true)
1212

1313
override fun load(): String {
1414
return "Loaded ${friends.size} friends"

common/src/main/kotlin/com/lambda/module/Module.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import com.lambda.event.listener.SafeListener.Companion.listener
1515
import com.lambda.event.listener.UnsafeListener
1616
import com.lambda.gui.impl.clickgui.LambdaClickGui
1717
import com.lambda.module.tag.ModuleTag
18-
import com.lambda.task.Task
1918
import com.lambda.util.KeyCode
2019
import com.lambda.util.Nameable
2120

@@ -99,7 +98,7 @@ abstract class Module(
9998
private val isEnabledSetting = setting("Enabled", enabledByDefault, visibility = { false })
10099
private val keybindSetting = setting("Keybind", defaultKeybind)
101100
private val isVisible = setting("Visible", true)
102-
val customTags = setting("Tags", emptySet<ModuleTag>(), visibility = { false })
101+
val customTags = setting("Tags", setOf<ModuleTag>(), visibility = { false })
103102

104103
var isEnabled by isEnabledSetting
105104
val isDisabled get() = !isEnabled
@@ -167,4 +166,4 @@ abstract class Module(
167166
if (from != to) block(to)
168167
}
169168
}
170-
}
169+
}

common/src/main/kotlin/com/lambda/module/modules/network/PacketLogger.kt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.lambda.module.modules.network
22

33
import com.lambda.Lambda
44
import com.lambda.Lambda.mc
5-
import com.lambda.event.EventFlow.lambdaScope
65
import com.lambda.event.events.PacketEvent
76
import com.lambda.event.events.TickEvent
87
import com.lambda.event.listener.UnsafeListener.Companion.unsafeConcurrentListener
@@ -16,10 +15,8 @@ import com.lambda.util.DynamicReflectionSerializer.dynamicString
1615
import com.lambda.util.FolderRegister
1716
import com.lambda.util.Formatting.getTime
1817
import com.lambda.util.text.*
19-
import kotlinx.coroutines.Dispatchers
2018
import kotlinx.coroutines.channels.BufferOverflow
2119
import kotlinx.coroutines.flow.MutableSharedFlow
22-
import kotlinx.coroutines.launch
2320
import net.minecraft.network.packet.Packet
2421
import java.awt.Color
2522
import java.io.File
@@ -38,8 +35,8 @@ object PacketLogger : Module(
3835
private val networkSide by setting("Network Side", NetworkSide.ANY, "Side of the network to log packets from")
3936
private val logTicks by setting("Log Ticks", true, "Show game ticks in the log")
4037
private val scope by setting("Scope", Scope.ANY, "Scope of packets to log")
41-
private val whitelist by setting("Whitelist Packets", arrayListOf<String>(), "Packets to whitelist") { scope == Scope.WHITELIST }
42-
private val blacklist by setting("Blacklist Packets", arrayListOf<String>(), "Packets to blacklist") { scope == Scope.BLACKLIST }
38+
private val whitelist by setting("Whitelist Packets", emptyList<String>(), "Packets to whitelist", visibility = { scope == Scope.WHITELIST })
39+
private val blacklist by setting("Blacklist Packets", emptyList<String>(), "Packets to blacklist", visibility = { scope == Scope.BLACKLIST })
4340
private val maxRecursionDepth by setting("Max Recursion Depth", 6, 1..10, 1, "Maximum recursion depth for packet serialization")
4441
private val logConcurrent by setting("Build Data Concurrent", false, "Whether to serialize packets concurrently. Will not save packets in chronological order but wont lag the game.")
4542

common/src/main/kotlin/com/lambda/module/modules/render/BlockESP.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import com.lambda.Lambda.mc
44
import com.lambda.graphics.renderer.esp.ChunkedESP.Companion.newChunkedESP
55
import com.lambda.graphics.renderer.esp.DirectionMask
66
import com.lambda.graphics.renderer.esp.DirectionMask.buildSideMesh
7-
import com.lambda.graphics.renderer.esp.DirectionMask.exclude
8-
import com.lambda.graphics.renderer.esp.DirectionMask.mask
97
import com.lambda.graphics.renderer.esp.ESPRenderer
108
import com.lambda.graphics.renderer.esp.global.buildFilled
119
import com.lambda.graphics.renderer.esp.global.buildOutline
@@ -17,7 +15,6 @@ import net.minecraft.block.Blocks
1715
import net.minecraft.client.render.model.BakedModel
1816
import net.minecraft.util.math.BlockPos
1917
import net.minecraft.util.math.Box
20-
import net.minecraft.util.math.Direction
2118
import java.awt.Color
2219

2320
object BlockESP : Module(
@@ -98,4 +95,4 @@ object BlockESP : Module(
9895
buildOutline(box, outlineColor, sides, outlineMode)
9996
}
10097
}
101-
}
98+
}

common/src/main/kotlin/com/lambda/util/BlockUtils.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import com.lambda.util.item.ItemUtils.shulkerBoxes
66
import net.minecraft.block.Block
77
import net.minecraft.block.BlockState
88
import net.minecraft.block.Blocks
9-
import net.minecraft.client.world.ClientWorld
109
import net.minecraft.fluid.FluidState
1110
import net.minecraft.fluid.Fluids
1211
import net.minecraft.item.Item

0 commit comments

Comments
 (0)