Skip to content

Commit

Permalink
Fix Typo and Added null check in RetirementDefectionTracker
Browse files Browse the repository at this point in the history
Corrected the typo in the resource key "recentPromotion" and added a `null` check for the last promotion date before calculating the months difference. This ensures the application does not encounter a silent null pointer exception.
  • Loading branch information
IllianiCBT committed Nov 24, 2024
1 parent 3979544 commit 580dec2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ founder.text=Founder
shares.text=Shares
administrativeStrain.text=Admin Strain
managementSkill.text=Management Skill
recentpromotion.text=Recently Promoted
recentPromotion.text=Recently Promoted
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,6 @@
*/
package mekhq.campaign.personnel.turnoverAndRetention;

import static mekhq.campaign.personnel.Person.getLoyaltyName;
import static mekhq.campaign.personnel.turnoverAndRetention.RetirementDefectionTracker.Payout.isBreakingContract;

import java.io.PrintWriter;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import megamek.codeUtilities.MathUtility;
import megamek.common.Compute;
import megamek.common.TargetRoll;
Expand All @@ -55,6 +42,18 @@
import mekhq.campaign.universe.Faction;
import mekhq.campaign.universe.FactionHints;
import mekhq.utilities.MHQXMLUtility;
import org.apache.commons.lang3.StringUtils;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import java.io.PrintWriter;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.stream.Collectors;

import static mekhq.campaign.personnel.Person.getLoyaltyName;
import static mekhq.campaign.personnel.turnoverAndRetention.RetirementDefectionTracker.Payout.isBreakingContract;

/**
* @author Neoancient
Expand Down Expand Up @@ -177,10 +176,12 @@ public Map<UUID, TargetRoll> getTargetNumbers(final @Nullable Mission mission, f
LocalDate today = campaign.getLocalDate();
LocalDate lastPromotionDate = person.getLastRankChangeDate();

long monthsBetween = ChronoUnit.MONTHS.between(lastPromotionDate, today);
if (lastPromotionDate != null) {
long monthsBetween = ChronoUnit.MONTHS.between(lastPromotionDate, today);

if (monthsBetween <= 6) {
targetNumber.addModifier(- 1, resources.getString("recentpromotion.text"));
if (monthsBetween <= 6) {
targetNumber.addModifier(-1, resources.getString("recentPromotion.text"));
}
}
}

Expand Down

0 comments on commit 580dec2

Please sign in to comment.