@@ -22,6 +22,7 @@ import com.lambda.brigadier.CommandResult.Companion.failure
2222import com.lambda.brigadier.CommandResult.Companion.success
2323import com.lambda.brigadier.argument.literal
2424import com.lambda.brigadier.argument.string
25+ import com.lambda.brigadier.argument.uuid
2526import com.lambda.brigadier.argument.value
2627import com.lambda.brigadier.execute
2728import com.lambda.brigadier.executeWithResult
@@ -33,26 +34,36 @@ import com.lambda.util.Communication.info
3334import com.lambda.util.extension.CommandBuilder
3435import com.lambda.util.text.ClickEvents
3536import com.lambda.util.text.buildText
36- import com.lambda.util.text.color
3737import com.lambda.util.text.literal
3838import com.lambda.util.text.styled
3939import java.awt.Color
4040
4141object FriendCommand : LambdaCommand(
42- name = " friend " ,
43- usage = " friend <add | remove> <name>" ,
42+ name = " friends " ,
43+ usage = " friends <add | remove> <name | uuid >" ,
4444 description = " Add or remove a friend"
4545) {
4646 override fun CommandBuilder.create () {
4747 execute {
4848 this @FriendCommand.info(
4949 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 " )
5061 styled(
5162 color = Color .CYAN ,
5263 underlined = true ,
53- clickEvent = ClickEvents .openFile(FriendConfig .primary.absolutePath ),
64+ clickEvent = ClickEvents .openFile(FriendConfig .primary.path ),
5465 ) {
55- literal(" Click to open your friend list" )
66+ literal(" Click to open your friends list as a file " )
5667 }
5768 }
5869 )
@@ -72,29 +83,47 @@ object FriendCommand : LambdaCommand(
7283
7384 executeWithResult {
7485 val name = player().value()
75- if (FriendManager .contains(name))
76- return @executeWithResult failure(" This player is already in your friend list" )
77-
7886 val id = mc.networkHandler
7987 ?.playerList
8088 ?.firstOrNull {
8189 it.profile.name == name &&
8290 it.profile != mc.gameProfile
8391 } ? : return @executeWithResult failure(" Could not find the player on the server" )
8492
85- FriendManager .add(id.profile)
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+ }
86101
87- this @FriendCommand.info(buildText {
88- color(Color .GREEN ) {
89- literal(" Added " )
90- color(Color .CYAN ) {
91- literal(name)
92- color(Color .WHITE ) { literal(" to your friend list" ) }
93- }
94- }
95- })
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()) }
96109
97- return @executeWithResult success()
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+ }
98127 }
99128 }
100129 }
@@ -113,19 +142,12 @@ object FriendCommand : LambdaCommand(
113142 val profile = FriendManager .gameProfile(name)
114143 ? : return @executeWithResult failure(" This player is not in your friend list" )
115144
116- FriendManager .remove(profile)
117-
118- this @FriendCommand.info(buildText {
119- color(Color .RED ) {
120- literal(" Removed " )
121- color(Color .CYAN ) {
122- literal(profile.name)
123- color(Color .WHITE ) { literal(" from your friend list" ) }
124- }
125- }
126- })
127-
128- return @executeWithResult success()
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+ }
129151 }
130152 }
131153 }
0 commit comments