40
40
import java .io .ObjectInputFilter .Config ;
41
41
import java .lang .management .ManagementFactory ;
42
42
import java .util .List ;
43
+ import java .util .Map ;
43
44
import java .util .UUID ;
44
45
import javax .swing .InputMap ;
45
46
import javax .swing .JOptionPane ;
@@ -108,8 +109,8 @@ public class MekHQ implements GameListener {
108
109
109
110
// region Variable Declarations
110
111
private static final SuitePreferences mhqPreferences = new SuitePreferences ();
111
- private static final MHQOptions mhqOptions = new MHQOptions ();
112
- private static final EventBus EVENT_BUS = new EventBus ();
112
+ private static final MHQOptions mhqOptions = new MHQOptions ();
113
+ private static final EventBus EVENT_BUS = new EventBus ();
113
114
114
115
private static ObservableString selectedTheme ;
115
116
@@ -124,21 +125,21 @@ public class MekHQ implements GameListener {
124
125
private static ObservableString financesDirectory ;
125
126
126
127
// stuff related to MM games
127
- private Server myServer = null ;
128
- private GameThread gameThread = null ;
129
- private Scenario currentScenario = null ;
130
- private Client client = null ;
128
+ private Server myServer = null ;
129
+ private GameThread gameThread = null ;
130
+ private Scenario currentScenario = null ;
131
+ private Client client = null ;
131
132
132
133
// the actual campaign - this is where the good stuff is
133
134
private CampaignController campaignController ;
134
- private CampaignGUI campaignGUI ;
135
+ private CampaignGUI campaignGUI ;
135
136
136
137
private final IconPackage iconPackage = new IconPackage ();
137
138
138
- private final IAutosaveService autosaveService ;
139
+ private final IAutosaveService autosaveService ;
139
140
// endregion Variable Declarations
140
141
private static final SanityInputFilter sanityInputFilter = new SanityInputFilter ();
141
- private static final String defaultTheme = "com.formdev.flatlaf.FlatDarculaLaf" ;
142
+ private static final String defaultTheme = "com.formdev.flatlaf.FlatDarculaLaf" ;
142
143
143
144
public static SuitePreferences getMHQPreferences () {
144
145
return mhqPreferences ;
@@ -318,9 +319,9 @@ public static void main(String... args) {
318
319
319
320
// First, create a global default exception handler
320
321
Thread .setDefaultUncaughtExceptionHandler ((thread , t ) -> {
321
- final String name = t .getClass ().getName ();
322
+ final String name = t .getClass ().getName ();
322
323
final String message = String .format (MMLoggingConstants .UNHANDLED_EXCEPTION , name );
323
- final String title = String .format (MMLoggingConstants .UNHANDLED_EXCEPTION_TITLE , name );
324
+ final String title = String .format (MMLoggingConstants .UNHANDLED_EXCEPTION_TITLE , name );
324
325
logger .errorDialog (t , message , title );
325
326
});
326
327
@@ -390,9 +391,9 @@ public void joinGame(Scenario scenario, List<Unit> meks) {
390
391
return ;
391
392
}
392
393
393
- final String playerName = joinGameDialog .getPlayerName ();
394
+ final String playerName = joinGameDialog .getPlayerName ();
394
395
final String serverAddress = joinGameDialog .getServerAddress ();
395
- final int port = joinGameDialog .getPort ();
396
+ final int port = joinGameDialog .getPort ();
396
397
joinGameDialog .dispose ();
397
398
398
399
try {
@@ -443,11 +444,11 @@ public void startHost(Scenario scenario, boolean loadSavegame, List<Unit> meks,
443
444
444
445
this .autosaveService .requestBeforeMissionAutosave (getCampaign ());
445
446
446
- final String playerName = hostDialog .getPlayerName ();
447
- final String password = hostDialog .getServerPass ();
448
- final int port = hostDialog .getPort ();
449
- final boolean register = hostDialog .isRegister ();
450
- final String metaserver = register ? hostDialog .getMetaserver () : "" ;
447
+ final String playerName = hostDialog .getPlayerName ();
448
+ final String password = hostDialog .getServerPass ();
449
+ final int port = hostDialog .getPort ();
450
+ final boolean register = hostDialog .isRegister ();
451
+ final String metaserver = register ? hostDialog .getMetaserver () : "" ;
451
452
452
453
// Force cleanup of the current modal, since we are (possibly) about to display a new one and macOS seems to
453
454
// struggle with that (see https://github.com/MegaMek/mekhq/issues/953)
@@ -583,7 +584,7 @@ public void gameVictory(PostGameResolution gve) {
583
584
BattlefieldControlType battlefieldControl = template .getBattlefieldControl ();
584
585
585
586
String controlMessage = MHQInternationalization .getText ("ResolveDialog.control." +
586
- battlefieldControl .name ());
587
+ battlefieldControl .name ());
587
588
588
589
victoryMessage = String .format ("%s\n \n %s" , controlMessage , victoryMessage );
589
590
}
@@ -632,7 +633,7 @@ public void resolveScenario(Scenario selectedScenario) {
632
633
BattlefieldControlType battlefieldControl = template .getBattlefieldControl ();
633
634
634
635
String controlMessage = MHQInternationalization .getText ("ResolveDialog.control." +
635
- battlefieldControl .name ());
636
+ battlefieldControl .name ());
636
637
637
638
victoryMessage = String .format ("%s\n \n %s" , controlMessage , victoryMessage );
638
639
}
@@ -763,7 +764,7 @@ public void autoResolveConcluded(AutoResolveConcludedEvent autoResolveConcludedE
763
764
BattlefieldControlType battlefieldControl = template .getBattlefieldControl ();
764
765
765
766
String controlMessage = MHQInternationalization .getText ("ResolveDialog.control." +
766
- battlefieldControl .name ());
767
+ battlefieldControl .name ());
767
768
768
769
victoryMessage = String .format ("%s\n \n %s\n \n %s" , controlMessage , victoryMessage , decisionMessage );
769
770
}
@@ -784,10 +785,38 @@ public void autoResolveConcluded(AutoResolveConcludedEvent autoResolveConcludedE
784
785
true ,
785
786
tracker );
786
787
resolveDialog .setVisible (true );
788
+ // TODO remove these safeties as they're shown to be unnecessary
789
+ if (resolveDialog == null ) {
790
+ throw new IllegalStateException ("resolveDialog is null" );
791
+ }
787
792
if (resolveDialog .wasAborted ()) {
793
+ // TODO remove these safeties as they're shown to be unnecessary
794
+ Map <UUID , ?> peopleStatus = tracker .getPeopleStatus ();
795
+ if (peopleStatus == null ) {
796
+ throw new IllegalStateException ("People status map in tracker is null" );
797
+ }
798
+
788
799
for (UUID personId : tracker .getPeopleStatus ().keySet ()) {
800
+ // TODO remove these safeties as they're shown to be unnecessary
801
+ if (getCampaign () == null ) {
802
+ throw new IllegalStateException ("Campaign instance is null" );
803
+ }
804
+
789
805
Person person = getCampaign ().getPerson (personId );
790
- person .setHits (person .getHitsPrior ());
806
+
807
+ if (person == null ) {
808
+ throw new IllegalArgumentException ("Person with ID " +
809
+ personId +
810
+ " does not exist in the campaign" );
811
+ }
812
+
813
+ Integer priorHits = person .getHitsPrior ();
814
+ // TODO remove these safeties as they're shown to be unnecessary
815
+ if (priorHits == null ) {
816
+ throw new IllegalStateException ("Person's prior hits are not set for person " +
817
+ person .getFullName ());
818
+ }
819
+ person .setHits (priorHits );
791
820
}
792
821
return ;
793
822
}
0 commit comments