private void closeDialogUnwrapped() { if (dialog != null) { dialog.close(); context.removePrototypeBean(dialog); getChildren().remove(dialog); dialog = null; dialogScope.closeScope(); } else { logger.warn("Tried to close the dialog but it was already null"); } }
@VisibleForTesting void removeFromFleet(IShip ship, IShipOwner owner) { if (owner instanceof IPlayer) { ((IPlayer) owner).getFleet().remove(ship); } if (owner instanceof ISeaPirate) { ISeaPirate pirate = (ISeaPirate) owner; IShipGroup oldGroup = pirate.getShip() instanceof IShipGroup ? (IShipGroup) pirate.getShip() : null; if (oldGroup != null) { oldGroup.removeShip(ship); if (oldGroup.getShips().size() == 1) { ((SeaPirate)pirate).setShip(oldGroup.getShips().get(0)); ((DependentAnnotationConfigApplicationContext)context).removePrototypeBean(oldGroup); } } else { piratesState.remove(pirate); ((DependentAnnotationConfigApplicationContext)context).removePrototypeBean(pirate); } } }
@Subscribe public void handleWeeklyUpdate(PeriodicalTimeWeekEndUpdate event) { for (ICityHall cityHall : cityHalls) { updateTreasuryWeekly(cityHall); List<ICityHallNotice> newNotices = citiesInteractionService.createNotices(cityHall.getCity()); List<ICityHallNotice> noticesToBeRemoved = cityHall.getNotices(); noticesToBeRemoved.stream().forEach(notice -> { context.removePrototypeBean(notice.getContact()); context.removePrototypeBean(notice); }); noticesToBeRemoved.clear(); noticesToBeRemoved.addAll(newNotices); checkPetitions(cityHall); if (cityHall.getAldermanOffice().isPresent()) { checkTasksFinished(cityHall.getAldermanOffice().get()); checkViolations(cityHall.getAldermanOffice().get(), cityHall.getAlderman(), cityHall); } } }
/** * A non free pirate becomes free. * @param pirate non free pirate instance that is to be freed. */ public void free(INonFreeSeaPirate pirate) { ISeaPirate freePirate = createNewPirate(pirate.getName(), pirate.getShip()); ((DependentAnnotationConfigApplicationContext)context).removePrototypeBean(pirate); piratesState.replace(pirate, freePirate); }
private void handleWeeklyUpdates() { try { for (CityState cityState : citiesState.getCityEngineStates()) { productionAndConsumtionService.produceWares(cityState); ICity city = cityState.getCity(); List<ITradingOffice> offices = city.findBuilding(ITradingOffice.class, Optional.empty()); for (ITradingOffice office : offices) { IBalanceSheet discardableSheet = office.getCurrentWeek(); IBalanceSheet newWeek = interactionFactory.createBalanceSheetFromPreviousWeek((BalanceSheet) discardableSheet); office.replaceBalanceSheet(newWeek); ((DependentAnnotationConfigApplicationContext)context).removePrototypeBean(discardableSheet); } } } finally { scheduleNextWeekUpdate(); } }