Null check to prevent game crashing on game-less server in JoinGameScreen
@@ -416,7 +416,12 @@ public String get() {
private String getWorldText(Future<ServerInfoMessage> info) {
try {
List<String> codedWorldInfo = new ArrayList<>();
- for (WorldInfo wi : info.get().getWorldInfoList()) {
+ ServerInfoMessage serverInfoMessage = info.get();
+
+ if(serverInfoMessage == null)
+ return FontColor.getColored(translationSystem.translate("${engine:menu#connection-failed}"), Color.RED);
+
+ for (WorldInfo wi : serverInfoMessage.getWorldInfoList()) {
float timeInDays = wi.getTime() / (float) WorldTime.DAY_LENGTH;
codedWorldInfo.add(String.format("%s (%.2f days)", wi.getTitle(), timeInDays));
}
@@ -430,6 +435,10 @@ private String getOnlinePlayersText(Future<ServerInfoMessage> info) {
try {
List<String> codedWorldInfo = new ArrayList<>();
ServerInfoMessage serverInfoMessage = info.get();
+
+ if(serverInfoMessage == null)
+ return FontColor.getColored(translationSystem.translate("${engine:menu#connection-failed}"), Color.RED);
+
codedWorldInfo.add(String.format("%d", serverInfoMessage.getOnlinePlayersAmount()));
return Joiner.on('\n').join(codedWorldInfo);
} catch (ExecutionException | InterruptedException e) {
@@ -441,6 +450,9 @@ private String getModulesText(Future<ServerInfoMessage> info) {
try {
ServerInfoMessage serverInfoMessage = info.get();
+ if(serverInfoMessage == null)
+ return FontColor.getColored(translationSystem.translate("${engine:menu#connection-failed}"), Color.RED);
+
List<String> codedModInfo = new ArrayList<>();
ModuleRegistry reg = moduleManager.getRegistry();
for (NameVersion entry : serverInfoMessage.getModuleList()) {
