mirror of
https://github.com/correl/mage.git
synced 2024-12-24 11:50:45 +00:00
rewrote singleton to enum where applicable
This commit is contained in:
parent
3b62489ef5
commit
234cfe9519
872 changed files with 1796 additions and 2135 deletions
|
@ -36,10 +36,10 @@ import mage.client.dialog.PreferencesDialog;
|
|||
|
||||
public class SortSettingBase extends SortSetting {
|
||||
|
||||
private final static SortSettingBase fInstance = new SortSettingBase();
|
||||
private final static SortSettingBase instance = new SortSettingBase();
|
||||
|
||||
public static SortSettingBase getInstance() {
|
||||
return fInstance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
private SortSettingBase() {
|
||||
|
|
|
@ -36,10 +36,10 @@ import mage.client.dialog.PreferencesDialog;
|
|||
|
||||
public class SortSettingDeck extends SortSetting {
|
||||
|
||||
private final static SortSettingDeck fInstance = new SortSettingDeck();
|
||||
private final static SortSettingDeck instance = new SortSettingDeck();
|
||||
|
||||
public static SortSettingDeck getInstance() {
|
||||
return fInstance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
private SortSettingDeck() {
|
||||
|
|
|
@ -36,10 +36,10 @@ import mage.client.dialog.PreferencesDialog;
|
|||
*/
|
||||
public class SortSettingDraft extends SortSetting {
|
||||
|
||||
private final static SortSettingDraft fInstance = new SortSettingDraft();
|
||||
private final static SortSettingDraft instance = new SortSettingDraft();
|
||||
|
||||
public static SortSettingDraft getInstance() {
|
||||
return fInstance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
private SortSettingDraft() {
|
||||
|
|
|
@ -36,10 +36,10 @@ import mage.client.dialog.PreferencesDialog;
|
|||
|
||||
public class SortSettingSideboard extends SortSetting {
|
||||
|
||||
private static final SortSettingSideboard fInstance = new SortSettingSideboard();
|
||||
private static final SortSettingSideboard instance = new SortSettingSideboard();
|
||||
|
||||
public static SortSettingSideboard getInstance() {
|
||||
return fInstance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
private SortSettingSideboard() {
|
||||
|
|
|
@ -35,7 +35,7 @@ public class Plugins implements MagePlugins {
|
|||
|
||||
public static final String PLUGINS_DIRECTORY = "plugins/";
|
||||
|
||||
private static final MagePlugins fINSTANCE = new Plugins();
|
||||
private static final MagePlugins instance = new Plugins();
|
||||
private static final Logger LOGGER = Logger.getLogger(Plugins.class);
|
||||
private static PluginManager pm;
|
||||
|
||||
|
@ -46,7 +46,7 @@ public class Plugins implements MagePlugins {
|
|||
private final Map<String, String> sortingOptions = new HashMap<>();
|
||||
|
||||
public static MagePlugins getInstance() {
|
||||
return fINSTANCE;
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -9,10 +9,10 @@ import java.util.Map;
|
|||
|
||||
|
||||
public class DelayedViewerThread extends Thread {
|
||||
private static final DelayedViewerThread fInstance = new DelayedViewerThread();
|
||||
private static final DelayedViewerThread instance = new DelayedViewerThread();
|
||||
|
||||
public static DelayedViewerThread getInstance() {
|
||||
return fInstance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
private final Map<Component, Long> delayedViewers;
|
||||
|
|
|
@ -8,10 +8,10 @@ import java.util.UUID;
|
|||
* @author nantuko
|
||||
*/
|
||||
public class GameManager {
|
||||
private static final GameManager fInstance = new GameManager();
|
||||
private static final GameManager instance = new GameManager();
|
||||
|
||||
public static GameManager getInstance() {
|
||||
return fInstance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void setStackSize(int stackSize) {
|
||||
|
|
|
@ -10,10 +10,10 @@ import org.mage.card.arcane.CardPanel;
|
|||
* @author nantuko
|
||||
*/
|
||||
public class SettingsManager {
|
||||
private static final SettingsManager fInstance = new SettingsManager();
|
||||
private static final SettingsManager instance = new SettingsManager();
|
||||
|
||||
public static SettingsManager getInstance() {
|
||||
return fInstance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
public int getScreenWidth() {
|
||||
|
|
|
@ -19,10 +19,10 @@ import org.mage.plugins.card.utils.Transparency;
|
|||
|
||||
public class ImageManagerImpl implements ImageManager {
|
||||
|
||||
private static final ImageManagerImpl fInstance = new ImageManagerImpl();
|
||||
private static final ImageManagerImpl instance = new ImageManagerImpl();
|
||||
|
||||
public static ImageManagerImpl getInstance() {
|
||||
return fInstance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
public ImageManagerImpl() {
|
||||
|
|
|
@ -44,19 +44,12 @@ import java.util.regex.Pattern;
|
|||
/**
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class ChatManager {
|
||||
public enum ChatManager {
|
||||
|
||||
instance;
|
||||
private static final Logger logger = Logger.getLogger(ChatManager.class);
|
||||
private static final HashMap<String, String> userMessages = new HashMap<>();
|
||||
|
||||
private static final ChatManager INSTANCE = new ChatManager();
|
||||
|
||||
public static ChatManager getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private ChatManager() {
|
||||
}
|
||||
|
||||
private final ConcurrentHashMap<UUID, ChatSession> chatSessions = new ConcurrentHashMap<>();
|
||||
|
||||
|
@ -113,7 +106,7 @@ public class ChatManager {
|
|||
ChatSession chatSession = chatSessions.get(chatId);
|
||||
if (chatSession != null) {
|
||||
if (message.startsWith("\\") || message.startsWith("/")) {
|
||||
User user = UserManager.getInstance().getUserByName(userName);
|
||||
User user = UserManager.instance.getUserByName(userName);
|
||||
if (user != null) {
|
||||
if (!performUserCommand(user, message, chatId, false)) {
|
||||
performUserCommand(user, message, chatId, true);
|
||||
|
@ -123,7 +116,7 @@ public class ChatManager {
|
|||
}
|
||||
|
||||
if (messageType != MessageType.GAME) {
|
||||
User user = UserManager.getInstance().getUserByName(userName);
|
||||
User user = UserManager.instance.getUserByName(userName);
|
||||
if (message != null && userName != null && !userName.isEmpty()) {
|
||||
|
||||
if (message.equals(userMessages.get(userName))) {
|
||||
|
@ -205,12 +198,12 @@ public class ChatManager {
|
|||
}
|
||||
|
||||
if (command.startsWith("H ") || command.startsWith("HISTORY ")) {
|
||||
message += "<br/>" + UserManager.getInstance().getUserHistory(message.substring(command.startsWith("H ") ? 3 : 9));
|
||||
message += "<br/>" + UserManager.instance.getUserHistory(message.substring(command.startsWith("H ") ? 3 : 9));
|
||||
chatSessions.get(chatId).broadcastInfoToUser(user, message);
|
||||
return true;
|
||||
}
|
||||
if (command.equals("ME")) {
|
||||
message += "<br/>" + UserManager.getInstance().getUserHistory(user.getName());
|
||||
message += "<br/>" + UserManager.instance.getUserHistory(user.getName());
|
||||
chatSessions.get(chatId).broadcastInfoToUser(user, message);
|
||||
return true;
|
||||
}
|
||||
|
@ -220,7 +213,7 @@ public class ChatManager {
|
|||
if (first > 1) {
|
||||
String userToName = rest.substring(0, first);
|
||||
rest = rest.substring(first + 1).trim();
|
||||
User userTo = UserManager.getInstance().getUserByName(userToName);
|
||||
User userTo = UserManager.instance.getUserByName(userToName);
|
||||
if (userTo != null) {
|
||||
if (!chatSessions.get(chatId).broadcastWhisperToUser(user, userTo, rest)) {
|
||||
message += new StringBuilder("<br/>User ").append(userToName).append(" not found").toString();
|
||||
|
@ -251,7 +244,7 @@ public class ChatManager {
|
|||
* @param color
|
||||
*/
|
||||
public void broadcast(UUID userId, String message, MessageColor color) throws UserNotFoundException {
|
||||
UserManager.getInstance().getUser(userId).ifPresent(user-> {
|
||||
UserManager.instance.getUser(userId).ifPresent(user-> {
|
||||
chatSessions.values()
|
||||
.stream()
|
||||
.filter(chat -> chat.hasUser(userId))
|
||||
|
@ -261,7 +254,7 @@ public class ChatManager {
|
|||
}
|
||||
|
||||
public void sendReconnectMessage(UUID userId) {
|
||||
UserManager.getInstance().getUser(userId).ifPresent(user ->
|
||||
UserManager.instance.getUser(userId).ifPresent(user ->
|
||||
chatSessions.values()
|
||||
.stream()
|
||||
.filter(chat -> chat.hasUser(userId))
|
||||
|
|
|
@ -61,7 +61,7 @@ public class ChatSession {
|
|||
}
|
||||
|
||||
public void join(UUID userId) {
|
||||
UserManager.getInstance().getUser(userId).ifPresent(user-> {
|
||||
UserManager.instance.getUser(userId).ifPresent(user-> {
|
||||
if (!clients.containsKey(userId)) {
|
||||
String userName = user.getName();
|
||||
clients.put(userId, userName);
|
||||
|
@ -142,7 +142,7 @@ public class ChatSession {
|
|||
HashSet<UUID> clientsToRemove = null;
|
||||
ClientCallback clientCallback = new ClientCallback("chatMessage", chatId, new ChatMessage(userName, message, (withTime ? timeFormatter.format(new Date()) : ""), color, messageType, soundToPlay));
|
||||
for (UUID userId : clients.keySet()) {
|
||||
Optional<User> user = UserManager.getInstance().getUser(userId);
|
||||
Optional<User> user = UserManager.instance.getUser(userId);
|
||||
if (user.isPresent()) {
|
||||
user.get().fireCallback(clientCallback);
|
||||
} else {
|
||||
|
|
|
@ -80,8 +80,8 @@ public final class GmailClient {
|
|||
Message message = new Message();
|
||||
message.setRaw(Base64.encodeBase64URLSafeString(baos.toByteArray()));
|
||||
|
||||
gmail.users().messages().send(ConfigSettings.getInstance().getGoogleAccount()
|
||||
+ (ConfigSettings.getInstance().getGoogleAccount().endsWith("@gmail.com") ? "" : "@gmail.com"), message).execute();
|
||||
gmail.users().messages().send(ConfigSettings.instance.getGoogleAccount()
|
||||
+ (ConfigSettings.instance.getGoogleAccount().endsWith("@gmail.com") ? "" : "@gmail.com"), message).execute();
|
||||
return true;
|
||||
} catch (MessagingException | IOException ex) {
|
||||
logger.error("Error sending message", ex);
|
||||
|
|
|
@ -90,12 +90,12 @@ public class MageServerImpl implements MageServer {
|
|||
public MageServerImpl(String adminPassword, boolean testMode) {
|
||||
this.adminPassword = adminPassword;
|
||||
this.testMode = testMode;
|
||||
ServerMessagesUtil.getInstance().getMessages();
|
||||
ServerMessagesUtil.instance.getMessages();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean registerUser(String sessionId, String userName, String password, String email) throws MageException {
|
||||
return SessionManager.getInstance().registerUser(sessionId, userName, password, email);
|
||||
return SessionManager.instance.registerUser(sessionId, userName, password, email);
|
||||
}
|
||||
|
||||
// generateAuthToken returns a uniformly distributed 6-digits string.
|
||||
|
@ -105,7 +105,7 @@ public class MageServerImpl implements MageServer {
|
|||
|
||||
@Override
|
||||
public boolean emailAuthToken(String sessionId, String email) throws MageException {
|
||||
if (!ConfigSettings.getInstance().isAuthenticationActivated()) {
|
||||
if (!ConfigSettings.instance.isAuthenticationActivated()) {
|
||||
sendErrorMessageToClient(sessionId, "Registration is disabled by the server config");
|
||||
return false;
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ public class MageServerImpl implements MageServer {
|
|||
String text = "Use this auth token to reset " + authorizedUser.name + "'s password: " + authToken + '\n'
|
||||
+ "It's valid until the next server restart.";
|
||||
boolean success;
|
||||
if (!ConfigSettings.getInstance().getMailUser().isEmpty()) {
|
||||
if (!ConfigSettings.instance.getMailUser().isEmpty()) {
|
||||
success = MailClient.sendMessage(email, subject, text);
|
||||
} else {
|
||||
success = MailgunClient.sendMessage(email, subject, text);
|
||||
|
@ -135,7 +135,7 @@ public class MageServerImpl implements MageServer {
|
|||
|
||||
@Override
|
||||
public boolean resetPassword(String sessionId, String email, String authToken, String password) throws MageException {
|
||||
if (!ConfigSettings.getInstance().isAuthenticationActivated()) {
|
||||
if (!ConfigSettings.instance.isAuthenticationActivated()) {
|
||||
sendErrorMessageToClient(sessionId, "Registration is disabled by the server config");
|
||||
return false;
|
||||
}
|
||||
|
@ -164,7 +164,7 @@ public class MageServerImpl implements MageServer {
|
|||
logger.info("MageVersionException: userName=" + userName + ", version=" + version);
|
||||
throw new MageVersionException(version, Main.getVersion());
|
||||
}
|
||||
return SessionManager.getInstance().connectUser(sessionId, userName, password, userIdStr);
|
||||
return SessionManager.instance.connectUser(sessionId, userName, password, userIdStr);
|
||||
} catch (MageException ex) {
|
||||
if (ex instanceof MageVersionException) {
|
||||
throw (MageVersionException) ex;
|
||||
|
@ -179,7 +179,7 @@ public class MageServerImpl implements MageServer {
|
|||
return executeWithResult("setUserData", sessionId, new ActionWithBooleanResult() {
|
||||
@Override
|
||||
public Boolean execute() throws MageException {
|
||||
return SessionManager.getInstance().setUserData(userName, sessionId, userData, clientVersion, userIdStr);
|
||||
return SessionManager.instance.setUserData(userName, sessionId, userData, clientVersion, userIdStr);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -193,7 +193,7 @@ public class MageServerImpl implements MageServer {
|
|||
if (!adminPassword.equals(this.adminPassword)) {
|
||||
throw new MageException("Wrong password");
|
||||
}
|
||||
return SessionManager.getInstance().connectAdmin(sessionId);
|
||||
return SessionManager.instance.connectAdmin(sessionId);
|
||||
} catch (Exception ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
|
@ -211,8 +211,8 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public TableView execute() throws MageException {
|
||||
try {
|
||||
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||
Optional<User> _user = UserManager.getInstance().getUser(userId);
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
Optional<User> _user = UserManager.instance.getUser(userId);
|
||||
if (!_user.isPresent()) {
|
||||
logger.error("User for session not found. session = " + sessionId);
|
||||
return null;
|
||||
|
@ -225,7 +225,7 @@ public class MageServerImpl implements MageServer {
|
|||
throw new MageException("No message");
|
||||
}
|
||||
// check AI players max
|
||||
String maxAiOpponents = ConfigSettings.getInstance().getMaxAiOpponents();
|
||||
String maxAiOpponents = ConfigSettings.instance.getMaxAiOpponents();
|
||||
if (maxAiOpponents != null) {
|
||||
int aiPlayers = 0;
|
||||
for (String playerType : options.getPlayerTypes()) {
|
||||
|
@ -247,7 +247,7 @@ public class MageServerImpl implements MageServer {
|
|||
user.showUserMessage("Create tournament", message);
|
||||
throw new MageException("No message");
|
||||
}
|
||||
TableView table = GamesRoomManager.getInstance().getRoom(roomId).createTournamentTable(userId, options);
|
||||
TableView table = GamesRoomManager.instance.getRoom(roomId).createTournamentTable(userId, options);
|
||||
logger.debug("Tournament table " + table.getTableId() + " created");
|
||||
return table;
|
||||
} catch (Exception ex) {
|
||||
|
@ -261,8 +261,8 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void removeTable(final String sessionId, final UUID roomId, final UUID tableId) throws MageException {
|
||||
execute("removeTable", sessionId, () -> {
|
||||
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||
TableManager.getInstance().removeTable(userId, tableId);
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
TableManager.instance.removeTable(userId, tableId);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -271,13 +271,13 @@ public class MageServerImpl implements MageServer {
|
|||
return executeWithResult("joinTable", sessionId, new ActionWithBooleanResult() {
|
||||
@Override
|
||||
public Boolean execute() throws MageException {
|
||||
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
logger.debug(name + " joins tableId: " + tableId);
|
||||
if (userId == null) {
|
||||
logger.fatal("Got no userId from sessionId" + sessionId + " tableId" + tableId);
|
||||
return false;
|
||||
}
|
||||
return GamesRoomManager.getInstance().getRoom(roomId).joinTable(userId, tableId, name, playerType, skill, deckList, password);
|
||||
return GamesRoomManager.instance.getRoom(roomId).joinTable(userId, tableId, name, playerType, skill, deckList, password);
|
||||
|
||||
}
|
||||
});
|
||||
|
@ -288,16 +288,16 @@ public class MageServerImpl implements MageServer {
|
|||
return executeWithResult("joinTournamentTable", sessionId, new ActionWithBooleanResult() {
|
||||
@Override
|
||||
public Boolean execute() throws MageException {
|
||||
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
if (logger.isTraceEnabled()) {
|
||||
Optional<User> user = UserManager.getInstance().getUser(userId);
|
||||
Optional<User> user = UserManager.instance.getUser(userId);
|
||||
user.ifPresent(user1 -> logger.trace("join tourn. tableId: " + tableId + ' ' + name));
|
||||
}
|
||||
if (userId == null) {
|
||||
logger.fatal("Got no userId from sessionId" + sessionId + " tableId" + tableId);
|
||||
return false;
|
||||
}
|
||||
return GamesRoomManager.getInstance().getRoom(roomId).joinTournamentTable(userId, tableId, name, playerType, skill, deckList, password);
|
||||
return GamesRoomManager.instance.getRoom(roomId).joinTournamentTable(userId, tableId, name, playerType, skill, deckList, password);
|
||||
|
||||
}
|
||||
});
|
||||
|
@ -308,8 +308,8 @@ public class MageServerImpl implements MageServer {
|
|||
return executeWithResult("submitDeck", sessionId, new ActionWithBooleanResult() {
|
||||
@Override
|
||||
public Boolean execute() throws MageException {
|
||||
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||
boolean ret = TableManager.getInstance().submitDeck(userId, tableId, deckList);
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
boolean ret = TableManager.instance.submitDeck(userId, tableId, deckList);
|
||||
logger.debug("Session " + sessionId + " submitted deck");
|
||||
return ret;
|
||||
}
|
||||
|
@ -319,8 +319,8 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void updateDeck(final String sessionId, final UUID tableId, final DeckCardLists deckList) throws MageException, GameException {
|
||||
execute("updateDeck", sessionId, () -> {
|
||||
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||
TableManager.getInstance().updateDeck(userId, tableId, deckList);
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
TableManager.instance.updateDeck(userId, tableId, deckList);
|
||||
logger.trace("Session " + sessionId + " updated deck");
|
||||
});
|
||||
}
|
||||
|
@ -329,7 +329,7 @@ public class MageServerImpl implements MageServer {
|
|||
//FIXME: why no sessionId here???
|
||||
public List<TableView> getTables(UUID roomId) throws MageException {
|
||||
try {
|
||||
GamesRoom room = GamesRoomManager.getInstance().getRoom(roomId);
|
||||
GamesRoom room = GamesRoomManager.instance.getRoom(roomId);
|
||||
if (room != null) {
|
||||
return room.getTables();
|
||||
} else {
|
||||
|
@ -345,7 +345,7 @@ public class MageServerImpl implements MageServer {
|
|||
//FIXME: why no sessionId here???
|
||||
public List<MatchView> getFinishedMatches(UUID roomId) throws MageException {
|
||||
try {
|
||||
GamesRoom room = GamesRoomManager.getInstance().getRoom(roomId);
|
||||
GamesRoom room = GamesRoomManager.instance.getRoom(roomId);
|
||||
if (room != null) {
|
||||
return room.getFinished();
|
||||
} else {
|
||||
|
@ -360,7 +360,7 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public List<RoomUsersView> getRoomUsers(UUID roomId) throws MageException {
|
||||
try {
|
||||
GamesRoom room = GamesRoomManager.getInstance().getRoom(roomId);
|
||||
GamesRoom room = GamesRoomManager.instance.getRoom(roomId);
|
||||
if (room != null) {
|
||||
return room.getRoomUsersInfo();
|
||||
} else {
|
||||
|
@ -376,7 +376,7 @@ public class MageServerImpl implements MageServer {
|
|||
//FIXME: why no sessionId here???
|
||||
public TableView getTable(UUID roomId, UUID tableId) throws MageException {
|
||||
try {
|
||||
GamesRoom room = GamesRoomManager.getInstance().getRoom(roomId);
|
||||
GamesRoom room = GamesRoomManager.instance.getRoom(roomId);
|
||||
if (room != null) {
|
||||
return room.getTable(tableId);
|
||||
} else {
|
||||
|
@ -390,7 +390,7 @@ public class MageServerImpl implements MageServer {
|
|||
|
||||
@Override
|
||||
public boolean ping(String sessionId, String pingInfo) {
|
||||
return SessionManager.getInstance().extendUserSession(sessionId, pingInfo);
|
||||
return SessionManager.instance.extendUserSession(sessionId, pingInfo);
|
||||
}
|
||||
|
||||
// @Override
|
||||
|
@ -398,19 +398,19 @@ public class MageServerImpl implements MageServer {
|
|||
// execute("deregisterClient", sessionId, new Action() {
|
||||
// @Override
|
||||
// public void execute() {
|
||||
// SessionManager.getInstance().disconnect(sessionId, true);
|
||||
// SessionManager.instance.disconnect(sessionId, true);
|
||||
// logger.debug("Client deregistered ...");
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
@Override
|
||||
public boolean startMatch(final String sessionId, final UUID roomId, final UUID tableId) throws MageException {
|
||||
if (!TableManager.getInstance().getController(tableId).changeTableStateToStarting()) {
|
||||
if (!TableManager.instance.getController(tableId).changeTableStateToStarting()) {
|
||||
return false;
|
||||
}
|
||||
execute("startMatch", sessionId, () -> {
|
||||
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||
TableManager.getInstance().startMatch(userId, roomId, tableId);
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
TableManager.instance.startMatch(userId, roomId, tableId);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
@ -420,19 +420,19 @@ public class MageServerImpl implements MageServer {
|
|||
// execute("startChallenge", sessionId, new Action() {
|
||||
// @Override
|
||||
// public void execute() {
|
||||
// UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||
// TableManager.getInstance().startChallenge(userId, roomId, tableId, challengeId);
|
||||
// UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
// TableManager.instance.startChallenge(userId, roomId, tableId, challengeId);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
@Override
|
||||
public boolean startTournament(final String sessionId, final UUID roomId, final UUID tableId) throws MageException {
|
||||
if (!TableManager.getInstance().getController(tableId).changeTableStateToStarting()) {
|
||||
if (!TableManager.instance.getController(tableId).changeTableStateToStarting()) {
|
||||
return false;
|
||||
}
|
||||
execute("startTournament", sessionId, () -> {
|
||||
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||
TableManager.getInstance().startTournament(userId, roomId, tableId);
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
TableManager.instance.startTournament(userId, roomId, tableId);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
@ -441,7 +441,7 @@ public class MageServerImpl implements MageServer {
|
|||
//FIXME: why no sessionId here???
|
||||
public TournamentView getTournament(UUID tournamentId) throws MageException {
|
||||
try {
|
||||
return TournamentManager.getInstance().getTournamentView(tournamentId);
|
||||
return TournamentManager.instance.getTournamentView(tournamentId);
|
||||
} catch (Exception ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
|
@ -453,7 +453,7 @@ public class MageServerImpl implements MageServer {
|
|||
public void sendChatMessage(final UUID chatId, final String userName, final String message) throws MageException {
|
||||
try {
|
||||
callExecutor.execute(
|
||||
() -> ChatManager.getInstance().broadcast(chatId, userName, StringEscapeUtils.escapeHtml4(message), MessageColor.BLUE, true, ChatMessage.MessageType.TALK, null)
|
||||
() -> ChatManager.instance.broadcast(chatId, userName, StringEscapeUtils.escapeHtml4(message), MessageColor.BLUE, true, ChatMessage.MessageType.TALK, null)
|
||||
);
|
||||
} catch (Exception ex) {
|
||||
handleException(ex);
|
||||
|
@ -463,8 +463,8 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void joinChat(final UUID chatId, final String sessionId, final String userName) throws MageException {
|
||||
execute("joinChat", sessionId, () -> {
|
||||
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||
ChatManager.getInstance().joinChat(chatId, userId);
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
ChatManager.instance.joinChat(chatId, userId);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -472,8 +472,8 @@ public class MageServerImpl implements MageServer {
|
|||
public void leaveChat(final UUID chatId, final String sessionId) throws MageException {
|
||||
execute("leaveChat", sessionId, () -> {
|
||||
if (chatId != null) {
|
||||
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||
ChatManager.getInstance().leaveChat(chatId, userId);
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
ChatManager.instance.leaveChat(chatId, userId);
|
||||
} else {
|
||||
logger.warn("The chatId is null. sessionId = " + sessionId);
|
||||
}
|
||||
|
@ -484,7 +484,7 @@ public class MageServerImpl implements MageServer {
|
|||
//FIXME: why no sessionId here???
|
||||
public UUID getMainRoomId() throws MageException {
|
||||
try {
|
||||
return GamesRoomManager.getInstance().getMainRoomId();
|
||||
return GamesRoomManager.instance.getMainRoomId();
|
||||
} catch (Exception ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
|
@ -495,7 +495,7 @@ public class MageServerImpl implements MageServer {
|
|||
//FIXME: why no sessionId here???
|
||||
public UUID getRoomChatId(UUID roomId) throws MageException {
|
||||
try {
|
||||
return GamesRoomManager.getInstance().getRoom(roomId).getChatId();
|
||||
return GamesRoomManager.instance.getRoom(roomId).getChatId();
|
||||
} catch (Exception ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
|
@ -507,8 +507,8 @@ public class MageServerImpl implements MageServer {
|
|||
return executeWithResult("isTableOwner", sessionId, new ActionWithBooleanResult() {
|
||||
@Override
|
||||
public Boolean execute() {
|
||||
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||
return TableManager.getInstance().isTableOwner(tableId, userId);
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
return TableManager.instance.isTableOwner(tableId, userId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -516,21 +516,21 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void swapSeats(final String sessionId, final UUID roomId, final UUID tableId, final int seatNum1, final int seatNum2) throws MageException {
|
||||
execute("swapSeats", sessionId, () -> {
|
||||
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||
TableManager.getInstance().swapSeats(tableId, userId, seatNum1, seatNum2);
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
TableManager.instance.swapSeats(tableId, userId, seatNum1, seatNum2);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean leaveTable(final String sessionId, final UUID roomId, final UUID tableId) throws MageException {
|
||||
TableState tableState = TableManager.getInstance().getController(tableId).getTableState();
|
||||
TableState tableState = TableManager.instance.getController(tableId).getTableState();
|
||||
if (tableState != TableState.WAITING && tableState != TableState.READY_TO_START) {
|
||||
// table was already started, so player can't leave anymore now
|
||||
return false;
|
||||
}
|
||||
execute("leaveTable", sessionId, () -> {
|
||||
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||
GamesRoomManager.getInstance().getRoom(roomId).leaveTable(userId, tableId);
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
GamesRoomManager.instance.getRoom(roomId).leaveTable(userId, tableId);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
@ -539,7 +539,7 @@ public class MageServerImpl implements MageServer {
|
|||
//FIXME: why no sessionId here???
|
||||
public UUID getTableChatId(UUID tableId) throws MageException {
|
||||
try {
|
||||
return TableManager.getInstance().getChatId(tableId);
|
||||
return TableManager.instance.getChatId(tableId);
|
||||
} catch (Exception ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
|
@ -549,24 +549,24 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void joinGame(final UUID gameId, final String sessionId) throws MageException {
|
||||
execute("joinGame", sessionId, () -> {
|
||||
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||
GameManager.getInstance().joinGame(gameId, userId);
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
GameManager.instance.joinGame(gameId, userId);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void joinDraft(final UUID draftId, final String sessionId) throws MageException {
|
||||
execute("joinDraft", sessionId, () -> {
|
||||
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||
DraftManager.getInstance().joinDraft(draftId, userId);
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
DraftManager.instance.joinDraft(draftId, userId);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void joinTournament(final UUID tournamentId, final String sessionId) throws MageException {
|
||||
execute("joinTournament", sessionId, () -> {
|
||||
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||
TournamentManager.getInstance().joinTournament(tournamentId, userId);
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
TournamentManager.instance.joinTournament(tournamentId, userId);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -574,7 +574,7 @@ public class MageServerImpl implements MageServer {
|
|||
//FIXME: why no sessionId here???
|
||||
public UUID getGameChatId(UUID gameId) throws MageException {
|
||||
try {
|
||||
return GameManager.getInstance().getChatId(gameId);
|
||||
return GameManager.instance.getChatId(gameId);
|
||||
} catch (Exception ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
|
@ -585,7 +585,7 @@ public class MageServerImpl implements MageServer {
|
|||
//FIXME: why no sessionId here???
|
||||
public UUID getTournamentChatId(UUID tournamentId) throws MageException {
|
||||
try {
|
||||
return TournamentManager.getInstance().getChatId(tournamentId);
|
||||
return TournamentManager.instance.getChatId(tournamentId);
|
||||
} catch (Exception ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
|
@ -595,7 +595,7 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void sendPlayerUUID(final UUID gameId, final String sessionId, final UUID data) throws MageException {
|
||||
execute("sendPlayerUUID", sessionId, () -> {
|
||||
Optional<User> user = SessionManager.getInstance().getUser(sessionId);
|
||||
Optional<User> user = SessionManager.instance.getUser(sessionId);
|
||||
if (user.isPresent()) {
|
||||
// logger.warn("sendPlayerUUID gameId=" + gameId + " sessionId=" + sessionId + " username=" + user.getName());
|
||||
user.get().sendPlayerUUID(gameId, data);
|
||||
|
@ -608,7 +608,7 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void sendPlayerString(final UUID gameId, final String sessionId, final String data) throws MageException {
|
||||
execute("sendPlayerString", sessionId, () -> {
|
||||
Optional<User> user = SessionManager.getInstance().getUser(sessionId);
|
||||
Optional<User> user = SessionManager.instance.getUser(sessionId);
|
||||
if (user.isPresent()) {
|
||||
user.get().sendPlayerString(gameId, data);
|
||||
} else {
|
||||
|
@ -620,7 +620,7 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void sendPlayerManaType(final UUID gameId, final UUID playerId, final String sessionId, final ManaType data) throws MageException {
|
||||
execute("sendPlayerManaType", sessionId, () -> {
|
||||
Optional<User> user = SessionManager.getInstance().getUser(sessionId);
|
||||
Optional<User> user = SessionManager.instance.getUser(sessionId);
|
||||
if (user.isPresent()) {
|
||||
user.get().sendPlayerManaType(gameId, playerId, data);
|
||||
} else {
|
||||
|
@ -632,7 +632,7 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void sendPlayerBoolean(final UUID gameId, final String sessionId, final Boolean data) throws MageException {
|
||||
execute("sendPlayerBoolean", sessionId, () -> {
|
||||
Optional<User> user = SessionManager.getInstance().getUser(sessionId);
|
||||
Optional<User> user = SessionManager.instance.getUser(sessionId);
|
||||
if (user.isPresent()) {
|
||||
user.get().sendPlayerBoolean(gameId, data);
|
||||
} else {
|
||||
|
@ -644,7 +644,7 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void sendPlayerInteger(final UUID gameId, final String sessionId, final Integer data) throws MageException {
|
||||
execute("sendPlayerInteger", sessionId, () -> {
|
||||
Optional<User> user = SessionManager.getInstance().getUser(sessionId);
|
||||
Optional<User> user = SessionManager.instance.getUser(sessionId);
|
||||
if (user.isPresent()) {
|
||||
user.get().sendPlayerInteger(gameId, data);
|
||||
} else {
|
||||
|
@ -661,9 +661,9 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void sendCardMark(final UUID draftId, final String sessionId, final UUID cardPick) throws MageException {
|
||||
execute("sendCardMark", sessionId, () -> {
|
||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||
Session session = SessionManager.instance.getSession(sessionId);
|
||||
if (session != null) {
|
||||
DraftManager.getInstance().sendCardMark(draftId, session.getUserId(), cardPick);
|
||||
DraftManager.instance.sendCardMark(draftId, session.getUserId(), cardPick);
|
||||
} else {
|
||||
logger.error("Session not found sessionId: " + sessionId + " draftId:" + draftId);
|
||||
}
|
||||
|
@ -673,9 +673,9 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void quitMatch(final UUID gameId, final String sessionId) throws MageException {
|
||||
execute("quitMatch", sessionId, () -> {
|
||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||
Session session = SessionManager.instance.getSession(sessionId);
|
||||
if (session != null) {
|
||||
GameManager.getInstance().quitMatch(gameId, session.getUserId());
|
||||
GameManager.instance.quitMatch(gameId, session.getUserId());
|
||||
} else {
|
||||
logger.error("Session not found sessionId: " + sessionId + " gameId:" + gameId);
|
||||
}
|
||||
|
@ -685,9 +685,9 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void quitTournament(final UUID tournamentId, final String sessionId) throws MageException {
|
||||
execute("quitTournament", sessionId, () -> {
|
||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||
Session session = SessionManager.instance.getSession(sessionId);
|
||||
if (session != null) {
|
||||
TournamentManager.getInstance().quit(tournamentId, session.getUserId());
|
||||
TournamentManager.instance.quit(tournamentId, session.getUserId());
|
||||
} else {
|
||||
logger.error("Session not found sessionId: " + sessionId + " tournamentId:" + tournamentId);
|
||||
}
|
||||
|
@ -697,16 +697,16 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void quitDraft(final UUID draftId, final String sessionId) throws MageException {
|
||||
execute("quitDraft", sessionId, () -> {
|
||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||
Session session = SessionManager.instance.getSession(sessionId);
|
||||
if (session == null) {
|
||||
logger.error("Session not found sessionId: " + sessionId + " draftId:" + draftId);
|
||||
return;
|
||||
}
|
||||
UUID tableId = DraftManager.getInstance().getControllerByDraftId(draftId).getTableId();
|
||||
Table table = TableManager.getInstance().getTable(tableId);
|
||||
UUID tableId = DraftManager.instance.getControllerByDraftId(draftId).getTableId();
|
||||
Table table = TableManager.instance.getTable(tableId);
|
||||
if (table.isTournament()) {
|
||||
UUID tournamentId = table.getTournament().getId();
|
||||
TournamentManager.getInstance().quit(tournamentId, session.getUserId());
|
||||
TournamentManager.instance.quit(tournamentId, session.getUserId());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -714,12 +714,12 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void sendPlayerAction(final PlayerAction playerAction, final UUID gameId, final String sessionId, final Object data) throws MageException {
|
||||
execute("sendPlayerAction", sessionId, () -> {
|
||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||
Session session = SessionManager.instance.getSession(sessionId);
|
||||
if (session == null) {
|
||||
logger.error("Session not found sessionId: " + sessionId + " gameId:" + gameId);
|
||||
return;
|
||||
}
|
||||
GameManager.getInstance().sendPlayerAction(playerAction, gameId, session.getUserId(), data);
|
||||
GameManager.instance.sendPlayerAction(playerAction, gameId, session.getUserId(), data);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -728,8 +728,8 @@ public class MageServerImpl implements MageServer {
|
|||
return executeWithResult("setUserData", sessionId, new ActionWithBooleanResult() {
|
||||
@Override
|
||||
public Boolean execute() throws MageException {
|
||||
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||
return GamesRoomManager.getInstance().getRoom(roomId).watchTable(userId, tableId);
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
return GamesRoomManager.instance.getRoom(roomId).watchTable(userId, tableId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -742,17 +742,17 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void watchGame(final UUID gameId, final String sessionId) throws MageException {
|
||||
execute("watchGame", sessionId, () -> {
|
||||
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||
GameManager.getInstance().watchGame(gameId, userId);
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
GameManager.instance.watchGame(gameId, userId);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopWatching(final UUID gameId, final String sessionId) throws MageException {
|
||||
execute("stopWatching", sessionId, () -> {
|
||||
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||
UserManager.getInstance().getUser(userId).ifPresent(user -> {
|
||||
GameManager.getInstance().stopWatching(gameId, userId);
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
UserManager.instance.getUser(userId).ifPresent(user -> {
|
||||
GameManager.instance.stopWatching(gameId, userId);
|
||||
user.removeGameWatchInfo(gameId);
|
||||
});
|
||||
|
||||
|
@ -762,48 +762,48 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void replayGame(final UUID gameId, final String sessionId) throws MageException {
|
||||
execute("replayGame", sessionId, () -> {
|
||||
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||
ReplayManager.getInstance().replayGame(gameId, userId);
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
ReplayManager.instance.replayGame(gameId, userId);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startReplay(final UUID gameId, final String sessionId) throws MageException {
|
||||
execute("startReplay", sessionId, () -> {
|
||||
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||
ReplayManager.getInstance().startReplay(gameId, userId);
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
ReplayManager.instance.startReplay(gameId, userId);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopReplay(final UUID gameId, final String sessionId) throws MageException {
|
||||
execute("stopReplay", sessionId, () -> {
|
||||
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||
ReplayManager.getInstance().stopReplay(gameId, userId);
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
ReplayManager.instance.stopReplay(gameId, userId);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void nextPlay(final UUID gameId, final String sessionId) throws MageException {
|
||||
execute("nextPlay", sessionId, () -> {
|
||||
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||
ReplayManager.getInstance().nextPlay(gameId, userId);
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
ReplayManager.instance.nextPlay(gameId, userId);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void previousPlay(final UUID gameId, final String sessionId) throws MageException {
|
||||
execute("previousPlay", sessionId, () -> {
|
||||
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||
ReplayManager.getInstance().previousPlay(gameId, userId);
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
ReplayManager.instance.previousPlay(gameId, userId);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void skipForward(final UUID gameId, final String sessionId, final int moves) throws MageException {
|
||||
execute("skipForward", sessionId, () -> {
|
||||
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||
ReplayManager.getInstance().skipForward(gameId, userId, moves);
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
ReplayManager.instance.skipForward(gameId, userId, moves);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -832,8 +832,8 @@ public class MageServerImpl implements MageServer {
|
|||
public void cheat(final UUID gameId, final String sessionId, final UUID playerId, final DeckCardLists deckList) throws MageException {
|
||||
execute("cheat", sessionId, () -> {
|
||||
if (testMode) {
|
||||
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||
GameManager.getInstance().cheat(gameId, userId, playerId, deckList);
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
GameManager.instance.cheat(gameId, userId, playerId, deckList);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -844,8 +844,8 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public Boolean execute() {
|
||||
if (testMode) {
|
||||
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||
return GameManager.getInstance().cheat(gameId, userId, playerId, cardName);
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
return GameManager.instance.cheat(gameId, userId, playerId, cardName);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -878,13 +878,13 @@ public class MageServerImpl implements MageServer {
|
|||
|
||||
@Override
|
||||
public void disconnectUser(final String sessionId, final String userSessionId) throws MageException {
|
||||
execute("disconnectUser", sessionId, () -> SessionManager.getInstance().disconnectUser(sessionId, userSessionId));
|
||||
execute("disconnectUser", sessionId, () -> SessionManager.instance.disconnectUser(sessionId, userSessionId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void muteUser(final String sessionId, final String userName, final long durationMinutes) throws MageException {
|
||||
execute("muteUser", sessionId, () -> {
|
||||
User user = UserManager.getInstance().getUserByName(userName);
|
||||
User user = UserManager.instance.getUserByName(userName);
|
||||
if (user != null) {
|
||||
Date muteUntil = new Date(Calendar.getInstance().getTimeInMillis() + (durationMinutes * Timer.ONE_MINUTE));
|
||||
user.showUserMessage("Admin info", "You were muted for chat messages until " + SystemUtil.dateFormat.format(muteUntil) + '.');
|
||||
|
@ -897,13 +897,13 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void lockUser(final String sessionId, final String userName, final long durationMinutes) throws MageException {
|
||||
execute("lockUser", sessionId, () -> {
|
||||
User user = UserManager.getInstance().getUserByName(userName);
|
||||
User user = UserManager.instance.getUserByName(userName);
|
||||
if (user != null) {
|
||||
Date lockUntil = new Date(Calendar.getInstance().getTimeInMillis() + (durationMinutes * Timer.ONE_MINUTE));
|
||||
user.showUserMessage("Admin info", "Your user profile was locked until " + SystemUtil.dateFormat.format(lockUntil) + '.');
|
||||
user.setLockedUntil(lockUntil);
|
||||
if (user.isConnected()) {
|
||||
SessionManager.getInstance().disconnectUser(sessionId, user.getSessionId());
|
||||
SessionManager.instance.disconnectUser(sessionId, user.getSessionId());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -914,11 +914,11 @@ public class MageServerImpl implements MageServer {
|
|||
public void setActivation(final String sessionId, final String userName, boolean active) throws MageException {
|
||||
execute("setActivation", sessionId, () -> {
|
||||
AuthorizedUser authorizedUser = AuthorizedUserRepository.instance.getByName(userName);
|
||||
User user = UserManager.getInstance().getUserByName(userName);
|
||||
User user = UserManager.instance.getUserByName(userName);
|
||||
if (user != null) {
|
||||
user.setActive(active);
|
||||
if (!user.isActive() && user.isConnected()) {
|
||||
SessionManager.getInstance().disconnectUser(sessionId, user.getSessionId());
|
||||
SessionManager.instance.disconnectUser(sessionId, user.getSessionId());
|
||||
}
|
||||
} else if (authorizedUser != null) {
|
||||
User theUser = new User(userName, "localhost", authorizedUser);
|
||||
|
@ -931,11 +931,11 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void toggleActivation(final String sessionId, final String userName) throws MageException {
|
||||
execute("toggleActivation", sessionId, () -> {
|
||||
User user = UserManager.getInstance().getUserByName(userName);
|
||||
User user = UserManager.instance.getUserByName(userName);
|
||||
if (user != null) {
|
||||
user.setActive(!user.isActive());
|
||||
if (!user.isActive() && user.isConnected()) {
|
||||
SessionManager.getInstance().disconnectUser(sessionId, user.getSessionId());
|
||||
SessionManager.instance.disconnectUser(sessionId, user.getSessionId());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -944,7 +944,7 @@ public class MageServerImpl implements MageServer {
|
|||
|
||||
@Override
|
||||
public void endUserSession(final String sessionId, final String userSessionId) throws MageException {
|
||||
execute("endUserSession", sessionId, () -> SessionManager.getInstance().endUserSession(sessionId, userSessionId));
|
||||
execute("endUserSession", sessionId, () -> SessionManager.instance.endUserSession(sessionId, userSessionId));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -957,8 +957,8 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void removeTable(final String sessionId, final UUID tableId) throws MageException {
|
||||
execute("removeTable", sessionId, () -> {
|
||||
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||
TableManager.getInstance().removeTable(userId, tableId);
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
TableManager.instance.removeTable(userId, tableId);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -971,7 +971,7 @@ public class MageServerImpl implements MageServer {
|
|||
public void sendFeedbackMessage(final String sessionId, final String username, final String title, final String type, final String message, final String email) throws MageException {
|
||||
if (title != null && message != null) {
|
||||
execute("sendFeedbackMessage", sessionId, () -> {
|
||||
String host = SessionManager.getInstance().getSession(sessionId).getHost();
|
||||
String host = SessionManager.instance.getSession(sessionId).getHost();
|
||||
FeedbackServiceImpl.instance.feedback(username, title, type, message, email, host);
|
||||
});
|
||||
}
|
||||
|
@ -981,7 +981,7 @@ public class MageServerImpl implements MageServer {
|
|||
public void sendBroadcastMessage(final String sessionId, final String message) throws MageException {
|
||||
if (message != null) {
|
||||
execute("sendBroadcastMessage", sessionId, () -> {
|
||||
for (User user : UserManager.getInstance().getUsers()) {
|
||||
for (User user : UserManager.instance.getUsers()) {
|
||||
if (message.toLowerCase(Locale.ENGLISH).startsWith("warn")) {
|
||||
user.fireCallback(new ClientCallback("serverMessage", null, new ChatMessage("SERVER", message, null, MessageColor.RED)));
|
||||
} else {
|
||||
|
@ -993,12 +993,12 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
|
||||
private void sendErrorMessageToClient(final String sessionId, final String message) throws MageException {
|
||||
execute("sendErrorMessageToClient", sessionId, () -> SessionManager.getInstance().sendErrorMessageToClient(sessionId, message));
|
||||
execute("sendErrorMessageToClient", sessionId, () -> SessionManager.instance.sendErrorMessageToClient(sessionId, message));
|
||||
}
|
||||
|
||||
protected void execute(final String actionName, final String sessionId, final Action action, boolean checkAdminRights) throws MageException {
|
||||
if (checkAdminRights) {
|
||||
if (!SessionManager.getInstance().isAdmin(sessionId)) {
|
||||
if (!SessionManager.instance.isAdmin(sessionId)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -1006,11 +1006,11 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
|
||||
protected void execute(final String actionName, final String sessionId, final Action action) throws MageException {
|
||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||
if (SessionManager.instance.isValidSession(sessionId)) {
|
||||
try {
|
||||
callExecutor.execute(
|
||||
() -> {
|
||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||
if (SessionManager.instance.isValidSession(sessionId)) {
|
||||
try {
|
||||
action.execute();
|
||||
} catch (MageException me) {
|
||||
|
@ -1027,7 +1027,7 @@ public class MageServerImpl implements MageServer {
|
|||
|
||||
protected <T> T executeWithResult(String actionName, final String sessionId, final ActionWithResult<T> action, boolean checkAdminRights) throws MageException {
|
||||
if (checkAdminRights) {
|
||||
if (!SessionManager.getInstance().isAdmin(sessionId)) {
|
||||
if (!SessionManager.instance.isAdmin(sessionId)) {
|
||||
return action.negativeResult();
|
||||
}
|
||||
}
|
||||
|
@ -1036,7 +1036,7 @@ public class MageServerImpl implements MageServer {
|
|||
|
||||
//TODO: also run in threads with future task
|
||||
protected <T> T executeWithResult(String actionName, final String sessionId, final ActionWithResult<T> action) throws MageException {
|
||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||
if (SessionManager.instance.isValidSession(sessionId)) {
|
||||
try {
|
||||
return action.execute();
|
||||
} catch (Exception ex) {
|
||||
|
@ -1065,7 +1065,7 @@ public class MageServerImpl implements MageServer {
|
|||
private static class MyActionWithNullNegativeResult extends ActionWithNullNegativeResult<Object> {
|
||||
@Override
|
||||
public Object execute() throws MageException {
|
||||
return CompressUtil.compress(ServerMessagesUtil.getInstance().getMessages());
|
||||
return CompressUtil.compress(ServerMessagesUtil.instance.getMessages());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1073,7 +1073,7 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public List<UserView> execute() throws MageException {
|
||||
List<UserView> users = new ArrayList<>();
|
||||
for (User user : UserManager.getInstance().getUsers()) {
|
||||
for (User user : UserManager.instance.getUsers()) {
|
||||
users.add(new UserView(
|
||||
user.getName(),
|
||||
user.getHost(),
|
||||
|
@ -1104,8 +1104,8 @@ public class MageServerImpl implements MageServer {
|
|||
|
||||
@Override
|
||||
public GameView execute() throws MageException {
|
||||
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||
return GameManager.getInstance().getGameView(gameId, userId, playerId);
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
return GameManager.instance.getGameView(gameId, userId, playerId);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1120,8 +1120,8 @@ public class MageServerImpl implements MageServer {
|
|||
|
||||
@Override
|
||||
public Boolean execute() throws MageException {
|
||||
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||
return TableManager.getInstance().watchTable(userId, tableId);
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
return TableManager.instance.watchTable(userId, tableId);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1140,9 +1140,9 @@ public class MageServerImpl implements MageServer {
|
|||
|
||||
@Override
|
||||
public DraftPickView execute() {
|
||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||
Session session = SessionManager.instance.getSession(sessionId);
|
||||
if (session != null) {
|
||||
return DraftManager.getInstance().sendCardPick(draftId, session.getUserId(), cardPick, hiddenCards);
|
||||
return DraftManager.instance.sendCardPick(draftId, session.getUserId(), cardPick, hiddenCards);
|
||||
} else {
|
||||
logger.error("Session not found sessionId: " + sessionId + " draftId:" + draftId);
|
||||
}
|
||||
|
@ -1163,8 +1163,8 @@ public class MageServerImpl implements MageServer {
|
|||
|
||||
@Override
|
||||
public TableView execute() throws MageException {
|
||||
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||
Optional<User> _user = UserManager.getInstance().getUser(userId);
|
||||
UUID userId = SessionManager.instance.getSession(sessionId).getUserId();
|
||||
Optional<User> _user = UserManager.instance.getUser(userId);
|
||||
if (!_user.isPresent()) {
|
||||
logger.error("User for session not found. session = " + sessionId);
|
||||
return null;
|
||||
|
@ -1183,11 +1183,11 @@ public class MageServerImpl implements MageServer {
|
|||
throw new MageException("No message");
|
||||
}
|
||||
|
||||
TableView table = GamesRoomManager.getInstance().getRoom(roomId).createTable(userId, options);
|
||||
TableView table = GamesRoomManager.instance.getRoom(roomId).createTable(userId, options);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("TABLE created - tableId: " + table.getTableId() + ' ' + table.getTableName());
|
||||
logger.debug("- " + user.getName() + " userId: " + user.getId());
|
||||
logger.debug("- chatId: " + TableManager.getInstance().getChatId(table.getTableId()));
|
||||
logger.debug("- chatId: " + TableManager.instance.getChatId(table.getTableId()));
|
||||
}
|
||||
return table;
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ public final class MailClient {
|
|||
logger.info("Email is not sent because the address is empty");
|
||||
return false;
|
||||
}
|
||||
ConfigSettings config = ConfigSettings.getInstance();
|
||||
ConfigSettings config = ConfigSettings.instance;
|
||||
|
||||
Properties properties = System.getProperties();
|
||||
properties.setProperty("mail.smtps.host", config.getMailSmtpHost());
|
||||
|
|
|
@ -19,8 +19,8 @@ public final class MailgunClient {
|
|||
return false;
|
||||
}
|
||||
Client client = Client.create();
|
||||
client.addFilter(new HTTPBasicAuthFilter("api", ConfigSettings.getInstance().getMailgunApiKey()));
|
||||
String domain = ConfigSettings.getInstance().getMailgunDomain();
|
||||
client.addFilter(new HTTPBasicAuthFilter("api", ConfigSettings.instance.getMailgunApiKey()));
|
||||
String domain = ConfigSettings.instance.getMailgunDomain();
|
||||
WebResource webResource = client.resource("https://api.mailgun.net/v3/" + domain + "/messages");
|
||||
MultivaluedMapImpl formData = new MultivaluedMapImpl();
|
||||
formData.add("from", "XMage <postmaster@" + domain + '>');
|
||||
|
|
|
@ -107,7 +107,7 @@ public final class Main {
|
|||
}
|
||||
}
|
||||
|
||||
if (ConfigSettings.getInstance().isAuthenticationActivated()) {
|
||||
if (ConfigSettings.instance.isAuthenticationActivated()) {
|
||||
logger.info("Check authorized user DB version ...");
|
||||
if (!AuthorizedUserRepository.instance.checkAlterAndMigrateAuthorizedUser()) {
|
||||
logger.fatal("Failed to start server.");
|
||||
|
@ -162,7 +162,7 @@ public final class Main {
|
|||
UserStatsRepository.instance.updateUserStats();
|
||||
logger.info("Done.");
|
||||
deleteSavedGames();
|
||||
ConfigSettings config = ConfigSettings.getInstance();
|
||||
ConfigSettings config = ConfigSettings.instance;
|
||||
for (GamePlugin plugin : config.getGameTypes()) {
|
||||
GameFactory.getInstance().addGameType(plugin.getName(), loadGameType(plugin), loadPlugin(plugin));
|
||||
}
|
||||
|
@ -240,7 +240,7 @@ public final class Main {
|
|||
}
|
||||
|
||||
static void initStatistics() {
|
||||
ServerMessagesUtil.getInstance().setStartDate(System.currentTimeMillis());
|
||||
ServerMessagesUtil.instance.setStartDate(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
static boolean isAlreadyRunning(InvokerLocator serverLocator) {
|
||||
|
@ -263,11 +263,11 @@ public final class Main {
|
|||
|
||||
@Override
|
||||
public void handleConnectionException(Throwable throwable, Client client) {
|
||||
Session session = SessionManager.getInstance().getSession(client.getSessionId());
|
||||
Session session = SessionManager.instance.getSession(client.getSessionId());
|
||||
if (session != null) {
|
||||
|
||||
StringBuilder sessionInfo = new StringBuilder();
|
||||
Optional<User> user = UserManager.getInstance().getUser(session.getUserId());
|
||||
Optional<User> user = UserManager.instance.getUser(session.getUserId());
|
||||
if (user.isPresent()) {
|
||||
sessionInfo.append(user.get().getName()).append(" [").append(user.get().getGameInfo()).append(']');
|
||||
} else {
|
||||
|
@ -277,12 +277,12 @@ public final class Main {
|
|||
if (throwable instanceof ClientDisconnectedException) {
|
||||
// Seems like the random diconnects from public server land here and should not be handled as explicit disconnects
|
||||
// So it should be possible to reconnect to server and continue games if DisconnectReason is set to LostConnection
|
||||
//SessionManager.getInstance().disconnect(client.getSessionId(), DisconnectReason.Disconnected);
|
||||
SessionManager.getInstance().disconnect(client.getSessionId(), DisconnectReason.LostConnection);
|
||||
//SessionManager.instance.disconnect(client.getSessionId(), DisconnectReason.Disconnected);
|
||||
SessionManager.instance.disconnect(client.getSessionId(), DisconnectReason.LostConnection);
|
||||
logger.info("CLIENT DISCONNECTED - " + sessionInfo);
|
||||
logger.debug("Stack Trace", throwable);
|
||||
} else {
|
||||
SessionManager.getInstance().disconnect(client.getSessionId(), DisconnectReason.LostConnection);
|
||||
SessionManager.instance.disconnect(client.getSessionId(), DisconnectReason.LostConnection);
|
||||
logger.info("LOST CONNECTION - " + sessionInfo);
|
||||
if (logger.isDebugEnabled()) {
|
||||
if (throwable == null) {
|
||||
|
@ -305,7 +305,7 @@ public final class Main {
|
|||
public MageTransporterServer(InvokerLocator locator, Object target, String subsystem, MageServerInvocationHandler serverInvocationHandler) throws Exception {
|
||||
super(locator, target, subsystem);
|
||||
connector.addInvocationHandler("callback", serverInvocationHandler);
|
||||
connector.setLeasePeriod(ConfigSettings.getInstance().getLeasePeriod());
|
||||
connector.setLeasePeriod(ConfigSettings.instance.getLeasePeriod());
|
||||
connector.addConnectionListener(new ClientConnectionListener());
|
||||
}
|
||||
|
||||
|
@ -343,9 +343,9 @@ public final class Main {
|
|||
|
||||
@Override
|
||||
public void setInvoker(ServerInvoker invoker) {
|
||||
((BisocketServerInvoker) invoker).setSecondaryBindPort(ConfigSettings.getInstance().getSecondaryBindPort());
|
||||
((BisocketServerInvoker) invoker).setBacklog(ConfigSettings.getInstance().getBacklogSize());
|
||||
((BisocketServerInvoker) invoker).setNumAcceptThreads(ConfigSettings.getInstance().getNumAcceptThreads());
|
||||
((BisocketServerInvoker) invoker).setSecondaryBindPort(ConfigSettings.instance.getSecondaryBindPort());
|
||||
((BisocketServerInvoker) invoker).setBacklog(ConfigSettings.instance.getBacklogSize());
|
||||
((BisocketServerInvoker) invoker).setNumAcceptThreads(ConfigSettings.instance.getNumAcceptThreads());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -354,7 +354,7 @@ public final class Main {
|
|||
ServerInvokerCallbackHandler handler = (ServerInvokerCallbackHandler) callbackHandler;
|
||||
try {
|
||||
String sessionId = handler.getClientSessionId();
|
||||
SessionManager.getInstance().createSession(sessionId, callbackHandler);
|
||||
SessionManager.instance.createSession(sessionId, callbackHandler);
|
||||
} catch (Throwable ex) {
|
||||
logger.fatal("", ex);
|
||||
}
|
||||
|
@ -372,7 +372,7 @@ public final class Main {
|
|||
} else {
|
||||
host = "localhost";
|
||||
}
|
||||
SessionManager.getInstance().getSession(sessionId).setHost(host);
|
||||
SessionManager.instance.getSession(sessionId).setHost(host);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -380,7 +380,7 @@ public final class Main {
|
|||
public void removeListener(InvokerCallbackHandler callbackHandler) {
|
||||
ServerInvokerCallbackHandler handler = (ServerInvokerCallbackHandler) callbackHandler;
|
||||
String sessionId = handler.getClientSessionId();
|
||||
SessionManager.getInstance().disconnect(sessionId, DisconnectReason.Disconnected);
|
||||
SessionManager.instance.disconnect(sessionId, DisconnectReason.Disconnected);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ public abstract class RoomImpl implements Room {
|
|||
|
||||
public RoomImpl() {
|
||||
roomId = UUID.randomUUID();
|
||||
chatId = ChatManager.getInstance().createChatSession("Room " + roomId);
|
||||
chatId = ChatManager.instance.createChatSession("Room " + roomId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -76,7 +76,7 @@ public class Session {
|
|||
}
|
||||
|
||||
public String registerUser(String userName, String password, String email) throws MageException {
|
||||
if (!ConfigSettings.getInstance().isAuthenticationActivated()) {
|
||||
if (!ConfigSettings.instance.isAuthenticationActivated()) {
|
||||
String returnMessage = "Registration is disabled by the server config";
|
||||
sendErrorMessageToClient(returnMessage);
|
||||
return returnMessage;
|
||||
|
@ -106,7 +106,7 @@ public class Session {
|
|||
|
||||
boolean success;
|
||||
String subject = "XMage Registration Completed";
|
||||
if (!ConfigSettings.getInstance().getMailUser().isEmpty()) {
|
||||
if (!ConfigSettings.instance.getMailUser().isEmpty()) {
|
||||
success = MailClient.sendMessage(email, subject, text);
|
||||
} else {
|
||||
success = MailgunClient.sendMessage(email, subject, text);
|
||||
|
@ -133,14 +133,14 @@ public class Session {
|
|||
if (userName.equals("Admin")) {
|
||||
return "User name Admin already in use";
|
||||
}
|
||||
ConfigSettings config = ConfigSettings.getInstance();
|
||||
ConfigSettings config = ConfigSettings.instance;
|
||||
if (userName.length() < config.getMinUserNameLength()) {
|
||||
return "User name may not be shorter than " + config.getMinUserNameLength() + " characters";
|
||||
}
|
||||
if (userName.length() > config.getMaxUserNameLength()) {
|
||||
return "User name may not be longer than " + config.getMaxUserNameLength() + " characters";
|
||||
}
|
||||
Pattern invalidUserNamePattern = Pattern.compile(ConfigSettings.getInstance().getInvalidUserNamePattern(), Pattern.CASE_INSENSITIVE);
|
||||
Pattern invalidUserNamePattern = Pattern.compile(ConfigSettings.instance.getInvalidUserNamePattern(), Pattern.CASE_INSENSITIVE);
|
||||
Matcher m = invalidUserNamePattern.matcher(userName);
|
||||
if (m.find()) {
|
||||
return "User name '" + userName + "' includes not allowed characters: use a-z, A-Z and 0-9";
|
||||
|
@ -153,7 +153,7 @@ public class Session {
|
|||
}
|
||||
|
||||
static private String validatePassword(String password, String userName) {
|
||||
ConfigSettings config = ConfigSettings.getInstance();
|
||||
ConfigSettings config = ConfigSettings.instance;
|
||||
if (password.length() < config.getMinPasswordLength()) {
|
||||
return "Password may not be shorter than " + config.getMinPasswordLength() + " characters";
|
||||
}
|
||||
|
@ -198,7 +198,7 @@ public class Session {
|
|||
public String connectUserHandling(String userName, String password) throws MageException {
|
||||
this.isAdmin = false;
|
||||
AuthorizedUser authorizedUser = null;
|
||||
if (ConfigSettings.getInstance().isAuthenticationActivated()) {
|
||||
if (ConfigSettings.instance.isAuthenticationActivated()) {
|
||||
authorizedUser = AuthorizedUserRepository.instance.getByName(userName);
|
||||
String errorMsg = "Wrong username or password. In case you haven't, please register your account first.";
|
||||
if (authorizedUser == null) {
|
||||
|
@ -216,19 +216,19 @@ public class Session {
|
|||
if (authorizedUser.lockedUntil.compareTo(Calendar.getInstance().getTime()) > 0) {
|
||||
return "Your profile is deactivated until " + SystemUtil.dateFormat.format(authorizedUser.lockedUntil);
|
||||
} else {
|
||||
User user = UserManager.getInstance().createUser(userName, host, authorizedUser);
|
||||
User user = UserManager.instance.createUser(userName, host, authorizedUser);
|
||||
if (user != null && authorizedUser.lockedUntil != null) {
|
||||
user.setLockedUntil(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
User user = UserManager.getInstance().createUser(userName, host, authorizedUser);
|
||||
User user = UserManager.instance.createUser(userName, host, authorizedUser);
|
||||
boolean reconnect = false;
|
||||
if (user == null) { // user already exists
|
||||
user = UserManager.getInstance().getUserByName(userName);
|
||||
user = UserManager.instance.getUserByName(userName);
|
||||
// If authentication is not activated, check the identity using IP address.
|
||||
if (ConfigSettings.getInstance().isAuthenticationActivated() || user.getHost().equals(host)) {
|
||||
if (ConfigSettings.instance.isAuthenticationActivated() || user.getHost().equals(host)) {
|
||||
user.updateLastActivity(null); // minimizes possible expiration
|
||||
this.userId = user.getId();
|
||||
if (user.getSessionId().isEmpty()) {
|
||||
|
@ -237,43 +237,43 @@ public class Session {
|
|||
} else {
|
||||
//disconnect previous session
|
||||
logger.info("Disconnecting another user instance: " + userName);
|
||||
SessionManager.getInstance().disconnect(user.getSessionId(), DisconnectReason.ConnectingOtherInstance);
|
||||
SessionManager.instance.disconnect(user.getSessionId(), DisconnectReason.ConnectingOtherInstance);
|
||||
}
|
||||
} else {
|
||||
return "User name " + userName + " already in use (or your IP address changed)";
|
||||
}
|
||||
}
|
||||
if (!UserManager.getInstance().connectToSession(sessionId, user.getId())) {
|
||||
if (!UserManager.instance.connectToSession(sessionId, user.getId())) {
|
||||
return "Error connecting " + userName;
|
||||
}
|
||||
this.userId = user.getId();
|
||||
if (reconnect) { // must be connected to receive the message
|
||||
UUID chatId = GamesRoomManager.getInstance().getRoom(GamesRoomManager.getInstance().getMainRoomId()).getChatId();
|
||||
UUID chatId = GamesRoomManager.instance.getRoom(GamesRoomManager.instance.getMainRoomId()).getChatId();
|
||||
if (chatId != null) {
|
||||
ChatManager.getInstance().joinChat(chatId, userId);
|
||||
ChatManager.instance.joinChat(chatId, userId);
|
||||
}
|
||||
ChatManager.getInstance().sendReconnectMessage(userId);
|
||||
ChatManager.instance.sendReconnectMessage(userId);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void connectAdmin() {
|
||||
this.isAdmin = true;
|
||||
User user = UserManager.getInstance().createUser("Admin", host, null);
|
||||
User user = UserManager.instance.createUser("Admin", host, null);
|
||||
if (user == null) {
|
||||
user = UserManager.getInstance().getUserByName("Admin");
|
||||
user = UserManager.instance.getUserByName("Admin");
|
||||
}
|
||||
UserData adminUserData = UserData.getDefaultUserDataView();
|
||||
adminUserData.setGroupId(UserGroup.ADMIN.getGroupId());
|
||||
user.setUserData(adminUserData);
|
||||
if (!UserManager.getInstance().connectToSession(sessionId, user.getId())) {
|
||||
if (!UserManager.instance.connectToSession(sessionId, user.getId())) {
|
||||
logger.info("Error connecting Admin!");
|
||||
}
|
||||
this.userId = user.getId();
|
||||
}
|
||||
|
||||
public boolean setUserData(String userName, UserData userData, String clientVersion, String userIdStr) {
|
||||
User user = UserManager.getInstance().getUserByName(userName);
|
||||
User user = UserManager.instance.getUserByName(userName);
|
||||
if (user != null) {
|
||||
if (clientVersion != null) {
|
||||
user.setClientVersion(clientVersion);
|
||||
|
@ -326,7 +326,7 @@ public class Session {
|
|||
} else {
|
||||
logger.error("CAN'T GET LOCK - userId: " + userId + " hold count: " + lock.getHoldCount());
|
||||
}
|
||||
Optional<User> _user = UserManager.getInstance().getUser(userId);
|
||||
Optional<User> _user = UserManager.instance.getUser(userId);
|
||||
if (!_user.isPresent()) {
|
||||
return; //user was already disconnected by other thread
|
||||
}
|
||||
|
@ -340,7 +340,7 @@ public class Session {
|
|||
return;
|
||||
}
|
||||
// logger.info("LOST CONNECTION - " + user.getName() + " id: " + userId);
|
||||
UserManager.getInstance().disconnect(userId, DisconnectReason.LostConnection);
|
||||
UserManager.instance.disconnect(userId, DisconnectReason.LostConnection);
|
||||
|
||||
} catch (InterruptedException ex) {
|
||||
logger.error("SESSION LOCK lost connection - userId: " + userId, ex);
|
||||
|
@ -362,7 +362,7 @@ public class Session {
|
|||
} else {
|
||||
logger.error("SESSION LOCK - kill: userId " + userId);
|
||||
}
|
||||
UserManager.getInstance().removeUser(userId, reason);
|
||||
UserManager.instance.removeUser(userId, reason);
|
||||
} catch (InterruptedException ex) {
|
||||
logger.error("SESSION LOCK - kill: userId " + userId, ex);
|
||||
} finally {
|
||||
|
@ -381,7 +381,7 @@ public class Session {
|
|||
callbackHandler.handleCallbackOneway(new Callback(call));
|
||||
} catch (HandleCallbackException ex) {
|
||||
ex.printStackTrace();
|
||||
UserManager.getInstance().getUser(userId).ifPresent(user-> {
|
||||
UserManager.instance.getUser(userId).ifPresent(user-> {
|
||||
logger.warn("SESSION CALLBACK EXCEPTION - " + user.getName() + " userId " + userId);
|
||||
logger.warn(" - method: " + call.getMethod());
|
||||
logger.warn(" - cause: " + getBasicCause(ex).toString());
|
||||
|
|
|
@ -42,20 +42,16 @@ import javax.annotation.Nonnull;
|
|||
/**
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class SessionManager {
|
||||
|
||||
public enum SessionManager {
|
||||
instance;
|
||||
private static final Logger logger = Logger.getLogger(SessionManager.class);
|
||||
private static final SessionManager INSTANCE = new SessionManager();
|
||||
|
||||
public static SessionManager getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private final ConcurrentHashMap<String, Session> sessions = new ConcurrentHashMap<>();
|
||||
|
||||
public Session getSession(@Nonnull String sessionId) {
|
||||
Session session = sessions.get(sessionId);
|
||||
if (session != null && session.getUserId() != null && UserManager.getInstance().getUser(session.getUserId()) == null) {
|
||||
if (session != null && session.getUserId() != null && UserManager.instance.getUser(session.getUserId()) == null) {
|
||||
logger.error("User for session " + sessionId + " with userId " + session.getUserId() + " is missing. Session removed.");
|
||||
// can happen if user from same host signs in multiple time with multiple clients, after he disconnects with one client
|
||||
disconnect(sessionId, DisconnectReason.ConnectingOtherInstance);
|
||||
|
@ -191,7 +187,7 @@ public class SessionManager {
|
|||
if (session == null) {
|
||||
return null;
|
||||
}
|
||||
return UserManager.getInstance().getUser(session.getUserId()).get();
|
||||
return UserManager.instance.getUser(session.getUserId()).get();
|
||||
}
|
||||
|
||||
public void endUserSession(String sessionId, String userSessionId) {
|
||||
|
@ -215,7 +211,7 @@ public class SessionManager {
|
|||
public Optional<User> getUser(@Nonnull String sessionId) {
|
||||
Session session = sessions.get(sessionId);
|
||||
if (session != null) {
|
||||
return UserManager.getInstance().getUser(sessions.get(sessionId).getUserId());
|
||||
return UserManager.instance.getUser(sessions.get(sessionId).getUserId());
|
||||
}
|
||||
logger.error(String.format("Session %s could not be found", sessionId));
|
||||
return Optional.empty();
|
||||
|
@ -224,7 +220,7 @@ public class SessionManager {
|
|||
public boolean extendUserSession(String sessionId, String pingInfo) {
|
||||
Session session = sessions.get(sessionId);
|
||||
if (session != null) {
|
||||
return UserManager.getInstance().extendUserSession(session.getUserId(), pingInfo);
|
||||
return UserManager.instance.extendUserSession(session.getUserId(), pingInfo);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -94,14 +94,14 @@ public class TableController {
|
|||
this.options = options;
|
||||
match = GameFactory.getInstance().createMatch(options.getGameType(), options);
|
||||
if (userId != null) {
|
||||
Optional<User> user = UserManager.getInstance().getUser(userId);
|
||||
Optional<User> user = UserManager.instance.getUser(userId);
|
||||
// TODO: Handle if user == null
|
||||
controllerName = user.map(User::getName).orElse("undefined");
|
||||
} else {
|
||||
controllerName = "System";
|
||||
}
|
||||
table = new Table(roomId, options.getGameType(), options.getName(), controllerName, DeckValidatorFactory.getInstance().createDeckValidator(options.getDeckType()), options.getPlayerTypes(), TableRecorderImpl.getInstance(), match, options.getBannedUsers());
|
||||
chatId = ChatManager.getInstance().createChatSession("Match Table " + table.getId());
|
||||
chatId = ChatManager.instance.createChatSession("Match Table " + table.getId());
|
||||
init();
|
||||
}
|
||||
|
||||
|
@ -109,7 +109,7 @@ public class TableController {
|
|||
this.userId = userId;
|
||||
tournament = TournamentFactory.getInstance().createTournament(options.getTournamentType(), options);
|
||||
if (userId != null) {
|
||||
Optional<User> user = UserManager.getInstance().getUser(userId);
|
||||
Optional<User> user = UserManager.instance.getUser(userId);
|
||||
if (!user.isPresent()) {
|
||||
logger.fatal(new StringBuilder("User for userId ").append(userId).append(" could not be retrieved from UserManager").toString());
|
||||
controllerName = "[unknown]";
|
||||
|
@ -120,7 +120,7 @@ public class TableController {
|
|||
controllerName = "System";
|
||||
}
|
||||
table = new Table(roomId, options.getTournamentType(), options.getName(), controllerName, DeckValidatorFactory.getInstance().createDeckValidator(options.getMatchOptions().getDeckType()), options.getPlayerTypes(), TableRecorderImpl.getInstance(), tournament, options.getMatchOptions().getBannedUsers());
|
||||
chatId = ChatManager.getInstance().createChatSession("Tourn. table " + table.getId());
|
||||
chatId = ChatManager.instance.createChatSession("Tourn. table " + table.getId());
|
||||
}
|
||||
|
||||
private void init() {
|
||||
|
@ -148,7 +148,7 @@ public class TableController {
|
|||
if (seat == null) {
|
||||
throw new GameException("No available seats.");
|
||||
}
|
||||
Optional<User> _user = UserManager.getInstance().getUser(userId);
|
||||
Optional<User> _user = UserManager.instance.getUser(userId);
|
||||
if (!_user.isPresent()) {
|
||||
logger.fatal(new StringBuilder("couldn't get user ").append(name).append(" for join tournament userId = ").append(userId).toString());
|
||||
return false;
|
||||
|
@ -182,7 +182,7 @@ public class TableController {
|
|||
user.showUserMessage("Join Table", sb.toString());
|
||||
if (isOwner(userId)) {
|
||||
logger.debug("New table removed because owner submitted invalid deck tableId " + table.getId());
|
||||
TableManager.getInstance().removeTable(table.getId());
|
||||
TableManager.instance.removeTable(table.getId());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -242,12 +242,12 @@ public class TableController {
|
|||
newTournamentPlayer.setState(oldTournamentPlayer.getState());
|
||||
newTournamentPlayer.setReplacedTournamentPlayer(oldTournamentPlayer);
|
||||
|
||||
DraftManager.getInstance().getController(table.getId()).replacePlayer(oldPlayer, newPlayer);
|
||||
DraftManager.instance.getController(table.getId()).replacePlayer(oldPlayer, newPlayer);
|
||||
return true;
|
||||
}
|
||||
|
||||
public synchronized boolean joinTable(UUID userId, String name, String playerType, int skill, DeckCardLists deckList, String password) throws MageException {
|
||||
Optional<User> _user = UserManager.getInstance().getUser(userId);
|
||||
Optional<User> _user = UserManager.instance.getUser(userId);
|
||||
if (!_user.isPresent()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -283,7 +283,7 @@ public class TableController {
|
|||
user.showUserMessage("Join Table", sb.toString());
|
||||
if (isOwner(userId)) {
|
||||
logger.debug("New table removed because owner submitted invalid deck tableId " + table.getId());
|
||||
TableManager.getInstance().removeTable(table.getId());
|
||||
TableManager.instance.removeTable(table.getId());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -433,17 +433,17 @@ public class TableController {
|
|||
private void submitDeck(UUID userId, UUID playerId, Deck deck) {
|
||||
if (table.getState() == TableState.SIDEBOARDING) {
|
||||
match.submitDeck(playerId, deck);
|
||||
UserManager.getInstance().getUser(userId).ifPresent(user -> user.removeSideboarding(table.getId()));
|
||||
UserManager.instance.getUser(userId).ifPresent(user -> user.removeSideboarding(table.getId()));
|
||||
} else {
|
||||
TournamentManager.getInstance().submitDeck(tournament.getId(), playerId, deck);
|
||||
UserManager.getInstance().getUser(userId).ifPresent(user -> user.removeConstructing(playerId));
|
||||
TournamentManager.instance.submitDeck(tournament.getId(), playerId, deck);
|
||||
UserManager.instance.getUser(userId).ifPresent(user -> user.removeConstructing(playerId));
|
||||
}
|
||||
}
|
||||
|
||||
private void updateDeck(UUID userId, UUID playerId, Deck deck) {
|
||||
if (table.isTournament()) {
|
||||
if (tournament != null) {
|
||||
TournamentManager.getInstance().updateDeck(tournament.getId(), playerId, deck);
|
||||
TournamentManager.instance.updateDeck(tournament.getId(), playerId, deck);
|
||||
} else {
|
||||
logger.fatal("Tournament == null table: " + table.getId() + " userId: " + userId);
|
||||
}
|
||||
|
@ -456,7 +456,7 @@ public class TableController {
|
|||
|
||||
public boolean watchTable(UUID userId) {
|
||||
if (table.isTournament()) {
|
||||
UserManager.getInstance().getUser(userId).ifPresent(user -> user.ccShowTournament(table.getTournament().getId()));
|
||||
UserManager.instance.getUser(userId).ifPresent(user -> user.ccShowTournament(table.getTournament().getId()));
|
||||
return true;
|
||||
} else {
|
||||
if (table.isTournamentSubTable() && !table.getTournament().getOptions().isWatchingAllowed()) {
|
||||
|
@ -469,7 +469,7 @@ public class TableController {
|
|||
if (userPlayerMap.get(userId) != null) {
|
||||
return false;
|
||||
}
|
||||
return UserManager.getInstance().getUser(userId).get().ccWatchGame(match.getGame().getId());
|
||||
return UserManager.instance.getUser(userId).get().ccWatchGame(match.getGame().getId());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -477,7 +477,7 @@ public class TableController {
|
|||
// if (table.getState() != TableState.FINISHED) {
|
||||
// return false;
|
||||
// }
|
||||
// ReplayManager.getInstance().replayGame(table.getId(), userId);
|
||||
// ReplayManager.instance.replayGame(table.getId(), userId);
|
||||
// return true;
|
||||
// }
|
||||
private Optional<Player> createPlayer(String name, String playerType, int skill) {
|
||||
|
@ -514,7 +514,7 @@ public class TableController {
|
|||
&& (table.getState() == TableState.WAITING
|
||||
|| table.getState() == TableState.READY_TO_START)) {
|
||||
// table not started yet and user is the owner, remove the table
|
||||
TableManager.getInstance().removeTable(table.getId());
|
||||
TableManager.instance.removeTable(table.getId());
|
||||
} else {
|
||||
UUID playerId = userPlayerMap.get(userId);
|
||||
if (playerId != null) {
|
||||
|
@ -525,9 +525,9 @@ public class TableController {
|
|||
} else {
|
||||
match.quitMatch(playerId);
|
||||
}
|
||||
Optional<User> user = UserManager.getInstance().getUser(userId);
|
||||
Optional<User> user = UserManager.instance.getUser(userId);
|
||||
if (!user.isPresent()) {
|
||||
ChatManager.getInstance().broadcast(chatId, user.get().getName(), "has left the table", ChatMessage.MessageColor.BLUE, true, ChatMessage.MessageType.STATUS, ChatMessage.SoundToPlay.PlayerLeft);
|
||||
ChatManager.instance.broadcast(chatId, user.get().getName(), "has left the table", ChatMessage.MessageColor.BLUE, true, ChatMessage.MessageType.STATUS, ChatMessage.SoundToPlay.PlayerLeft);
|
||||
if (!table.isTournamentSubTable()) {
|
||||
user.get().removeTable(playerId);
|
||||
}
|
||||
|
@ -538,9 +538,9 @@ public class TableController {
|
|||
} else if (table.getState() != TableState.FINISHED) {
|
||||
if (table.isTournament()) {
|
||||
logger.debug("Quit tournament sub tables for userId: " + userId);
|
||||
TableManager.getInstance().userQuitTournamentSubTables(tournament.getId(), userId);
|
||||
TableManager.instance.userQuitTournamentSubTables(tournament.getId(), userId);
|
||||
logger.debug("Quit tournament Id: " + table.getTournament().getId() + '(' + table.getTournament().getTournamentState() + ')');
|
||||
TournamentManager.getInstance().quit(tournament.getId(), userId);
|
||||
TournamentManager.instance.quit(tournament.getId(), userId);
|
||||
} else {
|
||||
MatchPlayer matchPlayer = match.getPlayer(playerId);
|
||||
if (matchPlayer != null && !match.hasEnded() && !matchPlayer.hasQuit()) {
|
||||
|
@ -548,7 +548,7 @@ public class TableController {
|
|||
if (game != null && !game.hasEnded()) {
|
||||
Player player = match.getPlayer(playerId).getPlayer();
|
||||
if (player != null && player.isInGame()) {
|
||||
GameManager.getInstance().quitMatch(game.getId(), userId);
|
||||
GameManager.instance.quitMatch(game.getId(), userId);
|
||||
}
|
||||
match.quitMatch(playerId);
|
||||
} else {
|
||||
|
@ -586,7 +586,7 @@ public class TableController {
|
|||
if (table.isTournamentSubTable()) {
|
||||
logger.info("Tourn. match started id:" + match.getId() + " tournId: " + table.getTournament().getId());
|
||||
} else {
|
||||
UserManager.getInstance().getUser(userId).ifPresent(user -> {
|
||||
UserManager.instance.getUser(userId).ifPresent(user -> {
|
||||
logger.info("MATCH started [" + match.getName() + "] " + match.getId() + '(' + user.getName() + ')');
|
||||
logger.debug("- " + match.getOptions().getGameType() + " - " + match.getOptions().getDeckType());
|
||||
});
|
||||
|
@ -607,12 +607,12 @@ public class TableController {
|
|||
GameOptions gameOptions = new GameOptions();
|
||||
gameOptions.rollbackTurnsAllowed = match.getOptions().isRollbackTurnsAllowed();
|
||||
match.getGame().setGameOptions(gameOptions);
|
||||
GameManager.getInstance().createGameSession(match.getGame(), userPlayerMap, table.getId(), choosingPlayerId, gameOptions);
|
||||
GameManager.instance.createGameSession(match.getGame(), userPlayerMap, table.getId(), choosingPlayerId, gameOptions);
|
||||
String creator = null;
|
||||
StringBuilder opponent = new StringBuilder();
|
||||
for (Entry<UUID, UUID> entry : userPlayerMap.entrySet()) { // do only for no AI players
|
||||
if (match.getPlayer(entry.getValue()) != null && !match.getPlayer(entry.getValue()).hasQuit()) {
|
||||
Optional<User> _user = UserManager.getInstance().getUser(entry.getKey());
|
||||
Optional<User> _user = UserManager.instance.getUser(entry.getKey());
|
||||
if (_user.isPresent()) {
|
||||
User user = _user.get();
|
||||
user.ccGameStarted(match.getGame().getId(), entry.getValue());
|
||||
|
@ -643,23 +643,23 @@ public class TableController {
|
|||
opponent.append(mPlayer.getName());
|
||||
}
|
||||
}
|
||||
ServerMessagesUtil.getInstance().incGamesStarted();
|
||||
ServerMessagesUtil.instance.incGamesStarted();
|
||||
|
||||
// log about game started
|
||||
logger.info("GAME started " + (match.getGame() != null ? match.getGame().getId() : "no Game") + " [" + match.getName() + "] " + creator + " - " + opponent.toString());
|
||||
logger.debug("- matchId: " + match.getId() + " [" + match.getName() + ']');
|
||||
if (match.getGame() != null) {
|
||||
logger.debug("- chatId: " + GameManager.getInstance().getChatId(match.getGame().getId()));
|
||||
logger.debug("- chatId: " + GameManager.instance.getChatId(match.getGame().getId()));
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.fatal("Error starting game table: " + table.getId(), ex);
|
||||
if (table != null) {
|
||||
TableManager.getInstance().removeTable(table.getId());
|
||||
TableManager.instance.removeTable(table.getId());
|
||||
}
|
||||
if (match != null) {
|
||||
Game game = match.getGame();
|
||||
if (game != null) {
|
||||
GameManager.getInstance().removeGame(game.getId());
|
||||
GameManager.instance.removeGame(game.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -669,27 +669,27 @@ public class TableController {
|
|||
try {
|
||||
if (userId.equals(this.userId) && table.getState() == TableState.STARTING) {
|
||||
tournament.setStartTime();
|
||||
TournamentManager.getInstance().createTournamentSession(tournament, userPlayerMap, table.getId());
|
||||
TournamentManager.instance.createTournamentSession(tournament, userPlayerMap, table.getId());
|
||||
for (Entry<UUID, UUID> entry : userPlayerMap.entrySet()) {
|
||||
UserManager.getInstance().getUser(entry.getKey()).ifPresent(user -> {
|
||||
UserManager.instance.getUser(entry.getKey()).ifPresent(user -> {
|
||||
logger.info(new StringBuilder("User ").append(user.getName()).append(" tournament started: ").append(tournament.getId()).append(" userId: ").append(user.getId()));
|
||||
user.ccTournamentStarted(tournament.getId(), entry.getValue());
|
||||
});
|
||||
}
|
||||
ServerMessagesUtil.getInstance().incTournamentsStarted();
|
||||
ServerMessagesUtil.instance.incTournamentsStarted();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.fatal("Error starting tournament", ex);
|
||||
TableManager.getInstance().removeTable(table.getId());
|
||||
TournamentManager.getInstance().quit(tournament.getId(), userId);
|
||||
TableManager.instance.removeTable(table.getId());
|
||||
TournamentManager.instance.quit(tournament.getId(), userId);
|
||||
}
|
||||
}
|
||||
|
||||
public void startDraft(Draft draft) {
|
||||
table.initDraft();
|
||||
DraftManager.getInstance().createDraftSession(draft, userPlayerMap, table.getId());
|
||||
DraftManager.instance.createDraftSession(draft, userPlayerMap, table.getId());
|
||||
for (Entry<UUID, UUID> entry : userPlayerMap.entrySet()) {
|
||||
Optional<User> user = UserManager.getInstance().getUser(entry.getKey());
|
||||
Optional<User> user = UserManager.instance.getUser(entry.getKey());
|
||||
if (user.isPresent()) {
|
||||
logger.info(new StringBuilder("User ").append(user.get().getName()).append(" draft started: ").append(draft.getId()).append(" userId: ").append(user.get().getId()));
|
||||
user.get().ccDraftStarted(draft.getId(), entry.getValue());
|
||||
|
@ -703,7 +703,7 @@ public class TableController {
|
|||
|
||||
for (Entry<UUID, UUID> entry : userPlayerMap.entrySet()) {
|
||||
if (entry.getValue().equals(playerId)) {
|
||||
Optional<User> user = UserManager.getInstance().getUser(entry.getKey());
|
||||
Optional<User> user = UserManager.instance.getUser(entry.getKey());
|
||||
int remaining = (int) futureTimeout.getDelay(TimeUnit.SECONDS);
|
||||
user.ifPresent(user1 -> user1.ccSideboard(deck, table.getId(), remaining, options.isLimited()));
|
||||
break;
|
||||
|
@ -744,12 +744,12 @@ public class TableController {
|
|||
}
|
||||
UUID choosingPlayerId = match.getChooser();
|
||||
match.endGame();
|
||||
if (ConfigSettings.getInstance().isSaveGameActivated() && !game.isSimulation()) {
|
||||
if (GameManager.getInstance().saveGame(game.getId())) {
|
||||
if (ConfigSettings.instance.isSaveGameActivated() && !game.isSimulation()) {
|
||||
if (GameManager.instance.saveGame(game.getId())) {
|
||||
match.setReplayAvailable(true);
|
||||
}
|
||||
}
|
||||
GameManager.getInstance().removeGame(game.getId());
|
||||
GameManager.instance.removeGame(game.getId());
|
||||
try {
|
||||
if (!match.hasEnded()) {
|
||||
if (match.getGame() != null && match.getGame().getGameType().isSideboardingAllowed()) {
|
||||
|
@ -810,7 +810,7 @@ public class TableController {
|
|||
// opponent(s) left during sideboarding
|
||||
if (matchPlayer != null) {
|
||||
if (!matchPlayer.hasQuit()) {
|
||||
UserManager.getInstance().getUser(entry.getKey()).ifPresent(user -> {
|
||||
UserManager.instance.getUser(entry.getKey()).ifPresent(user -> {
|
||||
if (table.getState() == TableState.SIDEBOARDING) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (table.isTournamentSubTable()) {
|
||||
|
@ -835,7 +835,7 @@ public class TableController {
|
|||
}
|
||||
}
|
||||
// free resources no longer needed
|
||||
match.cleanUpOnMatchEnd(ConfigSettings.getInstance().isSaveGameActivated(), table.isTournament());
|
||||
match.cleanUpOnMatchEnd(ConfigSettings.instance.isSaveGameActivated(), table.isTournament());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -907,7 +907,7 @@ public class TableController {
|
|||
public boolean isTournamentStillValid() {
|
||||
if (table.getTournament() != null) {
|
||||
if (table.getState() != TableState.WAITING && table.getState() != TableState.READY_TO_START && table.getState() != TableState.STARTING) {
|
||||
TournamentController tournamentController = TournamentManager.getInstance().getTournamentController(table.getTournament().getId());
|
||||
TournamentController tournamentController = TournamentManager.instance.getTournamentController(table.getTournament().getId());
|
||||
if (tournamentController != null) {
|
||||
return tournamentController.isTournamentStillValid(table.getState());
|
||||
} else {
|
||||
|
@ -915,7 +915,7 @@ public class TableController {
|
|||
}
|
||||
} else {
|
||||
// check if table creator is still a valid user, if not remove table
|
||||
return UserManager.getInstance().getUser(userId).isPresent();
|
||||
return UserManager.instance.getUser(userId).isPresent();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
@ -981,7 +981,7 @@ public class TableController {
|
|||
|| table.getState() == TableState.READY_TO_START)
|
||||
|| !match.isDoneSideboarding()
|
||||
|| (!matchPlayer.hasQuit() && match.getGame() != null && matchPlayer.getPlayer().isInGame())) {
|
||||
Optional<User> user = UserManager.getInstance().getUser(userPlayerEntry.getKey());
|
||||
Optional<User> user = UserManager.instance.getUser(userPlayerEntry.getKey());
|
||||
if (!user.isPresent()) {
|
||||
logger.debug("- Active user of match is missing: " + matchPlayer.getName());
|
||||
logger.debug("-- matchId:" + match.getId());
|
||||
|
@ -1005,12 +1005,12 @@ public class TableController {
|
|||
void cleanUp() {
|
||||
if (!table.isTournamentSubTable()) {
|
||||
for (Map.Entry<UUID, UUID> entry : userPlayerMap.entrySet()) {
|
||||
UserManager.getInstance().getUser(entry.getKey()).ifPresent(user
|
||||
UserManager.instance.getUser(entry.getKey()).ifPresent(user
|
||||
-> user.removeTable(entry.getValue()));
|
||||
}
|
||||
|
||||
}
|
||||
ChatManager.getInstance().destroyChatSession(chatId);
|
||||
ChatManager.instance.destroyChatSession(chatId);
|
||||
}
|
||||
|
||||
public synchronized TableState getTableState() {
|
||||
|
|
|
@ -59,14 +59,13 @@ import org.apache.log4j.Logger;
|
|||
/**
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class TableManager {
|
||||
|
||||
protected static final ScheduledExecutorService expireExecutor = Executors.newSingleThreadScheduledExecutor();
|
||||
public enum TableManager {
|
||||
instance;
|
||||
protected final ScheduledExecutorService expireExecutor = Executors.newSingleThreadScheduledExecutor();
|
||||
|
||||
// protected static ScheduledExecutorService expireExecutor = ThreadExecutor.getInstance().getExpireExecutor();
|
||||
|
||||
private static final TableManager INSTANCE = new TableManager();
|
||||
private static final Logger logger = Logger.getLogger(TableManager.class);
|
||||
private final Logger logger = Logger.getLogger(TableManager.class);
|
||||
private static final DateFormat formatter = new SimpleDateFormat("HH:mm:ss");
|
||||
|
||||
private final ConcurrentHashMap<UUID, TableController> controllers = new ConcurrentHashMap<>();
|
||||
|
@ -79,11 +78,8 @@ public class TableManager {
|
|||
*/
|
||||
private static final int EXPIRE_CHECK_PERIOD = 10;
|
||||
|
||||
public static TableManager getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private TableManager() {
|
||||
TableManager() {
|
||||
expireExecutor.scheduleAtFixedRate(() -> {
|
||||
try {
|
||||
checkTableHealthState();
|
||||
|
@ -151,7 +147,7 @@ public class TableManager {
|
|||
if (controllers.containsKey(tableId)) {
|
||||
return controllers.get(tableId).submitDeck(userId, deckList);
|
||||
}
|
||||
UserManager.getInstance().getUser(userId).ifPresent(user -> {
|
||||
UserManager.instance.getUser(userId).ifPresent(user -> {
|
||||
user.removeSideboarding(tableId);
|
||||
user.showUserMessage("Submit deck", "Table no longer active");
|
||||
|
||||
|
@ -198,12 +194,12 @@ public class TableManager {
|
|||
}
|
||||
|
||||
public boolean removeTable(UUID userId, UUID tableId) {
|
||||
if (isTableOwner(tableId, userId) || UserManager.getInstance().isAdmin(userId)) {
|
||||
if (isTableOwner(tableId, userId) || UserManager.instance.isAdmin(userId)) {
|
||||
logger.debug("Table remove request - userId: " + userId + " tableId: " + tableId);
|
||||
TableController tableController = controllers.get(tableId);
|
||||
if (tableController != null) {
|
||||
tableController.leaveTableAll();
|
||||
ChatManager.getInstance().destroyChatSession(tableController.getChatId());
|
||||
ChatManager.instance.destroyChatSession(tableController.getChatId());
|
||||
removeTable(tableId);
|
||||
}
|
||||
return true;
|
||||
|
@ -236,7 +232,7 @@ public class TableManager {
|
|||
if (controllers.containsKey(tableId)) {
|
||||
controllers.get(tableId).startMatch(userId);
|
||||
// chat of start dialog can be killed
|
||||
ChatManager.getInstance().destroyChatSession(controllers.get(tableId).getChatId());
|
||||
ChatManager.instance.destroyChatSession(controllers.get(tableId).getChatId());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -255,7 +251,7 @@ public class TableManager {
|
|||
public void startTournament(UUID userId, UUID roomId, UUID tableId) {
|
||||
if (controllers.containsKey(tableId)) {
|
||||
controllers.get(tableId).startTournament(userId);
|
||||
ChatManager.getInstance().destroyChatSession(controllers.get(tableId).getChatId());
|
||||
ChatManager.instance.destroyChatSession(controllers.get(tableId).getChatId());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -343,9 +339,9 @@ public class TableManager {
|
|||
// If table is not finished, the table has to be removed completly because it's not a normal state (if finished it will be removed in GamesRoomImpl.Update())
|
||||
if (table.getState() != TableState.FINISHED) {
|
||||
if (game != null) {
|
||||
GameManager.getInstance().removeGame(game.getId());
|
||||
GameManager.instance.removeGame(game.getId());
|
||||
}
|
||||
GamesRoomManager.getInstance().removeTable(tableId);
|
||||
GamesRoomManager.instance.removeTable(tableId);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -353,12 +349,12 @@ public class TableManager {
|
|||
|
||||
public void debugServerState() {
|
||||
logger.debug("--- Server state ----------------------------------------------");
|
||||
Collection<User> users = UserManager.getInstance().getUsers();
|
||||
Collection<User> users = UserManager.instance.getUsers();
|
||||
logger.debug("--------User: " + users.size() + " [userId | since | lock | name -----------------------");
|
||||
for (User user : users) {
|
||||
Session session = SessionManager.getInstance().getSession(user.getSessionId());
|
||||
Session session = SessionManager.instance.getSession(user.getSessionId());
|
||||
String sessionState = "N";
|
||||
if (session!=null) {
|
||||
if (session != null) {
|
||||
if (session.isLocked()) {
|
||||
sessionState = "L";
|
||||
} else {
|
||||
|
@ -370,14 +366,14 @@ public class TableManager {
|
|||
+ " | " + sessionState
|
||||
+ " | " + user.getName() + " (" + user.getUserState().toString() + " - " + user.getPingInfo() + ')');
|
||||
}
|
||||
ArrayList<ChatSession> chatSessions = ChatManager.getInstance().getChatSessions();
|
||||
ArrayList<ChatSession> chatSessions = ChatManager.instance.getChatSessions();
|
||||
logger.debug("------- ChatSessions: " + chatSessions.size() + " ----------------------------------");
|
||||
for (ChatSession chatSession : chatSessions) {
|
||||
logger.debug(chatSession.getChatId() + " " + formatter.format(chatSession.getCreateTime()) + ' ' + chatSession.getInfo() + ' ' + chatSession.getClients().values().toString());
|
||||
}
|
||||
logger.debug("------- Games: " + GameManager.getInstance().getNumberActiveGames() + " --------------------------------------------");
|
||||
logger.debug("------- Games: " + GameManager.instance.getNumberActiveGames() + " --------------------------------------------");
|
||||
logger.debug(" Active Game Worker: " + ThreadExecutor.getInstance().getActiveThreads(ThreadExecutor.getInstance().getGameExecutor()));
|
||||
for (Entry<UUID, GameController> entry : GameManager.getInstance().getGameController().entrySet()) {
|
||||
for (Entry<UUID, GameController> entry : GameManager.instance.getGameController().entrySet()) {
|
||||
logger.debug(entry.getKey() + entry.getValue().getPlayerNameList());
|
||||
}
|
||||
logger.debug("--- Server state END ------------------------------------------");
|
||||
|
|
|
@ -210,10 +210,10 @@ public class User {
|
|||
// Because watched games don't get restored after reconnection call stop watching
|
||||
for (Iterator<UUID> iterator = watchedGames.iterator(); iterator.hasNext();) {
|
||||
UUID gameId = iterator.next();
|
||||
GameManager.getInstance().stopWatching(gameId, userId);
|
||||
GameManager.instance.stopWatching(gameId, userId);
|
||||
iterator.remove();
|
||||
}
|
||||
ServerMessagesUtil.getInstance().incLostConnection();
|
||||
ServerMessagesUtil.instance.incLostConnection();
|
||||
}
|
||||
|
||||
public boolean isConnected() {
|
||||
|
@ -246,7 +246,7 @@ public class User {
|
|||
|
||||
public void fireCallback(final ClientCallback call) {
|
||||
if (isConnected()) {
|
||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||
Session session = SessionManager.instance.getSession(sessionId);
|
||||
if (session != null) {
|
||||
session.fireCallback(call);
|
||||
}
|
||||
|
@ -304,27 +304,27 @@ public class User {
|
|||
|
||||
public void sendPlayerUUID(final UUID gameId, final UUID data) {
|
||||
lastActivity = new Date();
|
||||
GameManager.getInstance().sendPlayerUUID(gameId, userId, data);
|
||||
GameManager.instance.sendPlayerUUID(gameId, userId, data);
|
||||
}
|
||||
|
||||
public void sendPlayerString(final UUID gameId, final String data) {
|
||||
lastActivity = new Date();
|
||||
GameManager.getInstance().sendPlayerString(gameId, userId, data);
|
||||
GameManager.instance.sendPlayerString(gameId, userId, data);
|
||||
}
|
||||
|
||||
public void sendPlayerManaType(final UUID gameId, final UUID playerId, final ManaType data) {
|
||||
lastActivity = new Date();
|
||||
GameManager.getInstance().sendPlayerManaType(gameId, playerId, userId, data);
|
||||
GameManager.instance.sendPlayerManaType(gameId, playerId, userId, data);
|
||||
}
|
||||
|
||||
public void sendPlayerBoolean(final UUID gameId, final Boolean data) {
|
||||
lastActivity = new Date();
|
||||
GameManager.getInstance().sendPlayerBoolean(gameId, userId, data);
|
||||
GameManager.instance.sendPlayerBoolean(gameId, userId, data);
|
||||
}
|
||||
|
||||
public void sendPlayerInteger(final UUID gameId, final Integer data) {
|
||||
lastActivity = new Date();
|
||||
GameManager.getInstance().sendPlayerInteger(gameId, userId, data);
|
||||
GameManager.instance.sendPlayerInteger(gameId, userId, data);
|
||||
}
|
||||
|
||||
public void updateLastActivity(String pingInfo) {
|
||||
|
@ -355,7 +355,7 @@ public class User {
|
|||
ccJoinedTable(entry.getValue().getRoomId(), entry.getValue().getId(), entry.getValue().isTournament());
|
||||
}
|
||||
for (Entry<UUID, UUID> entry : userTournaments.entrySet()) {
|
||||
TournamentController tournamentController = TournamentManager.getInstance().getTournamentController(entry.getValue());
|
||||
TournamentController tournamentController = TournamentManager.instance.getTournamentController(entry.getValue());
|
||||
if (tournamentController != null) {
|
||||
ccTournamentStarted(entry.getValue(), entry.getKey());
|
||||
tournamentController.rejoin(entry.getKey());
|
||||
|
@ -365,7 +365,7 @@ public class User {
|
|||
for (Entry<UUID, GameSessionPlayer> entry : gameSessions.entrySet()) {
|
||||
ccGameStarted(entry.getValue().getGameId(), entry.getKey());
|
||||
entry.getValue().init();
|
||||
GameManager.getInstance().sendPlayerString(entry.getValue().getGameId(), userId, "");
|
||||
GameManager.instance.sendPlayerString(entry.getValue().getGameId(), userId, "");
|
||||
}
|
||||
|
||||
for (Entry<UUID, DraftSession> entry : draftSessions.entrySet()) {
|
||||
|
@ -378,10 +378,10 @@ public class User {
|
|||
entry.getValue().construct(0); // TODO: Check if this is correct
|
||||
}
|
||||
for (Entry<UUID, Deck> entry : sideboarding.entrySet()) {
|
||||
TableController controller = TableManager.getInstance().getController(entry.getKey());
|
||||
TableController controller = TableManager.instance.getController(entry.getKey());
|
||||
ccSideboard(entry.getValue(), entry.getKey(), controller.getRemainingTime(), controller.getOptions().isLimited());
|
||||
}
|
||||
ServerMessagesUtil.getInstance().incReconnects();
|
||||
ServerMessagesUtil.instance.incReconnects();
|
||||
logger.trace(userName + " ended reconnect");
|
||||
}
|
||||
|
||||
|
@ -437,29 +437,29 @@ public class User {
|
|||
draftSessions.clear();
|
||||
logger.trace("REMOVE " + userName + " Tournament sessions " + userTournaments.size());
|
||||
for (UUID tournamentId : userTournaments.values()) {
|
||||
TournamentManager.getInstance().quit(tournamentId, userId);
|
||||
TournamentManager.instance.quit(tournamentId, userId);
|
||||
}
|
||||
userTournaments.clear();
|
||||
logger.trace("REMOVE " + userName + " Tables " + tables.size());
|
||||
for (Entry<UUID, Table> entry : tables.entrySet()) {
|
||||
logger.debug("-- leave tableId: " + entry.getValue().getId());
|
||||
TableManager.getInstance().leaveTable(userId, entry.getValue().getId());
|
||||
TableManager.instance.leaveTable(userId, entry.getValue().getId());
|
||||
}
|
||||
tables.clear();
|
||||
logger.trace("REMOVE " + userName + " Game sessions: " + gameSessions.size());
|
||||
for (GameSessionPlayer gameSessionPlayer : gameSessions.values()) {
|
||||
logger.debug("-- kill game session of gameId: " + gameSessionPlayer.getGameId());
|
||||
GameManager.getInstance().quitMatch(gameSessionPlayer.getGameId(), userId);
|
||||
GameManager.instance.quitMatch(gameSessionPlayer.getGameId(), userId);
|
||||
gameSessionPlayer.quitGame();
|
||||
}
|
||||
gameSessions.clear();
|
||||
logger.trace("REMOVE " + userName + " watched Games " + watchedGames.size());
|
||||
for (UUID gameId : watchedGames) {
|
||||
GameManager.getInstance().stopWatching(gameId, userId);
|
||||
GameManager.instance.stopWatching(gameId, userId);
|
||||
}
|
||||
watchedGames.clear();
|
||||
logger.trace("REMOVE " + userName + " Chats ");
|
||||
ChatManager.getInstance().removeUser(userId, reason);
|
||||
ChatManager.instance.removeUser(userId, reason);
|
||||
}
|
||||
|
||||
public void setUserData(UserData userData) {
|
||||
|
@ -784,7 +784,7 @@ public class User {
|
|||
if (table.getState() == TableState.FINISHED) {
|
||||
number++;
|
||||
} else {
|
||||
TableController tableController = TableManager.getInstance().getController(table.getId());
|
||||
TableController tableController = TableManager.instance.getController(table.getId());
|
||||
if (tableController != null && tableController.isUserStillActive(userId)) {
|
||||
number++;
|
||||
}
|
||||
|
|
|
@ -42,9 +42,10 @@ import java.util.concurrent.*;
|
|||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class UserManager {
|
||||
public enum UserManager {
|
||||
instance;
|
||||
|
||||
protected static final ScheduledExecutorService expireExecutor = Executors.newSingleThreadScheduledExecutor();
|
||||
protected final ScheduledExecutorService expireExecutor = Executors.newSingleThreadScheduledExecutor();
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(UserManager.class);
|
||||
|
||||
|
@ -53,13 +54,7 @@ public class UserManager {
|
|||
|
||||
private static final ExecutorService USER_EXECUTOR = ThreadExecutor.getInstance().getCallExecutor();
|
||||
|
||||
private static final UserManager INSTANCE = new UserManager();
|
||||
|
||||
public static UserManager getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private UserManager() {
|
||||
UserManager() {
|
||||
expireExecutor.scheduleAtFixedRate(this::checkExpired, 60, 60, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
|
@ -112,7 +107,7 @@ public class UserManager {
|
|||
if (user != null) {
|
||||
user.setSessionId(""); // Session will be set again with new id if user reconnects
|
||||
}
|
||||
ChatManager.getInstance().removeUser(userId, reason);
|
||||
ChatManager.instance.removeUser(userId, reason);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,10 +14,10 @@ import mage.game.match.Match;
|
|||
*/
|
||||
public class ChallengeManager {
|
||||
|
||||
public static final ChallengeManager fInstance = new ChallengeManager();
|
||||
public static final ChallengeManager instance = new ChallengeManager();
|
||||
|
||||
public static ChallengeManager getInstance() {
|
||||
return fInstance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void prepareChallenge(UUID playerId, Match match) {
|
||||
|
|
|
@ -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));
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -119,10 +119,10 @@ public class GameController implements GameCallback {
|
|||
public GameController(Game game, ConcurrentHashMap<UUID, UUID> userPlayerMap, UUID tableId, UUID choosingPlayerId, GameOptions gameOptions) {
|
||||
gameSessionId = UUID.randomUUID();
|
||||
this.userPlayerMap = userPlayerMap;
|
||||
chatId = ChatManager.getInstance().createChatSession("Game " + game.getId());
|
||||
chatId = ChatManager.instance.createChatSession("Game " + game.getId());
|
||||
this.userReqestingRollback = null;
|
||||
this.game = game;
|
||||
this.game.setSaveGame(ConfigSettings.getInstance().isSaveGameActivated());
|
||||
this.game.setSaveGame(ConfigSettings.instance.isSaveGameActivated());
|
||||
this.tableId = tableId;
|
||||
this.choosingPlayerId = choosingPlayerId;
|
||||
this.gameOptions = gameOptions;
|
||||
|
@ -141,7 +141,7 @@ public class GameController implements GameCallback {
|
|||
for (GameSessionPlayer gameSessionPlayer : gameSessions.values()) {
|
||||
gameSessionPlayer.cleanUp();
|
||||
}
|
||||
ChatManager.getInstance().destroyChatSession(chatId);
|
||||
ChatManager.instance.destroyChatSession(chatId);
|
||||
for (PriorityTimer priorityTimer : timers.values()) {
|
||||
priorityTimer.cancel();
|
||||
}
|
||||
|
@ -158,11 +158,11 @@ public class GameController implements GameCallback {
|
|||
updateGame();
|
||||
break;
|
||||
case INFO:
|
||||
ChatManager.getInstance().broadcast(chatId, "", event.getMessage(), MessageColor.BLACK, true, MessageType.GAME, null);
|
||||
ChatManager.instance.broadcast(chatId, "", event.getMessage(), MessageColor.BLACK, true, MessageType.GAME, null);
|
||||
logger.trace(game.getId() + " " + event.getMessage());
|
||||
break;
|
||||
case STATUS:
|
||||
ChatManager.getInstance().broadcast(chatId, "", event.getMessage(), MessageColor.ORANGE, event.getWithTime(), MessageType.GAME, null);
|
||||
ChatManager.instance.broadcast(chatId, "", event.getMessage(), MessageColor.ORANGE, event.getWithTime(), MessageType.GAME, null);
|
||||
logger.trace(game.getId() + " " + event.getMessage());
|
||||
break;
|
||||
case ERROR:
|
||||
|
@ -305,7 +305,7 @@ public class GameController implements GameCallback {
|
|||
|
||||
public void join(UUID userId) {
|
||||
UUID playerId = userPlayerMap.get(userId);
|
||||
Optional<User> user = UserManager.getInstance().getUser(userId);
|
||||
Optional<User> user = UserManager.instance.getUser(userId);
|
||||
if (userId == null || playerId == null) {
|
||||
logger.fatal("Join game failed!");
|
||||
logger.fatal("- gameId: " + game.getId());
|
||||
|
@ -332,7 +332,7 @@ public class GameController implements GameCallback {
|
|||
}
|
||||
user.get().addGame(playerId, gameSession);
|
||||
logger.debug("Player " + player.getName() + ' ' + playerId + " has " + joinType + " gameId: " + game.getId());
|
||||
ChatManager.getInstance().broadcast(chatId, "", game.getPlayer(playerId).getLogName() + " has " + joinType + " the game", MessageColor.ORANGE, true, MessageType.GAME, null);
|
||||
ChatManager.instance.broadcast(chatId, "", game.getPlayer(playerId).getLogName() + " has " + joinType + " the game", MessageColor.ORANGE, true, MessageType.GAME, null);
|
||||
checkStart();
|
||||
}
|
||||
|
||||
|
@ -356,10 +356,10 @@ public class GameController implements GameCallback {
|
|||
if (gameSessions.get(player.getId()) == null) {
|
||||
// join the game because player has not joined are was removed because of disconnect
|
||||
user.removeConstructing(player.getId());
|
||||
GameManager.getInstance().joinGame(game.getId(), user.getId());
|
||||
GameManager.instance.joinGame(game.getId(), user.getId());
|
||||
logger.debug("Player " + player.getName() + " (disconnected) has joined gameId: " + game.getId());
|
||||
}
|
||||
ChatManager.getInstance().broadcast(chatId, player.getName(), user.getPingInfo() + " is pending to join the game", MessageColor.BLUE, true, ChatMessage.MessageType.STATUS, null);
|
||||
ChatManager.instance.broadcast(chatId, player.getName(), user.getPingInfo() + " is pending to join the game", MessageColor.BLUE, true, ChatMessage.MessageType.STATUS, null);
|
||||
if (user.getSecondsDisconnected() > 240) {
|
||||
// Cancel player join possibility lately after 4 minutes
|
||||
logger.debug("Player " + player.getName() + " - canceled game (after 240 seconds) gameId: " + game.getId());
|
||||
|
@ -379,7 +379,7 @@ public class GameController implements GameCallback {
|
|||
private Optional<User> getUserByPlayerId(UUID playerId) {
|
||||
for (Map.Entry<UUID, UUID> entry : userPlayerMap.entrySet()) {
|
||||
if (entry.getValue().equals(playerId)) {
|
||||
return UserManager.getInstance().getUser(entry.getKey());
|
||||
return UserManager.instance.getUser(entry.getKey());
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
|
@ -418,19 +418,19 @@ public class GameController implements GameCallback {
|
|||
// You can't watch a game if you already watch it
|
||||
return;
|
||||
}
|
||||
UserManager.getInstance().getUser(userId).ifPresent(user -> {
|
||||
UserManager.instance.getUser(userId).ifPresent(user -> {
|
||||
GameSessionWatcher gameWatcher = new GameSessionWatcher(userId, game, false);
|
||||
watchers.put(userId, gameWatcher);
|
||||
gameWatcher.init();
|
||||
user.addGameWatchInfo(game.getId());
|
||||
ChatManager.getInstance().broadcast(chatId, user.getName(), " has started watching", MessageColor.BLUE, true, ChatMessage.MessageType.STATUS, null);
|
||||
ChatManager.instance.broadcast(chatId, user.getName(), " has started watching", MessageColor.BLUE, true, ChatMessage.MessageType.STATUS, null);
|
||||
});
|
||||
}
|
||||
|
||||
public void stopWatching(UUID userId) {
|
||||
watchers.remove(userId);
|
||||
UserManager.getInstance().getUser(userId).ifPresent(user -> {
|
||||
ChatManager.getInstance().broadcast(chatId, user.getName(), " has stopped watching", MessageColor.BLUE, true, ChatMessage.MessageType.STATUS, null);
|
||||
UserManager.instance.getUser(userId).ifPresent(user -> {
|
||||
ChatManager.instance.broadcast(chatId, user.getName(), " has stopped watching", MessageColor.BLUE, true, ChatMessage.MessageType.STATUS, null);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -599,7 +599,7 @@ public class GameController implements GameCallback {
|
|||
gameSession.requestPermissionToSeeHandCards(userIdRequester);
|
||||
} else {
|
||||
// player does not allow the request
|
||||
UserManager.getInstance().getUser(userIdRequester).ifPresent(requester -> {
|
||||
UserManager.instance.getUser(userIdRequester).ifPresent(requester -> {
|
||||
requester.showUserMessage("Request to show hand cards", "Player " + grantingPlayer.getName() + " does not allow to request to show hand cards!");
|
||||
});
|
||||
}
|
||||
|
@ -611,7 +611,7 @@ public class GameController implements GameCallback {
|
|||
}
|
||||
} else {
|
||||
// user can already see the cards
|
||||
UserManager.getInstance().getUser(userIdRequester).ifPresent(requester -> {
|
||||
UserManager.instance.getUser(userIdRequester).ifPresent(requester -> {
|
||||
requester.showUserMessage("Request to show hand cards", "You can see already the hand cards of player " + grantingPlayer.getName() + '!');
|
||||
});
|
||||
|
||||
|
@ -653,8 +653,8 @@ public class GameController implements GameCallback {
|
|||
if (player != null) {
|
||||
String sb = player.getLogName()
|
||||
+ " has timed out (player had priority and was not active for "
|
||||
+ ConfigSettings.getInstance().getMaxSecondsIdle() + " seconds ) - Auto concede.";
|
||||
ChatManager.getInstance().broadcast(chatId, "", sb, MessageColor.BLACK, true, MessageType.STATUS, null);
|
||||
+ ConfigSettings.instance.getMaxSecondsIdle() + " seconds ) - Auto concede.";
|
||||
ChatManager.instance.broadcast(chatId, "", sb, MessageColor.BLACK, true, MessageType.STATUS, null);
|
||||
game.idleTimeout(playerId);
|
||||
}
|
||||
}
|
||||
|
@ -667,7 +667,7 @@ public class GameController implements GameCallback {
|
|||
for (final GameSessionWatcher gameWatcher : watchers.values()) {
|
||||
gameWatcher.gameOver(message);
|
||||
}
|
||||
TableManager.getInstance().endGame(tableId);
|
||||
TableManager.instance.endGame(tableId);
|
||||
}
|
||||
|
||||
public UUID getSessionId() {
|
||||
|
@ -718,7 +718,7 @@ public class GameController implements GameCallback {
|
|||
}
|
||||
|
||||
private synchronized void endGameInfo() {
|
||||
Table table = TableManager.getInstance().getTable(tableId);
|
||||
Table table = TableManager.instance.getTable(tableId);
|
||||
if (table != null) {
|
||||
if (table.getMatch() != null) {
|
||||
for (final GameSessionPlayer gameSession : gameSessions.values()) {
|
||||
|
@ -967,7 +967,7 @@ public class GameController implements GameCallback {
|
|||
cancelTimeout();
|
||||
futureTimeout = timeoutIdleExecutor.schedule(
|
||||
() -> idleTimeout(playerId),
|
||||
Main.isTestMode() ? 3600 : ConfigSettings.getInstance().getMaxSecondsIdle(),
|
||||
Main.isTestMode() ? 3600 : ConfigSettings.instance.getMaxSecondsIdle(),
|
||||
TimeUnit.SECONDS
|
||||
);
|
||||
}
|
||||
|
|
|
@ -41,14 +41,8 @@ import mage.view.GameView;
|
|||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class GameManager {
|
||||
private static final GameManager INSTANCE = new GameManager();
|
||||
|
||||
public static GameManager getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private GameManager() {}
|
||||
public enum GameManager {
|
||||
instance;
|
||||
|
||||
private final ConcurrentHashMap<UUID, GameController> gameControllers = new ConcurrentHashMap<>();
|
||||
|
||||
|
|
|
@ -68,14 +68,14 @@ public class GameSessionPlayer extends GameSessionWatcher {
|
|||
|
||||
public void ask(final String question, final Map<String, Serializable> options) {
|
||||
if (!killed) {
|
||||
UserManager.getInstance().getUser(userId).ifPresent(user -> user.fireCallback(new ClientCallback("gameAsk", game.getId(), new GameClientMessage(getGameView(), question, options)))
|
||||
UserManager.instance.getUser(userId).ifPresent(user -> user.fireCallback(new ClientCallback("gameAsk", game.getId(), new GameClientMessage(getGameView(), question, options)))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public void target(final String question, final CardsView cardView, final Set<UUID> targets, final boolean required, final Map<String, Serializable> options) {
|
||||
if (!killed) {
|
||||
UserManager.getInstance().getUser(userId).ifPresent(user -> {
|
||||
UserManager.instance.getUser(userId).ifPresent(user -> {
|
||||
user.fireCallback(new ClientCallback("gameTarget", game.getId(), new GameClientMessage(getGameView(), question, cardView, targets, required, options)));
|
||||
});
|
||||
|
||||
|
@ -84,13 +84,13 @@ public class GameSessionPlayer extends GameSessionWatcher {
|
|||
|
||||
public void select(final String message, final Map<String, Serializable> options) {
|
||||
if (!killed) {
|
||||
UserManager.getInstance().getUser(userId).ifPresent(user -> user.fireCallback(new ClientCallback("gameSelect", game.getId(), new GameClientMessage(getGameView(), message, options))));
|
||||
UserManager.instance.getUser(userId).ifPresent(user -> user.fireCallback(new ClientCallback("gameSelect", game.getId(), new GameClientMessage(getGameView(), message, options))));
|
||||
}
|
||||
}
|
||||
|
||||
public void chooseAbility(final AbilityPickerView abilities) {
|
||||
if (!killed) {
|
||||
UserManager.getInstance().getUser(userId).ifPresent(user
|
||||
UserManager.instance.getUser(userId).ifPresent(user
|
||||
-> user.fireCallback(new ClientCallback("gameChooseAbility", game.getId(), abilities)));
|
||||
}
|
||||
|
||||
|
@ -98,7 +98,7 @@ public class GameSessionPlayer extends GameSessionWatcher {
|
|||
|
||||
public void choosePile(final String message, final CardsView pile1, final CardsView pile2) {
|
||||
if (!killed) {
|
||||
UserManager.getInstance().getUser(userId).ifPresent(user
|
||||
UserManager.instance.getUser(userId).ifPresent(user
|
||||
-> user.fireCallback(new ClientCallback("gameChoosePile", game.getId(), new GameClientMessage(message, pile1, pile2))));
|
||||
}
|
||||
|
||||
|
@ -106,7 +106,7 @@ public class GameSessionPlayer extends GameSessionWatcher {
|
|||
|
||||
public void chooseChoice(final Choice choice) {
|
||||
if (!killed) {
|
||||
UserManager.getInstance().getUser(userId).ifPresent(user
|
||||
UserManager.instance.getUser(userId).ifPresent(user
|
||||
-> user.fireCallback(new ClientCallback("gameChooseChoice", game.getId(), new GameClientMessage(choice))));
|
||||
}
|
||||
|
||||
|
@ -114,14 +114,14 @@ public class GameSessionPlayer extends GameSessionWatcher {
|
|||
|
||||
public void playMana(final String message, final Map<String, Serializable> options) {
|
||||
if (!killed) {
|
||||
UserManager.getInstance().getUser(userId).ifPresent(user
|
||||
UserManager.instance.getUser(userId).ifPresent(user
|
||||
-> user.fireCallback(new ClientCallback("gamePlayMana", game.getId(), new GameClientMessage(getGameView(), message, options))));
|
||||
}
|
||||
}
|
||||
|
||||
public void playXMana(final String message) {
|
||||
if (!killed) {
|
||||
UserManager.getInstance().getUser(userId).ifPresent(user
|
||||
UserManager.instance.getUser(userId).ifPresent(user
|
||||
-> user.fireCallback(new ClientCallback("gamePlayXMana", game.getId(), new GameClientMessage(getGameView(), message))));
|
||||
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ public class GameSessionPlayer extends GameSessionWatcher {
|
|||
|
||||
public void getAmount(final String message, final int min, final int max) {
|
||||
if (!killed) {
|
||||
UserManager.getInstance().getUser(userId).ifPresent(user -> {
|
||||
UserManager.instance.getUser(userId).ifPresent(user -> {
|
||||
user.fireCallback(new ClientCallback("gameSelectAmount", game.getId(), new GameClientMessage(message, min, max)));
|
||||
});
|
||||
}
|
||||
|
@ -137,15 +137,15 @@ public class GameSessionPlayer extends GameSessionWatcher {
|
|||
|
||||
public void endGameInfo(Table table) {
|
||||
if (!killed) {
|
||||
UserManager.getInstance().getUser(userId).ifPresent(user -> user.fireCallback(new ClientCallback("endGameInfo", game.getId(), getGameEndView(playerId, table))));
|
||||
UserManager.instance.getUser(userId).ifPresent(user -> user.fireCallback(new ClientCallback("endGameInfo", game.getId(), getGameEndView(playerId, table))));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void requestPermissionToRollbackTurn(UUID requestingUserId, int numberTurns) {
|
||||
if (!killed) {
|
||||
Optional<User> requestingUser = UserManager.getInstance().getUser(requestingUserId);
|
||||
Optional<User> requestedUser = UserManager.getInstance().getUser(userId);
|
||||
Optional<User> requestingUser = UserManager.instance.getUser(requestingUserId);
|
||||
Optional<User> requestedUser = UserManager.instance.getUser(userId);
|
||||
if (requestedUser.isPresent() && requestingUser.isPresent()) {
|
||||
String message;
|
||||
switch (numberTurns) {
|
||||
|
@ -171,8 +171,8 @@ public class GameSessionPlayer extends GameSessionWatcher {
|
|||
|
||||
public void requestPermissionToSeeHandCards(UUID watcherId) {
|
||||
if (!killed) {
|
||||
Optional<User> watcher = UserManager.getInstance().getUser(watcherId);
|
||||
Optional<User> user = UserManager.getInstance().getUser(userId);
|
||||
Optional<User> watcher = UserManager.instance.getUser(watcherId);
|
||||
Optional<User> user = UserManager.instance.getUser(userId);
|
||||
if (user.isPresent() && watcher.isPresent()) {
|
||||
UserRequestMessage userRequestMessage = new UserRequestMessage(
|
||||
"User request",
|
||||
|
@ -241,7 +241,7 @@ public class GameSessionPlayer extends GameSessionWatcher {
|
|||
}
|
||||
|
||||
public void removeGame() {
|
||||
UserManager.getInstance().getUser(userId).ifPresent(user -> user.removeGame(playerId));
|
||||
UserManager.instance.getUser(userId).ifPresent(user -> user.removeGame(playerId));
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ public class GameSessionWatcher {
|
|||
|
||||
public boolean init() {
|
||||
if (!killed) {
|
||||
Optional<User> user = UserManager.getInstance().getUser(userId);
|
||||
Optional<User> user = UserManager.instance.getUser(userId);
|
||||
if (user.isPresent()) {
|
||||
user.get().fireCallback(new ClientCallback("gameInit", game.getId(), getGameView()));
|
||||
return true;
|
||||
|
@ -76,28 +76,28 @@ public class GameSessionWatcher {
|
|||
|
||||
public void update() {
|
||||
if (!killed) {
|
||||
UserManager.getInstance().getUser(userId).ifPresent(user -> user.fireCallback(new ClientCallback("gameUpdate", game.getId(), getGameView())));
|
||||
UserManager.instance.getUser(userId).ifPresent(user -> user.fireCallback(new ClientCallback("gameUpdate", game.getId(), getGameView())));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void inform(final String message) {
|
||||
if (!killed) {
|
||||
UserManager.getInstance().getUser(userId).ifPresent(user -> user.fireCallback(new ClientCallback("gameInform", game.getId(), new GameClientMessage(getGameView(), message))));
|
||||
UserManager.instance.getUser(userId).ifPresent(user -> user.fireCallback(new ClientCallback("gameInform", game.getId(), new GameClientMessage(getGameView(), message))));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void informPersonal(final String message) {
|
||||
if (!killed) {
|
||||
UserManager.getInstance().getUser(userId).ifPresent(user -> user.fireCallback(new ClientCallback("gameInformPersonal", game.getId(), new GameClientMessage(getGameView(), message))));
|
||||
UserManager.instance.getUser(userId).ifPresent(user -> user.fireCallback(new ClientCallback("gameInformPersonal", game.getId(), new GameClientMessage(getGameView(), message))));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void gameOver(final String message) {
|
||||
if (!killed) {
|
||||
UserManager.getInstance().getUser(userId).ifPresent(user -> {
|
||||
UserManager.instance.getUser(userId).ifPresent(user -> {
|
||||
user.removeGameWatchInfo(game.getId());
|
||||
user.fireCallback(new ClientCallback("gameOver", game.getId(), message));
|
||||
});
|
||||
|
@ -113,7 +113,7 @@ public class GameSessionWatcher {
|
|||
|
||||
public void gameError(final String message) {
|
||||
if (!killed) {
|
||||
UserManager.getInstance().getUser(userId).ifPresent(user -> user.fireCallback(new ClientCallback("gameError", game.getId(), message)));
|
||||
UserManager.instance.getUser(userId).ifPresent(user -> user.fireCallback(new ClientCallback("gameError", game.getId(), message)));
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -100,7 +100,7 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
|
|||
} else {
|
||||
// more since 50 matches finished since this match so remove it
|
||||
if (table.isTournament()) {
|
||||
TournamentManager.getInstance().removeTournament(table.getTournament().getId());
|
||||
TournamentManager.instance.removeTournament(table.getTournament().getId());
|
||||
}
|
||||
this.removeTable(table.getId());
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
|
|||
tableView = tableList;
|
||||
matchView = matchList;
|
||||
List<UsersView> users = new ArrayList<>();
|
||||
for (User user : UserManager.getInstance().getUsers()) {
|
||||
for (User user : UserManager.instance.getUsers()) {
|
||||
try {
|
||||
users.add(new UsersView(user.getUserData().getFlagName(), user.getName(),
|
||||
user.getMatchHistory(), user.getMatchQuitRatio(), user.getTourneyHistory(),
|
||||
|
@ -135,9 +135,9 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
|
|||
users.sort((one, two) -> one.getUserName().compareToIgnoreCase(two.getUserName()));
|
||||
List<RoomUsersView> roomUserInfo = new ArrayList<>();
|
||||
roomUserInfo.add(new RoomUsersView(users,
|
||||
GameManager.getInstance().getNumberActiveGames(),
|
||||
GameManager.instance.getNumberActiveGames(),
|
||||
ThreadExecutor.getInstance().getActiveThreads(ThreadExecutor.getInstance().getGameExecutor()),
|
||||
ConfigSettings.getInstance().getMaxGameThreads()
|
||||
ConfigSettings.instance.getMaxGameThreads()
|
||||
));
|
||||
roomUsersView = roomUserInfo;
|
||||
}
|
||||
|
@ -150,7 +150,7 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
|
|||
@Override
|
||||
public boolean joinTable(UUID userId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList, String password) throws MageException {
|
||||
if (tables.containsKey(tableId)) {
|
||||
return TableManager.getInstance().joinTable(userId, tableId, name, playerType, skill, deckList, password);
|
||||
return TableManager.instance.joinTable(userId, tableId, name, playerType, skill, deckList, password);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
@ -158,7 +158,7 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
|
|||
|
||||
@Override
|
||||
public TableView createTable(UUID userId, MatchOptions options) {
|
||||
Table table = TableManager.getInstance().createTable(this.getRoomId(), userId, options);
|
||||
Table table = TableManager.instance.createTable(this.getRoomId(), userId, options);
|
||||
tables.put(table.getId(), table);
|
||||
return new TableView(table);
|
||||
}
|
||||
|
@ -166,7 +166,7 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
|
|||
@Override
|
||||
public boolean joinTournamentTable(UUID userId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList, String password) throws GameException {
|
||||
if (tables.containsKey(tableId)) {
|
||||
return TableManager.getInstance().joinTournament(userId, tableId, name, playerType, skill, deckList, password);
|
||||
return TableManager.instance.joinTournament(userId, tableId, name, playerType, skill, deckList, password);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
@ -174,7 +174,7 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
|
|||
|
||||
@Override
|
||||
public TableView createTournamentTable(UUID userId, TournamentOptions options) {
|
||||
Table table = TableManager.getInstance().createTournamentTable(this.getRoomId(), userId, options);
|
||||
Table table = TableManager.instance.createTournamentTable(this.getRoomId(), userId, options);
|
||||
tables.put(table.getId(), table);
|
||||
return new TableView(table);
|
||||
}
|
||||
|
@ -206,12 +206,12 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
|
|||
|
||||
@Override
|
||||
public void leaveTable(UUID userId, UUID tableId) {
|
||||
TableManager.getInstance().leaveTable(userId, tableId);
|
||||
TableManager.instance.leaveTable(userId, tableId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean watchTable(UUID userId, UUID tableId) throws MageException {
|
||||
return TableManager.getInstance().watchTable(userId, tableId);
|
||||
return TableManager.instance.watchTable(userId, tableId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -32,22 +32,16 @@ import java.util.UUID;
|
|||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class GamesRoomManager {
|
||||
|
||||
private static final GamesRoomManager INSTANCE = new GamesRoomManager();
|
||||
// private static final Logger logger = Logger.getLogger(GamesRoomManager.class);
|
||||
public enum GamesRoomManager {
|
||||
instance;
|
||||
|
||||
private final ConcurrentHashMap<UUID, GamesRoom> rooms = new ConcurrentHashMap<>();
|
||||
private final UUID mainRoomId;
|
||||
|
||||
public static GamesRoomManager getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private GamesRoomManager() {
|
||||
GamesRoomManager() {
|
||||
GamesRoom mainRoom = new GamesRoomImpl();
|
||||
mainRoomId = mainRoom.getRoomId();
|
||||
rooms.put(mainRoomId, mainRoom);
|
||||
|
@ -68,7 +62,7 @@ public class GamesRoomManager {
|
|||
}
|
||||
|
||||
public void removeTable(UUID tableId) {
|
||||
for (GamesRoom room: rooms.values()) {
|
||||
for (GamesRoom room : rooms.values()) {
|
||||
room.removeTable(tableId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,21 +36,15 @@ import mage.server.UserManager;
|
|||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class ReplayManager {
|
||||
private static final ReplayManager INSTANCE = new ReplayManager();
|
||||
|
||||
public static ReplayManager getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private ReplayManager() {}
|
||||
public enum ReplayManager {
|
||||
instance;
|
||||
|
||||
private final ConcurrentHashMap<String, ReplaySession> replaySessions = new ConcurrentHashMap<>();
|
||||
|
||||
public void replayGame(UUID gameId, UUID userId) {
|
||||
ReplaySession replaySession = new ReplaySession(gameId, userId);
|
||||
replaySessions.put(gameId.toString() + userId.toString(), replaySession);
|
||||
UserManager.getInstance().getUser(userId).ifPresent(user->user.ccReplayGame(gameId));
|
||||
UserManager.instance.getUser(userId).ifPresent(user->user.ccReplayGame(gameId));
|
||||
}
|
||||
|
||||
public void startReplay(UUID gameId, UUID userId) {
|
||||
|
|
|
@ -51,7 +51,7 @@ public class ReplaySession implements GameCallback {
|
|||
|
||||
public void replay() {
|
||||
replay.start();
|
||||
UserManager.getInstance().getUser(userId).ifPresent(user ->
|
||||
UserManager.instance.getUser(userId).ifPresent(user ->
|
||||
user.fireCallback(new ClientCallback("replayInit", replay.getGame().getId(), new GameView(replay.next(), replay.getGame(), null, null))));
|
||||
|
||||
}
|
||||
|
@ -77,17 +77,17 @@ public class ReplaySession implements GameCallback {
|
|||
|
||||
@Override
|
||||
public void gameResult(final String result) {
|
||||
UserManager.getInstance().getUser(userId).ifPresent(user ->
|
||||
UserManager.instance.getUser(userId).ifPresent(user ->
|
||||
user.fireCallback(new ClientCallback("replayDone", replay.getGame().getId(), result)));
|
||||
|
||||
ReplayManager.getInstance().endReplay(replay.getGame().getId(), userId);
|
||||
ReplayManager.instance.endReplay(replay.getGame().getId(), userId);
|
||||
}
|
||||
|
||||
private void updateGame(final GameState state, Game game) {
|
||||
if (state == null) {
|
||||
gameResult("game ended");
|
||||
} else {
|
||||
UserManager.getInstance().getUser(userId).ifPresent(user ->
|
||||
UserManager.instance.getUser(userId).ifPresent(user ->
|
||||
user.fireCallback(new ClientCallback("replayUpdate", replay.getGame().getId(), new GameView(state, game, null, null))));
|
||||
|
||||
}
|
||||
|
|
|
@ -17,6 +17,6 @@ public class TableRecorderImpl implements TableRecorder {
|
|||
public void record(Table table) {
|
||||
TableProto proto = table.toProto();
|
||||
TableRecordRepository.instance.add(new TableRecord(proto, proto.getEndTimeMs()));
|
||||
UserManager.getInstance().updateUserHistory();
|
||||
UserManager.instance.updateUserHistory();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ public class TournamentController {
|
|||
|
||||
public TournamentController(Tournament tournament, ConcurrentHashMap<UUID, UUID> userPlayerMap, UUID tableId) {
|
||||
this.userPlayerMap = userPlayerMap;
|
||||
chatId = ChatManager.getInstance().createChatSession("Tournament " + tournament.getId());
|
||||
chatId = ChatManager.instance.createChatSession("Tournament " + tournament.getId());
|
||||
this.tournament = tournament;
|
||||
this.tableId = tableId;
|
||||
init();
|
||||
|
@ -91,7 +91,7 @@ public class TournamentController {
|
|||
checkPlayersState();
|
||||
break;
|
||||
case INFO:
|
||||
ChatManager.getInstance().broadcast(chatId, "", event.getMessage(), MessageColor.BLACK, true, MessageType.STATUS, null);
|
||||
ChatManager.instance.broadcast(chatId, "", event.getMessage(), MessageColor.BLACK, true, MessageType.STATUS, null);
|
||||
logger.debug(tournament.getId() + " " + event.getMessage());
|
||||
break;
|
||||
case START_DRAFT:
|
||||
|
@ -146,7 +146,7 @@ public class TournamentController {
|
|||
if (!player.getPlayer().isHuman()) {
|
||||
player.setJoined();
|
||||
logger.debug("player " + player.getPlayer().getId() + " has joined tournament " + tournament.getId());
|
||||
ChatManager.getInstance().broadcast(chatId, "", player.getPlayer().getLogName() + " has joined the tournament", MessageColor.BLACK, true, MessageType.STATUS, null);
|
||||
ChatManager.instance.broadcast(chatId, "", player.getPlayer().getLogName() + " has joined the tournament", MessageColor.BLACK, true, MessageType.STATUS, null);
|
||||
}
|
||||
}
|
||||
checkStart();
|
||||
|
@ -156,7 +156,7 @@ public class TournamentController {
|
|||
UUID playerId = userPlayerMap.get(userId);
|
||||
if (playerId == null) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
UserManager.getInstance().getUser(userId).ifPresent(user ->
|
||||
UserManager.instance.getUser(userId).ifPresent(user ->
|
||||
logger.debug(user.getName() + " shows tournament panel tournamentId: " + tournament.getId()));
|
||||
|
||||
}
|
||||
|
@ -169,14 +169,14 @@ public class TournamentController {
|
|||
// first join of player
|
||||
TournamentSession tournamentSession = new TournamentSession(tournament, userId, tableId, playerId);
|
||||
tournamentSessions.put(playerId, tournamentSession);
|
||||
Optional<User> _user = UserManager.getInstance().getUser(userId);
|
||||
Optional<User> _user = UserManager.instance.getUser(userId);
|
||||
if (_user.isPresent()) {
|
||||
User user = _user.get();
|
||||
user.addTournament(playerId, tournament.getId());
|
||||
TournamentPlayer player = tournament.getPlayer(playerId);
|
||||
player.setJoined();
|
||||
logger.debug("player " + player.getPlayer().getName() + " - client has joined tournament " + tournament.getId());
|
||||
ChatManager.getInstance().broadcast(chatId, "", player.getPlayer().getLogName() + " has joined the tournament", MessageColor.BLACK, true, MessageType.STATUS, null);
|
||||
ChatManager.instance.broadcast(chatId, "", player.getPlayer().getLogName() + " has joined the tournament", MessageColor.BLACK, true, MessageType.STATUS, null);
|
||||
checkStart();
|
||||
} else {
|
||||
logger.error("User not found userId: " + userId + " tournamentId: " + tournament.getId());
|
||||
|
@ -235,15 +235,15 @@ public class TournamentController {
|
|||
tournamentSession.tournamentOver();
|
||||
}
|
||||
this.tournamentSessions.clear();
|
||||
TableManager.getInstance().endTournament(tableId, tournament);
|
||||
TableManager.instance.endTournament(tableId, tournament);
|
||||
tournament.cleanUpOnTournamentEnd();
|
||||
|
||||
}
|
||||
|
||||
private void startMatch(TournamentPairing pair, MatchOptions matchOptions) {
|
||||
try {
|
||||
TableManager tableManager = TableManager.getInstance();
|
||||
Table table = tableManager.createTable(GamesRoomManager.getInstance().getMainRoomId(), matchOptions);
|
||||
TableManager tableManager = TableManager.instance;
|
||||
Table table = tableManager.createTable(GamesRoomManager.instance.getMainRoomId(), matchOptions);
|
||||
table.setTournamentSubTable(true);
|
||||
table.setTournament(tournament);
|
||||
table.setState(TableState.WAITING);
|
||||
|
@ -266,8 +266,8 @@ public class TournamentController {
|
|||
|
||||
private void startMultiplayerMatch(MultiplayerRound round, MatchOptions matchOptions) {
|
||||
try {
|
||||
TableManager tableManager = TableManager.getInstance();
|
||||
Table table = tableManager.createTable(GamesRoomManager.getInstance().getMainRoomId(), matchOptions);
|
||||
TableManager tableManager = TableManager.instance;
|
||||
Table table = tableManager.createTable(GamesRoomManager.instance.getMainRoomId(), matchOptions);
|
||||
table.setTournamentSubTable(true);
|
||||
table.setTournament(tournament);
|
||||
table.setState(TableState.WAITING);
|
||||
|
@ -290,16 +290,16 @@ public class TournamentController {
|
|||
}
|
||||
|
||||
private void startDraft(Draft draft) {
|
||||
TableManager.getInstance().startDraft(tableId, draft);
|
||||
TableManager.instance.startDraft(tableId, draft);
|
||||
}
|
||||
|
||||
private void construct() {
|
||||
TableManager.getInstance().construct(tableId);
|
||||
TableManager.instance.construct(tableId);
|
||||
}
|
||||
|
||||
private void initTournament() {
|
||||
if (TableManager.getInstance().getTable(tableId).getState() != TableState.DUELING) {
|
||||
TableManager.getInstance().initTournament(tableId);
|
||||
if (TableManager.instance.getTable(tableId).getState() != TableState.DUELING) {
|
||||
TableManager.instance.initTournament(tableId);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -307,7 +307,7 @@ public class TournamentController {
|
|||
if (tournamentSessions.containsKey(playerId)) {
|
||||
TournamentSession tournamentSession = tournamentSessions.get(playerId);
|
||||
tournamentSession.construct(timeout);
|
||||
UserManager.getInstance().getUser(getPlayerUserId(playerId)).get().addConstructing(playerId, tournamentSession);
|
||||
UserManager.instance.getUser(getPlayerUserId(playerId)).get().addConstructing(playerId, tournamentSession);
|
||||
TournamentPlayer player = tournament.getPlayer(playerId);
|
||||
player.setState(TournamentPlayerState.CONSTRUCTING);
|
||||
}
|
||||
|
@ -318,7 +318,7 @@ public class TournamentController {
|
|||
TournamentPlayer player = tournament.getPlayer(playerId);
|
||||
if (player != null && !player.hasQuit()) {
|
||||
tournamentSessions.get(playerId).submitDeck(deck);
|
||||
ChatManager.getInstance().broadcast(chatId, "", player.getPlayer().getLogName() + " has submitted his or her tournament deck", MessageColor.BLACK, true, MessageType.STATUS, SoundToPlay.PlayerSubmittedDeck);
|
||||
ChatManager.instance.broadcast(chatId, "", player.getPlayer().getLogName() + " has submitted his or her tournament deck", MessageColor.BLACK, true, MessageType.STATUS, SoundToPlay.PlayerSubmittedDeck);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -336,7 +336,7 @@ public class TournamentController {
|
|||
tournament.autoSubmit(userPlayerMap.get(userId), tournamentPlayer.generateDeck());
|
||||
} else {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
UserManager.getInstance().getUser(userId).ifPresent(user ->
|
||||
UserManager.instance.getUser(userId).ifPresent(user ->
|
||||
sb.append(user.getName()));
|
||||
|
||||
sb.append(" - no deck found for auto submit");
|
||||
|
@ -378,18 +378,18 @@ public class TournamentController {
|
|||
if (tournament.isDoneConstructing()) {
|
||||
info = new StringBuilder("during round ").append(tournament.getRounds().size()).toString();
|
||||
// quit active matches of that tournament
|
||||
TableManager.getInstance().userQuitTournamentSubTables(tournament.getId(), userId);
|
||||
TableManager.instance.userQuitTournamentSubTables(tournament.getId(), userId);
|
||||
status = TourneyQuitStatus.DURING_ROUND;
|
||||
} else if (tournamentPlayer.getState() == TournamentPlayerState.DRAFTING) {
|
||||
info = "during Draft phase";
|
||||
if (!checkToReplaceDraftPlayerByAi(userId, tournamentPlayer)) {
|
||||
this.abortDraftTournament();
|
||||
} else {
|
||||
DraftController draftController = DraftManager.getInstance().getController(tableId);
|
||||
DraftController draftController = DraftManager.instance.getController(tableId);
|
||||
if (draftController != null) {
|
||||
DraftSession draftSession = draftController.getDraftSession(playerId);
|
||||
if (draftSession != null) {
|
||||
DraftManager.getInstance().kill(draftSession.getDraftId(), userId);
|
||||
DraftManager.instance.kill(draftSession.getDraftId(), userId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -404,7 +404,7 @@ public class TournamentController {
|
|||
tournamentPlayer.setQuit(info, status);
|
||||
tournament.quit(playerId);
|
||||
tournamentSession.quit();
|
||||
ChatManager.getInstance().broadcast(chatId, "", tournamentPlayer.getPlayer().getLogName() + " has quit the tournament", MessageColor.BLACK, true, MessageType.STATUS, SoundToPlay.PlayerQuitTournament);
|
||||
ChatManager.instance.broadcast(chatId, "", tournamentPlayer.getPlayer().getLogName() + " has quit the tournament", MessageColor.BLACK, true, MessageType.STATUS, SoundToPlay.PlayerQuitTournament);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -418,8 +418,8 @@ public class TournamentController {
|
|||
}
|
||||
// replace player that quits with draft bot
|
||||
if (humans > 1) {
|
||||
Optional<User> user = UserManager.getInstance().getUser(userId);
|
||||
TableController tableController = TableManager.getInstance().getController(tableId);
|
||||
Optional<User> user = UserManager.instance.getUser(userId);
|
||||
TableController tableController = TableManager.instance.getController(tableId);
|
||||
if (tableController != null) {
|
||||
String replacePlayerName = "Draftbot";
|
||||
if (user.isPresent()) {
|
||||
|
@ -431,7 +431,7 @@ public class TournamentController {
|
|||
user.get().removeTable(leavingPlayer.getPlayer().getId());
|
||||
user.get().removeTournament(leavingPlayer.getPlayer().getId());
|
||||
}
|
||||
ChatManager.getInstance().broadcast(chatId, "", leavingPlayer.getPlayer().getLogName() + " was replaced by draftbot", MessageColor.BLACK, true, MessageType.STATUS, null);
|
||||
ChatManager.instance.broadcast(chatId, "", leavingPlayer.getPlayer().getLogName() + " was replaced by draftbot", MessageColor.BLACK, true, MessageType.STATUS, null);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -453,7 +453,7 @@ public class TournamentController {
|
|||
|
||||
private void abortDraftTournament() {
|
||||
tournament.setAbort(true);
|
||||
DraftManager.getInstance().getController(tableId).abortDraft();
|
||||
DraftManager.instance.getController(tableId).abortDraft();
|
||||
}
|
||||
|
||||
public boolean isAbort() {
|
||||
|
@ -478,7 +478,7 @@ public class TournamentController {
|
|||
}
|
||||
|
||||
public void cleanUpOnRemoveTournament() {
|
||||
ChatManager.getInstance().destroyChatSession(chatId);
|
||||
ChatManager.instance.destroyChatSession(chatId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -496,7 +496,7 @@ public class TournamentController {
|
|||
if (tournamentPlayer != null) {
|
||||
if (!tournamentPlayer.hasQuit()) {
|
||||
if (tournamentPlayer.getPlayer().isHuman()) {
|
||||
Optional<User> user = UserManager.getInstance().getUser(entry.getKey());
|
||||
Optional<User> user = UserManager.instance.getUser(entry.getKey());
|
||||
if (!user.isPresent()) {
|
||||
logger.debug("Tournament user is missing but player active -> start quit - tournamentId: " + tournament.getId() + " state: " + tableState.toString());
|
||||
// active tournament player but the user is no longer online
|
||||
|
|
|
@ -30,25 +30,19 @@ package mage.server.tournament;
|
|||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
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 class TournamentManager {
|
||||
|
||||
private static final TournamentManager INSTANCE = new TournamentManager();
|
||||
|
||||
public enum TournamentManager {
|
||||
instance;
|
||||
private final ConcurrentHashMap<UUID, TournamentController> controllers = new ConcurrentHashMap<>();
|
||||
|
||||
public static TournamentManager getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public TournamentController getTournamentController(UUID tournamentId) {
|
||||
return controllers.get(tournamentId);
|
||||
}
|
||||
|
@ -84,7 +78,7 @@ public class TournamentManager {
|
|||
}
|
||||
|
||||
public TournamentView getTournamentView(UUID tournamentId) {
|
||||
TournamentController tournamentController = controllers.get(tournamentId);
|
||||
TournamentController tournamentController = controllers.get(tournamentId);
|
||||
if (tournamentController != null) {
|
||||
return tournamentController.getTournamentView();
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ public class TournamentSession {
|
|||
|
||||
public boolean init() {
|
||||
if (!killed) {
|
||||
Optional<User> user = UserManager.getInstance().getUser(userId);
|
||||
Optional<User> user = UserManager.instance.getUser(userId);
|
||||
if (user.isPresent()) {
|
||||
user.get().fireCallback(new ClientCallback("tournamentInit", tournament.getId(), getTournamentView()));
|
||||
return true;
|
||||
|
@ -78,7 +78,7 @@ public class TournamentSession {
|
|||
|
||||
public void update() {
|
||||
if (!killed) {
|
||||
UserManager.getInstance().getUser(userId).ifPresent(user ->
|
||||
UserManager.instance.getUser(userId).ifPresent(user ->
|
||||
user.fireCallback(new ClientCallback("tournamentUpdate", tournament.getId(), getTournamentView())));
|
||||
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ public class TournamentSession {
|
|||
|
||||
public void gameOver(final String message) {
|
||||
if (!killed) {
|
||||
UserManager.getInstance().getUser(userId).ifPresent(user ->
|
||||
UserManager.instance.getUser(userId).ifPresent(user ->
|
||||
user.fireCallback(new ClientCallback("tournamentOver", tournament.getId(), message)));
|
||||
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ public class TournamentSession {
|
|||
public void construct(int timeout) {
|
||||
if (!killed) {
|
||||
setupTimeout(timeout);
|
||||
UserManager.getInstance().getUser(userId).ifPresent(user -> {
|
||||
UserManager.instance.getUser(userId).ifPresent(user -> {
|
||||
int remaining = (int) futureTimeout.getDelay(TimeUnit.SECONDS);
|
||||
user.ccConstruct(tournament.getPlayer(playerId).getDeck(), tableId, remaining);
|
||||
});
|
||||
|
@ -128,7 +128,7 @@ public class TournamentSession {
|
|||
futureTimeout = timeoutExecutor.schedule(
|
||||
() -> {
|
||||
try {
|
||||
TournamentManager.getInstance().timeout(tournament.getId(), userId);
|
||||
TournamentManager.instance.timeout(tournament.getId(), userId);
|
||||
} catch (Exception e) {
|
||||
logger.fatal("TournamentSession error - userId " + userId + " tId " + tournament.getId(), e);
|
||||
}
|
||||
|
@ -170,7 +170,7 @@ public class TournamentSession {
|
|||
}
|
||||
|
||||
private void removeTournamentForUser() {
|
||||
UserManager.getInstance().getUser(userId).ifPresent(user ->
|
||||
UserManager.instance.getUser(userId).ifPresent(user ->
|
||||
user.removeTournament(playerId));
|
||||
|
||||
|
||||
|
|
|
@ -33,27 +33,23 @@ import java.util.List;
|
|||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
|
||||
import mage.server.util.config.Config;
|
||||
import mage.server.util.config.GamePlugin;
|
||||
import mage.server.util.config.Plugin;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class ConfigSettings {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(ConfigSettings.class);
|
||||
private static final ConfigSettings INSTANCE = new ConfigSettings();
|
||||
public enum ConfigSettings {
|
||||
instance;
|
||||
private final Logger logger = Logger.getLogger(ConfigSettings.class);
|
||||
|
||||
private Config config;
|
||||
|
||||
public static ConfigSettings getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private ConfigSettings() {
|
||||
ConfigSettings() {
|
||||
try {
|
||||
JAXBContext jaxbContext = JAXBContext.newInstance("mage.server.util.config");
|
||||
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
|
||||
|
|
|
@ -48,13 +48,11 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
|
|||
*
|
||||
* @author nantuko
|
||||
*/
|
||||
public class ServerMessagesUtil {
|
||||
|
||||
private static final ServerMessagesUtil instance = new ServerMessagesUtil();
|
||||
|
||||
public enum ServerMessagesUtil {
|
||||
instance;
|
||||
private static final Logger log = Logger.getLogger(ServerMessagesUtil.class);
|
||||
private static final String SERVER_MSG_TXT_FILE = "server.msg.txt";
|
||||
private static ScheduledExecutorService updateExecutor;
|
||||
private ScheduledExecutorService updateExecutor;
|
||||
|
||||
private final List<String> messages = new ArrayList<>();
|
||||
private final ReadWriteLock lock = new ReentrantReadWriteLock();
|
||||
|
@ -73,14 +71,12 @@ public class ServerMessagesUtil {
|
|||
pathToExternalMessages = System.getProperty("messagesPath");
|
||||
}
|
||||
|
||||
public ServerMessagesUtil() {
|
||||
ServerMessagesUtil() {
|
||||
updateExecutor = Executors.newSingleThreadScheduledExecutor();
|
||||
updateExecutor.scheduleAtFixedRate(this::reloadMessages, 5, 5 * 60, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
public static ServerMessagesUtil getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
public List<String> getMessages() {
|
||||
lock.readLock().lock();
|
||||
|
|
|
@ -42,7 +42,7 @@ public class ThreadExecutor {
|
|||
|
||||
private static final ExecutorService callExecutor = Executors.newCachedThreadPool();
|
||||
private static final ExecutorService userExecutor = Executors.newCachedThreadPool();
|
||||
private static final ExecutorService gameExecutor = Executors.newFixedThreadPool(ConfigSettings.getInstance().getMaxGameThreads());
|
||||
private static final ExecutorService gameExecutor = Executors.newFixedThreadPool(ConfigSettings.instance.getMaxGameThreads());
|
||||
private static final ScheduledExecutorService timeoutExecutor = Executors.newScheduledThreadPool(4);
|
||||
private static final ScheduledExecutorService timeoutIdleExecutor = Executors.newScheduledThreadPool(4);
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ public class AbzanBeastmaster extends CardImpl {
|
|||
// At the beginning of your upkeep, draw a card if you control the creature with the greatest toughness or tied for the greatest toughness.
|
||||
this.addAbility(new ConditionalTriggeredAbility(
|
||||
new BeginningOfUpkeepTriggeredAbility(new DrawCardSourceControllerEffect(1), TargetController.YOU, false),
|
||||
ControlsCreatureGreatestToughnessCondition.getInstance(),
|
||||
ControlsCreatureGreatestToughnessCondition.instance,
|
||||
"At the beginning of your upkeep, draw a card if you control the creature with the greatest toughness or tied for the greatest toughness."
|
||||
));
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ public class AetherFigment extends CardImpl {
|
|||
// If Aether Figment was kicked, it enters the battlefield with two +1/+1 counters on it
|
||||
Ability ability = new EntersBattlefieldAbility(
|
||||
new AddCountersSourceEffect(CounterType.P1P1.createInstance(2)),
|
||||
KickedCondition.getInstance(),
|
||||
KickedCondition.instance,
|
||||
"If {this} was kicked, it enters the battlefield with two +1/+1 counters on it",
|
||||
"");
|
||||
this.addAbility(ability);
|
||||
|
|
|
@ -61,7 +61,7 @@ public class AfflictedDeserter extends CardImpl {
|
|||
// At the beginning of each upkeep, if no spells were cast last turn, transform Afflicted Deserter.
|
||||
this.addAbility(new TransformAbility());
|
||||
TriggeredAbility ability = new BeginningOfUpkeepTriggeredAbility(new TransformSourceEffect(true), TargetController.ANY, false);
|
||||
this.addAbility(new ConditionalTriggeredAbility(ability, NoSpellsWereCastLastTurnCondition.getInstance(), TransformAbility.NO_SPELLS_TRANSFORM_RULE));
|
||||
this.addAbility(new ConditionalTriggeredAbility(ability, NoSpellsWereCastLastTurnCondition.instance, TransformAbility.NO_SPELLS_TRANSFORM_RULE));
|
||||
}
|
||||
|
||||
public AfflictedDeserter(final AfflictedDeserter card) {
|
||||
|
|
|
@ -67,7 +67,7 @@ public class AgonizingDemise extends CardImpl {
|
|||
//If Agonizing Demise was kicked, it deals damage equal to that creature's power to the creature's controller.
|
||||
this.getSpellAbility().addEffect(new ConditionalOneShotEffect(
|
||||
new DamageTargetControllerEffect(new TargetPermanentPowerCount()),
|
||||
KickedCondition.getInstance(),
|
||||
KickedCondition.instance,
|
||||
"If {this} was kicked, it deals damage equal to that creature's power to the creature's controller."));
|
||||
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ public class AidFromTheCowl extends CardImpl {
|
|||
// <i>Revolt</i> — At the beginning of your end step, if a permanent you controlled left the battlefield this turn,
|
||||
// reveal the top card of your library. If it is a permanent card, you may put it onto the battlefield. Otherwise, put it on the bottom of your library.
|
||||
TriggeredAbility ability = new BeginningOfYourEndStepTriggeredAbility(new AidFromTheCowlEffect(), false);
|
||||
this.addAbility(new ConditionalTriggeredAbility(ability, RevoltCondition.getInstance(), ruleText), new RevoltWatcher());
|
||||
this.addAbility(new ConditionalTriggeredAbility(ability, RevoltCondition.instance, ruleText), new RevoltWatcher());
|
||||
}
|
||||
|
||||
public AidFromTheCowl(final AidFromTheCowl card) {
|
||||
|
|
|
@ -60,7 +60,7 @@ public class AirdropAeronauts extends CardImpl {
|
|||
|
||||
// <i>Revolt</i> — When Airdrop Aeronauts enters the battlefield, if a permanent you controlled left the battlefield this turn, you gain 5 life.
|
||||
Ability ability = new ConditionalTriggeredAbility(new EntersBattlefieldTriggeredAbility(
|
||||
new GainLifeEffect(5), false), RevoltCondition.getInstance(),
|
||||
new GainLifeEffect(5), false), RevoltCondition.instance,
|
||||
"<i>Revolt</i> — When {this} enters the battlefield, if a permanent you controlled left"
|
||||
+ " the battlefield this turn, you gain 5 life."
|
||||
);
|
||||
|
|
|
@ -57,7 +57,7 @@ public class Aleatory extends CardImpl {
|
|||
super(ownerId,setInfo,new CardType[]{CardType.INSTANT},"{1}{R}");
|
||||
|
||||
// Cast Aleatory only during combat after blockers are declared.
|
||||
this.addAbility(new CastOnlyDuringPhaseStepSourceAbility(TurnPhase.COMBAT, AfterBlockersAreDeclaredCondition.getInstance()));
|
||||
this.addAbility(new CastOnlyDuringPhaseStepSourceAbility(TurnPhase.COMBAT, AfterBlockersAreDeclaredCondition.instance));
|
||||
|
||||
// Flip a coin. If you win the flip, target creature gets +1/+1 until end of turn.
|
||||
this.getSpellAbility().addEffect(new AleatoryEffect());
|
||||
|
|
|
@ -102,7 +102,7 @@ class AlurenRuleEffect extends ContinuousEffectImpl {
|
|||
filter.add(new ConvertedManaCostPredicate(ComparisonType.LessThan, 4));
|
||||
}
|
||||
|
||||
static AlternativeCostSourceAbility alternativeCastingCostAbility = new AlternativeCostSourceAbility(null, SourceIsSpellCondition.getInstance(), null, filter, true);
|
||||
static AlternativeCostSourceAbility alternativeCastingCostAbility = new AlternativeCostSourceAbility(null, SourceIsSpellCondition.instance, null, filter, true);
|
||||
|
||||
public AlurenRuleEffect() {
|
||||
super(Duration.WhileOnBattlefield, Outcome.Detriment);
|
||||
|
|
|
@ -73,7 +73,7 @@ public class AngelOfDeliverance extends CardImpl {
|
|||
// exile target creature an opponent controls.
|
||||
Ability ability = new ConditionalTriggeredAbility(
|
||||
new AngelOfDeliveranceDealsDamageTriggeredAbility(),
|
||||
new DeliriumCondition(),
|
||||
DeliriumCondition.instance,
|
||||
"<i>Delirium</i> — Whenever {this} deals damage, if there are four or more card types among cards in your graveyard, exile target creature an opponent controls"
|
||||
);
|
||||
ability.addTarget(new TargetCreaturePermanent(filter));
|
||||
|
|
|
@ -72,7 +72,7 @@ public class AngryMob extends CardImpl {
|
|||
PermanentsOnBattlefieldCount swamps = new PermanentsOnBattlefieldCount(filter);
|
||||
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new ConditionalContinuousEffect(
|
||||
new BoostSourceEffect(swamps, swamps, Duration.WhileOnBattlefield),
|
||||
MyTurnCondition.getInstance(),
|
||||
MyTurnCondition.instance,
|
||||
"As long as it's your turn, Angry Mob's power and toughness are each equal to 2 plus the number of Swamps your opponents control. As long as it's not your turn, Angry Mob's power and toughness are each 2")));
|
||||
|
||||
}
|
||||
|
|
|
@ -83,10 +83,10 @@ public class AngusMackenzie extends CardImpl {
|
|||
}
|
||||
|
||||
class BeforeCombatDamageCondition implements Condition {
|
||||
private static final BeforeCombatDamageCondition fInstance = new BeforeCombatDamageCondition();
|
||||
private static final BeforeCombatDamageCondition instance = new BeforeCombatDamageCondition();
|
||||
|
||||
public static Condition getInstance() {
|
||||
return fInstance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -103,7 +103,7 @@ class AnimistsAwakeningEffect extends OneShotEffect {
|
|||
controller.moveCards(toBattlefield, Zone.BATTLEFIELD, source, game, true, false, true, null);
|
||||
controller.putCardsOnBottomOfLibrary(cards, game, source, true);
|
||||
|
||||
if (SpellMasteryCondition.getInstance().apply(game, source)) {
|
||||
if (SpellMasteryCondition.instance.apply(game, source)) {
|
||||
for (Card card : toBattlefield) {
|
||||
Permanent land = game.getPermanent(card.getId());
|
||||
if (land != null) {
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
package mage.cards.a;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.common.AttacksCreatureYouControlTriggeredAbility;
|
||||
import mage.abilities.common.SimpleStaticAbility;
|
||||
|
@ -46,13 +47,12 @@ import mage.game.Game;
|
|||
import mage.game.events.GameEvent;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JotaPeRL
|
||||
*/
|
||||
public class AnthemOfRakdos extends CardImpl {
|
||||
|
||||
public AnthemOfRakdos(UUID ownerId, CardSetInfo setInfo) {
|
||||
super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{2}{B}{R}{R}");
|
||||
super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{2}{B}{R}{R}");
|
||||
|
||||
// Whenever a creature you control attacks, it gets +2/+0 until end of turn and Anthem of Rakdos deals 1 damage to you.
|
||||
Effect effect = new BoostTargetEffect(2, 0, Duration.EndOfTurn);
|
||||
|
@ -101,7 +101,7 @@ class AnthemOfRakdosHellbentEffect extends ReplacementEffectImpl {
|
|||
|
||||
@Override
|
||||
public boolean applies(GameEvent event, Ability source, Game game) {
|
||||
return game.getControllerId(event.getSourceId()).equals(source.getControllerId()) && HellbentCondition.getInstance().apply(game, source);
|
||||
return game.getControllerId(event.getSourceId()).equals(source.getControllerId()) && HellbentCondition.instance.apply(game, source);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -73,7 +73,7 @@ public class AnyaMercilessAngel extends CardImpl {
|
|||
// As long as an opponent's life total is less than half his or her starting life total, Anya has indestructible.
|
||||
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD,
|
||||
new ConditionalContinuousEffect(new GainAbilitySourceEffect(IndestructibleAbility.getInstance(), Duration.WhileOnBattlefield),
|
||||
AnyaMercilessAngelCondition.getInstance(),
|
||||
AnyaMercilessAngelCondition.instance,
|
||||
"As long as an opponent's life total is less than half his or her starting life total, {this} has indestructible")));
|
||||
}
|
||||
|
||||
|
@ -121,16 +121,9 @@ class AnyaMercilessAngelDynamicValue implements DynamicValue {
|
|||
}
|
||||
}
|
||||
|
||||
class AnyaMercilessAngelCondition implements Condition {
|
||||
|
||||
private static final AnyaMercilessAngelCondition fInstance = new AnyaMercilessAngelCondition();
|
||||
|
||||
public static AnyaMercilessAngelCondition getInstance() {
|
||||
return fInstance;
|
||||
}
|
||||
|
||||
private AnyaMercilessAngelCondition() {}
|
||||
enum AnyaMercilessAngelCondition implements Condition {
|
||||
|
||||
instance;
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
return new AnyaMercilessAngelDynamicValue().calculate(game, source, null) > 0;
|
||||
|
|
|
@ -84,14 +84,14 @@ public class ArcTrail extends CardImpl {
|
|||
|
||||
class ArcTrailEffect extends OneShotEffect {
|
||||
|
||||
private static final ArcTrailEffect fINSTANCE = new ArcTrailEffect();
|
||||
private static final ArcTrailEffect instance = new ArcTrailEffect();
|
||||
|
||||
private Object readResolve() throws ObjectStreamException {
|
||||
return fINSTANCE;
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static ArcTrailEffect getInstance() {
|
||||
return fINSTANCE;
|
||||
return instance;
|
||||
}
|
||||
|
||||
private ArcTrailEffect ( ) {
|
||||
|
@ -128,7 +128,7 @@ class ArcTrailEffect extends OneShotEffect {
|
|||
|
||||
@Override
|
||||
public Effect copy() {
|
||||
return fINSTANCE;
|
||||
return instance;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -113,10 +113,10 @@ class ArchiveTrapWatcher extends Watcher {
|
|||
|
||||
class OpponentSearchesLibCondition implements Condition {
|
||||
|
||||
private static final OpponentSearchesLibCondition fInstance = new OpponentSearchesLibCondition();
|
||||
private static final OpponentSearchesLibCondition instance = new OpponentSearchesLibCondition();
|
||||
|
||||
public static Condition getInstance() {
|
||||
return fInstance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -60,7 +60,7 @@ public class ArcticMerfolk extends CardImpl {
|
|||
// If Arctic Merfolk was kicked, it enters the battlefield with a +1/+1 counter on it.
|
||||
this.addAbility(new EntersBattlefieldAbility(
|
||||
new AddCountersSourceEffect(CounterType.P1P1.createInstance()),
|
||||
KickedCondition.getInstance(),"If Arctic Merfolk was kicked, it enters the battlefield with a +1/+1 counter on it.",""));
|
||||
KickedCondition.instance,"If Arctic Merfolk was kicked, it enters the battlefield with a +1/+1 counter on it.",""));
|
||||
}
|
||||
|
||||
public ArcticMerfolk(final ArcticMerfolk card) {
|
||||
|
|
|
@ -57,7 +57,7 @@ public class ArdentRecruit extends CardImpl {
|
|||
this.power = new MageInt(1);
|
||||
this.toughness = new MageInt(1);
|
||||
ContinuousEffect boostSource = new BoostSourceEffect(2, 2, Duration.WhileOnBattlefield);
|
||||
ConditionalContinuousEffect effect = new ConditionalContinuousEffect(boostSource, MetalcraftCondition.getInstance(), "Ardent Recruit gets +2/+2 as long as you control three or more artifacts");
|
||||
ConditionalContinuousEffect effect = new ConditionalContinuousEffect(boostSource, MetalcraftCondition.instance, "Ardent Recruit gets +2/+2 as long as you control three or more artifacts");
|
||||
Ability ability = new SimpleStaticAbility(Zone.BATTLEFIELD, effect);
|
||||
ability.setAbilityWord(AbilityWord.METALCRAFT);
|
||||
this.addAbility(ability);
|
||||
|
|
|
@ -59,7 +59,7 @@ public class ArdentSoldier extends CardImpl {
|
|||
this.addAbility(VigilanceAbility.getInstance());
|
||||
// If Ardent Soldier was kicked, it enters the battlefield with a +1/+1 counter on it.
|
||||
this.addAbility(new EntersBattlefieldAbility(new AddCountersSourceEffect(CounterType.P1P1.createInstance(1)),
|
||||
KickedCondition.getInstance(), "If {this} was kicked, it enters the battlefield with a +1/+1 counter on it.", ""));
|
||||
KickedCondition.instance, "If {this} was kicked, it enters the battlefield with a +1/+1 counter on it.", ""));
|
||||
}
|
||||
|
||||
public ArdentSoldier(final ArdentSoldier card) {
|
||||
|
|
|
@ -66,7 +66,7 @@ public class ArgentSphinx extends CardImpl {
|
|||
this.addAbility(FlyingAbility.getInstance());
|
||||
|
||||
// Metalcraft - {U}: Exile Argent Sphinx. Return it to the battlefield under your control at the beginning of the next end step. Activate this ability only if you control three or more artifacts.
|
||||
Ability ability = new ActivateIfConditionActivatedAbility(Zone.BATTLEFIELD, new ArgentSphinxEffect(), new ManaCostsImpl("{U}"), MetalcraftCondition.getInstance());
|
||||
Ability ability = new ActivateIfConditionActivatedAbility(Zone.BATTLEFIELD, new ArgentSphinxEffect(), new ManaCostsImpl("{U}"), MetalcraftCondition.instance);
|
||||
ability.setAbilityWord(AbilityWord.METALCRAFT);
|
||||
this.addAbility(ability);
|
||||
}
|
||||
|
|
|
@ -51,13 +51,13 @@ public class ArrowStorm extends CardImpl {
|
|||
// Arrow Storm deals 4 damage to target creature or player.
|
||||
this.getSpellAbility().addEffect(new ConditionalOneShotEffect(
|
||||
new DamageTargetEffect(4),
|
||||
new InvertCondition(RaidCondition.getInstance()),
|
||||
new InvertCondition(RaidCondition.instance),
|
||||
"{this} deals 4 damage to target creature or player"));
|
||||
this.getSpellAbility().addTarget(new TargetCreatureOrPlayer());
|
||||
// Raid - If you attacked with a creature this turn, instead Arrow Storm deals 5 damage to that creature or player and the damage can't be prevented.
|
||||
this.getSpellAbility().addEffect(new ConditionalOneShotEffect(
|
||||
new DamageTargetEffect(5, false),
|
||||
RaidCondition.getInstance(),
|
||||
RaidCondition.instance,
|
||||
"<br/><br/><i>Raid</i> - If you attacked with a creature this turn, instead {this} deals 5 damage to that creature or player and the damage can't be prevented"));
|
||||
this.getSpellAbility().addWatcher(new PlayerAttackedWatcher());
|
||||
}
|
||||
|
|
|
@ -70,10 +70,10 @@ public class ArrowVolleyTrap extends CardImpl {
|
|||
|
||||
class ArrowVolleyTrapCondition implements Condition {
|
||||
|
||||
private static final ArrowVolleyTrapCondition fInstance = new ArrowVolleyTrapCondition();
|
||||
private static final ArrowVolleyTrapCondition instance = new ArrowVolleyTrapCondition();
|
||||
|
||||
public static Condition getInstance() {
|
||||
return fInstance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
package mage.cards.a;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import mage.MageInt;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.common.AttacksTriggeredAbility;
|
||||
|
@ -47,13 +48,12 @@ import mage.target.common.TargetCreaturePermanent;
|
|||
import mage.watchers.common.LifeLossOtherFromCombatWatcher;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Styxo
|
||||
*/
|
||||
public class AsajjVentress extends CardImpl {
|
||||
|
||||
public AsajjVentress(UUID ownerId, CardSetInfo setInfo) {
|
||||
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{1}{U}{B}{R}");
|
||||
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{1}{U}{B}{R}");
|
||||
this.supertype.add("Legendary");
|
||||
this.subtype.add("Dathomirian");
|
||||
this.subtype.add("Sith");
|
||||
|
@ -72,7 +72,7 @@ public class AsajjVentress extends CardImpl {
|
|||
// <i>Hate</i> — Whenever Asajj Ventress attacks, if an opponent lost life from a source other than combat damage this turn, target creature blocks this turn if able.
|
||||
Ability ability = new ConditionalTriggeredAbility(
|
||||
new AttacksTriggeredAbility(new BlocksIfAbleTargetEffect(Duration.EndOfTurn), false),
|
||||
HateCondition.getInstance(),
|
||||
HateCondition.instance,
|
||||
"<i>Hate</i> — Whenever Asajj Ventress attacks, if an opponent lost life from a source other than combat damage this turn, target creature blocks this turn if able");
|
||||
ability.addTarget(new TargetCreaturePermanent());
|
||||
this.addAbility(ability, new LifeLossOtherFromCombatWatcher());
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
package mage.cards.a;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.common.SimpleActivatedAbility;
|
||||
import mage.abilities.common.SkipUntapOptionalAbility;
|
||||
|
@ -44,20 +45,19 @@ import mage.constants.Zone;
|
|||
import mage.target.common.TargetControlledCreaturePermanent;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LoneFox
|
||||
*/
|
||||
public class AshnodsBattleGear extends CardImpl {
|
||||
|
||||
public AshnodsBattleGear(UUID ownerId, CardSetInfo setInfo) {
|
||||
super(ownerId,setInfo,new CardType[]{CardType.ARTIFACT},"{2}");
|
||||
super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT}, "{2}");
|
||||
|
||||
// You may choose not to untap Ashnod's Battle Gear during your untap step.
|
||||
this.addAbility(new SkipUntapOptionalAbility());
|
||||
// {2}, {tap}: Target creature you control gets +2/-2 for as long as Ashnod's Battle Gear remains tapped.
|
||||
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new ConditionalContinuousEffect(
|
||||
new BoostTargetEffect(2, -2, Duration.Custom), SourceTappedCondition.getInstance(),
|
||||
"target creature you control gets +2/-2 for as long as {this} remains tapped"), new ManaCostsImpl("{2}"));
|
||||
new BoostTargetEffect(2, -2, Duration.Custom), SourceTappedCondition.instance,
|
||||
"target creature you control gets +2/-2 for as long as {this} remains tapped"), new ManaCostsImpl("{2}"));
|
||||
ability.addCost(new TapSourceCost());
|
||||
ability.addTarget(new TargetControlledCreaturePermanent());
|
||||
this.addAbility(ability);
|
||||
|
|
|
@ -59,7 +59,7 @@ public class AtarkaBeastbreaker extends CardImpl {
|
|||
Zone.BATTLEFIELD,
|
||||
new BoostSourceEffect(4,4, Duration.EndOfTurn),
|
||||
new ManaCostsImpl("{4}{G}"),
|
||||
FormidableCondition.getInstance());
|
||||
FormidableCondition.instance);
|
||||
ability.setAbilityWord(AbilityWord.FORMIDABLE);
|
||||
this.addAbility(ability);
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ public class AtarkaPummeler extends CardImpl {
|
|||
Zone.BATTLEFIELD,
|
||||
new GainAbilityAllEffect(new MenaceAbility(), Duration.EndOfTurn, filter),
|
||||
new ManaCostsImpl("{3}{R}{R}"),
|
||||
FormidableCondition.getInstance());
|
||||
FormidableCondition.instance);
|
||||
ability.setAbilityWord(AbilityWord.FORMIDABLE);
|
||||
this.addAbility(ability);
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ public class AuriokEdgewright extends CardImpl {
|
|||
this.toughness = new MageInt(2);
|
||||
|
||||
ContinuousEffect effect = new GainAbilitySourceEffect(DoubleStrikeAbility.getInstance(), Duration.WhileOnBattlefield);
|
||||
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new ConditionalContinuousEffect(effect, MetalcraftCondition.getInstance(), effectText)));
|
||||
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new ConditionalContinuousEffect(effect, MetalcraftCondition.instance, effectText)));
|
||||
}
|
||||
|
||||
public AuriokEdgewright(final AuriokEdgewright card) {
|
||||
|
|
|
@ -60,9 +60,9 @@ public class AuriokSunchaser extends CardImpl {
|
|||
this.toughness = new MageInt(1);
|
||||
|
||||
ContinuousEffect effect1 = new BoostSourceEffect(2, 2, Duration.WhileOnBattlefield);
|
||||
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new ConditionalContinuousEffect(effect1, MetalcraftCondition.getInstance(), effect1Text)));
|
||||
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new ConditionalContinuousEffect(effect1, MetalcraftCondition.instance, effect1Text)));
|
||||
ContinuousEffect effect2 = new GainAbilitySourceEffect(FlyingAbility.getInstance(), Duration.WhileOnBattlefield);
|
||||
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new ConditionalContinuousEffect(effect2, MetalcraftCondition.getInstance(), effect2Text)));
|
||||
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new ConditionalContinuousEffect(effect2, MetalcraftCondition.instance, effect2Text)));
|
||||
}
|
||||
|
||||
public AuriokSunchaser(final AuriokSunchaser card) {
|
||||
|
|
|
@ -59,7 +59,7 @@ public class AutumnalGloom extends CardImpl {
|
|||
|
||||
// <i>Delirium</i> — At the beginning of your end step, if there are four or more card types among cards in your graveyard, transform Autumnal Gloom.
|
||||
this.addAbility(new TransformAbility());
|
||||
Ability ability = new BeginningOfEndStepTriggeredAbility(Zone.BATTLEFIELD, new TransformSourceEffect(true), TargetController.YOU, DeliriumCondition.getInstance(), false);
|
||||
Ability ability = new BeginningOfEndStepTriggeredAbility(Zone.BATTLEFIELD, new TransformSourceEffect(true), TargetController.YOU, DeliriumCondition.instance, false);
|
||||
ability.setAbilityWord(AbilityWord.DELIRIUM);
|
||||
this.addAbility(ability);
|
||||
}
|
||||
|
|
|
@ -56,9 +56,9 @@ public class BackwoodsSurvivalists extends CardImpl {
|
|||
this.toughness = new MageInt(3);
|
||||
|
||||
// <i>Delirium</i> — Backwoods Survivalists gets +1/+1 and has trample as long as there are four or more card types among cards in your graveyard.
|
||||
ConditionalContinuousEffect effect = new ConditionalContinuousEffect(new BoostSourceEffect(1, 1, Duration.WhileOnBattlefield), DeliriumCondition.getInstance(), "<i>Delirium</i> — {this} gets +1/+1");
|
||||
ConditionalContinuousEffect effect = new ConditionalContinuousEffect(new BoostSourceEffect(1, 1, Duration.WhileOnBattlefield), DeliriumCondition.instance, "<i>Delirium</i> — {this} gets +1/+1");
|
||||
Ability ability = new SimpleStaticAbility(Zone.BATTLEFIELD, effect);
|
||||
ability.addEffect(new ConditionalContinuousEffect(new GainAbilitySourceEffect(TrampleAbility.getInstance()), DeliriumCondition.getInstance(), "and has trample as long as there are four or more card types among cards in your graveyard."));
|
||||
ability.addEffect(new ConditionalContinuousEffect(new GainAbilitySourceEffect(TrampleAbility.getInstance()), DeliriumCondition.instance, "and has trample as long as there are four or more card types among cards in your graveyard."));
|
||||
this.addAbility(ability);
|
||||
}
|
||||
|
||||
|
|
|
@ -71,10 +71,10 @@ public class BalothCageTrap extends CardImpl {
|
|||
|
||||
class BalothCageTrapCondition implements Condition {
|
||||
|
||||
private static final BalothCageTrapCondition fInstance = new BalothCageTrapCondition();
|
||||
private static final BalothCageTrapCondition instance = new BalothCageTrapCondition();
|
||||
|
||||
public static Condition getInstance() {
|
||||
return fInstance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -64,7 +64,7 @@ public class BaneOfHanweir extends CardImpl {
|
|||
|
||||
// At the beginning of each upkeep, if a player cast two or more spells last turn, transform Bane of Hanweir.
|
||||
TriggeredAbility ability = new BeginningOfUpkeepTriggeredAbility(new TransformSourceEffect(false), TargetController.ANY, false);
|
||||
this.addAbility(new ConditionalTriggeredAbility(ability, TwoOrMoreSpellsWereCastLastTurnCondition.getInstance(), TransformAbility.TWO_OR_MORE_SPELLS_TRANSFORM_RULE));
|
||||
this.addAbility(new ConditionalTriggeredAbility(ability, TwoOrMoreSpellsWereCastLastTurnCondition.instance, TransformAbility.TWO_OR_MORE_SPELLS_TRANSFORM_RULE));
|
||||
}
|
||||
|
||||
public BaneOfHanweir(final BaneOfHanweir card) {
|
||||
|
|
|
@ -64,7 +64,7 @@ public class BarrageOfBoulders extends CardImpl {
|
|||
Effect effect = new ConditionalRestrictionEffect(
|
||||
Duration.EndOfTurn,
|
||||
new CantBlockAllEffect(new FilterCreaturePermanent("creatures"), Duration.EndOfTurn),
|
||||
new LockedInCondition(FerociousCondition.getInstance()), null);
|
||||
new LockedInCondition(FerociousCondition.instance), null);
|
||||
effect.setText("<br/><i>Ferocious</i> — If you control a creature with power 4 or greater, creatures can't block this turn");
|
||||
this.getSpellAbility().addEffect(effect);
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ public class BatheInBacta extends CardImpl {
|
|||
// You gain 6 life. If you lost life from a source other than combat damage this turn, you gain 9 life instead.
|
||||
this.getSpellAbility().addEffect(new ConditionalOneShotEffect(
|
||||
new GainLifeEffect(6), new GainLifeEffect(9),
|
||||
new InvertCondition(HateCondition.getInstance()),
|
||||
new InvertCondition(HateCondition.instance),
|
||||
"You gain 6 life. If you lost life from a source other than combat damage this turn, you gain 9 life instead"));
|
||||
this.getSpellAbility().addWatcher(new LifeLossOtherFromCombatWatcher());
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ public class BellowingSaddlebrute extends CardImpl {
|
|||
// Raid - When Bellowing Saddlebrute enters the battlefield, you lose 4 life unless you attacked with a creature this turn
|
||||
this.addAbility(new ConditionalTriggeredAbility(
|
||||
new EntersBattlefieldTriggeredAbility(new LoseLifeSourceControllerEffect(4)),
|
||||
new InvertCondition(RaidCondition.getInstance()),
|
||||
new InvertCondition(RaidCondition.instance),
|
||||
"<i>Raid</i> - When {this} enters the battlefield, you lose 4 life unless you attacked with a creature this turn"
|
||||
), new PlayerAttackedWatcher());
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ public class BenalishEmissary extends CardImpl {
|
|||
// When Benalish Emissary enters the battlefield, if it was kicked, destroy target land.
|
||||
TriggeredAbility ability = new EntersBattlefieldTriggeredAbility(new DestroyTargetEffect());
|
||||
ability.addTarget(new TargetLandPermanent());
|
||||
this.addAbility(new ConditionalTriggeredAbility(ability, KickedCondition.getInstance(),
|
||||
this.addAbility(new ConditionalTriggeredAbility(ability, KickedCondition.instance,
|
||||
"When {this} enters the battlefield, if it was kicked, destroy target land."));
|
||||
}
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ public class BenalishLancer extends CardImpl {
|
|||
|
||||
// If Benalish Lancer was kicked, it enters the battlefield with two +1/+1 counters on it and with first strike.
|
||||
Ability ability = new EntersBattlefieldAbility(new AddCountersSourceEffect(CounterType.P1P1.createInstance(2)),
|
||||
KickedCondition.getInstance(),
|
||||
KickedCondition.instance,
|
||||
"If {this} was kicked, it enters the battlefield with two +1/+1 counters on it and with first strike.", "");
|
||||
ability.addEffect(new GainAbilitySourceEffect(FirstStrikeAbility.getInstance(), Duration.WhileOnBattlefield));
|
||||
this.addAbility(ability);
|
||||
|
|
|
@ -59,7 +59,7 @@ public class BladeTribeBerserkers extends CardImpl {
|
|||
|
||||
TriggeredAbility ability = new EntersBattlefieldTriggeredAbility(new BoostSourceEffect(3, 3, Duration.EndOfTurn), false);
|
||||
ability.addEffect(new GainAbilitySourceEffect(HasteAbility.getInstance(), Duration.EndOfTurn));
|
||||
this.addAbility(new ConditionalTriggeredAbility(ability, MetalcraftCondition.getInstance(), effectText));
|
||||
this.addAbility(new ConditionalTriggeredAbility(ability, MetalcraftCondition.instance, effectText));
|
||||
}
|
||||
|
||||
public BladeTribeBerserkers(final BladeTribeBerserkers card) {
|
||||
|
|
|
@ -62,7 +62,7 @@ public class BleakCovenVampires extends CardImpl {
|
|||
Target target = new TargetPlayer();
|
||||
ability.addTarget(target);
|
||||
|
||||
this.addAbility(new ConditionalTriggeredAbility(ability, MetalcraftCondition.getInstance(), effectText));
|
||||
this.addAbility(new ConditionalTriggeredAbility(ability, MetalcraftCondition.instance, effectText));
|
||||
}
|
||||
|
||||
public BleakCovenVampires(final BleakCovenVampires card) {
|
||||
|
|
|
@ -105,10 +105,10 @@ class TargetMatchesFilterCondition implements Condition {
|
|||
|
||||
class TargetPermanentToughnessMinus1Value implements DynamicValue {
|
||||
|
||||
private static final TargetPermanentToughnessMinus1Value fINSTANCE = new TargetPermanentToughnessMinus1Value();
|
||||
private static final TargetPermanentToughnessMinus1Value instance = new TargetPermanentToughnessMinus1Value();
|
||||
|
||||
public static TargetPermanentToughnessMinus1Value getInstance() {
|
||||
return fINSTANCE;
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -74,7 +74,7 @@ public class BloodTribute extends CardImpl {
|
|||
// If Blood Tribute was kicked, you gain life equal to the life lost this way.
|
||||
Effect effect = new ConditionalOneShotEffect(
|
||||
new BloodTributeGainLifeEffect(),
|
||||
KickedCondition.getInstance(),
|
||||
KickedCondition.instance,
|
||||
"If {this} was kicked, you gain life equal to the life lost this way");
|
||||
this.getSpellAbility().addEffect(effect);
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ public class BloodhallPriest extends CardImpl {
|
|||
triggeredAbility.addTarget(new TargetCreatureOrPlayer());
|
||||
this.addAbility(new ConditionalTriggeredAbility(
|
||||
triggeredAbility,
|
||||
HellbentCondition.getInstance(),
|
||||
HellbentCondition.instance,
|
||||
"Whenever {this} enters the battlefield or attacks, if you have no cards in hand, {this} deals 2 damage to target creature or player"
|
||||
));
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ public class BloodsoakedChampion extends CardImpl {
|
|||
Zone.GRAVEYARD,
|
||||
new ReturnSourceFromGraveyardToBattlefieldEffect(),
|
||||
new ManaCostsImpl<>("{1}{B}"),
|
||||
RaidCondition.getInstance(),
|
||||
RaidCondition.instance,
|
||||
"<i>Raid</i> - {1}{B}: Return {this} from your graveyard to the battlefield. Activate this ability only if you attacked with a creature this turn");
|
||||
this.addAbility(ability, new PlayerAttackedWatcher());
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ public class BogDown extends CardImpl {
|
|||
this.addAbility(new KickerAbility(new SacrificeTargetCost(new TargetControlledPermanent(2, 2, new FilterControlledLandPermanent("two lands"), true))));
|
||||
// Target player discards two cards. If Bog Down was kicked, that player discards three cards instead.
|
||||
this.getSpellAbility().addEffect(new ConditionalOneShotEffect(new DiscardTargetEffect(3),
|
||||
new DiscardTargetEffect(2), KickedCondition.getInstance(),
|
||||
new DiscardTargetEffect(2), KickedCondition.instance,
|
||||
"Target player discards two cards. If {this} was kicked, that player discards three cards instead."));
|
||||
this.getSpellAbility().addTarget(new TargetPlayer());
|
||||
}
|
||||
|
|
|
@ -55,10 +55,10 @@ public class BoldDefense extends CardImpl {
|
|||
|
||||
// Creatures you control get +1/+1 until end of turn. If Bold Defense was kicked, instead creatures you control get +2/+2 and gain first strike until end of turn.
|
||||
this.getSpellAbility().addEffect(new ConditionalContinuousEffect(new BoostControlledEffect(2, 2, Duration.EndOfTurn),
|
||||
new BoostTargetEffect(1, 1, Duration.EndOfTurn), new LockedInCondition(KickedCondition.getInstance()),
|
||||
new BoostTargetEffect(1, 1, Duration.EndOfTurn), new LockedInCondition(KickedCondition.instance),
|
||||
"Creatures you control get +1/+1 until end of turn. If {this} was kicked, instead creatures you control get +2/+2"));
|
||||
this.getSpellAbility().addEffect(new ConditionalContinuousEffect(new GainAbilityControlledEffect(FirstStrikeAbility.getInstance(), Duration.EndOfTurn, new FilterCreaturePermanent(), false),
|
||||
null, new LockedInCondition(KickedCondition.getInstance()),
|
||||
null, new LockedInCondition(KickedCondition.instance),
|
||||
"and gain first strike until end of turn"));
|
||||
}
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ public class BottomlessVault extends CardImpl {
|
|||
this.addAbility(new SkipUntapOptionalAbility());
|
||||
// At the beginning of your upkeep, if Bottomless Vault is tapped, put a storage counter on it.
|
||||
OneShotEffect addStorageCounter = new AddCountersSourceEffect(CounterType.STORAGE.createInstance());
|
||||
Effect effect = new ConditionalOneShotEffect(addStorageCounter, SourceTappedCondition.getInstance(), "if {this} is tapped, put a storage counter on it");
|
||||
Effect effect = new ConditionalOneShotEffect(addStorageCounter, SourceTappedCondition.instance, "if {this} is tapped, put a storage counter on it");
|
||||
this.addAbility(new BeginningOfUpkeepTriggeredAbility(Zone.BATTLEFIELD, effect, TargetController.YOU, false));
|
||||
// {tap}, Remove any number of storage counters from Bottomless Vault: Add {B} to your mana pool for each storage counter removed this way.
|
||||
Ability ability = new DynamicManaAbility(
|
||||
|
|
|
@ -59,7 +59,7 @@ public class BrandedHowler extends CardImpl {
|
|||
|
||||
// At the beginning of each upkeep, if a player cast two or more spells last turn, transform Branded Howler.
|
||||
TriggeredAbility ability = new BeginningOfUpkeepTriggeredAbility(new TransformSourceEffect(false), TargetController.ANY, false);
|
||||
this.addAbility(new ConditionalTriggeredAbility(ability, TwoOrMoreSpellsWereCastLastTurnCondition.getInstance(), TransformAbility.TWO_OR_MORE_SPELLS_TRANSFORM_RULE));
|
||||
this.addAbility(new ConditionalTriggeredAbility(ability, TwoOrMoreSpellsWereCastLastTurnCondition.instance, TransformAbility.TWO_OR_MORE_SPELLS_TRANSFORM_RULE));
|
||||
}
|
||||
|
||||
public BrandedHowler(final BrandedHowler card) {
|
||||
|
|
|
@ -56,7 +56,7 @@ public class BreakOfDay extends CardImpl {
|
|||
// Fateful hour - If you have 5 or less life, those creatures also are indestructible this turn.
|
||||
this.getSpellAbility().addEffect(new ConditionalContinuousEffect(
|
||||
new GainAbilityAllEffect(IndestructibleAbility.getInstance(), Duration.EndOfTurn, new FilterControlledCreaturePermanent("creatures you control"), false),
|
||||
new LockedInCondition(FatefulHourCondition.getInstance()),
|
||||
new LockedInCondition(FatefulHourCondition.instance),
|
||||
"If you have 5 or less life, those creatures also are indestructible this turn"));
|
||||
}
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ public class BreakneckRider extends CardImpl {
|
|||
// At the beginning of each upkeep, if no spells were cast last turn, transform Breakneck Rider.
|
||||
this.addAbility(new TransformAbility());
|
||||
TriggeredAbility ability = new BeginningOfUpkeepTriggeredAbility(new TransformSourceEffect(true), TargetController.ANY, false);
|
||||
this.addAbility(new ConditionalTriggeredAbility(ability, NoSpellsWereCastLastTurnCondition.getInstance(), TransformAbility.NO_SPELLS_TRANSFORM_RULE));
|
||||
this.addAbility(new ConditionalTriggeredAbility(ability, NoSpellsWereCastLastTurnCondition.instance, TransformAbility.NO_SPELLS_TRANSFORM_RULE));
|
||||
}
|
||||
|
||||
public BreakneckRider(final BreakneckRider card) {
|
||||
|
|
|
@ -60,7 +60,7 @@ public class BreathOfDarigaaz extends CardImpl {
|
|||
|
||||
// Breath of Darigaaz deals 1 damage to each creature without flying and each player. If Breath of Darigaaz was kicked, it deals 4 damage to each creature without flying and each player instead.
|
||||
this.getSpellAbility().addEffect(new ConditionalOneShotEffect(new DamageEverythingEffect(4, filter),
|
||||
new DamageEverythingEffect(1, filter), KickedCondition.getInstance(),
|
||||
new DamageEverythingEffect(1, filter), KickedCondition.instance,
|
||||
"{this} deals 1 damage to each creature without flying and each player. If {this} was kicked, it deals 4 damage to each creature without flying and each player instead."));
|
||||
}
|
||||
|
||||
|
|
|
@ -79,10 +79,10 @@ public class BriarbridgePatrol extends CardImpl {
|
|||
|
||||
class BriarbridgePatrolCondition implements Condition {
|
||||
|
||||
private static final BriarbridgePatrolCondition fInstance = new BriarbridgePatrolCondition();
|
||||
private static final BriarbridgePatrolCondition instance = new BriarbridgePatrolCondition();
|
||||
|
||||
public static Condition getInstance() {
|
||||
return fInstance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -59,7 +59,7 @@ public class BullRancor extends CardImpl {
|
|||
// As long as Bull Rancor is monstrous, creatures you control have menace.
|
||||
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new ConditionalContinuousEffect(
|
||||
new GainAbilityControlledEffect(new MenaceAbility(), Duration.WhileOnBattlefield),
|
||||
MonstrousCondition.getInstance(),
|
||||
MonstrousCondition.instance,
|
||||
"As long as Bull Rancor is monstrous, creatures you control have menace")
|
||||
));
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ public class BurstLightning extends CardImpl {
|
|||
// Burst Lightning deals 2 damage to target creature or player. If Burst Lightning was kicked, it deals 4 damage to that creature or player instead.
|
||||
this.getSpellAbility().addTarget(new TargetCreatureOrPlayer());
|
||||
this.getSpellAbility().addEffect(new ConditionalOneShotEffect(new DamageTargetEffect(4),
|
||||
new DamageTargetEffect(2), KickedCondition.getInstance(), "{this} deals 2 damage to target creature or player. If {this} was kicked, it deals 4 damage to that creature or player instead"));
|
||||
new DamageTargetEffect(2), KickedCondition.instance, "{this} deals 2 damage to target creature or player. If {this} was kicked, it deals 4 damage to that creature or player instead"));
|
||||
}
|
||||
|
||||
public BurstLightning(final BurstLightning card) {
|
||||
|
|
|
@ -51,12 +51,12 @@ public class CacklingFlames extends CardImpl {
|
|||
// Cackling Flames deals 3 damage to target creature or player.
|
||||
this.getSpellAbility().addEffect(new ConditionalOneShotEffect(
|
||||
new DamageTargetEffect(3),
|
||||
new InvertCondition(HellbentCondition.getInstance()),
|
||||
new InvertCondition(HellbentCondition.instance),
|
||||
"{this} deals 3 damage to target creature or player"));
|
||||
// Hellbent - Cackling Flames deals 5 damage to that creature or player instead if you have no cards in hand.
|
||||
this.getSpellAbility().addEffect(new ConditionalOneShotEffect(
|
||||
new DamageTargetEffect(5),
|
||||
HellbentCondition.getInstance(),
|
||||
HellbentCondition.instance,
|
||||
"<br/><br/><i>Hellbent</i> - {this} deals 5 damage to that creature or player instead if you have no cards in hand."));
|
||||
|
||||
this.getSpellAbility().addTarget(new TargetCreatureOrPlayer());
|
||||
|
|
|
@ -51,7 +51,7 @@ public class CalculatedDismissal extends CardImpl {
|
|||
this.getSpellAbility().addTarget(new TargetSpell());
|
||||
this.getSpellAbility().addEffect(new CounterUnlessPaysEffect(new GenericManaCost(3)));
|
||||
// <i>Spell mastery</i> — If there are two or more instant and/or sorcery cards in your graveyard, scry 2.
|
||||
this.getSpellAbility().addEffect(new ConditionalOneShotEffect(new ScryEffect(2), SpellMasteryCondition.getInstance(),
|
||||
this.getSpellAbility().addEffect(new ConditionalOneShotEffect(new ScryEffect(2), SpellMasteryCondition.instance,
|
||||
"<br><i>Spell mastery</i> — If there are two or more instant and/or sorcery cards in your graveyard, scry 2"));
|
||||
}
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ public class CallForUnity extends CardImpl {
|
|||
|
||||
// <i>Revolt</i> — At the beginning of your end step, if a permanent you controlled left the battlefield this turn, put a unity counter on Call for Unity.
|
||||
TriggeredAbility ability = new BeginningOfYourEndStepTriggeredAbility(new AddCountersSourceEffect(CounterType.UNITY.createInstance(), true), false);
|
||||
this.addAbility(new ConditionalTriggeredAbility(ability, RevoltCondition.getInstance(), ruleText), new RevoltWatcher());
|
||||
this.addAbility(new ConditionalTriggeredAbility(ability, RevoltCondition.instance, ruleText), new RevoltWatcher());
|
||||
|
||||
// Creatures you control get +1/+1 for each unity counter on Call for Unity.
|
||||
Effect effect = new BoostControlledEffect(new CountersSourceCount(CounterType.UNITY), new CountersSourceCount(CounterType.UNITY), Duration.WhileOnBattlefield,
|
||||
|
|
|
@ -78,7 +78,7 @@ public class CallOfTheFullMoon extends CardImpl {
|
|||
|
||||
// At the beginning of each upkeep, if a player cast two or more spells last turn, sacrifice Call of the Full Moon.
|
||||
TriggeredAbility ability2 = new BeginningOfUpkeepTriggeredAbility(new SacrificeSourceEffect(), TargetController.ANY, false);
|
||||
this.addAbility(new ConditionalTriggeredAbility(ability2, TwoOrMoreSpellsWereCastLastTurnCondition.getInstance(),
|
||||
this.addAbility(new ConditionalTriggeredAbility(ability2, TwoOrMoreSpellsWereCastLastTurnCondition.instance,
|
||||
"At the beginning of each upkeep, if a player cast two or more spells last turn, sacrifice {this}."));
|
||||
}
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ public class CanopySurge extends CardImpl {
|
|||
this.addAbility(new KickerAbility("{2}"));
|
||||
// Canopy Surge deals 1 damage to each creature with flying and each player. If Canopy Surge was kicked, it deals 4 damage to each creature with flying and each player instead.
|
||||
this.getSpellAbility().addEffect(new ConditionalOneShotEffect(new DamageEverythingEffect(4, filter),
|
||||
new DamageEverythingEffect(1, filter), KickedCondition.getInstance(),
|
||||
new DamageEverythingEffect(1, filter), KickedCondition.instance,
|
||||
"{this} deals 1 damage to each creature with flying and each player. If {this} was kicked, it deals 4 damage to each creature with flying and each player instead."));
|
||||
}
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue