mirror of
https://github.com/correl/mage.git
synced 2024-12-25 03:00:15 +00:00
Merge pull request #2968 from ingmargoudt/singleton-as-enum
rewrote singleton to enum where applicable
This commit is contained in:
commit
68d398c6fb
909 changed files with 1935 additions and 2292 deletions
|
@ -229,14 +229,14 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
}
|
||||
|
||||
ManaSymbols.loadImages();
|
||||
Plugins.getInstance().loadPlugins();
|
||||
Plugins.instance.loadPlugins();
|
||||
|
||||
initComponents();
|
||||
|
||||
desktopPane.setDesktopManager(new MageDesktopManager());
|
||||
|
||||
setSize(1024, 768);
|
||||
SettingsManager.getInstance().setScreenWidthAndHeight(1024, 768);
|
||||
SettingsManager.instance.setScreenWidthAndHeight(1024, 768);
|
||||
DialogManager.updateParams(768, 1024, false);
|
||||
this.setExtendedState(JFrame.MAXIMIZED_BOTH);
|
||||
|
||||
|
@ -265,7 +265,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
setBackground();
|
||||
addMageLabel();
|
||||
setAppIcon();
|
||||
MageTray.getInstance().install();
|
||||
MageTray.instance.install();
|
||||
|
||||
desktopPane.add(ArrowBuilder.getBuilder().getArrowsManagerPanel(), JLayeredPane.DRAG_LAYER);
|
||||
|
||||
|
@ -274,7 +274,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
public void componentResized(ComponentEvent e) {
|
||||
int width = ((JComponent) e.getSource()).getWidth();
|
||||
int height = ((JComponent) e.getSource()).getHeight();
|
||||
SettingsManager.getInstance().setScreenWidthAndHeight(width, height);
|
||||
SettingsManager.instance.setScreenWidthAndHeight(width, height);
|
||||
if (!liteMode && !grayMode) {
|
||||
backgroundPane.setSize(width, height);
|
||||
}
|
||||
|
@ -295,8 +295,8 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
mageToolbar.add(createSwitchPanelsButton(), 0);
|
||||
mageToolbar.add(new javax.swing.JToolBar.Separator(), 1);
|
||||
|
||||
if (Plugins.getInstance().isCounterPluginLoaded()) {
|
||||
int i = Plugins.getInstance().getGamesPlayed();
|
||||
if (Plugins.instance.isCounterPluginLoaded()) {
|
||||
int i = Plugins.instance.getGamesPlayed();
|
||||
JLabel label = new JLabel(" Games played: " + String.valueOf(i));
|
||||
desktopPane.add(label, JLayeredPane.DEFAULT_LAYER + 1);
|
||||
label.setVisible(true);
|
||||
|
@ -338,7 +338,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
}
|
||||
|
||||
private void addTooltipContainer() {
|
||||
final JEditorPane cardInfoPane = (JEditorPane) Plugins.getInstance().getCardInfoPane();
|
||||
final JEditorPane cardInfoPane = (JEditorPane) Plugins.instance.getCardInfoPane();
|
||||
if (cardInfoPane == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -422,8 +422,8 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
}
|
||||
String filename = "/background.jpg";
|
||||
try {
|
||||
if (Plugins.getInstance().isThemePluginLoaded()) {
|
||||
backgroundPane = (ImagePanel) Plugins.getInstance().updateTablePanel(new HashMap<>());
|
||||
if (Plugins.instance.isThemePluginLoaded()) {
|
||||
backgroundPane = (ImagePanel) Plugins.instance.updateTablePanel(new HashMap<>());
|
||||
} else {
|
||||
InputStream is = this.getClass().getResourceAsStream(filename);
|
||||
BufferedImage background = ImageIO.read(is);
|
||||
|
@ -460,7 +460,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
}
|
||||
|
||||
private void setAppIcon() {
|
||||
Image image = ImageManagerImpl.getInstance().getAppImage();
|
||||
Image image = ImageManagerImpl.instance.getAppImage();
|
||||
setIconImage(image);
|
||||
}
|
||||
|
||||
|
@ -1323,7 +1323,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
public void sendUserReplay(PlayerAction playerAction, UserRequestMessage userRequestMessage) {
|
||||
switch (playerAction) {
|
||||
case CLIENT_DOWNLOAD_SYMBOLS:
|
||||
Plugins.getInstance().downloadSymbols();
|
||||
Plugins.instance.downloadSymbols();
|
||||
break;
|
||||
case CLIENT_DOWNLOAD_CARD_IMAGES:
|
||||
DownloadPictures.startDownload(null, missingCards);
|
||||
|
@ -1361,7 +1361,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
}
|
||||
CardRepository.instance.closeDB();
|
||||
tablesPane.cleanUp();
|
||||
Plugins.getInstance().shutdown();
|
||||
Plugins.instance.shutdown();
|
||||
dispose();
|
||||
System.exit(0);
|
||||
break;
|
||||
|
@ -1390,7 +1390,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
|
||||
setGUISizeTooltipContainer();
|
||||
|
||||
Plugins.getInstance().changeGUISize();
|
||||
Plugins.instance.changeGUISize();
|
||||
CountryUtil.changeGUISize();
|
||||
for (Component component : desktopPane.getComponents()) {
|
||||
if (component instanceof MageDialog) {
|
||||
|
@ -1410,7 +1410,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
}
|
||||
|
||||
} catch (Exception ex) {
|
||||
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
this.revalidate();
|
||||
|
|
|
@ -81,7 +81,7 @@ public class BigCard extends JComponent {
|
|||
|
||||
public BigCard(boolean rotated) {
|
||||
initComponents();
|
||||
if (!Plugins.getInstance().isCardPluginLoaded()) {
|
||||
if (!Plugins.instance.isCardPluginLoaded()) {
|
||||
initBounds(rotated);
|
||||
}
|
||||
setDoubleBuffered(true);
|
||||
|
|
|
@ -148,7 +148,7 @@ public class CardArea extends JPanel implements MouseListener {
|
|||
tmp.setAbility(card); // cross-reference, required for ability picker
|
||||
card = tmp;
|
||||
}
|
||||
MageCard cardPanel = Plugins.getInstance().getMageCard(card, bigCard, cardDimension, gameId, true, true);
|
||||
MageCard cardPanel = Plugins.instance.getMageCard(card, bigCard, cardDimension, gameId, true, true);
|
||||
|
||||
cardPanel.setBounds(rectangle);
|
||||
cardPanel.addMouseListener(this);
|
||||
|
|
|
@ -57,7 +57,7 @@ public class CardDraggerGlassPane implements MouseListener, MouseMotionListener
|
|||
currentCards = new ArrayList<>(source.dragCardList());
|
||||
|
||||
// Make a view for the first one and add it to us
|
||||
dragView = Plugins.getInstance().getMageCard(currentCards.get(0), null, new Dimension(100, 140), null, true, false);
|
||||
dragView = Plugins.instance.getMageCard(currentCards.get(0), null, new Dimension(100, 140), null, true, false);
|
||||
for (MouseListener l: dragView.getMouseListeners()) {
|
||||
dragView.removeMouseListener(l);
|
||||
}
|
||||
|
|
|
@ -133,7 +133,7 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener,
|
|||
}
|
||||
|
||||
private void addCard(CardView card, BigCard bigCard, UUID gameId, boolean drawImage) {
|
||||
MageCard cardImg = Plugins.getInstance().getMageCard(card, bigCard, cardDimension, gameId, drawImage, true);
|
||||
MageCard cardImg = Plugins.instance.getMageCard(card, bigCard, cardDimension, gameId, drawImage, true);
|
||||
cards.put(card.getId(), cardImg);
|
||||
cardImg.addMouseListener(this);
|
||||
add(cardImg);
|
||||
|
|
|
@ -98,7 +98,7 @@ public class Cards extends javax.swing.JPanel {
|
|||
jScrollPane1.getViewport().setOpaque(false);
|
||||
jScrollPane1.setBorder(EMPTY_BORDER);
|
||||
}
|
||||
if (Plugins.getInstance().isCardPluginLoaded()) {
|
||||
if (Plugins.instance.isCardPluginLoaded()) {
|
||||
cardArea.setLayout(null);
|
||||
}
|
||||
cardArea.setBorder(EMPTY_BORDER);
|
||||
|
@ -263,7 +263,7 @@ public class Cards extends javax.swing.JPanel {
|
|||
}
|
||||
|
||||
private void addCard(CardView card, BigCard bigCard, UUID gameId) {
|
||||
MageCard mageCard = Plugins.getInstance().getMageCard(card, bigCard, getCardDimension(), gameId, true, true);
|
||||
MageCard mageCard = Plugins.instance.getMageCard(card, bigCard, getCardDimension(), gameId, true, true);
|
||||
if (zone != null) {
|
||||
mageCard.setZone(zone);
|
||||
}
|
||||
|
|
|
@ -425,7 +425,7 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
|
|||
}
|
||||
|
||||
private MageCard addCard(CardView card, BigCard bigCard, UUID gameId) {
|
||||
MageCard cardImg = Plugins.getInstance().getMageCard(card, bigCard, cardDimension, gameId, true, true);
|
||||
MageCard cardImg = Plugins.instance.getMageCard(card, bigCard, cardDimension, gameId, true, true);
|
||||
cardArea.add(cardImg);
|
||||
cardImg.update(card);
|
||||
cardImg.addMouseListener(this);
|
||||
|
|
|
@ -127,7 +127,7 @@ public class DraftGrid extends javax.swing.JPanel implements MouseListener {
|
|||
List<CardView> sortedCards = new ArrayList<>(booster.values());
|
||||
sortedCards.sort(new CardViewRarityComparator());
|
||||
for (CardView card: sortedCards) {
|
||||
MageCard cardImg = Plugins.getInstance().getMageCard(card, bigCard, dimension, null, true, true);
|
||||
MageCard cardImg = Plugins.instance.getMageCard(card, bigCard, dimension, null, true, true);
|
||||
cardImg.addMouseListener(this);
|
||||
add(cardImg);
|
||||
cardImg.update(card);
|
||||
|
@ -156,7 +156,7 @@ public class DraftGrid extends javax.swing.JPanel implements MouseListener {
|
|||
}
|
||||
|
||||
private void hidePopup() {
|
||||
Plugins.getInstance().getActionCallback().mouseExited(null, null);
|
||||
Plugins.instance.getActionCallback().mouseExited(null, null);
|
||||
}
|
||||
|
||||
/** This method is called from within the constructor to
|
||||
|
|
|
@ -1767,7 +1767,7 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
|||
updateCounts();
|
||||
|
||||
// Create the card view
|
||||
final MageCard cardPanel = Plugins.getInstance().getMageCard(card, lastBigCard, new Dimension(getCardWidth(), getCardHeight()), null, true, true);
|
||||
final MageCard cardPanel = Plugins.instance.getMageCard(card, lastBigCard, new Dimension(getCardWidth(), getCardHeight()), null, true, true);
|
||||
cardPanel.update(card);
|
||||
cardPanel.setTextOffset(0);
|
||||
|
||||
|
|
|
@ -118,12 +118,12 @@ public class CombatManager {
|
|||
blockerPoint.translate(-parentPoint.x, -parentPoint.y);
|
||||
Point attackerPoint = attackerCard.getLocationOnScreen();
|
||||
attackerPoint.translate(-parentPoint.x, -parentPoint.y);
|
||||
double yRateA = (attackerCard.getSize().height / SettingsManager.getInstance().getCardSize().height);
|
||||
double xRateA = (attackerCard.getSize().width / SettingsManager.getInstance().getCardSize().width);
|
||||
double yRateB = (blockerCard.getSize().height / SettingsManager.getInstance().getCardSize().height);
|
||||
double xRateB = (blockerCard.getSize().width / SettingsManager.getInstance().getCardSize().width);
|
||||
ArrowBuilder.getBuilder().addArrow(gameId, (int) blockerPoint.getX() + (int)(55*xRateB), (int) blockerPoint.getY() + (int)(25*xRateB),
|
||||
(int) attackerPoint.getX() + (int)(70*xRateA), (int) attackerPoint.getY() + (int)(25*yRateA), Color.blue, ArrowBuilder.Type.COMBAT);
|
||||
double yRateA = (attackerCard.getSize().height / SettingsManager.instance.getCardSize().height);
|
||||
double xRateA = (attackerCard.getSize().width / SettingsManager.instance.getCardSize().width);
|
||||
double yRateB = (blockerCard.getSize().height / SettingsManager.instance.getCardSize().height);
|
||||
double xRateB = (blockerCard.getSize().width / SettingsManager.instance.getCardSize().width);
|
||||
ArrowBuilder.getBuilder().addArrow(gameId, (int) blockerPoint.getX() + (int) (55 * xRateB), (int) blockerPoint.getY() + (int) (25 * xRateB),
|
||||
(int) attackerPoint.getX() + (int) (70 * xRateA), (int) attackerPoint.getY() + (int) (25 * yRateA), Color.blue, ArrowBuilder.Type.COMBAT);
|
||||
globalBlockersCount++;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -112,7 +112,7 @@ public class AbilityPicker extends JXPanel implements MouseWheelListener {
|
|||
this.selected = false; // back to false - waiting for selection
|
||||
setVisible(true);
|
||||
|
||||
Point centered = SettingsManager.getInstance().getComponentPosition(DIALOG_WIDTH, DIALOG_HEIGHT);
|
||||
Point centered = SettingsManager.instance.getComponentPosition(DIALOG_WIDTH, DIALOG_HEIGHT);
|
||||
this.setLocation(centered.x, centered.y);
|
||||
GuiDisplayUtil.keepComponentInsideScreen(centered.x, centered.y, this);
|
||||
|
||||
|
|
|
@ -130,7 +130,7 @@ public class ChoiceDialog extends IDialogPanel {
|
|||
return;
|
||||
}
|
||||
|
||||
java.util.List<Component> toRemove = new ArrayList<>();
|
||||
ArrayList<Component> toRemove = new ArrayList<>();
|
||||
for (int i = getComponentCount() - 1; i > 0; i--) {
|
||||
Component o = getComponent(i);
|
||||
if (o instanceof MageCard) {
|
||||
|
@ -141,10 +141,10 @@ public class ChoiceDialog extends IDialogPanel {
|
|||
remove(toRemove.get(i));
|
||||
}
|
||||
|
||||
java.util.List<CardView> cardList = new ArrayList<>(cards.values());
|
||||
ArrayList<CardView> cardList = new ArrayList<>(cards.values());
|
||||
|
||||
int width = SettingsManager.getInstance().getCardSize().width;
|
||||
int height = SettingsManager.getInstance().getCardSize().height;
|
||||
int width = SettingsManager.instance.getCardSize().width;
|
||||
int height = SettingsManager.instance.getCardSize().height;
|
||||
|
||||
int dx = 0;
|
||||
int dy = 30;
|
||||
|
@ -161,7 +161,7 @@ public class ChoiceDialog extends IDialogPanel {
|
|||
}
|
||||
|
||||
CardView card = cardList.get(i);
|
||||
MageCard cardImg = Plugins.getInstance().getMageCard(card, bigCard, getCardDimension(), gameId, true, true);
|
||||
MageCard cardImg = Plugins.instance.getMageCard(card, bigCard, getCardDimension(), gameId, true, true);
|
||||
|
||||
cardImg.setLocation(dx, dy + j*(height + 30));
|
||||
add(cardImg);
|
||||
|
@ -174,9 +174,9 @@ public class ChoiceDialog extends IDialogPanel {
|
|||
|
||||
private HoverButton getJButtonOK() {
|
||||
if (jButtonOK == null) {
|
||||
jButtonOK = new HoverButton("", ImageManagerImpl.getInstance().getDlgAcceptButtonImage(),
|
||||
ImageManagerImpl.getInstance().getDlgActiveAcceptButtonImage(),
|
||||
ImageManagerImpl.getInstance().getDlgAcceptButtonImage(),
|
||||
jButtonOK = new HoverButton("", ImageManagerImpl.instance.getDlgAcceptButtonImage(),
|
||||
ImageManagerImpl.instance.getDlgActiveAcceptButtonImage(),
|
||||
ImageManagerImpl.instance.getDlgAcceptButtonImage(),
|
||||
new Rectangle(60, 60));
|
||||
int w = getDlgParams().rect.width - 75;
|
||||
int h = getDlgParams().rect.height - 90;
|
||||
|
@ -190,9 +190,9 @@ public class ChoiceDialog extends IDialogPanel {
|
|||
|
||||
private HoverButton getJButtonPrevPage() {
|
||||
if (jButtonPrevPage == null) {
|
||||
jButtonPrevPage = new HoverButton("", ImageManagerImpl.getInstance().getDlgPrevButtonImage(),
|
||||
ImageManagerImpl.getInstance().getDlgActivePrevButtonImage(),
|
||||
ImageManagerImpl.getInstance().getDlgPrevButtonImage(),
|
||||
jButtonPrevPage = new HoverButton("", ImageManagerImpl.instance.getDlgPrevButtonImage(),
|
||||
ImageManagerImpl.instance.getDlgActivePrevButtonImage(),
|
||||
ImageManagerImpl.instance.getDlgPrevButtonImage(),
|
||||
new Rectangle(60, 60));
|
||||
int w = getDlgParams().rect.width - 75;
|
||||
int h = getDlgParams().rect.height - 90;
|
||||
|
@ -229,9 +229,9 @@ public class ChoiceDialog extends IDialogPanel {
|
|||
*/
|
||||
private HoverButton getJButtonNextPage() {
|
||||
if (jButtonNextPage == null) {
|
||||
jButtonNextPage = new HoverButton("", ImageManagerImpl.getInstance().getDlgNextButtonImage(),
|
||||
ImageManagerImpl.getInstance().getDlgActiveNextButtonImage(),
|
||||
ImageManagerImpl.getInstance().getDlgNextButtonImage(),
|
||||
jButtonNextPage = new HoverButton("", ImageManagerImpl.instance.getDlgNextButtonImage(),
|
||||
ImageManagerImpl.instance.getDlgActiveNextButtonImage(),
|
||||
ImageManagerImpl.instance.getDlgNextButtonImage(),
|
||||
new Rectangle(60, 60));
|
||||
int w = getDlgParams().rect.width - 75;
|
||||
int h = getDlgParams().rect.height - 90;
|
||||
|
@ -317,9 +317,9 @@ public class ChoiceDialog extends IDialogPanel {
|
|||
*/
|
||||
private HoverButton getJButtonCancel() {
|
||||
if (jButtonCancel == null) {
|
||||
jButtonCancel = new HoverButton("", ImageManagerImpl.getInstance().getDlgCancelButtonImage(),
|
||||
ImageManagerImpl.getInstance().getDlgActiveCancelButtonImage(),
|
||||
ImageManagerImpl.getInstance().getDlgCancelButtonImage(),
|
||||
jButtonCancel = new HoverButton("", ImageManagerImpl.instance.getDlgCancelButtonImage(),
|
||||
ImageManagerImpl.instance.getDlgActiveCancelButtonImage(),
|
||||
ImageManagerImpl.instance.getDlgCancelButtonImage(),
|
||||
new Rectangle(60, 60));
|
||||
int w = getDlgParams().rect.width - 75;
|
||||
int h = getDlgParams().rect.height - 90;
|
||||
|
|
|
@ -110,7 +110,7 @@ public class StackDialog extends IDialogPanel {
|
|||
/**
|
||||
* Display spells and theis targets above them
|
||||
*/
|
||||
int dx = (SettingsManager.getInstance().getCardSize().width + 15) * (cards.size() - 1);
|
||||
int dx = (SettingsManager.instance.getCardSize().width + 15) * (cards.size() - 1);
|
||||
int dy = 30;
|
||||
|
||||
for (CardView card : cards.values()) {
|
||||
|
@ -124,21 +124,21 @@ public class StackDialog extends IDialogPanel {
|
|||
card = tmp;
|
||||
}
|
||||
|
||||
MageCard cardImg = Plugins.getInstance().getMageCard(card, bigCard, getCardDimension(), gameId, true, true);
|
||||
MageCard cardImg = Plugins.instance.getMageCard(card, bigCard, getCardDimension(), gameId, true, true);
|
||||
//cardImg.setBorder(BorderFactory.createLineBorder(Color.red));
|
||||
cardImg.setLocation(dx, dy);
|
||||
|
||||
jLayeredPane.add(cardImg, JLayeredPane.DEFAULT_LAYER, 1);
|
||||
|
||||
dx -= (SettingsManager.getInstance().getCardSize().width + 15);
|
||||
dx -= (SettingsManager.instance.getCardSize().width + 15);
|
||||
}
|
||||
}
|
||||
|
||||
private HoverButton getJButtonAccept() {
|
||||
if (jButtonAccept == null) {
|
||||
jButtonAccept = new HoverButton("", ImageManagerImpl.getInstance().getDlgAcceptButtonImage(),
|
||||
ImageManagerImpl.getInstance().getDlgActiveAcceptButtonImage(),
|
||||
ImageManagerImpl.getInstance().getDlgAcceptButtonImage(),
|
||||
jButtonAccept = new HoverButton("", ImageManagerImpl.instance.getDlgAcceptButtonImage(),
|
||||
ImageManagerImpl.instance.getDlgActiveAcceptButtonImage(),
|
||||
ImageManagerImpl.instance.getDlgAcceptButtonImage(),
|
||||
new Rectangle(60, 60));
|
||||
int w = getDlgParams().rect.width - 90;
|
||||
int h = getDlgParams().rect.height - 90;
|
||||
|
@ -160,9 +160,9 @@ public class StackDialog extends IDialogPanel {
|
|||
|
||||
private HoverButton getJButtonResponse() {
|
||||
if (jButtonResponse == null) {
|
||||
jButtonResponse = new HoverButton("", ImageManagerImpl.getInstance().getDlgCancelButtonImage(),
|
||||
ImageManagerImpl.getInstance().getDlgActiveCancelButtonImage(),
|
||||
ImageManagerImpl.getInstance().getDlgCancelButtonImage(),
|
||||
jButtonResponse = new HoverButton("", ImageManagerImpl.instance.getDlgCancelButtonImage(),
|
||||
ImageManagerImpl.instance.getDlgActiveCancelButtonImage(),
|
||||
ImageManagerImpl.instance.getDlgCancelButtonImage(),
|
||||
new Rectangle(60, 60));
|
||||
int w = getDlgParams().rect.width - 90;
|
||||
int h = getDlgParams().rect.height - 90;
|
||||
|
|
|
@ -9,9 +9,9 @@ import org.mage.plugins.card.utils.impl.ImageManagerImpl;
|
|||
/**
|
||||
* @author noxx
|
||||
*/
|
||||
public class MageTray {
|
||||
public enum MageTray {
|
||||
|
||||
private static final MageTray instance = new MageTray();
|
||||
instance;
|
||||
|
||||
private static final Logger log = Logger.getLogger(MageTray.class);
|
||||
|
||||
|
@ -19,11 +19,8 @@ public class MageTray {
|
|||
private Image flashedImage;
|
||||
private TrayIcon trayIcon;
|
||||
|
||||
private static int state = 0;
|
||||
private int state = 0;
|
||||
|
||||
public static MageTray getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void install() {
|
||||
if (!SystemTray.isSupported()) {
|
||||
|
@ -32,8 +29,8 @@ public class MageTray {
|
|||
}
|
||||
|
||||
try {
|
||||
mainImage = ImageManagerImpl.getInstance().getAppSmallImage();
|
||||
flashedImage = ImageManagerImpl.getInstance().getAppFlashedImage();
|
||||
mainImage = ImageManagerImpl.instance.getAppSmallImage();
|
||||
flashedImage = ImageManagerImpl.instance.getAppFlashedImage();
|
||||
trayIcon = new TrayIcon(mainImage);
|
||||
trayIcon.setImageAutoSize(true);
|
||||
|
||||
|
|
|
@ -55,9 +55,9 @@ public class DeckEditorPane extends MagePane {
|
|||
public DeckEditorPane() {
|
||||
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||
boolean initialized = false;
|
||||
if (Plugins.getInstance().isThemePluginLoaded()) {
|
||||
if (Plugins.instance.isThemePluginLoaded()) {
|
||||
Map<String, JComponent> uiMap = new HashMap<>();
|
||||
JComponent container = Plugins.getInstance().updateTablePanel(uiMap);
|
||||
JComponent container = Plugins.instance.updateTablePanel(uiMap);
|
||||
if (container != null) {
|
||||
deckEditorPanel1 = new mage.client.deckeditor.DeckEditorPanel();
|
||||
initComponents(container);
|
||||
|
|
|
@ -288,7 +288,7 @@ public class DeckEditorPanel extends javax.swing.JPanel {
|
|||
this.deckArea.clearDeckEventListeners();
|
||||
this.deckArea.addDeckEventListener(
|
||||
(Listener<Event>) event -> {
|
||||
if (mode == DeckEditorMode.FREE_BUILDING){
|
||||
if (mode == DeckEditorMode.FREE_BUILDING) {
|
||||
switch (event.getEventName()) {
|
||||
case "double-click": {
|
||||
SimpleCardView cardView = (SimpleCardView) event.getSource();
|
||||
|
@ -336,7 +336,7 @@ public class DeckEditorPanel extends javax.swing.JPanel {
|
|||
break;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
// constructing phase or sideboarding during match -> card goes always to sideboard
|
||||
switch (event.getEventName()) {
|
||||
case "double-click":
|
||||
|
@ -541,7 +541,7 @@ public class DeckEditorPanel extends javax.swing.JPanel {
|
|||
}
|
||||
|
||||
private void hidePopup() {
|
||||
Plugins.getInstance().getActionCallback().mouseExited(null, null);
|
||||
Plugins.instance.getActionCallback().mouseExited(null, null);
|
||||
}
|
||||
|
||||
public void removeDeckEditor() {
|
||||
|
@ -631,7 +631,7 @@ public class DeckEditorPanel extends javax.swing.JPanel {
|
|||
|
||||
bigCard.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
|
||||
|
||||
cardInfoPane = Plugins.getInstance().getCardInfoPane();
|
||||
cardInfoPane = Plugins.instance.getCardInfoPane();
|
||||
if (cardInfoPane != null && System.getProperty("testCardInfo") != null) {
|
||||
cardInfoPane.setPreferredSize(new Dimension(170, 150));
|
||||
cardInfoPane.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(200, 0, 0)));
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -46,9 +46,9 @@ public class CollectionViewerPane extends MagePane {
|
|||
public CollectionViewerPane() {
|
||||
boolean initialized = false;
|
||||
this.setTitle("Collection Viewer");
|
||||
if (Plugins.getInstance().isThemePluginLoaded()) {
|
||||
if (Plugins.instance.isThemePluginLoaded()) {
|
||||
Map<String, JComponent> uiComponents = new HashMap<>();
|
||||
JComponent container = Plugins.getInstance().updateTablePanel(uiComponents);
|
||||
JComponent container = Plugins.instance.updateTablePanel(uiComponents);
|
||||
if (container != null) {
|
||||
collectionViewerPanel = new CollectionViewerPanel();
|
||||
initComponents(container);
|
||||
|
|
|
@ -185,7 +185,7 @@ public final class CollectionViewerPanel extends JPanel {
|
|||
}
|
||||
|
||||
private void hidePopup() {
|
||||
Plugins.getInstance().getActionCallback().mouseExited(null, null);
|
||||
Plugins.instance.getActionCallback().mouseExited(null, null);
|
||||
}
|
||||
|
||||
public void removeCollectionViewer() {
|
||||
|
|
|
@ -236,7 +236,7 @@ public class MageBook extends JComponent {
|
|||
if (cardDimension == null) {
|
||||
cardDimension = new Dimension(Config.dimensions.frameWidth, Config.dimensions.frameHeight);
|
||||
}
|
||||
final MageCard cardImg = Plugins.getInstance().getMageCard(card, bigCard, cardDimension, gameId, true, true);
|
||||
final MageCard cardImg = Plugins.instance.getMageCard(card, bigCard, cardDimension, gameId, true, true);
|
||||
cardImg.setBounds(rectangle);
|
||||
jLayeredPane.add(cardImg, JLayeredPane.DEFAULT_LAYER, 10);
|
||||
cardImg.update(card);
|
||||
|
|
|
@ -11,7 +11,7 @@ import org.mage.card.arcane.ManaSymbols;
|
|||
*/
|
||||
public class TestMageBook extends JFrame {
|
||||
public static void main(String[] args) {
|
||||
Plugins.getInstance().loadPlugins();
|
||||
Plugins.instance.loadPlugins();
|
||||
ManaSymbols.loadImages();
|
||||
CardScanner.scan();
|
||||
JFrame frame = new TestMageBook();
|
||||
|
|
|
@ -406,7 +406,7 @@ public class TableModel extends AbstractTableModel implements ICardGrid {
|
|||
CardView card = view.get(row);
|
||||
if (!card.getId().equals(bigCard.getCardId())) {
|
||||
if (!MageFrame.isLite()) {
|
||||
Image image = Plugins.getInstance().getOriginalImage(card);
|
||||
Image image = Plugins.instance.getOriginalImage(card);
|
||||
if (image != null && image instanceof BufferedImage) {
|
||||
// XXX: scaled to fit width
|
||||
bigCard.setCard(card.getId(), EnlargeMode.NORMAL, image, new ArrayList<>(), false);
|
||||
|
|
|
@ -83,11 +83,11 @@ public class CardInfoWindowDialog extends MageDialog {
|
|||
this.setModal(false);
|
||||
switch (this.showType) {
|
||||
case LOOKED_AT:
|
||||
this.setFrameIcon(new ImageIcon(ImageManagerImpl.getInstance().getLookedAtImage()));
|
||||
this.setFrameIcon(new ImageIcon(ImageManagerImpl.instance.getLookedAtImage()));
|
||||
this.setClosable(true);
|
||||
break;
|
||||
case REVEAL:
|
||||
this.setFrameIcon(new ImageIcon(ImageManagerImpl.getInstance().getRevealedImage()));
|
||||
this.setFrameIcon(new ImageIcon(ImageManagerImpl.instance.getRevealedImage()));
|
||||
this.setClosable(true);
|
||||
break;
|
||||
case REVEAL_TOP_LIBRARY:
|
||||
|
@ -106,7 +106,7 @@ public class CardInfoWindowDialog extends MageDialog {
|
|||
});
|
||||
break;
|
||||
case EXILE:
|
||||
this.setFrameIcon(new ImageIcon(ImageManagerImpl.getInstance().getExileImage()));
|
||||
this.setFrameIcon(new ImageIcon(ImageManagerImpl.instance.getExileImage()));
|
||||
break;
|
||||
default:
|
||||
// no icon yet
|
||||
|
@ -189,7 +189,7 @@ public class CardInfoWindowDialog extends MageDialog {
|
|||
int width = CardInfoWindowDialog.this.getWidth();
|
||||
int height = CardInfoWindowDialog.this.getHeight();
|
||||
if (width > 0 && height > 0) {
|
||||
Point centered = SettingsManager.getInstance().getComponentPosition(width, height);
|
||||
Point centered = SettingsManager.instance.getComponentPosition(width, height);
|
||||
if (!positioned) {
|
||||
int xPos = centered.x / 2;
|
||||
int yPos = centered.y / 2;
|
||||
|
|
|
@ -82,7 +82,7 @@ public class PickChoiceDialog extends MageDialog {
|
|||
mageDialogState.setStateToDialog(this);
|
||||
|
||||
} else {
|
||||
Point centered = SettingsManager.getInstance().getComponentPosition(getWidth(), getHeight());
|
||||
Point centered = SettingsManager.instance.getComponentPosition(getWidth(), getHeight());
|
||||
this.setLocation(centered.x, centered.y);
|
||||
GuiDisplayUtil.keepComponentInsideScreen(centered.x, centered.y, this);
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ public class PickNumberDialog extends MageDialog {
|
|||
this.btnCancel.setVisible(false);
|
||||
this.pack();
|
||||
|
||||
Point centered = SettingsManager.getInstance().getComponentPosition(getWidth(), getHeight());
|
||||
Point centered = SettingsManager.instance.getComponentPosition(getWidth(), getHeight());
|
||||
this.setLocation(centered.x, centered.y);
|
||||
GuiDisplayUtil.keepComponentInsideScreen(centered.x, centered.y, this);
|
||||
|
||||
|
|
|
@ -107,7 +107,7 @@ public class PickPileDialog extends MageDialog {
|
|||
}
|
||||
pack();
|
||||
|
||||
Point centered = SettingsManager.getInstance().getComponentPosition(getWidth(), getHeight());
|
||||
Point centered = SettingsManager.instance.getComponentPosition(getWidth(), getHeight());
|
||||
this.setLocation(centered.x, centered.y);
|
||||
GuiDisplayUtil.keepComponentInsideScreen(centered.x, centered.y, this);
|
||||
|
||||
|
|
|
@ -134,7 +134,7 @@ public class ShowCardsDialog extends MageDialog {
|
|||
int width = ShowCardsDialog.this.getWidth();
|
||||
int height = ShowCardsDialog.this.getHeight();
|
||||
if (width > 0 && height > 0) {
|
||||
Point centered = SettingsManager.getInstance().getComponentPosition(width, height);
|
||||
Point centered = SettingsManager.instance.getComponentPosition(width, height);
|
||||
ShowCardsDialog.this.setLocation(centered.x, centered.y);
|
||||
positioned = true;
|
||||
GuiDisplayUtil.keepComponentInsideScreen(centered.x, centered.y, ShowCardsDialog.this);
|
||||
|
|
|
@ -432,12 +432,12 @@ class UpdateSeatsTask extends SwingWorker<Void, TableView> {
|
|||
if (current != count) {
|
||||
if (count > 0) {
|
||||
if (current > count) {
|
||||
MageTray.getInstance().displayMessage("New player joined your game.");
|
||||
MageTray.instance.displayMessage("New player joined your game.");
|
||||
AudioManager.playPlayerJoinedTable();
|
||||
} else {
|
||||
MageTray.getInstance().displayMessage("A player left your game.");
|
||||
MageTray.instance.displayMessage("A player left your game.");
|
||||
}
|
||||
MageTray.getInstance().blink();
|
||||
MageTray.instance.blink();
|
||||
}
|
||||
count = current;
|
||||
}
|
||||
|
|
|
@ -52,9 +52,9 @@ public class DraftPane extends MagePane {
|
|||
*/
|
||||
public DraftPane() {
|
||||
boolean initialized = false;
|
||||
if (Plugins.getInstance().isThemePluginLoaded()) {
|
||||
if (Plugins.instance.isThemePluginLoaded()) {
|
||||
Map<String, JComponent> uiComponents = new HashMap<>();
|
||||
JComponent container = Plugins.getInstance().updateTablePanel(uiComponents);
|
||||
JComponent container = Plugins.instance.updateTablePanel(uiComponents);
|
||||
if (container != null) {
|
||||
draftPanel1 = new mage.client.draft.DraftPanel();
|
||||
initComponents(container);
|
||||
|
|
|
@ -328,7 +328,7 @@ public class DraftPanel extends javax.swing.JPanel {
|
|||
if (view != null) {
|
||||
loadCardsToPickedCardsArea(view.getPicks());
|
||||
draftBooster.loadBooster(EMPTY_VIEW, bigCard);
|
||||
Plugins.getInstance().getActionCallback().hideOpenComponents();
|
||||
Plugins.instance.getActionCallback().hideOpenComponents();
|
||||
setMessage("Waiting for other players");
|
||||
}
|
||||
}
|
||||
|
@ -340,8 +340,8 @@ public class DraftPanel extends javax.swing.JPanel {
|
|||
);
|
||||
setMessage("Pick a card");
|
||||
if (!MageFrame.getInstance().isActive()) {
|
||||
MageTray.getInstance().displayMessage("Pick the next card.");
|
||||
MageTray.getInstance().blink();
|
||||
MageTray.instance.displayMessage("Pick the next card.");
|
||||
MageTray.instance.blink();
|
||||
}
|
||||
countdown.stop();
|
||||
this.timeout = draftPickView.getTimeout();
|
||||
|
|
|
@ -252,8 +252,8 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane {
|
|||
if (cardDimension == null) {
|
||||
cardDimension = new Dimension(Config.dimensions.frameWidth, Config.dimensions.frameHeight);
|
||||
}
|
||||
final MagePermanent perm = Plugins.getInstance().getMagePermanent(permanent, bigCard, cardDimension, gameId, true);
|
||||
if (!Plugins.getInstance().isCardPluginLoaded()) {
|
||||
final MagePermanent perm = Plugins.instance.getMagePermanent(permanent, bigCard, cardDimension, gameId, true);
|
||||
if (!Plugins.instance.isCardPluginLoaded()) {
|
||||
//perm.setBounds(findEmptySpace(new Dimension(Config.dimensions.frameWidth, Config.dimensions.frameHeight)));
|
||||
} else {
|
||||
//perm.setAlpha(0);
|
||||
|
@ -262,12 +262,12 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane {
|
|||
|
||||
BattlefieldPanel.this.jPanel.add(perm, 10);
|
||||
//this.jPanel.add(perm);
|
||||
if (!Plugins.getInstance().isCardPluginLoaded()) {
|
||||
if (!Plugins.instance.isCardPluginLoaded()) {
|
||||
moveToFront(perm);
|
||||
perm.update(permanent);
|
||||
} else {
|
||||
moveToFront(jPanel);
|
||||
Plugins.getInstance().onAddCard(perm, 1);
|
||||
Plugins.instance.onAddCard(perm, 1);
|
||||
/*Thread t = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
@ -299,7 +299,7 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane {
|
|||
} else if (comp instanceof MagePermanent) {
|
||||
if (((MagePermanent) comp).getOriginal().getId().equals(permanentId)) {
|
||||
Thread t = new Thread(() -> {
|
||||
Plugins.getInstance().onRemoveCard((MagePermanent) comp, count);
|
||||
Plugins.instance.onRemoveCard((MagePermanent) comp, count);
|
||||
comp.setVisible(false);
|
||||
BattlefieldPanel.this.jPanel.remove(comp);
|
||||
});
|
||||
|
|
|
@ -219,7 +219,7 @@ public final class GamePanel extends javax.swing.JPanel {
|
|||
jLayeredBackgroundPane.add(jSplitPane0, JLayeredPane.DEFAULT_LAYER);
|
||||
|
||||
Map<String, JComponent> myUi = getUIComponents(jLayeredBackgroundPane);
|
||||
Plugins.getInstance().updateGamePanel(myUi);
|
||||
Plugins.instance.updateGamePanel(myUi);
|
||||
|
||||
// Enlarge jlayeredpane on resize of game panel
|
||||
addComponentListener(new ComponentAdapter() {
|
||||
|
@ -332,7 +332,7 @@ public final class GamePanel extends javax.swing.JPanel {
|
|||
pickTargetDialog.cleanUp();
|
||||
pickTargetDialog.removeDialog();
|
||||
}
|
||||
Plugins.getInstance().getActionCallback().hideOpenComponents();
|
||||
Plugins.instance.getActionCallback().hideOpenComponents();
|
||||
try {
|
||||
Component popupContainer = MageFrame.getUI().getComponent(MageComponents.POPUP_CONTAINER);
|
||||
popupContainer.setVisible(false);
|
||||
|
@ -839,7 +839,7 @@ public final class GamePanel extends javax.swing.JPanel {
|
|||
gamePane.setTitle(sb.toString());
|
||||
}
|
||||
|
||||
GameManager.getInstance().setStackSize(game.getStack().size());
|
||||
GameManager.instance.setStackSize(game.getStack().size());
|
||||
displayStack(game, bigCard, feedbackPanel, gameId);
|
||||
|
||||
for (ExileView exile : game.getExile()) {
|
||||
|
@ -902,7 +902,7 @@ public final class GamePanel extends javax.swing.JPanel {
|
|||
this.repaint();
|
||||
}
|
||||
|
||||
static final int BORDER_SIZE = 2;
|
||||
private static final int BORDER_SIZE = 2;
|
||||
|
||||
private void updateSkipButtons(boolean turn, boolean endOfTurn, boolean nextMain, boolean allTurns, boolean stack, boolean endStepBeforeYourStep) {
|
||||
if (turn) { //F4
|
||||
|
@ -1249,7 +1249,7 @@ public final class GamePanel extends javax.swing.JPanel {
|
|||
}
|
||||
|
||||
private void hideAll() {
|
||||
ActionCallback callback = Plugins.getInstance().getActionCallback();
|
||||
ActionCallback callback = Plugins.instance.getActionCallback();
|
||||
((MageActionCallback) callback).hideGameUpdate(gameId);
|
||||
}
|
||||
|
||||
|
@ -1442,7 +1442,7 @@ public final class GamePanel extends javax.swing.JPanel {
|
|||
|
||||
btnCancelSkip.setContentAreaFilled(false);
|
||||
btnCancelSkip.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE));
|
||||
btnCancelSkip.setIcon(new ImageIcon(ImageManagerImpl.getInstance().getCancelSkipButtonImage()));
|
||||
btnCancelSkip.setIcon(new ImageIcon(ImageManagerImpl.instance.getCancelSkipButtonImage()));
|
||||
btnCancelSkip.setToolTipText("Cancel all skip actions ("
|
||||
+ getCachedKeyText(KEY_CONTROL_CANCEL_SKIP) + ").");
|
||||
btnCancelSkip.setFocusable(false);
|
||||
|
@ -1457,7 +1457,7 @@ public final class GamePanel extends javax.swing.JPanel {
|
|||
|
||||
btnSkipToNextTurn.setContentAreaFilled(false);
|
||||
btnSkipToNextTurn.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE));
|
||||
btnSkipToNextTurn.setIcon(new ImageIcon(ImageManagerImpl.getInstance().getSkipNextTurnButtonImage()));
|
||||
btnSkipToNextTurn.setIcon(new ImageIcon(ImageManagerImpl.instance.getSkipNextTurnButtonImage()));
|
||||
btnSkipToNextTurn.setToolTipText("Skip to next turn ("
|
||||
+ getCachedKeyText(KEY_CONTROL_NEXT_TURN) + ").");
|
||||
btnSkipToNextTurn.setFocusable(false);
|
||||
|
@ -1481,7 +1481,7 @@ public final class GamePanel extends javax.swing.JPanel {
|
|||
|
||||
btnSkipToEndTurn.setContentAreaFilled(false);
|
||||
btnSkipToEndTurn.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE));
|
||||
btnSkipToEndTurn.setIcon(new ImageIcon(ImageManagerImpl.getInstance().getSkipEndTurnButtonImage()));
|
||||
btnSkipToEndTurn.setIcon(new ImageIcon(ImageManagerImpl.instance.getSkipEndTurnButtonImage()));
|
||||
btnSkipToEndTurn.setToolTipText("Skip to (opponents/next) end of turn step ("
|
||||
+ getCachedKeyText(KEY_CONTROL_END_STEP) + ") - adjust using preferences.");
|
||||
btnSkipToEndTurn.setFocusable(false);
|
||||
|
@ -1514,7 +1514,7 @@ public final class GamePanel extends javax.swing.JPanel {
|
|||
|
||||
btnSkipToNextMain.setContentAreaFilled(false);
|
||||
btnSkipToNextMain.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE));
|
||||
btnSkipToNextMain.setIcon(new ImageIcon(ImageManagerImpl.getInstance().getSkipMainButtonImage()));
|
||||
btnSkipToNextMain.setIcon(new ImageIcon(ImageManagerImpl.instance.getSkipMainButtonImage()));
|
||||
btnSkipToNextMain.setToolTipText("Skip to (your) next main phase ("
|
||||
+ getCachedKeyText(KEY_CONTROL_MAIN_STEP) + ") - adjust using preferences.");
|
||||
btnSkipToNextMain.setFocusable(false);
|
||||
|
@ -1538,7 +1538,7 @@ public final class GamePanel extends javax.swing.JPanel {
|
|||
|
||||
btnSkipToYourTurn.setContentAreaFilled(false);
|
||||
btnSkipToYourTurn.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE));
|
||||
btnSkipToYourTurn.setIcon(new ImageIcon(ImageManagerImpl.getInstance().getSkipYourNextTurnButtonImage()));
|
||||
btnSkipToYourTurn.setIcon(new ImageIcon(ImageManagerImpl.instance.getSkipYourNextTurnButtonImage()));
|
||||
btnSkipToYourTurn.setToolTipText("Skip to your next turn ("
|
||||
+ getCachedKeyText(KEY_CONTROL_YOUR_TURN) + ").");
|
||||
btnSkipToYourTurn.setFocusable(false);
|
||||
|
@ -1562,7 +1562,7 @@ public final class GamePanel extends javax.swing.JPanel {
|
|||
|
||||
btnSkipToEndStepBeforeYourTurn.setContentAreaFilled(false);
|
||||
btnSkipToEndStepBeforeYourTurn.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE));
|
||||
btnSkipToEndStepBeforeYourTurn.setIcon(new ImageIcon(ImageManagerImpl.getInstance().getSkipEndStepBeforeYourTurnButtonImage()));
|
||||
btnSkipToEndStepBeforeYourTurn.setIcon(new ImageIcon(ImageManagerImpl.instance.getSkipEndStepBeforeYourTurnButtonImage()));
|
||||
btnSkipToEndStepBeforeYourTurn.setToolTipText("Skip to the end step before your turn ("
|
||||
+ getCachedKeyText(KEY_CONTROL_PRIOR_END) + ") - adjust using preferences.");
|
||||
btnSkipToEndStepBeforeYourTurn.setFocusable(false);
|
||||
|
@ -1586,7 +1586,7 @@ public final class GamePanel extends javax.swing.JPanel {
|
|||
|
||||
btnSkipStack.setContentAreaFilled(false);
|
||||
btnSkipStack.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE));
|
||||
btnSkipStack.setIcon(new ImageIcon(ImageManagerImpl.getInstance().getSkipStackButtonImage()));
|
||||
btnSkipStack.setIcon(new ImageIcon(ImageManagerImpl.instance.getSkipStackButtonImage()));
|
||||
btnSkipStack.setToolTipText("Skip until stack is resolved ("
|
||||
+ getCachedKeyText(KEY_CONTROL_SKIP_STACK) + ").");
|
||||
btnSkipStack.setFocusable(false);
|
||||
|
@ -1610,7 +1610,7 @@ public final class GamePanel extends javax.swing.JPanel {
|
|||
|
||||
btnConcede.setContentAreaFilled(false);
|
||||
btnConcede.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE));
|
||||
btnConcede.setIcon(new ImageIcon(ImageManagerImpl.getInstance().getConcedeButtonImage()));
|
||||
btnConcede.setIcon(new ImageIcon(ImageManagerImpl.instance.getConcedeButtonImage()));
|
||||
btnConcede.setToolTipText("Concede the current game.");
|
||||
btnConcede.setFocusable(false);
|
||||
btnConcede.addMouseListener(new MouseAdapter() {
|
||||
|
@ -1638,7 +1638,7 @@ public final class GamePanel extends javax.swing.JPanel {
|
|||
this.getActionMap().put("ENLARGE", new AbstractAction() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
ActionCallback callback = Plugins.getInstance().getActionCallback();
|
||||
ActionCallback callback = Plugins.instance.getActionCallback();
|
||||
((MageActionCallback) callback).enlargeCard(EnlargeMode.NORMAL);
|
||||
}
|
||||
});
|
||||
|
@ -1648,7 +1648,7 @@ public final class GamePanel extends javax.swing.JPanel {
|
|||
this.getActionMap().put("ENLARGE_SOURCE", new AbstractAction() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
ActionCallback callback = Plugins.getInstance().getActionCallback();
|
||||
ActionCallback callback = Plugins.instance.getActionCallback();
|
||||
((MageActionCallback) callback).enlargeCard(EnlargeMode.ALTERNATE);
|
||||
}
|
||||
});
|
||||
|
@ -1697,7 +1697,7 @@ public final class GamePanel extends javax.swing.JPanel {
|
|||
this.getActionMap().put("ENLARGE_RELEASE", new AbstractAction() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
ActionCallback callback = Plugins.getInstance().getActionCallback();
|
||||
ActionCallback callback = Plugins.instance.getActionCallback();
|
||||
((MageActionCallback) callback).hideEnlargedCard();
|
||||
}
|
||||
});
|
||||
|
@ -1718,7 +1718,7 @@ public final class GamePanel extends javax.swing.JPanel {
|
|||
|
||||
btnSwitchHands.setContentAreaFilled(false);
|
||||
btnSwitchHands.setBorder(new EmptyBorder(0, 0, 0, 0));
|
||||
btnSwitchHands.setIcon(new ImageIcon(ImageManagerImpl.getInstance().getSwitchHandsButtonImage()));
|
||||
btnSwitchHands.setIcon(new ImageIcon(ImageManagerImpl.instance.getSwitchHandsButtonImage()));
|
||||
btnSwitchHands.setFocusable(false);
|
||||
btnSwitchHands.setToolTipText("Switch between your hand cards and hand cards of controlled players.");
|
||||
btnSwitchHands.addMouseListener(new MouseAdapter() {
|
||||
|
@ -1732,7 +1732,7 @@ public final class GamePanel extends javax.swing.JPanel {
|
|||
|
||||
btnStopWatching.setContentAreaFilled(false);
|
||||
btnStopWatching.setBorder(new EmptyBorder(0, 0, 0, 0));
|
||||
btnStopWatching.setIcon(new ImageIcon(ImageManagerImpl.getInstance().getStopWatchButtonImage()));
|
||||
btnStopWatching.setIcon(new ImageIcon(ImageManagerImpl.instance.getStopWatchButtonImage()));
|
||||
btnStopWatching.setFocusable(false);
|
||||
btnStopWatching.setToolTipText("Stop watching this game.");
|
||||
btnStopWatching.addMouseListener(new MouseAdapter() {
|
||||
|
@ -2192,7 +2192,7 @@ public final class GamePanel extends javax.swing.JPanel {
|
|||
hoverButtons = new LinkedHashMap<>();
|
||||
}
|
||||
Rectangle rect = new Rectangle(36, 36);
|
||||
HoverButton button = new HoverButton("", ImageManagerImpl.getInstance().getPhaseImage(name), rect);
|
||||
HoverButton button = new HoverButton("", ImageManagerImpl.instance.getPhaseImage(name), rect);
|
||||
button.setToolTipText(name.replaceAll("_", " "));
|
||||
button.setPreferredSize(new Dimension(36, 36));
|
||||
button.addMouseListener(mouseAdapter);
|
||||
|
|
|
@ -106,7 +106,7 @@ public class MageActionCallback implements ActionCallback {
|
|||
|
||||
public synchronized void refreshSession() {
|
||||
if (cardInfoPane == null) {
|
||||
cardInfoPane = Plugins.getInstance().getCardInfoPane();
|
||||
cardInfoPane = Plugins.instance.getCardInfoPane();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -268,7 +268,7 @@ public class MageActionCallback implements ActionCallback {
|
|||
|
||||
@Override
|
||||
public void mouseMoved(MouseEvent e, TransferData transferData) {
|
||||
if (!Plugins.getInstance().isCardPluginLoaded()) {
|
||||
if (!Plugins.instance.isCardPluginLoaded()) {
|
||||
return;
|
||||
}
|
||||
if (!popupData.card.equals(transferData.card)) {
|
||||
|
|
|
@ -8,6 +8,7 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import javax.swing.JComponent;
|
||||
|
||||
import mage.cards.MageCard;
|
||||
import mage.cards.MagePermanent;
|
||||
import mage.cards.action.ActionCallback;
|
||||
|
@ -31,11 +32,10 @@ import org.apache.log4j.Logger;
|
|||
import org.mage.plugins.card.CardPluginImpl;
|
||||
import org.mage.plugins.theme.ThemePluginImpl;
|
||||
|
||||
public class Plugins implements MagePlugins {
|
||||
|
||||
public enum Plugins implements MagePlugins {
|
||||
instance;
|
||||
public static final String PLUGINS_DIRECTORY = "plugins/";
|
||||
|
||||
private static final MagePlugins fINSTANCE = new Plugins();
|
||||
private static final Logger LOGGER = Logger.getLogger(Plugins.class);
|
||||
private static PluginManager pm;
|
||||
|
||||
|
@ -45,9 +45,6 @@ public class Plugins implements MagePlugins {
|
|||
private static final MageActionCallback mageActionCallback = new MageActionCallback();
|
||||
private final Map<String, String> sortingOptions = new HashMap<>();
|
||||
|
||||
public static MagePlugins getInstance() {
|
||||
return fINSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadPlugins() {
|
||||
|
|
|
@ -87,7 +87,7 @@ public class CallbackClientImpl implements CallbackClient {
|
|||
switch (callback.getMethod()) {
|
||||
case "startGame": {
|
||||
TableClientMessage message = (TableClientMessage) callback.getData();
|
||||
GameManager.getInstance().setCurrentPlayerUUID(message.getPlayerId());
|
||||
GameManager.instance.setCurrentPlayerUUID(message.getPlayerId());
|
||||
gameStarted(message.getGameId(), message.getPlayerId());
|
||||
break;
|
||||
}
|
||||
|
@ -457,8 +457,8 @@ public class CallbackClientImpl implements CallbackClient {
|
|||
handleException(ex);
|
||||
}
|
||||
|
||||
if (Plugins.getInstance().isCounterPluginLoaded()) {
|
||||
Plugins.getInstance().addGamesPlayed();
|
||||
if (Plugins.instance.isCounterPluginLoaded()) {
|
||||
Plugins.instance.addGamesPlayed();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,9 +45,9 @@ public class TablesPane extends MagePane {
|
|||
*/
|
||||
public TablesPane() {
|
||||
boolean initialized = false;
|
||||
if (Plugins.getInstance().isThemePluginLoaded()) {
|
||||
if (Plugins.instance.isThemePluginLoaded()) {
|
||||
tablesPanel = new mage.client.table.TablesPanel();
|
||||
JComponent container = Plugins.getInstance().updateTablePanel(tablesPanel.getUIComponents());
|
||||
JComponent container = Plugins.instance.updateTablePanel(tablesPanel.getUIComponents());
|
||||
if (container != null) {
|
||||
initComponents(container);
|
||||
container.add(tablesPanel);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -7,12 +7,8 @@ import java.util.UUID;
|
|||
*
|
||||
* @author nantuko
|
||||
*/
|
||||
public class GameManager {
|
||||
private static final GameManager fInstance = new GameManager();
|
||||
|
||||
public static GameManager getInstance() {
|
||||
return fInstance;
|
||||
}
|
||||
public enum GameManager {
|
||||
instance;
|
||||
|
||||
public void setStackSize(int stackSize) {
|
||||
this.stackSize = stackSize;
|
||||
|
|
|
@ -9,12 +9,8 @@ import org.mage.card.arcane.CardPanel;
|
|||
*
|
||||
* @author nantuko
|
||||
*/
|
||||
public class SettingsManager {
|
||||
private static final SettingsManager fInstance = new SettingsManager();
|
||||
|
||||
public static SettingsManager getInstance() {
|
||||
return fInstance;
|
||||
}
|
||||
public enum SettingsManager {
|
||||
instance;
|
||||
|
||||
public int getScreenWidth() {
|
||||
return screenWidth;
|
||||
|
|
|
@ -35,7 +35,7 @@ public class OldCardLayoutStrategy implements CardLayoutStrategy {
|
|||
Map<UUID, MagePermanent> permanents = battlefieldPanel.getPermanents();
|
||||
JLayeredPane jPanel = battlefieldPanel.getMainPanel();
|
||||
|
||||
int height = Plugins.getInstance().sortPermanents(battlefieldPanel.getUiComponentsList(), permanents.values(), battlefieldPanel.isTopPanelBattlefield());
|
||||
int height = Plugins.instance.sortPermanents(battlefieldPanel.getUiComponentsList(), permanents.values(), battlefieldPanel.isTopPanelBattlefield());
|
||||
jPanel.setPreferredSize(new Dimension(width - 30, height));
|
||||
|
||||
for (PermanentView permanent : battlefieldPanel.getBattlefield().values()) {
|
||||
|
@ -54,7 +54,7 @@ public class OldCardLayoutStrategy implements CardLayoutStrategy {
|
|||
int position = jLayeredPane.getPosition(perm);
|
||||
perm.getLinks().clear();
|
||||
Rectangle rectangleBaseCard = perm.getBounds();
|
||||
if (!Plugins.getInstance().isCardPluginLoaded()) {
|
||||
if (!Plugins.instance.isCardPluginLoaded()) {
|
||||
for (UUID attachmentId : permanent.getAttachments()) {
|
||||
MagePermanent link = permanents.get(attachmentId);
|
||||
if (link != null) {
|
||||
|
|
|
@ -136,7 +136,7 @@ public abstract class CardPanel extends MagePermanent implements MouseListener,
|
|||
dayNightButton = new JButton("");
|
||||
dayNightButton.setSize(32, 32);
|
||||
dayNightButton.setToolTipText("This permanent is a double faced card. To see the back face card, push this button or turn mouse wheel down while hovering with the mouse pointer over the permanent.");
|
||||
BufferedImage day = ImageManagerImpl.getInstance().getDayImage();
|
||||
BufferedImage day = ImageManagerImpl.instance.getDayImage();
|
||||
dayNightButton.setIcon(new ImageIcon(day));
|
||||
dayNightButton.addActionListener(e -> {
|
||||
// if card is being rotated, ignore action performed
|
||||
|
@ -159,9 +159,9 @@ public abstract class CardPanel extends MagePermanent implements MouseListener,
|
|||
showCopySourceButton.setSize(32, 32);
|
||||
showCopySourceButton.setToolTipText("This permanent is copying a target. To see original card, push this button or turn mouse wheel down while hovering with the mouse pointer over the permanent.");
|
||||
showCopySourceButton.setVisible(((PermanentView) this.gameCard).isCopy());
|
||||
showCopySourceButton.setIcon(new ImageIcon(ImageManagerImpl.getInstance().getCopyInformIconImage()));
|
||||
showCopySourceButton.setIcon(new ImageIcon(ImageManagerImpl.instance.getCopyInformIconImage()));
|
||||
showCopySourceButton.addActionListener(e -> {
|
||||
ActionCallback callback1 = Plugins.getInstance().getActionCallback();
|
||||
ActionCallback callback1 = Plugins.instance.getActionCallback();
|
||||
((MageActionCallback) callback1).enlargeCard(EnlargeMode.COPY);
|
||||
});
|
||||
|
||||
|
@ -553,9 +553,9 @@ public abstract class CardPanel extends MagePermanent implements MouseListener,
|
|||
if (card.canTransform()) {
|
||||
BufferedImage transformIcon;
|
||||
if (isTransformed() || card.isTransformed()) {
|
||||
transformIcon = ImageManagerImpl.getInstance().getNightImage();
|
||||
transformIcon = ImageManagerImpl.instance.getNightImage();
|
||||
} else {
|
||||
transformIcon = ImageManagerImpl.getInstance().getDayImage();
|
||||
transformIcon = ImageManagerImpl.instance.getDayImage();
|
||||
}
|
||||
if (dayNightButton != null) {
|
||||
dayNightButton.setVisible(!isPermanent);
|
||||
|
@ -763,7 +763,7 @@ public abstract class CardPanel extends MagePermanent implements MouseListener,
|
|||
this.transformed = !this.transformed;
|
||||
if (transformed) {
|
||||
if (dayNightButton != null) { // if transformbable card is copied, button can be null
|
||||
BufferedImage night = ImageManagerImpl.getInstance().getNightImage();
|
||||
BufferedImage night = ImageManagerImpl.instance.getNightImage();
|
||||
dayNightButton.setIcon(new ImageIcon(night));
|
||||
}
|
||||
if (this.gameCard.getSecondCardFace() == null) {
|
||||
|
@ -776,7 +776,7 @@ public abstract class CardPanel extends MagePermanent implements MouseListener,
|
|||
}
|
||||
} else {
|
||||
if (dayNightButton != null) { // if transformbable card is copied, button can be null
|
||||
BufferedImage day = ImageManagerImpl.getInstance().getDayImage();
|
||||
BufferedImage day = ImageManagerImpl.instance.getDayImage();
|
||||
dayNightButton.setIcon(new ImageIcon(day));
|
||||
}
|
||||
if (!isPermanent) { // use only for custom transformation (when pressing day-night button)
|
||||
|
|
|
@ -207,15 +207,15 @@ public class CardPanelComponentImpl extends CardPanel {
|
|||
// Ability icon
|
||||
if (newGameCard.isAbility()) {
|
||||
if (newGameCard.getAbilityType() == AbilityType.TRIGGERED) {
|
||||
setTypeIcon(ImageManagerImpl.getInstance().getTriggeredAbilityImage(), "Triggered Ability");
|
||||
setTypeIcon(ImageManagerImpl.instance.getTriggeredAbilityImage(), "Triggered Ability");
|
||||
} else if (newGameCard.getAbilityType() == AbilityType.ACTIVATED) {
|
||||
setTypeIcon(ImageManagerImpl.getInstance().getActivatedAbilityImage(), "Activated Ability");
|
||||
setTypeIcon(ImageManagerImpl.instance.getActivatedAbilityImage(), "Activated Ability");
|
||||
}
|
||||
}
|
||||
|
||||
// Token icon
|
||||
if (this.gameCard.isToken()) {
|
||||
setTypeIcon(ImageManagerImpl.getInstance().getTokenIconImage(), "Token Permanent");
|
||||
setTypeIcon(ImageManagerImpl.instance.getTokenIconImage(), "Token Permanent");
|
||||
}
|
||||
|
||||
displayTitleAnyway = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_SHOW_CARD_NAMES, "true").equals("true");
|
||||
|
@ -243,7 +243,7 @@ public class CardPanelComponentImpl extends CardPanel {
|
|||
add(ptText);
|
||||
|
||||
// Sickness overlay
|
||||
BufferedImage sickness = ImageManagerImpl.getInstance().getSicknessImage();
|
||||
BufferedImage sickness = ImageManagerImpl.instance.getSicknessImage();
|
||||
overlayPanel = new ImagePanel(sickness, ImagePanelStyle.SCALED);
|
||||
overlayPanel.setOpaque(false);
|
||||
add(overlayPanel);
|
||||
|
@ -620,21 +620,21 @@ public class CardPanelComponentImpl extends CardPanel {
|
|||
case "+1/+1":
|
||||
if (counterView.getCount() != plusCounter) {
|
||||
plusCounter = counterView.getCount();
|
||||
plusCounterLabel.setIcon(getCounterImageWithAmount(plusCounter, ImageManagerImpl.getInstance().getCounterImageGreen(), getCardWidth()));
|
||||
plusCounterLabel.setIcon(getCounterImageWithAmount(plusCounter, ImageManagerImpl.instance.getCounterImageGreen(), getCardWidth()));
|
||||
}
|
||||
plusCounterLabel.setVisible(true);
|
||||
break;
|
||||
case "-1/-1":
|
||||
if (counterView.getCount() != minusCounter) {
|
||||
minusCounter = counterView.getCount();
|
||||
minusCounterLabel.setIcon(getCounterImageWithAmount(minusCounter, ImageManagerImpl.getInstance().getCounterImageRed(), getCardWidth()));
|
||||
minusCounterLabel.setIcon(getCounterImageWithAmount(minusCounter, ImageManagerImpl.instance.getCounterImageRed(), getCardWidth()));
|
||||
}
|
||||
minusCounterLabel.setVisible(true);
|
||||
break;
|
||||
case "loyalty":
|
||||
if (counterView.getCount() != loyaltyCounter) {
|
||||
loyaltyCounter = counterView.getCount();
|
||||
loyaltyCounterLabel.setIcon(getCounterImageWithAmount(loyaltyCounter, ImageManagerImpl.getInstance().getCounterImageViolet(), getCardWidth()));
|
||||
loyaltyCounterLabel.setIcon(getCounterImageWithAmount(loyaltyCounter, ImageManagerImpl.instance.getCounterImageViolet(), getCardWidth()));
|
||||
}
|
||||
loyaltyCounterLabel.setVisible(true);
|
||||
break;
|
||||
|
@ -643,7 +643,7 @@ public class CardPanelComponentImpl extends CardPanel {
|
|||
name = counterView.getName();
|
||||
otherCounter = counterView.getCount();
|
||||
otherCounterLabel.setToolTipText(name);
|
||||
otherCounterLabel.setIcon(getCounterImageWithAmount(otherCounter, ImageManagerImpl.getInstance().getCounterImageGrey(), getCardWidth()));
|
||||
otherCounterLabel.setIcon(getCounterImageWithAmount(otherCounter, ImageManagerImpl.instance.getCounterImageGrey(), getCardWidth()));
|
||||
otherCounterLabel.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,15 +17,11 @@ import mage.client.util.gui.BufferedImageBuilder;
|
|||
import org.mage.plugins.card.utils.ImageManager;
|
||||
import org.mage.plugins.card.utils.Transparency;
|
||||
|
||||
public class ImageManagerImpl implements ImageManager {
|
||||
public enum ImageManagerImpl implements ImageManager {
|
||||
instance;
|
||||
|
||||
private static final ImageManagerImpl fInstance = new ImageManagerImpl();
|
||||
|
||||
public static ImageManagerImpl getInstance() {
|
||||
return fInstance;
|
||||
}
|
||||
|
||||
public ImageManagerImpl() {
|
||||
ImageManagerImpl() {
|
||||
init();
|
||||
}
|
||||
|
||||
|
|
|
@ -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,29 +30,23 @@ 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);
|
||||
}
|
||||
|
||||
|
||||
public void createTournamentSession(Tournament tournament, ConcurrentHashMap<UUID, UUID> userPlayerMap, UUID tableId) {
|
||||
TournamentController tournamentController = new TournamentController(tournament, userPlayerMap, tableId);
|
||||
controllers.put(tournament.getId(), tournamentController);
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -94,13 +88,13 @@ public class TournamentManager {
|
|||
public UUID getChatId(UUID tournamentId) {
|
||||
return controllers.get(tournamentId).getChatId();
|
||||
}
|
||||
|
||||
|
||||
public void removeTournament(UUID tournamentId) {
|
||||
TournamentController tournamentController = controllers.get(tournamentId);
|
||||
if (tournamentController != null) {
|
||||
controllers.remove(tournamentId);
|
||||
tournamentController.cleanUpOnRemoveTournament();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue