@@ -36,13 +36,11 @@ import net.minecraft.client.texture.NativeImageBackedTexture
3636import java.io.ByteArrayOutputStream
3737import java.util.UUID
3838import java.util.concurrent.ConcurrentHashMap
39- import kotlin.io.path.ExperimentalPathApi
4039import kotlin.io.path.extension
4140import kotlin.io.path.inputStream
4241import kotlin.io.path.nameWithoutExtension
4342import kotlin.io.path.walk
4443
45- @OptIn(ExperimentalPathApi ::class )
4644@Suppress(" JavaIoSerializableObjectMustHaveReadResolve" )
4745object CapeManager : ConcurrentHashMap<UUID, String>(), Loadable {
4846 /* *
@@ -55,22 +53,26 @@ object CapeManager : ConcurrentHashMap<UUID, String>(), Loadable {
5553
5654 /* *
5755 * Sets the current player's cape
56+ *
57+ * @param block Lambda called once the coroutine completes, it contains the throwable if any
5858 */
59- fun updateCape (cape : String , block : () -> Unit = {}) = runIO {
60- setCape(cape)
61- }.invokeOnCompletion { block() }
59+ fun updateCape (cape : String , block : (Throwable ? ) -> Unit = {}) = runIO {
60+ setCape(cape).getOrThrow()
61+ }.invokeOnCompletion { block(it ) }
6262
6363 /* *
6464 * Fetches the cape of the given player id
65+ *
66+ * @param block Lambda called once the coroutine completes, it contains the throwable if any
6567 */
66- fun SafeContext.fetchCape (uuid : UUID , block : () -> Unit = {}) = runIO {
68+ fun SafeContext.fetchCape (uuid : UUID , block : (Throwable ? ) -> Unit = {}) = runIO {
6769 val cape = getCape(uuid).getOrThrow()
6870
6971 mc.textureManager.get(cape.identifier) ? : download(cape)
7072 put(uuid, cape.id)
71- }.invokeOnCompletion { block() }
73+ }.invokeOnCompletion { block(it ) }
7274
73- private fun SafeContext.download (cape : Cape , block : () -> Unit = {}) = runIO {
75+ private fun SafeContext.download (cape : Cape , block : (Throwable ? ) -> Unit = {}) = runIO {
7476 val destination = capes.resolveFile(" ${cape.id} .png" )
7577 val output = ByteArrayOutputStream ()
7678
@@ -84,7 +86,7 @@ object CapeManager : ConcurrentHashMap<UUID, String>(), Loadable {
8486 val id = cape.identifier
8587
8688 mc.textureManager.registerTexture(id, native)
87- }.invokeOnCompletion { block() }
89+ }.invokeOnCompletion { block(it ) }
8890
8991 override fun load () = " Loaded ${images.size} cached capes"
9092
0 commit comments