@@ -30,12 +30,14 @@ import com.lambda.brigadier.required
3030import com.lambda.command.LambdaCommand
3131import com.lambda.config.configurations.FriendConfig
3232import com.lambda.friend.FriendManager
33+ import com.lambda.network.mojang.getProfile
3334import com.lambda.util.Communication.info
3435import com.lambda.util.extension.CommandBuilder
3536import com.lambda.util.text.ClickEvents
3637import com.lambda.util.text.buildText
3738import com.lambda.util.text.literal
3839import com.lambda.util.text.styled
40+ import kotlinx.coroutines.runBlocking
3941import java.awt.Color
4042
4143object FriendCommand : LambdaCommand(
@@ -82,20 +84,24 @@ object FriendCommand : LambdaCommand(
8284 }
8385
8486 executeWithResult {
85- val name = player().value()
86-
87- if (mc.gameProfile.name == name) return @executeWithResult failure(" You can't befriend yourself" )
88-
89- val id = mc.networkHandler
90- ?.playerList
91- ?.firstOrNull { it.profile.name == name }
92- ? : return @executeWithResult failure(" Could not find the player on the server" )
93-
94- return @executeWithResult if (FriendManager .befriend(id.profile)) {
95- info(FriendManager .befriendedText(id.profile.name))
96- success()
97- } else {
98- failure(" This player is already in your friend list" )
87+ runBlocking {
88+ val name = player().value()
89+
90+ if (mc.gameProfile.name == name) return @runBlocking failure(" You can't befriend yourself" )
91+
92+ val profile = mc.networkHandler
93+ ?.playerList
94+ ?.map { it.profile }
95+ ?.firstOrNull { it.name == name }
96+ ? : getProfile(name)
97+ .getOrElse { return @runBlocking failure(" Could not find the player" ) }
98+
99+ return @runBlocking if (FriendManager .befriend(profile)) {
100+ info(FriendManager .befriendedText(profile.name))
101+ success()
102+ } else {
103+ failure(" This player is already in your friend list" )
104+ }
99105 }
100106 }
101107 }
@@ -112,19 +118,24 @@ object FriendCommand : LambdaCommand(
112118 }
113119
114120 executeWithResult {
115- val uuid = player().value()
116-
117- if (mc.gameProfile.id == uuid) return @executeWithResult failure(" You can't befriend yourself" )
118-
119- val id = mc.networkHandler
120- ?.playerList
121- ?.firstOrNull { it.profile.id == uuid } ? : return @executeWithResult failure(" Could not find the player on the server" )
122-
123- return @executeWithResult if (FriendManager .befriend(id.profile)) {
124- this @FriendCommand.info(FriendManager .befriendedText(id.profile.name))
125- success()
126- } else {
127- failure(" This player is already in your friend list" )
121+ runBlocking {
122+ val uuid = player().value()
123+
124+ if (mc.gameProfile.id == uuid) return @runBlocking failure(" You can't befriend yourself" )
125+
126+ val profile = mc.networkHandler
127+ ?.playerList
128+ ?.map { it.profile }
129+ ?.firstOrNull { it.id == uuid }
130+ ? : getProfile(uuid)
131+ .getOrElse { return @runBlocking failure(" Could not find the player" ) }
132+
133+ return @runBlocking if (FriendManager .befriend(profile)) {
134+ this @FriendCommand.info(FriendManager .befriendedText(profile.name))
135+ success()
136+ } else {
137+ failure(" This player is already in your friend list" )
138+ }
128139 }
129140 }
130141 }
0 commit comments