@Override public boolean handleJSON(String... messages) { // analyze the JSON message JsonObject event = new JsonObject().withValue(messages); String timestampString = event.getString("@ts"); Long timestamp = Long.parseLong(timestampString); String source = event.getString("@src"); String property = event.getString("@prop"); String oldValue = null; if (event.has("@ov")) oldValue = event.getString("@ov"); String newValue = null; if (event.has("@nv")) newValue = event.getString("@nv"); String sourceClass = source.split("@")[0]; // is not responsible if the source is not correct if (!sourceClass.equals(CLASS_ZOMBIE_FIGHT_GAME)) return false; // save the data to the model ZombieFightGame zfg = ZombieFightGame.getInstanceById(source); if (zfg == null) zfg = Mediator.getInstance().getZombieFighter().createCurrentGame().withId(source); switch (property) { case "guide": Guide newGuide = Guide.getInstanceById(newValue); if (newGuide == null && newValue != null) newGuide = new Guide().withId(newValue); Guide oldGuide = Guide.getInstanceById(oldValue); if (oldValue != newValue) { zfg.withGuide(newGuide); } break; case "users": UserAssets newUser = UserAssets.getInstanceById(newValue); if (newUser == null && newValue != null) newUser = new UserAssets().withId(newValue); UserAssets oldUser = UserAssets.getInstanceById(oldValue); if (oldValue != newValue) { zfg.withoutUsers(oldUser); zfg.withUsers(newUser); } break; case "fields": Field newField = Field.getInstanceById(newValue); if (newField == null && newValue != null) newField = new Field().withId(newValue); Field oldField = Field.getInstanceById(oldValue); if (oldValue != newValue) { zfg.withoutFields(oldField); zfg.withFields(newField); } break; case "winner": GameUser newWinner = GameUser.getInstanceById(newValue); // if (newWinner == null && newValue != null) // newWinner = new GameUser().withId(newValue); GameUser oldWinner = GameUser.getInstanceById(oldValue); if (oldValue != newValue) { zfg.withWinner(newWinner); } break; case "name": zfg.withName(newValue); break; case "numPlayers": zfg.withNumPlayers(Integer.parseInt(newValue)); break; case "running": zfg.withRunning(Boolean.parseBoolean(newValue)); break; case "testGame": zfg.withTestGame(Boolean.parseBoolean(newValue)); break; case "nextIncome": zfg.withNextIncome(Double.parseDouble(newValue)); break; case "speed": zfg.withSpeed(Double.parseDouble(newValue)); // Change scene after Loading datamodell showWaitingScreen(); break; default: break; } return true; }