Kotlin & Coroutines with Event Propagation

melodev

New member
Jun 2, 2024
2
0
1
Firstly,

Hello everyone. I'm creating some plugin to Paper that will care about player metrics.

For that I have a list of metrics, that will have a lot of handlers for each metric. Like: playerDamageToPlayers, playerMinedBlockOres, etc.

1717346122384.png

This implies that I can many metrics for each spread event, so when player break a block, I can have one or more metrics, like this one above.

The event handler will get the metrics list and do something like that:

1717346191651.png

The problem:

I'm running this metrics in some Coroutine with launch() from kotlin. So lines like:

1717346356965.png
1717346339854.png


Evaluate different types of blocks. I think that happens because when I use .block (getBlock) out of the coroutine the event get the context has the blocks as being dirt yet, but in coroutine the block has been break already, so it gets the type air, because the block is now air. Something like that.

How do you guys handle that when using kotlin and have to use coroutines?
 

melodev

New member
Jun 2, 2024
2
0
1
Ok, I found one way to use a coroutine without losing the context.1717350333086.png


A friend of mine and me, think that this is related to TLS.

1717350392539.png

Not AIR anymore :ninja: