Skip to content

Commit 8683549

Browse files
committed
Fix saving friends and safer management
1 parent abd7dc0 commit 8683549

File tree

7 files changed

+38
-32
lines changed

7 files changed

+38
-32
lines changed

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() {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import java.awt.Color
4040

4141
object FriendCommand : LambdaCommand(
4242
name = "friend",
43-
usage = "friend [add/remove] [name]",
43+
usage = "friend <add | remove> <name>",
4444
description = "Add or remove a friend"
4545
) {
4646
override fun CommandBuilder.create() {
@@ -80,7 +80,7 @@ object FriendCommand : LambdaCommand(
8080
?.firstOrNull {
8181
it.profile.name == name &&
8282
it.profile != mc.gameProfile
83-
} ?: return@executeWithResult failure("Could not find the player in the server")
83+
} ?: return@executeWithResult failure("Could not find the player on the server")
8484

8585
FriendManager.add(id.profile)
8686

@@ -110,7 +110,7 @@ object FriendCommand : LambdaCommand(
110110

111111
executeWithResult {
112112
val name = player().value()
113-
val profile = FriendManager.get(name)
113+
val profile = FriendManager.gameProfile(name)
114114
?: return@executeWithResult failure("This player is not in your friend list")
115115

116116
FriendManager.remove(profile)

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/friend/FriendManager.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ import java.util.*
2626

2727
object FriendManager : Configurable(FriendConfig), Loadable {
2828
override val name = "friends"
29-
val friends by setting("friends", listOf<GameProfile>(), hackDelegates = true)
29+
val friends by setting("friends", setOf<GameProfile>())
3030

31-
fun add(profile: GameProfile) { if (!contains(profile)) friends.add(profile) }
31+
fun add(profile: GameProfile) = friends.add(profile)
3232

33-
fun remove(profile: GameProfile) = friends.remove(profile) // FixMe: For some reasons you can't remove friends
33+
fun remove(profile: GameProfile): Boolean = friends.remove(profile)
3434

35-
fun get(name: String) = friends.firstOrNull { it.name == name }
36-
fun get(uuid: UUID) = friends.firstOrNull { it.id == uuid }
35+
fun gameProfile(name: String) = friends.firstOrNull { it.name == name }
36+
fun gameProfile(uuid: UUID) = friends.firstOrNull { it.id == uuid }
3737

3838
fun contains(profile: GameProfile) = friends.contains(profile)
3939
fun contains(name: String) = friends.any { it.name == name }

common/src/main/kotlin/com/lambda/module/modules/player/ClickFriend.kt

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ object ClickFriend : Module(
4444
description = "Add or remove friends with a single click",
4545
defaultTags = setOf(ModuleTag.PLAYER)
4646
) {
47-
private val friendButton by setting("Friend Button", Mouse.Button.Right, description = "Button to press to friend a player")
47+
private val friendButton by setting("Friend Button", Mouse.Button.Middle, description = "Button to press to befriend a player")
4848
private val friendAction by setting("Action", Mouse.Action.Release, description = "What mouse action should add or remove the player")
4949
private val comboUnfriend by setting("Combo Unfriend", false, description = "Press a key and right click a player to unfriend")
5050
private val modUnfriend by setting("Combo Key", MouseMod.Shift, description = "The key to press to activate the unfriend combo") { comboUnfriend }
@@ -59,30 +59,23 @@ object ClickFriend : Module(
5959
val target = mc.crosshairTarget?.entityResult?.entity as? OtherClientPlayerEntity
6060
?: return@listener
6161

62-
if ((modUnfriend.flagsPresent(it.modifiers) || !comboUnfriend) && target.isFriend) {
63-
target.unfriend()
64-
info(buildText {
65-
color(Color.RED) {
66-
literal("Removed ")
67-
color(Color.CYAN) {
62+
if (modUnfriend.flagsPresent(it.modifiers) || !comboUnfriend) {
63+
when {
64+
target.isFriend && target.unfriend() -> {
65+
this@ClickFriend.info(buildText {
66+
literal(Color.RED, "Removed ")
6867
text(target.name)
69-
color(Color.WHITE) { literal(" from your friend list") }
70-
}
68+
literal(Color.WHITE, " from your friend list")
69+
})
7170
}
72-
})
73-
}
74-
75-
if (!modUnfriend.flagsPresent(it.modifiers) && !target.isFriend) {
76-
target.befriend()
77-
info(buildText {
78-
color(Color.GREEN) {
79-
literal("Added ")
80-
color(Color.CYAN) {
71+
!target.isFriend && target.befriend() -> {
72+
this@ClickFriend.info(buildText {
73+
literal(Color.GREEN, "Added ")
8174
text(target.name)
82-
color(Color.WHITE) { literal(" to your friend list") }
83-
}
75+
literal(Color.WHITE, " to your friend list")
76+
})
8477
}
85-
})
78+
}
8679
}
8780
}
8881
}

common/src/main/kotlin/com/lambda/util/text/TextDsl.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,19 @@ fun TextBuilder.literal(value: String) {
113113
styleAndAppend(Text.literal(value))
114114
}
115115

116+
/**
117+
* Adds a literal text.
118+
*
119+
* @param value The text.
120+
* @see StyleBuilder for action
121+
*/
122+
@TextDsl
123+
fun TextBuilder.literal(color: Color, value: String) {
124+
color(color) {
125+
literal(value)
126+
}
127+
}
128+
116129
/**
117130
* Adds a mutable key bind text.
118131
*

0 commit comments

Comments
 (0)