/** Clear the list of characters and recycle all of them. */ void clear() { if (CombatHandler.getInstance().isAttacking()) { CombatHandler.getInstance().standDown(); } charsLock.writeLock().lock(); try { cleanRemovalList(); for (final Char character : chars.values()) { character.recycle(); } chars.clear(); } finally { charsLock.writeLock().unlock(); } }
/** * Remove a character from the game list and recycle the character reference for later usage. Also * clean up everything related to this character such as the attacking marker. * * @param id the ID of the character that shall be removed */ public void removeCharacter(final CharacterId id) { throwPlayerCharacter(id); charsLock.writeLock().lock(); try { final Char chara = chars.get(id); if (chara != null) { EventBus.publish(new CharRemovedEvent(id)); // cancel attack when character is removed if (CombatHandler.getInstance().isAttacking(chara)) { CombatHandler.getInstance().standDown(); } chars.remove(id); chara.recycle(); } } finally { charsLock.writeLock().unlock(); } }