Skip to content

Commit

Permalink
Do not give players a shulker if run context failed to initialize
Browse files Browse the repository at this point in the history
  • Loading branch information
4Ply committed Dec 23, 2024
1 parent 2901948 commit aaf0975
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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!!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class AgroNetPlayerConnectionListener(
return
}

var givePlayerTheirShulker = false
try {
if (!RunContext.initialized) {
claimApi.claimsGet(
Expand All @@ -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)
Expand Down Expand Up @@ -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()
}
}
}
}
Expand Down

0 comments on commit aaf0975

Please sign in to comment.