@@ -42,20 +42,26 @@ import java.awt.Color
4242
4343object FriendCommand : LambdaCommand(
4444 name = " friends" ,
45- usage = " friends <add | remove> <name | uuid >" ,
45+ usage = " friends <add <name> | add-uuid <uuid> | remove <name> >" ,
4646 description = " Add or remove a friend"
4747) {
4848 override fun CommandBuilder.create () {
4949 execute {
50- this @FriendCommand. info(
50+ info(
5151 buildText {
5252 if (FriendManager .friends.isEmpty()) {
5353 literal(" You have no friends yet. Go make some! :3\n " )
5454 } else {
5555 literal(" Your friends (${FriendManager .friends.size} ):\n " )
5656
5757 FriendManager .friends.forEachIndexed { index, gameProfile ->
58- literal(" ${index + 1 } . ${gameProfile.name} \n " )
58+ literal(" ${index + 1 } . ${gameProfile.name} " )
59+ styled(
60+ color = Color .RED ,
61+ clickEvent = ClickEvents .suggestCommand(" ;friends remove ${gameProfile.name} " )
62+ ) {
63+ literal(" x\n " )
64+ }
5965 }
6066 }
6167
@@ -84,24 +90,26 @@ object FriendCommand : LambdaCommand(
8490 }
8591
8692 executeWithResult {
87- runBlocking {
88- val name = player().value()
93+ val name = player().value()
94+
95+ if (FriendManager .isFriend(name))
96+ return @executeWithResult failure(" This player is already in your friend list" )
8997
90- if (mc.gameProfile.name == name) return @runBlocking failure(" You can't befriend yourself" )
98+ if (mc.gameProfile.name == name)
99+ return @executeWithResult failure(" You can't befriend yourself" )
91100
101+ runBlocking {
92102 val profile = mc.networkHandler
93103 ?.playerList
94104 ?.map { it.profile }
95105 ?.firstOrNull { it.name == name }
96106 ? : getProfile(name)
97107 .getOrElse { return @runBlocking failure(" Could not find the player" ) }
98108
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- }
109+ FriendManager .befriend(profile)
110+
111+ info(FriendManager .befriendedText(profile.name))
112+ success()
105113 }
106114 }
107115 }
@@ -120,24 +128,26 @@ object FriendCommand : LambdaCommand(
120128 }
121129
122130 executeWithResult {
123- runBlocking {
124- val uuid = player().value()
131+ val uuid = player().value()
132+
133+ if (FriendManager .isFriend(uuid))
134+ return @executeWithResult failure(" This player is already in your friend list" )
125135
126- if (mc.gameProfile.id == uuid) return @runBlocking failure(" You can't befriend yourself" )
136+ if (mc.gameProfile.id == uuid)
137+ return @executeWithResult failure(" You can't befriend yourself" )
127138
139+ runBlocking {
128140 val profile = mc.networkHandler
129141 ?.playerList
130142 ?.map { it.profile }
131143 ?.firstOrNull { it.id == uuid }
132144 ? : getProfile(uuid)
133145 .getOrElse { return @runBlocking failure(" Could not find the player" ) }
134146
135- return @runBlocking if (FriendManager .befriend(profile)) {
136- this @FriendCommand.info(FriendManager .befriendedText(profile.name))
137- success()
138- } else {
139- failure(" This player is already in your friend list" )
140- }
147+ FriendManager .befriend(profile)
148+
149+ info(FriendManager .befriendedText(profile.name))
150+ success()
141151 }
142152 }
143153 }
@@ -157,12 +167,10 @@ object FriendCommand : LambdaCommand(
157167 val profile = FriendManager .gameProfile(name)
158168 ? : return @executeWithResult failure(" This player is not in your friend list" )
159169
160- return @executeWithResult if (FriendManager .unfriend(profile)) {
161- this @FriendCommand.info(FriendManager .unfriendedText(name))
162- success()
163- } else {
164- failure(" This player is not in your friend list" )
165- }
170+ FriendManager .unfriend(profile)
171+
172+ info(FriendManager .unfriendedText(name))
173+ success()
166174 }
167175 }
168176 }
0 commit comments