Skip to content

Commit

Permalink
#567 Improved cancellation exception handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shynixn committed Jan 5, 2024
1 parent 678373a commit f677e6a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 2 additions & 2 deletions docs/wiki/docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ Rotates the pet to the exact line of the nearest x or z axe.
* Name: Identifier of a pet
* Player: Optional player_name/player_UUID parameter targeting a player from the console or command block.

### /petblocks moveforward>
### /petblocks moveforward

```
/petblocks moveforward <name> <speed> [player]
Expand All @@ -387,7 +387,7 @@ Lets the pet move forward in its current direction. Executing the snap command b
move in a straight direction. If the pet reaches a cliff (1 block difference), moving forward stops.

* Name: Identifier of a pet
* Speed: Speed parameter, should be command values e.g. 0.3
* Speed: Speed parameter, should be comma values e.g. 0.3
* Player: Optional player_name/player_UUID parameter targeting a player from the console or command block.

### /petblocks rotaterel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.github.shynixn.petblocks.impl.physic.ArmorstandEntityComponent
import com.github.shynixn.petblocks.impl.physic.MathComponent
import com.github.shynixn.petblocks.impl.physic.MoveToTargetComponent
import com.github.shynixn.petblocks.impl.physic.PlayerComponent
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.delay
import org.bukkit.*
import org.bukkit.block.Block
Expand Down Expand Up @@ -87,6 +88,12 @@ class PetEntityImpl(
cancellationTokenLoop = CancellationToken()
petActionExecutionService.executeAction(pet.player, pet, loop, cancellationTokenLoop)
delay(1.ticks)
} catch (e: CancellationException) {
// Ignore Coroutine Cancel
break
} catch (e: IllegalStateException) {
// Ignore Coroutine Cancel
break
} catch (e: Exception) {
plugin.logger.log(Level.SEVERE, "Cannot execute pet loop '${pet.loop}'.", e)
break
Expand Down Expand Up @@ -257,7 +264,7 @@ class PetEntityImpl(
cancellationTokenLongRunning.isCancelled = true
cancellationTokenLongRunning = CancellationToken()

val token = cancellationTokenLongRunning
val token = cancellationTokenLongRunning

plugin.launch {
while (true) {
Expand Down

0 comments on commit f677e6a

Please sign in to comment.