fix ghost LaborRecord entries for non-working prisoners on escape

This commit is contained in:
NotEvil
2026-04-16 14:36:45 +02:00
parent f4aa5ffdc5
commit 27c86bc831
2 changed files with 11 additions and 2 deletions

View File

@@ -113,6 +113,14 @@ public class PrisonerManager extends SavedData {
return laborRecords.computeIfAbsent(playerId, id -> new LaborRecord()); return laborRecords.computeIfAbsent(playerId, id -> new LaborRecord());
} }
/**
* Get labor record only if one exists. Does not create ghost entries.
*/
@Nullable
public LaborRecord getLaborRecordIfExists(UUID playerId) {
return laborRecords.get(playerId);
}
/** /**
* Set the labor record for a player. * Set the labor record for a player.
*/ */

View File

@@ -94,8 +94,9 @@ public class EscapeMonitorService {
); );
// Step 1: Save guard ID BEFORE state transition (manager.escape() removes the LaborRecord) // Step 1: Save guard ID BEFORE state transition (manager.escape() removes the LaborRecord)
LaborRecord laborBeforeEscape = manager.getLaborRecord(playerId); // Use direct map lookup to avoid creating ghost LaborRecord entries for non-WORKING prisoners
UUID guardId = laborBeforeEscape.getGuardId(); LaborRecord laborBeforeEscape = manager.getLaborRecordIfExists(playerId);
UUID guardId = laborBeforeEscape != null ? laborBeforeEscape.getGuardId() : null;
// Step 2: Transition prisoner state to FREE // Step 2: Transition prisoner state to FREE
boolean stateChanged = manager.escape(playerId, currentTime, reason); boolean stateChanged = manager.escape(playerId, currentTime, reason);