From aaf0975d4b4b1179dbad2e7e24b0abee41c50f06 Mon Sep 17 00:00:00 2001 From: 4Ply Date: Mon, 23 Dec 2024 20:03:20 +0200 Subject: [PATCH] Do not give players a shulker if run context failed to initialize --- .../actions/AddDeckToPlayerInventoryAction.kt | 5 ++++ .../AgroNetPlayerConnectionListener.kt | 23 ++++++++++++------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/org/trackedout/actions/AddDeckToPlayerInventoryAction.kt b/src/main/kotlin/org/trackedout/actions/AddDeckToPlayerInventoryAction.kt index 62b56b6..1e7753c 100644 --- a/src/main/kotlin/org/trackedout/actions/AddDeckToPlayerInventoryAction.kt +++ b/src/main/kotlin/org/trackedout/actions/AddDeckToPlayerInventoryAction.kt @@ -43,6 +43,11 @@ class AddDeckToPlayerInventoryAction( return } + if (!RunContext.initialized) { + player.sendMessage("Run data is not initialized, unable to determine which deck to give to $playerName", Formatting.RED) + return + } + val context = RunContext.playerContext(playerName) player.sendMessage("Fetching ${context.fullRunType()} mode Decked Out shulker #${context.shortDeckId()} from Dunga Dunga...", Formatting.GRAY) val cards = inventoryApi.inventoryCardsGet(player = playerName, limit = 200, deckType = context.runType(), deckId = context.fullDeckId()).results!! diff --git a/src/main/kotlin/org/trackedout/listeners/AgroNetPlayerConnectionListener.kt b/src/main/kotlin/org/trackedout/listeners/AgroNetPlayerConnectionListener.kt index 01ab237..623cb80 100644 --- a/src/main/kotlin/org/trackedout/listeners/AgroNetPlayerConnectionListener.kt +++ b/src/main/kotlin/org/trackedout/listeners/AgroNetPlayerConnectionListener.kt @@ -67,6 +67,7 @@ class AgroNetPlayerConnectionListener( return } + var givePlayerTheirShulker = false try { if (!RunContext.initialized) { claimApi.claimsGet( @@ -80,6 +81,8 @@ class AgroNetPlayerConnectionListener( // TODO: Store deck-id - https://github.com/trackedout/agronet-fabric/issues/31 logger.info("Setting state of Claim ${claim.id} to 'in-use'") claimApi.claimsIdPatch(claim.id!!, claim.copy(id = null, state = "in-use", claimant = serverName)) + givePlayerTheirShulker = true + RunContext.initialized = true } ?: run { logger.error("No matching claim found for $playerName") handler.player.sendMessage("No matching claim found for your run, contact a moderator (unless you are spectating)", Formatting.RED) @@ -137,16 +140,20 @@ class AgroNetPlayerConnectionListener( } catch (e: Exception) { e.printStackTrace() - handler.player.sendMessage("A critical error occurred when attempting to fetch your data from dunga-dunga, " + - "and your data could not be imported. Contact a moderator.", Formatting.RED) + handler.player.sendMessage( + "A critical error occurred when attempting to fetch your data from dunga-dunga, " + + "and your data could not be imported. Contact a moderator.", Formatting.RED + ) } - handler.player?.let { player -> - server.commandSource?.let { commandSource -> - try { - addDeckToPlayerInventoryAction.execute(commandSource, player) - } catch (e: Exception) { - e.printStackTrace() + if (givePlayerTheirShulker) { + handler.player?.let { player -> + server.commandSource?.let { commandSource -> + try { + addDeckToPlayerInventoryAction.execute(commandSource, player) + } catch (e: Exception) { + e.printStackTrace() + } } } }