@@ -39,6 +39,7 @@ import com.lambda.util.text.buildText
3939import com.lambda.util.text.literal
4040import com.lambda.util.text.styled
4141import kotlinx.coroutines.runBlocking
42+ import net.minecraft.command.CommandSource.suggestMatching
4243import java.awt.Color
4344import java.util.UUID
4445
@@ -87,13 +88,12 @@ object FriendCommand : LambdaCommand(
8788 required(literal(" add" )) {
8889 required(string(" player name" )) { player ->
8990 suggests { _, builder ->
90- mc.networkHandler
91+ val playerNames = mc.networkHandler
9192 ?.playerList
92- ?.filter { it.profile != mc.gameProfile }
9393 ?.map { it.profile.name }
94- ?.forEach { builder.suggest(it) }
94+ ?.toList() ? : emptyList()
9595
96- builder.buildFuture( )
96+ suggestMatching(playerNames, builder )
9797 }
9898
9999 executeWithResult {
@@ -103,9 +103,6 @@ object FriendCommand : LambdaCommand(
103103 val profile = FriendManager .latestGameProfile(name)
104104 ? : return @runBlocking failure(" Could not find the player" )
105105
106- if (mc.gameProfile.id == profile.id)
107- return @runBlocking failure(" You can't befriend yourself" )
108-
109106 if (FriendManager .isFriend(profile.id))
110107 return @runBlocking failure(" This player is already in your friend list" )
111108
@@ -121,21 +118,17 @@ object FriendCommand : LambdaCommand(
121118 required(literal(" add-uuid" )) {
122119 required(uuid(" player uuid" )) { player ->
123120 suggests { _, builder ->
124- mc.networkHandler
121+ val uuids = mc.networkHandler
125122 ?.playerList
126- ?.filter { it.profile != mc.gameProfile }
127- ?.map { it.profile.id }
128- ?.forEach { builder.suggest(it.toString()) }
123+ ?.map { it.profile.id.toString() }
124+ ?.toList() ? : emptyList()
129125
130- builder.buildFuture( )
126+ suggestMatching(uuids, builder )
131127 }
132128
133129 executeWithResult {
134130 val uuid = player().value()
135131
136- if (mc.gameProfile.id == uuid)
137- return @executeWithResult failure(" You can't befriend yourself" )
138-
139132 if (FriendManager .isFriend(uuid))
140133 return @executeWithResult failure(" This player is already in your friend list" )
141134
@@ -159,11 +152,8 @@ object FriendCommand : LambdaCommand(
159152 required(literal(" remove" )) {
160153 required(string(" player name" )) { player ->
161154 suggests { _, builder ->
162- FriendManager .friends
163- .map { FriendManager .friendDisplayName(it) }
164- .forEach { builder.suggest(it) }
165-
166- builder.buildFuture()
155+ val playerNames = FriendManager .friends.map { FriendManager .friendDisplayName(it) }
156+ suggestMatching(playerNames, builder)
167157 }
168158
169159 executeWithResult {
@@ -189,6 +179,15 @@ object FriendCommand : LambdaCommand(
189179
190180 required(literal(" remove-uuid" )) {
191181 required(uuid(" player uuid" )) { player ->
182+ suggests { _, builder ->
183+ val uuids = mc.networkHandler
184+ ?.playerList
185+ ?.map { it.profile.id.toString() }
186+ ?.toList() ? : emptyList()
187+
188+ suggestMatching(uuids, builder)
189+ }
190+
192191 executeWithResult {
193192 val uuid = player().value()
194193
0 commit comments