forked from External/mage
[app-wiring-refactor]: Remove static initialisation
- Remove all enum static managers - Introduce interfaces for the managers - Define new application wiring class (`ManagerFactory`) - Externalise the configuration
This commit is contained in:
parent
cf3dd2d94c
commit
d0c2135e17
48 changed files with 1385 additions and 911 deletions
|
|
@ -1,36 +1,46 @@
|
|||
|
||||
package mage.server.tournament;
|
||||
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.game.tournament.Tournament;
|
||||
import mage.server.managers.ITournamentManager;
|
||||
import mage.server.managers.ManagerFactory;
|
||||
import mage.view.TournamentView;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.game.tournament.Tournament;
|
||||
import mage.view.TournamentView;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public enum TournamentManager {
|
||||
instance;
|
||||
public class TournamentManager implements ITournamentManager {
|
||||
|
||||
private final ManagerFactory managerFactory;
|
||||
private final ConcurrentMap<UUID, TournamentController> controllers = new ConcurrentHashMap<>();
|
||||
|
||||
public TournamentManager(ManagerFactory managerFactory) {
|
||||
this.managerFactory = managerFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<TournamentController> getTournamentController(UUID tournamentId) {
|
||||
return Optional.ofNullable(controllers.get(tournamentId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createTournamentSession(Tournament tournament, ConcurrentHashMap<UUID, UUID> userPlayerMap, UUID tableId) {
|
||||
TournamentController tournamentController = new TournamentController(tournament, userPlayerMap, tableId);
|
||||
TournamentController tournamentController = new TournamentController(managerFactory, tournament, userPlayerMap, tableId);
|
||||
controllers.put(tournament.getId(), tournamentController);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void joinTournament(UUID tournamentId, UUID userId) {
|
||||
controllers.get(tournamentId).join(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void quit(UUID tournamentId, UUID userId) {
|
||||
TournamentController tournamentController = controllers.get(tournamentId);
|
||||
if (tournamentController != null) {
|
||||
|
|
@ -40,18 +50,22 @@ public enum TournamentManager {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void timeout(UUID tournamentId, UUID userId) {
|
||||
controllers.get(tournamentId).timeout(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void submitDeck(UUID tournamentId, UUID playerId, Deck deck) {
|
||||
controllers.get(tournamentId).submitDeck(playerId, deck);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateDeck(UUID tournamentId, UUID playerId, Deck deck) {
|
||||
return controllers.get(tournamentId).updateDeck(playerId, deck);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TournamentView getTournamentView(UUID tournamentId) {
|
||||
TournamentController tournamentController = controllers.get(tournamentId);
|
||||
if (tournamentController != null) {
|
||||
|
|
@ -60,6 +74,7 @@ public enum TournamentManager {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<UUID> getChatId(UUID tournamentId) {
|
||||
if (controllers.containsKey(tournamentId)) {
|
||||
return Optional.of(controllers.get(tournamentId).getChatId());
|
||||
|
|
@ -67,6 +82,7 @@ public enum TournamentManager {
|
|||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeTournament(UUID tournamentId) {
|
||||
TournamentController tournamentController = controllers.get(tournamentId);
|
||||
if (tournamentController != null) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue