Skip to content

Commit aa4206f

Browse files
committed
Log error instead of propagate
1 parent d79aac4 commit aa4206f

File tree

2 files changed

+19
-25
lines changed

2 files changed

+19
-25
lines changed

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

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,15 @@
1717

1818
package com.lambda.command.commands
1919

20-
import com.lambda.brigadier.CommandResult.Companion.success
20+
import com.lambda.brigadier.argument.literal
2121
import com.lambda.brigadier.argument.string
2222
import com.lambda.brigadier.argument.value
23-
import com.lambda.brigadier.executeWithResult
23+
import com.lambda.brigadier.execute
2424
import com.lambda.brigadier.required
2525
import com.lambda.command.LambdaCommand
2626
import com.lambda.network.CapeManager.updateCape
2727
import com.lambda.network.NetworkManager
2828
import com.lambda.threading.runSafe
29-
import com.lambda.util.Communication.info
3029
import com.lambda.util.extension.CommandBuilder
3130

3231
object CapeCommand : LambdaCommand(
@@ -35,27 +34,21 @@ object CapeCommand : LambdaCommand(
3534
description = "Sets your cape",
3635
) {
3736
override fun CommandBuilder.create() {
38-
required(string("id")) { id ->
39-
suggests { _, builder ->
40-
NetworkManager.capes
41-
.forEach { builder.suggest(it) }
37+
required(literal("set")) {
38+
required(string("id")) { id ->
39+
suggests { _, builder ->
40+
NetworkManager.capes
41+
.forEach { builder.suggest(it) }
4242

43-
builder.buildFuture()
44-
}
45-
46-
executeWithResult {
47-
runSafe {
48-
val cape = id().value()
49-
50-
// FixMe:
51-
// try-catch is stupid -
52-
// cannot propagate errors correctly -
53-
// spam the user and fuck off
54-
updateCape(cape)
55-
this@CapeCommand.info("Successfully updated the cape")
43+
builder.buildFuture()
44+
}
5645

57-
success()
58-
}!!
46+
execute {
47+
runSafe {
48+
val cape = id().value()
49+
updateCape(cape)
50+
}
51+
}
5952
}
6053
}
6154
}

common/src/main/kotlin/com/lambda/network/CapeManager.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import com.lambda.network.api.v1.endpoints.getCape
2929
import com.lambda.network.api.v1.endpoints.setCape
3030
import com.lambda.network.api.v1.models.Cape
3131
import com.lambda.sound.SoundManager.toIdentifier
32+
import com.lambda.util.Communication.info
3233
import com.lambda.util.Communication.logError
3334
import com.lambda.util.FolderRegister.capes
3435
import com.lambda.util.extension.get
@@ -57,11 +58,11 @@ object CapeManager : ConcurrentHashMap<UUID, String>(), Loadable {
5758
/**
5859
* Sets the current player's cape
5960
*/
60-
fun SafeContext.updateCape(cape: String) =
61+
fun SafeContext.updateCape(cape: String): CancellableRequest =
6162
setCape(cape,
62-
success = { fetchCape(player.uuid) },
63+
success = { fetchCape(player.uuid); info("Successfully update your cape to $cape") },
6364
failure = { logError("Could not update the player cape", it) }
64-
)//.join()
65+
)
6566

6667
/**
6768
* Fetches the cape of the given player id

0 commit comments

Comments
 (0)