forked from External/mage
rewrote singleton to enum where applicable
This commit is contained in:
parent
3b62489ef5
commit
234cfe9519
872 changed files with 1796 additions and 2135 deletions
|
|
@ -121,7 +121,7 @@ public class DraftController {
|
|||
UUID playerId = userPlayerMap.get(userId);
|
||||
DraftSession draftSession = new DraftSession(draft, userId, playerId);
|
||||
draftSessions.put(playerId, draftSession);
|
||||
UserManager.getInstance().getUser(userId).ifPresent(user-> {
|
||||
UserManager.instance.getUser(userId).ifPresent(user-> {
|
||||
user.addDraft(playerId, draftSession);
|
||||
logger.debug("User " + user.getName() + " has joined draft " + draft.getId());
|
||||
draft.getPlayer(playerId).setJoined();
|
||||
|
|
@ -187,8 +187,8 @@ public class DraftController {
|
|||
draftSession.draftOver();
|
||||
draftSession.removeDraft();
|
||||
}
|
||||
TableManager.getInstance().endDraft(tableId, draft);
|
||||
DraftManager.getInstance().removeDraft(draft.getId());
|
||||
TableManager.instance.endDraft(tableId, draft);
|
||||
DraftManager.instance.removeDraft(draft.getId());
|
||||
}
|
||||
|
||||
public void kill(UUID userId) {
|
||||
|
|
|
|||
|
|
@ -38,14 +38,8 @@ import mage.view.DraftPickView;
|
|||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class DraftManager {
|
||||
private static final DraftManager INSTANCE = new DraftManager();
|
||||
|
||||
public static DraftManager getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private DraftManager() {}
|
||||
public enum DraftManager {
|
||||
instance;
|
||||
|
||||
private final ConcurrentHashMap<UUID, DraftController> draftControllers = new ConcurrentHashMap<>();
|
||||
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ public class DraftSession {
|
|||
|
||||
public boolean init() {
|
||||
if (!killed) {
|
||||
Optional<User> user = UserManager.getInstance().getUser(userId);
|
||||
Optional<User> user = UserManager.instance.getUser(userId);
|
||||
if (user.isPresent()) {
|
||||
if (futureTimeout != null && !futureTimeout.isDone()) {
|
||||
int remaining = (int) futureTimeout.getDelay(TimeUnit.SECONDS);
|
||||
|
|
@ -85,7 +85,7 @@ public class DraftSession {
|
|||
|
||||
public void update() {
|
||||
if (!killed) {
|
||||
UserManager.getInstance()
|
||||
UserManager.instance
|
||||
.getUser(userId).
|
||||
ifPresent(user -> user.fireCallback(
|
||||
new ClientCallback("draftUpdate", draft.getId(), getDraftView())));
|
||||
|
|
@ -96,7 +96,7 @@ public class DraftSession {
|
|||
//
|
||||
public void inform(final String message) {
|
||||
if (!killed) {
|
||||
UserManager.getInstance()
|
||||
UserManager.instance
|
||||
.getUser(userId)
|
||||
.ifPresent(user -> user.fireCallback(new ClientCallback("draftInform", draft.getId(), new DraftClientMessage(getDraftView(), message))));
|
||||
}
|
||||
|
|
@ -105,7 +105,7 @@ public class DraftSession {
|
|||
|
||||
public void draftOver() {
|
||||
if (!killed) {
|
||||
UserManager.getInstance()
|
||||
UserManager.instance
|
||||
.getUser(userId)
|
||||
.ifPresent(user -> user.fireCallback(new ClientCallback("draftOver", draft.getId())));
|
||||
|
||||
|
|
@ -115,7 +115,7 @@ public class DraftSession {
|
|||
public void pickCard(int timeout) {
|
||||
if (!killed) {
|
||||
setupTimeout(timeout);
|
||||
UserManager.getInstance()
|
||||
UserManager.instance
|
||||
.getUser(userId)
|
||||
.ifPresent(user -> user.fireCallback(new ClientCallback("draftPick", draft.getId(), new DraftClientMessage(getDraftPickView(timeout)))));
|
||||
|
||||
|
|
@ -126,7 +126,7 @@ public class DraftSession {
|
|||
cancelTimeout();
|
||||
if (seconds > 0) {
|
||||
futureTimeout = timeoutExecutor.schedule(
|
||||
() -> DraftManager.getInstance().timeout(draft.getId(), userId),
|
||||
() -> DraftManager.instance.timeout(draft.getId(), userId),
|
||||
seconds, TimeUnit.SECONDS
|
||||
);
|
||||
}
|
||||
|
|
@ -140,7 +140,7 @@ public class DraftSession {
|
|||
|
||||
protected void handleRemoteException(RemoteException ex) {
|
||||
logger.fatal("DraftSession error ", ex);
|
||||
DraftManager.getInstance().kill(draft.getId(), userId);
|
||||
DraftManager.instance.kill(draft.getId(), userId);
|
||||
}
|
||||
|
||||
public void setKilled() {
|
||||
|
|
@ -156,7 +156,7 @@ public class DraftSession {
|
|||
}
|
||||
|
||||
public void removeDraft() {
|
||||
UserManager.getInstance().getUser(userId).ifPresent(user -> user.removeDraft(playerId));
|
||||
UserManager.instance.getUser(userId).ifPresent(user -> user.removeDraft(playerId));
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue