Skip to content

Commit a79cf40

Browse files
committed
Merge remote-tracking branch 'origin/refactor/ui' into refactor/ui
# Conflicts: # common/src/main/kotlin/com/lambda/graphics/RenderPipeline.kt # common/src/main/kotlin/com/lambda/graphics/renderer/esp/global/StaticESP.kt # common/src/main/kotlin/com/lambda/module/modules/player/FastBreak.kt # common/src/main/kotlin/com/lambda/module/modules/player/PacketMine.kt
2 parents 0f8e2e4 + 519b96d commit a79cf40

File tree

90 files changed

+1173
-771
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+1173
-771
lines changed

.github/CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ Enhancement suggestions are tracked as [GitHub issues](https://github.com/lambda
9999
- **Explain why this enhancement would be useful** to most Lambda users. You may also want to point out the other projects that solved it better and which could serve as inspiration.
100100

101101
### Your First Code Contribution
102-
First of all, make sure to read or simply check the [Official Kotlin Coding Convention](https://kotlinlang.org/docs/coding-conventions.html#control-flow-statements)
102+
First of all, make sure to read or simply check the [Official Kotlin Coding Convention](https://kotlinlang.org/docs/coding-conventions.html)
103103

104104
This is required for pull requests to be accepted, or even reviewed.
105105

common/src/main/kotlin/com/lambda/command/commands/ConfigCommand.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import com.lambda.util.extension.CommandBuilder
2929
object ConfigCommand : LambdaCommand(
3030
name = "config",
3131
aliases = setOf("cfg"),
32-
usage = "config <save|load>",
32+
usage = "config <save | load>",
3333
description = "Save or load the configuration files"
3434
) {
3535
override fun CommandBuilder.create() {
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
/*
2+
* Copyright 2024 Lambda
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.lambda.command.commands
19+
20+
import com.lambda.Lambda.mc
21+
import com.lambda.brigadier.CommandResult.Companion.failure
22+
import com.lambda.brigadier.CommandResult.Companion.success
23+
import com.lambda.brigadier.argument.literal
24+
import com.lambda.brigadier.argument.string
25+
import com.lambda.brigadier.argument.uuid
26+
import com.lambda.brigadier.argument.value
27+
import com.lambda.brigadier.execute
28+
import com.lambda.brigadier.executeWithResult
29+
import com.lambda.brigadier.required
30+
import com.lambda.command.LambdaCommand
31+
import com.lambda.config.configurations.FriendConfig
32+
import com.lambda.friend.FriendManager
33+
import com.lambda.util.Communication.info
34+
import com.lambda.util.extension.CommandBuilder
35+
import com.lambda.util.text.ClickEvents
36+
import com.lambda.util.text.buildText
37+
import com.lambda.util.text.literal
38+
import com.lambda.util.text.styled
39+
import java.awt.Color
40+
41+
object FriendCommand : LambdaCommand(
42+
name = "friends",
43+
usage = "friends <add | remove> <name | uuid>",
44+
description = "Add or remove a friend"
45+
) {
46+
override fun CommandBuilder.create() {
47+
execute {
48+
this@FriendCommand.info(
49+
buildText {
50+
if (FriendManager.friends.isEmpty()) {
51+
literal("You have no friends yet. Go make some! :3\n")
52+
} else {
53+
literal("Your friends (${FriendManager.friends.size}):\n")
54+
55+
FriendManager.friends.forEachIndexed { index, gameProfile ->
56+
literal(" ${index + 1}. ${gameProfile.name}\n")
57+
}
58+
}
59+
60+
literal("\n")
61+
styled(
62+
color = Color.CYAN,
63+
underlined = true,
64+
clickEvent = ClickEvents.openFile(FriendConfig.primary.path),
65+
) {
66+
literal("Click to open your friends list as a file")
67+
}
68+
}
69+
)
70+
}
71+
72+
required(literal("add")) {
73+
required(string("player name")) { player ->
74+
suggests { _, builder ->
75+
mc.networkHandler
76+
?.playerList
77+
?.filter { it.profile != mc.gameProfile }
78+
?.map { it.profile.name }
79+
?.forEach { builder.suggest(it) }
80+
81+
builder.buildFuture()
82+
}
83+
84+
executeWithResult {
85+
val name = player().value()
86+
val id = mc.networkHandler
87+
?.playerList
88+
?.firstOrNull {
89+
it.profile.name == name &&
90+
it.profile != mc.gameProfile
91+
} ?: return@executeWithResult failure("Could not find the player on the server")
92+
93+
return@executeWithResult if (FriendManager.befriend(id.profile)) {
94+
this@FriendCommand.info(FriendManager.befriendedText(id.profile.name))
95+
success()
96+
} else {
97+
failure("This player is already in your friend list")
98+
}
99+
}
100+
}
101+
102+
required(uuid("player uuid")) { player ->
103+
suggests { _, builder ->
104+
mc.networkHandler
105+
?.playerList
106+
?.filter { it.profile != mc.gameProfile }
107+
?.map { it.profile.id }
108+
?.forEach { builder.suggest(it.toString()) }
109+
110+
builder.buildFuture()
111+
}
112+
113+
executeWithResult {
114+
val uuid = player().value()
115+
val id = mc.networkHandler
116+
?.playerList
117+
?.firstOrNull {
118+
it.profile.id == uuid && it.profile != mc.gameProfile
119+
} ?: return@executeWithResult failure("Could not find the player on the server")
120+
121+
return@executeWithResult if (FriendManager.befriend(id.profile)) {
122+
this@FriendCommand.info(FriendManager.befriendedText(id.profile.name))
123+
success()
124+
} else {
125+
failure("This player is already in your friend list")
126+
}
127+
}
128+
}
129+
}
130+
131+
required(literal("remove")) {
132+
required(string("player name")) { player ->
133+
suggests { _, builder ->
134+
FriendManager.friends.map { it.name }
135+
.forEach { builder.suggest(it) }
136+
137+
builder.buildFuture()
138+
}
139+
140+
executeWithResult {
141+
val name = player().value()
142+
val profile = FriendManager.gameProfile(name)
143+
?: return@executeWithResult failure("This player is not in your friend list")
144+
145+
return@executeWithResult if (FriendManager.unfriend(profile)) {
146+
this@FriendCommand.info(FriendManager.unfriendedText(name))
147+
success()
148+
} else {
149+
failure("This player is not in your friend list")
150+
}
151+
}
152+
}
153+
}
154+
}
155+
}

common/src/main/kotlin/com/lambda/command/commands/ReplayCommand.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import com.lambda.util.extension.CommandBuilder
3333

3434
object ReplayCommand : LambdaCommand(
3535
name = "replay",
36-
usage = "replay <play|load|save|prune>",
36+
usage = "replay <play | load | save | prune>",
3737
description = "Play, load, save, or prune a replay"
3838
) {
3939
override fun CommandBuilder.create() {

common/src/main/kotlin/com/lambda/command/commands/TransferCommand.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import com.lambda.util.extension.CommandBuilder
3232

3333
object TransferCommand : LambdaCommand(
3434
name = "transfer",
35-
usage = "transfer <move|cancel|undo> <item> <amount> <to>",
35+
usage = "transfer <move | cancel | undo> <item> <amount> <to>",
3636
description = "Transfer items from anywhere to anywhere",
3737
) {
3838
private var lastTransfer: TransferResult.Transfer? = null

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ abstract class AbstractSetting<T : Any>(
100100
value = gson.fromJson(serialized, type)
101101
}
102102

103+
/**
104+
* Will only register changes of the variable, not the content of the variable!
105+
* E.g., if the variable is a list, it will only register if the list reference changes, not if the content of the list changes.
106+
*/
103107
fun onValueChange(block: SafeContext.(from: T, to: T) -> Unit) {
104108
listeners.add(ValueListener(true) { from, to ->
105109
runSafe {

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,6 @@ abstract class Configurable(
248248
* @param name The unique identifier for the setting.
249249
* @param defaultValue The default [Set] value of type [T] for the setting.
250250
* @param description A brief explanation of the setting's purpose and behavior.
251-
* @param hackDelegates A flag that determines whether the setting should be serialized with the default value.
252251
* @param visibility A lambda expression that determines the visibility status of the setting.
253252
*
254253
* ```kotlin
@@ -262,14 +261,12 @@ abstract class Configurable(
262261
name: String,
263262
defaultValue: Set<T>,
264263
description: String = "",
265-
hackDelegates: Boolean = false,
266264
noinline visibility: () -> Boolean = { true },
267265
) = SetSetting(
268266
name,
269267
defaultValue.toMutableSet(),
270268
TypeToken.getParameterized(MutableSet::class.java, T::class.java).type,
271269
description,
272-
hackDelegates,
273270
visibility,
274271
).also {
275272
settings.add(it)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import com.lambda.Lambda.LOG
2424
import com.lambda.Lambda.gson
2525
import com.lambda.config.configurations.ModuleConfig
2626
import com.lambda.event.events.ClientEvent
27-
import com.lambda.event.listener.UnsafeListener.Companion.unsafeListener
27+
import com.lambda.event.listener.UnsafeListener.Companion.listenUnsafe
2828
import com.lambda.threading.runIO
2929
import com.lambda.util.Communication.info
3030
import com.lambda.util.Communication.logError
@@ -57,9 +57,9 @@ abstract class Configuration : Jsonable {
5757
get() = File("${primary.parent}/${primary.nameWithoutExtension}-backup.${primary.extension}")
5858

5959
init {
60-
unsafeListener<ClientEvent.Startup> { tryLoad() }
60+
listenUnsafe<ClientEvent.Startup> { tryLoad() }
6161

62-
unsafeListener<ClientEvent.Shutdown>(Int.MIN_VALUE) { trySave() }
62+
listenUnsafe<ClientEvent.Shutdown>(Int.MIN_VALUE) { trySave() }
6363

6464
register()
6565
}

common/src/main/kotlin/com/lambda/config/settings/collections/SetSetting.kt

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
package com.lambda.config.settings.collections
1919

20-
import com.google.gson.JsonElement
21-
import com.lambda.Lambda.gson
2220
import com.lambda.config.AbstractSetting
2321
import java.lang.reflect.Type
2422

@@ -27,27 +25,13 @@ import java.lang.reflect.Type
2725
*/
2826
class SetSetting<T : Any>(
2927
override val name: String,
30-
private val defaultValue: MutableSet<T>,
28+
defaultValue: MutableSet<T>,
3129
type: Type,
3230
description: String,
33-
private val hackDelegates: Boolean,
3431
visibility: () -> Boolean,
3532
) : AbstractSetting<MutableSet<T>>(
3633
defaultValue,
3734
type,
3835
description,
3936
visibility
40-
) {
41-
override fun toJson(): JsonElement {
42-
return if (hackDelegates) gson.toJsonTree(defaultValue, type)
43-
else super.toJson()
44-
}
45-
46-
override fun loadFromJson(serialized: JsonElement) {
47-
if (hackDelegates) {
48-
defaultValue.addAll(gson.fromJson(serialized, type))
49-
setValue(this, ::value, defaultValue.distinct().toMutableSet())
50-
}
51-
else super.loadFromJson(serialized)
52-
}
53-
}
37+
)

common/src/main/kotlin/com/lambda/core/PingManager.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package com.lambda.core
1919

2020
import com.lambda.event.events.PacketEvent
2121
import com.lambda.event.events.TickEvent
22-
import com.lambda.event.listener.SafeListener.Companion.listener
22+
import com.lambda.event.listener.SafeListener.Companion.listen
2323
import com.lambda.util.collections.LimitedOrderedSet
2424
import net.minecraft.network.packet.c2s.query.QueryPingC2SPacket
2525
import net.minecraft.network.packet.s2c.query.PingResultS2CPacket
@@ -33,12 +33,12 @@ object PingManager : Loadable {
3333
get() = pings.lastOrNull() ?: 0
3434

3535
init {
36-
listener<TickEvent.Pre> {
36+
listen<TickEvent.Pre> {
3737
connection.sendPacket(QueryPingC2SPacket(Util.getMeasuringTimeMs()))
3838
}
3939

40-
listener<PacketEvent.Receive.Pre> { event ->
41-
if (event.packet !is PingResultS2CPacket) return@listener
40+
listen<PacketEvent.Receive.Pre> { event ->
41+
if (event.packet !is PingResultS2CPacket) return@listen
4242

4343
pings.add(Util.getMeasuringTimeMs() - event.packet.startTime)
4444
}

0 commit comments

Comments
 (0)