Mostly code format fixes.

This commit is contained in:
vraskulin 2017-02-09 18:30:31 +03:00
parent 7cf4ca3cae
commit f99cd21275
37 changed files with 226 additions and 189 deletions

View file

@ -1443,7 +1443,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
((MagePane) component).changeGUISize(); ((MagePane) component).changeGUISize();
} }
} }
for (ChatPanelBasic chatPanel : getChatPanels().values()) { for (ChatPanelBasic chatPanel : CHATS.values()) {
chatPanel.changeGUISize(GUISizeHelper.chatFont); chatPanel.changeGUISize(GUISizeHelper.chatFont);
} }
try { try {

View file

@ -1718,8 +1718,8 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
private void updateCounts() { private void updateCounts() {
deckNameAndCountLabel.setText(role.getName() + " - " + allCards.size()); deckNameAndCountLabel.setText(role.getName() + " - " + allCards.size());
creatureCountLabel.setText("" + creatureCounter.get()); creatureCountLabel.setText(String.valueOf(creatureCounter.get()));
landCountLabel.setText("" + landCounter.get()); landCountLabel.setText(String.valueOf(landCounter.get()));
for (CardType cardType : selectByTypeButtons.keySet()) { for (CardType cardType : selectByTypeButtons.keySet()) {
AbstractButton button = selectByTypeButtons.get(cardType); AbstractButton button = selectByTypeButtons.get(cardType);
String text = cardType.toString(); String text = cardType.toString();
@ -2058,7 +2058,7 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
if (stack.isEmpty()) { if (stack.isEmpty()) {
countLabel.setVisible(false); countLabel.setVisible(false);
} else { } else {
countLabel.setText("" + stack.size()); countLabel.setText(String.valueOf(stack.size()));
countLabel.setLocation(GRID_PADDING + (cardWidth + GRID_PADDING) * colIndex, currentY - COUNT_LABEL_HEIGHT); countLabel.setLocation(GRID_PADDING + (cardWidth + GRID_PADDING) * colIndex, currentY - COUNT_LABEL_HEIGHT);
countLabel.setSize(cardWidth, COUNT_LABEL_HEIGHT); countLabel.setSize(cardWidth, COUNT_LABEL_HEIGHT);
countLabel.setVisible(true); countLabel.setVisible(true);

View file

@ -195,7 +195,7 @@ public class ChatPanelBasic extends javax.swing.JPanel {
if (level.equals("0")) { if (level.equals("0")) {
return false; return false;
} }
message = "." + message + "."; message = '.' + message + '.';
message = message.toLowerCase(); message = message.toLowerCase();
message = message.replaceAll("[a@]([s5][s5]+)", "axyx"); message = message.replaceAll("[a@]([s5][s5]+)", "axyx");
@ -217,7 +217,7 @@ public class ChatPanelBasic extends javax.swing.JPanel {
if (level.equals("2")) { if (level.equals("2")) {
message = message.replaceAll("\\.", ""); message = message.replaceAll("\\.", "");
message = "." + message + "."; message = '.' + message + '.';
matchPattern = profanity2Pattern.matcher(message); matchPattern = profanity2Pattern.matcher(message);
if (matchPattern.find()) { if (matchPattern.find()) {
return true; return true;

View file

@ -45,7 +45,9 @@ public class KeyBindButton extends JButton implements ActionListener {
private void applyNewKeycode(int code) { private void applyNewKeycode(int code) {
preferences.getKeybindButtons().stream() preferences.getKeybindButtons().stream()
.filter(b -> b != KeyBindButton.this) .filter(b -> b != KeyBindButton.this)
.filter(b -> b.getKeyCode() == code) .filter(b -> {
return b.keyCode == code;
})
.forEach(b -> b.setKeyCode(0)); .forEach(b -> b.setKeyCode(0));
setKeyCode(code); setKeyCode(code);

View file

@ -27,8 +27,8 @@ public class DialogManager extends JComponent implements MouseListener,
synchronized (dialogManagers) { synchronized (dialogManagers) {
if (!dialogManagers.containsKey(gameId)) { if (!dialogManagers.containsKey(gameId)) {
DialogManager dialogManager = new DialogManager(); DialogManager dialogManager = new DialogManager();
dialogManager.setScreenWidth(768); dialogManager.screen_width = 768;
dialogManager.setScreenHeight(1024); dialogManager.screen_height = 1024;
dialogManager.setBounds(0, 0, 768, 1024); dialogManager.setBounds(0, 0, 768, 1024);
dialogManager.setVisible(false); dialogManager.setVisible(false);
dialogManagers.put(gameId, dialogManager); dialogManagers.put(gameId, dialogManager);
@ -96,8 +96,8 @@ public class DialogManager extends JComponent implements MouseListener,
public static void updateParams(int width, int height, boolean isVisible) { public static void updateParams(int width, int height, boolean isVisible) {
synchronized (dialogManagers) { synchronized (dialogManagers) {
for (DialogManager dialogManager : dialogManagers.values()) { for (DialogManager dialogManager : dialogManagers.values()) {
dialogManager.setScreenWidth(width); dialogManager.screen_width = width;
dialogManager.setScreenHeight(height); dialogManager.screen_height = height;
dialogManager.setBounds(0, 0, width, height); dialogManager.setBounds(0, 0, width, height);
} }
} }

View file

@ -141,8 +141,7 @@ public class ChoiceDialog extends IDialogPanel {
remove(toRemove.get(i)); remove(toRemove.get(i));
} }
java.util.List<CardView> cardList = new ArrayList<CardView>(); java.util.List<CardView> cardList = new ArrayList<CardView>(cards.values());
cardList.addAll(cards.values());
int width = SettingsManager.getInstance().getCardSize().width; int width = SettingsManager.getInstance().getCardSize().width;
int height = SettingsManager.getInstance().getCardSize().height; int height = SettingsManager.getInstance().getCardSize().height;

View file

@ -346,7 +346,7 @@ public class DeckEditorPanel extends javax.swing.JPanel {
if (card.getId().equals(cardView.getId())) { if (card.getId().equals(cardView.getId())) {
deck.getCards().remove(card); deck.getCards().remove(card);
deck.getSideboard().add(card); deck.getSideboard().add(card);
cardSelector.loadSideboard(new ArrayList<>(deck.getSideboard()), getBigCard()); cardSelector.loadSideboard(new ArrayList<>(deck.getSideboard()), this.bigCard);
break; break;
} }
} }

View file

@ -537,7 +537,7 @@ public class NewTournamentDialog extends MageDialog {
tOptions.getLimitedOptions().setIsRandom(tournamentType.isRandom()); tOptions.getLimitedOptions().setIsRandom(tournamentType.isRandom());
if (tournamentType.isCubeBooster()) { if (tournamentType.isCubeBooster()) {
tOptions.getLimitedOptions().setDraftCubeName(this.cbDraftCube.getSelectedItem().toString()); tOptions.getLimitedOptions().setDraftCubeName(this.cbDraftCube.getSelectedItem().toString());
if (!(cubeFromDeckFilename.equals(""))) { if (!(cubeFromDeckFilename.isEmpty())) {
Deck cubeFromDeck = new Deck(); Deck cubeFromDeck = new Deck();
try { try {
cubeFromDeck = Deck.load(DeckImporterUtil.importDeck(cubeFromDeckFilename), true, true); cubeFromDeck = Deck.load(DeckImporterUtil.importDeck(cubeFromDeckFilename), true, true);
@ -828,8 +828,7 @@ public class NewTournamentDialog extends MageDialog {
String randomPrefs = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TOURNAMENT_PACKS_RANDOM_DRAFT, ""); String randomPrefs = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TOURNAMENT_PACKS_RANDOM_DRAFT, "");
if (!randomPrefs.isEmpty()) { if (!randomPrefs.isEmpty()) {
txtRandomPacks.setText(randomPrefs); txtRandomPacks.setText(randomPrefs);
ArrayList<String> theList = new ArrayList<>(); ArrayList<String> theList = new ArrayList<>(Arrays.asList(randomPrefs.split(";")));
theList.addAll(Arrays.asList(randomPrefs.split(";")));
randomPackSelector.setSelectedPacks(theList); randomPackSelector.setSelectedPacks(theList);
} else { } else {
ExpansionInfo[] allExpansions = ExpansionRepository.instance.getWithBoostersSortedByReleaseDate(); ExpansionInfo[] allExpansions = ExpansionRepository.instance.getWithBoostersSortedByReleaseDate();

View file

@ -162,8 +162,7 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane {
if (s1 != s2) { if (s1 != s2) {
changed = true; changed = true;
} else if (s1 > 0) { } else if (s1 > 0) {
Set<UUID> attachmentIds = new HashSet<>(); Set<UUID> attachmentIds = new HashSet<>(permanent.getAttachments());
attachmentIds.addAll(permanent.getAttachments());
for (MagePermanent magePermanent : oldMagePermanent.getLinks()) { for (MagePermanent magePermanent : oldMagePermanent.getLinks()) {
if (!attachmentIds.contains(magePermanent.getOriginalPermanent().getId())) { if (!attachmentIds.contains(magePermanent.getOriginalPermanent().getId())) {
// that means that the amount of attachments is the same // that means that the amount of attachments is the same

View file

@ -533,7 +533,7 @@ public final class GamePanel extends javax.swing.JPanel {
if (!SessionHandler.watchGame(gameId)) { if (!SessionHandler.watchGame(gameId)) {
removeGame(); removeGame();
} }
for (PlayAreaPanel panel : getPlayers().values()) { for (PlayAreaPanel panel : players.values()) {
panel.setPlayingMode(false); panel.setPlayingMode(false);
} }
} }
@ -553,7 +553,7 @@ public final class GamePanel extends javax.swing.JPanel {
if (!SessionHandler.startReplay(gameId)) { if (!SessionHandler.startReplay(gameId)) {
removeGame(); removeGame();
} }
for (PlayAreaPanel panel : getPlayers().values()) { for (PlayAreaPanel panel : players.values()) {
panel.setPlayingMode(false); panel.setPlayingMode(false);
} }
} }
@ -815,7 +815,7 @@ public final class GamePanel extends javax.swing.JPanel {
logger.warn(" uuid:" + player.getPlayerId()); logger.warn(" uuid:" + player.getPlayerId());
logger.warn(" players:"); logger.warn(" players:");
for (PlayAreaPanel p : players.values()) { for (PlayAreaPanel p : players.values()) {
logger.warn("" + p); logger.warn(String.valueOf(p));
} }
} }
} }

View file

@ -114,7 +114,7 @@ public class ButtonColumn extends AbstractCellEditor implements TableCellRendere
if (table.getRowCount() > 0 && table.getRowCount() >= table.getEditingRow() && table.getEditingRow() >= 0) { if (table.getRowCount() > 0 && table.getRowCount() >= table.getEditingRow() && table.getEditingRow() >= 0) {
int row = table.convertRowIndexToModel(table.getEditingRow()); int row = table.convertRowIndexToModel(table.getEditingRow());
fireEditingStopped(); fireEditingStopped();
ActionEvent event = new ActionEvent(table, ActionEvent.ACTION_PERFORMED, "" + row); ActionEvent event = new ActionEvent(table, ActionEvent.ACTION_PERFORMED, String.valueOf(row));
action.actionPerformed(event); action.actionPerformed(event);
} }
} }

View file

@ -68,70 +68,70 @@ public class AudioManager {
if (audioManager.nextPageClip == null) { if (audioManager.nextPageClip == null) {
audioManager.nextPageClip = new MageClip(Constants.BASE_SOUND_PATH + "OnPrevPage.wav", AudioGroup.OtherSounds); audioManager.nextPageClip = new MageClip(Constants.BASE_SOUND_PATH + "OnPrevPage.wav", AudioGroup.OtherSounds);
} }
checkAndPlayClip(getManager().nextPageClip); checkAndPlayClip(audioManager.nextPageClip);
} }
public static void playPrevPage() { public static void playPrevPage() {
if (audioManager.prevPageClip == null) { if (audioManager.prevPageClip == null) {
audioManager.prevPageClip = new MageClip(Constants.BASE_SOUND_PATH + "OnPrevPage.wav", AudioGroup.OtherSounds); audioManager.prevPageClip = new MageClip(Constants.BASE_SOUND_PATH + "OnPrevPage.wav", AudioGroup.OtherSounds);
} }
checkAndPlayClip(getManager().prevPageClip); checkAndPlayClip(audioManager.prevPageClip);
} }
public static void playAnotherTab() { public static void playAnotherTab() {
if (audioManager.anotherTabClip == null) { if (audioManager.anotherTabClip == null) {
audioManager.anotherTabClip = new MageClip(Constants.BASE_SOUND_PATH + "OnNextPage.wav", AudioGroup.OtherSounds); audioManager.anotherTabClip = new MageClip(Constants.BASE_SOUND_PATH + "OnNextPage.wav", AudioGroup.OtherSounds);
} }
checkAndPlayClip(getManager().anotherTabClip); checkAndPlayClip(audioManager.anotherTabClip);
} }
public static void playNextPhase() { public static void playNextPhase() {
if (audioManager.nextPhaseClip == null) { if (audioManager.nextPhaseClip == null) {
audioManager.nextPhaseClip = new MageClip(Constants.BASE_SOUND_PATH + "OnNextPhase.wav", AudioGroup.GameSounds); audioManager.nextPhaseClip = new MageClip(Constants.BASE_SOUND_PATH + "OnNextPhase.wav", AudioGroup.GameSounds);
} }
checkAndPlayClip(getManager().nextPhaseClip); checkAndPlayClip(audioManager.nextPhaseClip);
} }
public static void playEndTurn() { public static void playEndTurn() {
if (audioManager.endTurnClip == null) { if (audioManager.endTurnClip == null) {
audioManager.endTurnClip = new MageClip(Constants.BASE_SOUND_PATH + "OnEndTurn.wav", AudioGroup.GameSounds); audioManager.endTurnClip = new MageClip(Constants.BASE_SOUND_PATH + "OnEndTurn.wav", AudioGroup.GameSounds);
} }
checkAndPlayClip(getManager().endTurnClip); checkAndPlayClip(audioManager.endTurnClip);
} }
public static void playTapPermanent() { public static void playTapPermanent() {
if (audioManager.tapPermanentClip == null) { if (audioManager.tapPermanentClip == null) {
audioManager.tapPermanentClip = new MageClip(Constants.BASE_SOUND_PATH + "OnTapPermanent.wav", AudioGroup.GameSounds); audioManager.tapPermanentClip = new MageClip(Constants.BASE_SOUND_PATH + "OnTapPermanent.wav", AudioGroup.GameSounds);
} }
checkAndPlayClip(getManager().tapPermanentClip); checkAndPlayClip(audioManager.tapPermanentClip);
} }
public static void playSummon() { public static void playSummon() {
if (audioManager.summonClip == null) { if (audioManager.summonClip == null) {
audioManager.summonClip = new MageClip(Constants.BASE_SOUND_PATH + "OnSummon.wav", AudioGroup.GameSounds); audioManager.summonClip = new MageClip(Constants.BASE_SOUND_PATH + "OnSummon.wav", AudioGroup.GameSounds);
} }
checkAndPlayClip(getManager().summonClip); checkAndPlayClip(audioManager.summonClip);
} }
public static void playDiedCreature() { public static void playDiedCreature() {
if (audioManager.diedCreatureClip == null) { if (audioManager.diedCreatureClip == null) {
audioManager.diedCreatureClip = new MageClip(Constants.BASE_SOUND_PATH + "OnSummon-.wav", AudioGroup.GameSounds); audioManager.diedCreatureClip = new MageClip(Constants.BASE_SOUND_PATH + "OnSummon-.wav", AudioGroup.GameSounds);
} }
checkAndPlayClip(getManager().diedCreatureClip); checkAndPlayClip(audioManager.diedCreatureClip);
} }
public static void playDraw() { public static void playDraw() {
if (audioManager.drawClip == null) { if (audioManager.drawClip == null) {
audioManager.drawClip = new MageClip(Constants.BASE_SOUND_PATH + "OnDraw.wav", AudioGroup.GameSounds); audioManager.drawClip = new MageClip(Constants.BASE_SOUND_PATH + "OnDraw.wav", AudioGroup.GameSounds);
} }
checkAndPlayClip(getManager().drawClip); checkAndPlayClip(audioManager.drawClip);
} }
public static void playButtonOk() { public static void playButtonOk() {
if (audioManager.buttonOkClip == null) { if (audioManager.buttonOkClip == null) {
audioManager.buttonOkClip = new MageClip(Constants.BASE_SOUND_PATH + "OnButtonOk.wav", AudioGroup.GameSounds); audioManager.buttonOkClip = new MageClip(Constants.BASE_SOUND_PATH + "OnButtonOk.wav", AudioGroup.GameSounds);
} }
checkAndPlayClip(getManager().buttonOkClip); checkAndPlayClip(audioManager.buttonOkClip);
} }
public static void playButtonCancel() { public static void playButtonCancel() {
@ -139,105 +139,105 @@ public class AudioManager {
audioManager.buttonCancelClip = new MageClip(Constants.BASE_SOUND_PATH + "OnButtonCancel.wav", AudioGroup.SkipSounds); audioManager.buttonCancelClip = new MageClip(Constants.BASE_SOUND_PATH + "OnButtonCancel.wav", AudioGroup.SkipSounds);
} }
checkAndPlayClip(getManager().buttonCancelClip); checkAndPlayClip(audioManager.buttonCancelClip);
} }
public static void playAttack() { public static void playAttack() {
if (audioManager.attackClip == null) { if (audioManager.attackClip == null) {
audioManager.attackClip = new MageClip(Constants.BASE_SOUND_PATH + "OnAttack.wav", AudioGroup.GameSounds); audioManager.attackClip = new MageClip(Constants.BASE_SOUND_PATH + "OnAttack.wav", AudioGroup.GameSounds);
} }
checkAndPlayClip(getManager().attackClip); checkAndPlayClip(audioManager.attackClip);
} }
public static void playBlock() { public static void playBlock() {
if (audioManager.blockClip == null) { if (audioManager.blockClip == null) {
audioManager.blockClip = new MageClip(Constants.BASE_SOUND_PATH + "OnBlock.wav", AudioGroup.GameSounds); audioManager.blockClip = new MageClip(Constants.BASE_SOUND_PATH + "OnBlock.wav", AudioGroup.GameSounds);
} }
checkAndPlayClip(getManager().blockClip); checkAndPlayClip(audioManager.blockClip);
} }
public static void playAddPermanent() { public static void playAddPermanent() {
if (audioManager.addPermanentClip == null) { if (audioManager.addPermanentClip == null) {
audioManager.addPermanentClip = new MageClip(Constants.BASE_SOUND_PATH + "OnAddPermanent.wav", AudioGroup.GameSounds); audioManager.addPermanentClip = new MageClip(Constants.BASE_SOUND_PATH + "OnAddPermanent.wav", AudioGroup.GameSounds);
} }
checkAndPlayClip(getManager().addPermanentClip); checkAndPlayClip(audioManager.addPermanentClip);
} }
public static void playAddArtifact() { public static void playAddArtifact() {
if (audioManager.addArtifactClip == null) { if (audioManager.addArtifactClip == null) {
audioManager.addArtifactClip = new MageClip(Constants.BASE_SOUND_PATH + "OnAddArtifact.wav", AudioGroup.GameSounds); audioManager.addArtifactClip = new MageClip(Constants.BASE_SOUND_PATH + "OnAddArtifact.wav", AudioGroup.GameSounds);
} }
checkAndPlayClip(getManager().addArtifactClip); checkAndPlayClip(audioManager.addArtifactClip);
} }
public static void playStackNew() { public static void playStackNew() {
if (audioManager.updateStackClip == null) { if (audioManager.updateStackClip == null) {
audioManager.updateStackClip = new MageClip(Constants.BASE_SOUND_PATH + "OnStackNew.wav", AudioGroup.GameSounds); audioManager.updateStackClip = new MageClip(Constants.BASE_SOUND_PATH + "OnStackNew.wav", AudioGroup.GameSounds);
} }
checkAndPlayClip(getManager().updateStackClip); checkAndPlayClip(audioManager.updateStackClip);
} }
public static void playOnHover() { public static void playOnHover() {
if (audioManager.onHover == null) { if (audioManager.onHover == null) {
audioManager.onHover = new MageClip(Constants.BASE_SOUND_PATH + "OnHover.wav", AudioGroup.GameSounds); audioManager.onHover = new MageClip(Constants.BASE_SOUND_PATH + "OnHover.wav", AudioGroup.GameSounds);
} }
checkAndPlayClip(getManager().onHover); checkAndPlayClip(audioManager.onHover);
} }
public static void playOnCountdown1() { public static void playOnCountdown1() {
if (audioManager.onCountdown1 == null) { if (audioManager.onCountdown1 == null) {
audioManager.onCountdown1 = new MageClip(Constants.BASE_SOUND_PATH + "OnCountdown1.wav", AudioGroup.DraftSounds); audioManager.onCountdown1 = new MageClip(Constants.BASE_SOUND_PATH + "OnCountdown1.wav", AudioGroup.DraftSounds);
} }
checkAndPlayClip(getManager().onCountdown1); checkAndPlayClip(audioManager.onCountdown1);
} }
public static void playOnDraftSelect() { public static void playOnDraftSelect() {
if (audioManager.onDraftSelect == null) { if (audioManager.onDraftSelect == null) {
audioManager.onDraftSelect = new MageClip(Constants.BASE_SOUND_PATH + "OnDraftSelect.wav", AudioGroup.DraftSounds); audioManager.onDraftSelect = new MageClip(Constants.BASE_SOUND_PATH + "OnDraftSelect.wav", AudioGroup.DraftSounds);
} }
checkAndPlayClip(getManager().onDraftSelect); checkAndPlayClip(audioManager.onDraftSelect);
} }
public static void playOnSkipButton() { public static void playOnSkipButton() {
if (audioManager.onSkipButton == null) { if (audioManager.onSkipButton == null) {
audioManager.onSkipButton = new MageClip(Constants.BASE_SOUND_PATH + "OnSkipButton.wav", AudioGroup.SkipSounds); audioManager.onSkipButton = new MageClip(Constants.BASE_SOUND_PATH + "OnSkipButton.wav", AudioGroup.SkipSounds);
} }
checkAndPlayClip(getManager().onSkipButton); checkAndPlayClip(audioManager.onSkipButton);
} }
public static void playOnSkipButtonCancel() { public static void playOnSkipButtonCancel() {
if (audioManager.onSkipButtonCancel == null) { if (audioManager.onSkipButtonCancel == null) {
audioManager.onSkipButtonCancel = new MageClip(Constants.BASE_SOUND_PATH + "OnSkipButtonCancel.wav", AudioGroup.SkipSounds); audioManager.onSkipButtonCancel = new MageClip(Constants.BASE_SOUND_PATH + "OnSkipButtonCancel.wav", AudioGroup.SkipSounds);
} }
checkAndPlayClip(getManager().onSkipButtonCancel); checkAndPlayClip(audioManager.onSkipButtonCancel);
} }
public static void playPlayerJoinedTable() { public static void playPlayerJoinedTable() {
if (audioManager.playerJoinedTable == null) { if (audioManager.playerJoinedTable == null) {
audioManager.playerJoinedTable = new MageClip(Constants.BASE_SOUND_PATH + "OnPlayerJoined.wav", AudioGroup.OtherSounds); audioManager.playerJoinedTable = new MageClip(Constants.BASE_SOUND_PATH + "OnPlayerJoined.wav", AudioGroup.OtherSounds);
} }
checkAndPlayClip(getManager().playerJoinedTable); checkAndPlayClip(audioManager.playerJoinedTable);
} }
public static void playYourGameStarted() { public static void playYourGameStarted() {
if (audioManager.yourGameStarted == null) { if (audioManager.yourGameStarted == null) {
audioManager.yourGameStarted = new MageClip(Constants.BASE_SOUND_PATH + "OnGameStart.wav", AudioGroup.OtherSounds); audioManager.yourGameStarted = new MageClip(Constants.BASE_SOUND_PATH + "OnGameStart.wav", AudioGroup.OtherSounds);
} }
checkAndPlayClip(getManager().yourGameStarted); checkAndPlayClip(audioManager.yourGameStarted);
} }
public static void playTournamentStarted() { public static void playTournamentStarted() {
if (audioManager.tournamentStarted == null) { if (audioManager.tournamentStarted == null) {
audioManager.tournamentStarted = new MageClip(Constants.BASE_SOUND_PATH + "OnTournamentStart.wav", AudioGroup.OtherSounds); audioManager.tournamentStarted = new MageClip(Constants.BASE_SOUND_PATH + "OnTournamentStart.wav", AudioGroup.OtherSounds);
} }
checkAndPlayClip(getManager().tournamentStarted); checkAndPlayClip(audioManager.tournamentStarted);
} }
public static void playPlayerWhispered() { public static void playPlayerWhispered() {
if (audioManager.playerWhispered == null) { if (audioManager.playerWhispered == null) {
audioManager.playerWhispered = new MageClip(Constants.BASE_SOUND_PATH + "OnPlayerWhispered.wav", AudioGroup.OtherSounds); audioManager.playerWhispered = new MageClip(Constants.BASE_SOUND_PATH + "OnPlayerWhispered.wav", AudioGroup.OtherSounds);
} }
checkAndPlayClip(getManager().playerWhispered); checkAndPlayClip(audioManager.playerWhispered);
} }
public static void playPlayerSubmittedDeck() { public static void playPlayerSubmittedDeck() {
@ -245,14 +245,14 @@ public class AudioManager {
audioManager.playerSubmittedDeck = new MageClip(Constants.BASE_SOUND_PATH + "OnPlayerSubmittedDeck.wav", audioManager.playerSubmittedDeck = new MageClip(Constants.BASE_SOUND_PATH + "OnPlayerSubmittedDeck.wav",
AudioGroup.OtherSounds); AudioGroup.OtherSounds);
} }
checkAndPlayClip(getManager().playerSubmittedDeck); checkAndPlayClip(audioManager.playerSubmittedDeck);
} }
public static void playPlayerLeft() { public static void playPlayerLeft() {
if (audioManager.playerLeft == null) { if (audioManager.playerLeft == null) {
audioManager.playerLeft = new MageClip(Constants.BASE_SOUND_PATH + "OnPlayerLeft.wav", AudioGroup.OtherSounds); audioManager.playerLeft = new MageClip(Constants.BASE_SOUND_PATH + "OnPlayerLeft.wav", AudioGroup.OtherSounds);
} }
checkAndPlayClip(getManager().playerLeft); checkAndPlayClip(audioManager.playerLeft);
} }
public static void playPlayerQuitTournament() { public static void playPlayerQuitTournament() {
@ -260,21 +260,21 @@ public class AudioManager {
audioManager.playerQuitTournament = new MageClip(Constants.BASE_SOUND_PATH + "OnPlayerQuitTournament.wav", audioManager.playerQuitTournament = new MageClip(Constants.BASE_SOUND_PATH + "OnPlayerQuitTournament.wav",
AudioGroup.OtherSounds); AudioGroup.OtherSounds);
} }
checkAndPlayClip(getManager().playerQuitTournament); checkAndPlayClip(audioManager.playerQuitTournament);
} }
public static void playPlayerLost() { public static void playPlayerLost() {
if (audioManager.playerLost == null) { if (audioManager.playerLost == null) {
audioManager.playerLost = new MageClip(Constants.BASE_SOUND_PATH + "OnPlayerLost.wav", AudioGroup.GameSounds); audioManager.playerLost = new MageClip(Constants.BASE_SOUND_PATH + "OnPlayerLost.wav", AudioGroup.GameSounds);
} }
checkAndPlayClip(getManager().playerLost); checkAndPlayClip(audioManager.playerLost);
} }
public static void playPlayerWon() { public static void playPlayerWon() {
if (audioManager.playerWon == null) { if (audioManager.playerWon == null) {
audioManager.playerWon = new MageClip(Constants.BASE_SOUND_PATH + "OnPlayerWon.wav", AudioGroup.GameSounds); audioManager.playerWon = new MageClip(Constants.BASE_SOUND_PATH + "OnPlayerWon.wav", AudioGroup.GameSounds);
} }
checkAndPlayClip(getManager().playerWon); checkAndPlayClip(audioManager.playerWon);
} }
private static boolean audioGroupEnabled(AudioGroup audioGroup) { private static boolean audioGroupEnabled(AudioGroup audioGroup) {

View file

@ -574,12 +574,12 @@ public abstract class CardPanel extends MagePermanent implements MouseListener,
int cx = getCardX() - component.x; int cx = getCardX() - component.x;
int cy = getCardY() - component.y; int cy = getCardY() - component.y;
int cw = getCardWidth(); int cw = cardWidth;
int ch = getCardHeight(); int ch = cardHeight;
if (isTapped()) { if (isTapped()) {
cy = ch - cw + cx; cy = ch - cw + cx;
ch = cw; ch = cw;
cw = getCardHeight(); cw = cardHeight;
} }
return x >= cx && x <= cx + cw && y >= cy && y <= cy + ch; return x >= cx && x <= cx + cw && y >= cy && y <= cy + ch;

View file

@ -290,7 +290,7 @@ public abstract class CardRenderer {
g2.setColor(Color.black); g2.setColor(Color.black);
g2.drawPolygon(p); g2.drawPolygon(p);
g2.setFont(new Font("Arial", Font.BOLD, 7)); g2.setFont(new Font("Arial", Font.BOLD, 7));
String cstr = "" + v.getCount(); String cstr = String.valueOf(v.getCount());
int strW = g2.getFontMetrics().stringWidth(cstr); int strW = g2.getFontMetrics().stringWidth(cstr);
g2.drawString(cstr, 5 - strW / 2, 8); g2.drawString(cstr, 5 - strW / 2, 8);
g2.dispose(); g2.dispose();

View file

@ -707,7 +707,7 @@ public class ModernCardRenderer extends CardRenderer {
if ((cardView instanceof PermanentView) && ((PermanentView) cardView).getDamage() > 0) { if ((cardView instanceof PermanentView) && ((PermanentView) cardView).getDamage() > 0) {
int x = cardWidth - partWidth - borderWidth; int x = cardWidth - partWidth - borderWidth;
int y = curY - boxHeight; int y = curY - boxHeight;
String damage = "" + ((PermanentView) cardView).getDamage(); String damage = String.valueOf(((PermanentView) cardView).getDamage());
g.setFont(ptTextFont); g.setFont(ptTextFont);
int txWidth = g.getFontMetrics().stringWidth(damage); int txWidth = g.getFontMetrics().stringWidth(damage);
g.setColor(Color.red); g.setColor(Color.red);
@ -986,7 +986,7 @@ public class ModernCardRenderer extends CardRenderer {
g.setColor(Color.black); g.setColor(Color.black);
g.fillOval(borderWidth + 1, totalContentInset + 1, boxHeight - 2, boxHeight - 2); g.fillOval(borderWidth + 1, totalContentInset + 1, boxHeight - 2, boxHeight - 2);
g.setColor(Color.white); g.setColor(Color.white);
if (isNightCard()) { if (isTransformed) {
g.fillArc(borderWidth + 3, totalContentInset + 3, boxHeight - 6, boxHeight - 6, 90, 270); g.fillArc(borderWidth + 3, totalContentInset + 3, boxHeight - 6, boxHeight - 6, 90, 270);
g.setColor(Color.black); g.setColor(Color.black);
g.fillArc(borderWidth + 3 + 3, totalContentInset + 3, boxHeight - 6 - 3, boxHeight - 6, 90, 270); g.fillArc(borderWidth + 3 + 3, totalContentInset + 3, boxHeight - 6 - 3, boxHeight - 6, 90, 270);
@ -1012,7 +1012,7 @@ public class ModernCardRenderer extends CardRenderer {
// Determine the color of the name / type line text // Determine the color of the name / type line text
protected Color getBoxTextColor() { protected Color getBoxTextColor() {
if (isNightCard()) { if (isTransformed) {
return Color.white; return Color.white;
} else if (cardView.isAbility()) { } else if (cardView.isAbility()) {
return Color.white; return Color.white;

View file

@ -22,7 +22,7 @@ public class TextboxLoyaltyRule extends TextboxRule {
} else if (loyaltyChange > 0) { } else if (loyaltyChange > 0) {
return "+" + loyaltyChange; return "+" + loyaltyChange;
} else { } else {
return "" + loyaltyChange; return String.valueOf(loyaltyChange);
} }
} }

View file

@ -186,10 +186,10 @@ public class TextboxRuleParser {
if (levelMatch.find()) { if (levelMatch.find()) {
try { try {
levelFrom = Integer.parseInt(levelMatch.group(1)); levelFrom = Integer.parseInt(levelMatch.group(1));
if (!levelMatch.group(2).equals("")) { if (!levelMatch.group(2).isEmpty()) {
levelTo = Integer.parseInt(levelMatch.group(2)); levelTo = Integer.parseInt(levelMatch.group(2));
} }
if (!levelMatch.group(3).equals("")) { if (!levelMatch.group(3).isEmpty()) {
levelTo = TextboxLevelRule.AND_HIGHER; levelTo = TextboxLevelRule.AND_HIGHER;
} }
isLeveler = true; isLeveler = true;

View file

@ -53,7 +53,9 @@ public class DownloadGui extends JPanel {
p.setBorder(BorderFactory.createTitledBorder("Progress:")); p.setBorder(BorderFactory.createTitledBorder("Progress:"));
p.add(progress); p.add(progress);
JButton b = new JButton("X"); JButton b = new JButton("X");
b.addActionListener(e -> getDownloader().dispose()); b.addActionListener(e -> {
d.dispose();
});
p.add(b, BorderLayout.EAST); p.add(b, BorderLayout.EAST);
add(p, BorderLayout.NORTH); add(p, BorderLayout.NORTH);
@ -154,10 +156,10 @@ public class DownloadGui extends JPanel {
add(bar = new JProgressBar(job.getProgress())); add(bar = new JProgressBar(job.getProgress()));
JButton b = new JButton("X"); JButton b = new JButton("X");
b.addActionListener(e -> { b.addActionListener(e -> {
switch(getJob().getState()) { switch(this.job.getState()) {
case NEW: case NEW:
case WORKING: case WORKING:
getJob().setState(State.ABORTED); this.job.setState(State.ABORTED);
} }
}); });
add(b, BorderLayout.EAST); add(b, BorderLayout.EAST);

View file

@ -90,7 +90,7 @@ public class DownloadJob extends AbstractLaternaBean {
public void setError(String message, Exception error) { public void setError(String message, Exception error) {
if (message == null) { if (message == null) {
message = "Download of " + this.getName() + "from " + this.getSource().toString() + " caused error: " + error.toString(); message = "Download of " + name + "from " + source.toString() + " caused error: " + error.toString();
} }
// log.warn(message, error); // log.warn(message, error);
log.warn(message); log.warn(message);
@ -167,7 +167,7 @@ public class DownloadJob extends AbstractLaternaBean {
@Override @Override
public String toString() { public String toString() {
return proxy != null ? proxy.type().toString() + ' ' : "" + url; return proxy != null ? proxy.type().toString() + ' ' : url;
} }
}; };
@ -196,7 +196,7 @@ public class DownloadJob extends AbstractLaternaBean {
@Override @Override
public String toString() { public String toString() {
return proxy != null ? proxy.type().toString() + ' ' : "" + url; return proxy != null ? proxy.type().toString() + ' ' : String.valueOf(url);
} }
}; };
} }

View file

@ -57,7 +57,7 @@ public class Downloader extends AbstractLaternaBean implements Disposable {
@Override @Override
public void dispose() { public void dispose() {
for (DownloadJob j : getJobs()) { for (DownloadJob j : jobs) {
switch (j.getState()) { switch (j.getState()) {
case NEW: case NEW:
case WORKING: case WORKING:

View file

@ -59,7 +59,7 @@ public class GathererSymbols implements Iterable<DownloadJob> {
if (symIndex < symbols.length) { if (symIndex < symbols.length) {
sym = symbols[symIndex++]; sym = symbols[symIndex++];
} else if (numeric <= maxNumeric) { } else if (numeric <= maxNumeric) {
sym = "" + (numeric++); sym = String.valueOf(numeric++);
} else { } else {
sizeIndex++; sizeIndex++;
if (sizeIndex == sizes.length) { if (sizeIndex == sizes.length) {

View file

@ -71,7 +71,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
JDialog dlg = download.getDlg(frame); JDialog dlg = download.getDlg(frame);
dlg.setVisible(true); dlg.setVisible(true);
dlg.dispose(); dlg.dispose();
download.setCancel(true); download.cancel = true;
} }
public JDialog getDlg(JFrame frame) { public JDialog getDlg(JFrame frame) {

View file

@ -124,7 +124,7 @@ public class ThemePluginImpl implements ThemePlugin {
private BufferedImage loadbuffer_selected() throws IOException { private BufferedImage loadbuffer_selected() throws IOException {
BufferedImage res; BufferedImage res;
String path = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_BATTLEFIELD_IMAGE, ""); String path = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_BATTLEFIELD_IMAGE, "");
if (path != null && !path.equals("")) { if (path != null && !path.isEmpty()) {
try { try {
res = ImageIO.read(new File(path)); res = ImageIO.read(new File(path));
return res; return res;
@ -162,7 +162,7 @@ public class ThemePluginImpl implements ThemePlugin {
background = ImageIO.read(is); background = ImageIO.read(is);
} else { } else {
String path = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_BACKGROUND_IMAGE, ""); String path = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_BACKGROUND_IMAGE, "");
if (path != null && !path.equals("")) { if (path != null && !path.isEmpty()) {
try { try {
File f = new File(path); File f = new File(path);
if (f != null) { if (f != null) {

View file

@ -245,7 +245,6 @@ public class ChatManager {
*/ */
public void broadcast(UUID userId, String message, MessageColor color) throws UserNotFoundException { public void broadcast(UUID userId, String message, MessageColor color) throws UserNotFoundException {
UserManager.getInstance().getUser(userId).ifPresent(user-> { UserManager.getInstance().getUser(userId).ifPresent(user-> {
chatSessions.values() chatSessions.values()
.stream() .stream()
.filter(chat -> chat.hasUser(userId)) .filter(chat -> chat.hasUser(userId))

View file

@ -49,7 +49,7 @@ import java.util.concurrent.ConcurrentHashMap;
public class ChatSession { public class ChatSession {
private static final Logger logger = Logger.getLogger(ChatSession.class); private static final Logger logger = Logger.getLogger(ChatSession.class);
private static final DateFormat timeFormatter = SimpleDateFormat.getTimeInstance(SimpleDateFormat.SHORT); private static final DateFormat timeFormatter = DateFormat.getTimeInstance(DateFormat.SHORT);
private final ConcurrentHashMap<UUID, String> clients = new ConcurrentHashMap<>(); private final ConcurrentHashMap<UUID, String> clients = new ConcurrentHashMap<>();
private final UUID chatId; private final UUID chatId;

View file

@ -202,38 +202,7 @@ public class MageServerImpl implements MageServer {
@Override @Override
public TableView createTable(final String sessionId, final UUID roomId, final MatchOptions options) throws MageException { public TableView createTable(final String sessionId, final UUID roomId, final MatchOptions options) throws MageException {
return executeWithResult("createTable", sessionId, new ActionWithTableViewResult() { return executeWithResult("createTable", sessionId, new MyActionWithTableViewResult(sessionId, options, roomId));
@Override
public TableView execute() throws MageException {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
Optional<User> _user = UserManager.getInstance().getUser(userId);
if (!_user.isPresent()) {
logger.error("User for session not found. session = " + sessionId);
return null;
}
User user = _user.get();
// check if user can create another table
int notStartedTables = user.getNumberOfNotStartedTables();
if (notStartedTables > 1) {
user.showUserMessage("Create table", "You have already " + notStartedTables + " not started table" + (notStartedTables == 1 ? "" : "s") + ". You can't create another.");
throw new MageException("No message");
}
// check if the user itself satisfies the quitRatio requirement.
int quitRatio = options.getQuitRatio();
if (quitRatio < user.getMatchQuitRatio()) {
user.showUserMessage("Create table", "Your quit ratio " + user.getMatchQuitRatio() + "% is higher than the table requirement " + quitRatio + '%');
throw new MageException("No message");
}
TableView table = GamesRoomManager.getInstance().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()));
}
return table;
}
});
} }
@Override @Override
@ -322,9 +291,7 @@ public class MageServerImpl implements MageServer {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId(); UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
if (logger.isTraceEnabled()) { if (logger.isTraceEnabled()) {
Optional<User> user = UserManager.getInstance().getUser(userId); Optional<User> user = UserManager.getInstance().getUser(userId);
if (user.isPresent()) { user.ifPresent(user1 -> logger.trace("join tourn. tableId: " + tableId + ' ' + name));
logger.trace("join tourn. tableId: " + tableId + ' ' + name);
}
} }
if (userId == null) { if (userId == null) {
logger.fatal("Got no userId from sessionId" + sessionId + " tableId" + tableId); logger.fatal("Got no userId from sessionId" + sessionId + " tableId" + tableId);
@ -688,18 +655,7 @@ public class MageServerImpl implements MageServer {
@Override @Override
public DraftPickView sendCardPick(final UUID draftId, final String sessionId, final UUID cardPick, final Set<UUID> hiddenCards) throws MageException { public DraftPickView sendCardPick(final UUID draftId, final String sessionId, final UUID cardPick, final Set<UUID> hiddenCards) throws MageException {
return executeWithResult("sendCardPick", sessionId, new ActionWithNullNegativeResult<DraftPickView>() { return executeWithResult("sendCardPick", sessionId, new DraftPickViewActionWithNullNegativeResult(sessionId, draftId, cardPick, hiddenCards));
@Override
public DraftPickView execute() {
Session session = SessionManager.getInstance().getSession(sessionId);
if (session != null) {
return DraftManager.getInstance().sendCardPick(draftId, session.getUserId(), cardPick, hiddenCards);
} else {
logger.error("Session not found sessionId: " + sessionId + " draftId:" + draftId);
}
return null;
}
});
} }
@Override @Override
@ -780,13 +736,7 @@ public class MageServerImpl implements MageServer {
@Override @Override
public boolean watchTournamentTable(final String sessionId, final UUID tableId) throws MageException { public boolean watchTournamentTable(final String sessionId, final UUID tableId) throws MageException {
return executeWithResult("setUserData", sessionId, new ActionWithBooleanResult() { return executeWithResult("setUserData", sessionId, new MyActionWithBooleanResult(sessionId, tableId));
@Override
public Boolean execute() throws MageException {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
return TableManager.getInstance().watchTable(userId, tableId);
}
});
} }
@Override @Override
@ -911,13 +861,7 @@ public class MageServerImpl implements MageServer {
@Override @Override
public GameView getGameView(final UUID gameId, final String sessionId, final UUID playerId) throws MageException { public GameView getGameView(final UUID gameId, final String sessionId, final UUID playerId) throws MageException {
return executeWithResult("getGameView", sessionId, new ActionWithNullNegativeResult<GameView>() { return executeWithResult("getGameView", sessionId, new GameViewActionWithNullNegativeResult(sessionId, gameId, playerId));
@Override
public GameView execute() throws MageException {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
return GameManager.getInstance().getGameView(gameId, userId, playerId);
}
});
} }
/** /**
@ -929,27 +873,7 @@ public class MageServerImpl implements MageServer {
*/ */
@Override @Override
public List<UserView> getUsers(String sessionId) throws MageException { public List<UserView> getUsers(String sessionId) throws MageException {
return executeWithResult("getUsers", sessionId, new ActionWithNullNegativeResult<List<UserView>>() { return executeWithResult("getUsers", sessionId, new ListActionWithNullNegativeResult(), true);
@Override
public List<UserView> execute() throws MageException {
List<UserView> users = new ArrayList<>();
for (User user : UserManager.getInstance().getUsers()) {
users.add(new UserView(
user.getName(),
user.getHost(),
user.getSessionId(),
user.getConnectionTime(),
user.getGameInfo(),
user.getUserState().toString(),
user.getChatLockedUntil(),
user.getClientVersion(),
user.getEmail(),
user.getUserIdStr()
));
}
return users;
}
}, true);
} }
@Override @Override
@ -1040,12 +964,7 @@ public class MageServerImpl implements MageServer {
@Override @Override
public Object getServerMessagesCompressed(String sessionId) throws MageException { public Object getServerMessagesCompressed(String sessionId) throws MageException {
return executeWithResult("getGameView", sessionId, new ActionWithNullNegativeResult<Object>() { return executeWithResult("getGameView", sessionId, new MyActionWithNullNegativeResult());
@Override
public Object execute() throws MageException {
return CompressUtil.compress(ServerMessagesUtil.getInstance().getMessages());
}
});
} }
@Override @Override
@ -1142,4 +1061,135 @@ public class MageServerImpl implements MageServer {
public List<CardInfo> getMissingCardsData(List<String> classNames) { public List<CardInfo> getMissingCardsData(List<String> classNames) {
return CardRepository.instance.getMissingCards(classNames); return CardRepository.instance.getMissingCards(classNames);
} }
private static class MyActionWithNullNegativeResult extends ActionWithNullNegativeResult<Object> {
@Override
public Object execute() throws MageException {
return CompressUtil.compress(ServerMessagesUtil.getInstance().getMessages());
}
}
private static class ListActionWithNullNegativeResult extends ActionWithNullNegativeResult<List<UserView>> {
@Override
public List<UserView> execute() throws MageException {
List<UserView> users = new ArrayList<>();
for (User user : UserManager.getInstance().getUsers()) {
users.add(new UserView(
user.getName(),
user.getHost(),
user.getSessionId(),
user.getConnectionTime(),
user.getGameInfo(),
user.getUserState().toString(),
user.getChatLockedUntil(),
user.getClientVersion(),
user.getEmail(),
user.getUserIdStr()
));
}
return users;
}
}
private static class GameViewActionWithNullNegativeResult extends ActionWithNullNegativeResult<GameView> {
private final String sessionId;
private final UUID gameId;
private final UUID playerId;
public GameViewActionWithNullNegativeResult(String sessionId, UUID gameId, UUID playerId) {
this.sessionId = sessionId;
this.gameId = gameId;
this.playerId = playerId;
}
@Override
public GameView execute() throws MageException {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
return GameManager.getInstance().getGameView(gameId, userId, playerId);
}
}
private static class MyActionWithBooleanResult extends ActionWithBooleanResult {
private final String sessionId;
private final UUID tableId;
public MyActionWithBooleanResult(String sessionId, UUID tableId) {
this.sessionId = sessionId;
this.tableId = tableId;
}
@Override
public Boolean execute() throws MageException {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
return TableManager.getInstance().watchTable(userId, tableId);
}
}
private static class DraftPickViewActionWithNullNegativeResult extends ActionWithNullNegativeResult<DraftPickView> {
private final String sessionId;
private final UUID draftId;
private final UUID cardPick;
private final Set<UUID> hiddenCards;
public DraftPickViewActionWithNullNegativeResult(String sessionId, UUID draftId, UUID cardPick, Set<UUID> hiddenCards) {
this.sessionId = sessionId;
this.draftId = draftId;
this.cardPick = cardPick;
this.hiddenCards = hiddenCards;
}
@Override
public DraftPickView execute() {
Session session = SessionManager.getInstance().getSession(sessionId);
if (session != null) {
return DraftManager.getInstance().sendCardPick(draftId, session.getUserId(), cardPick, hiddenCards);
} else {
logger.error("Session not found sessionId: " + sessionId + " draftId:" + draftId);
}
return null;
}
}
private static class MyActionWithTableViewResult extends ActionWithTableViewResult {
private final String sessionId;
private final MatchOptions options;
private final UUID roomId;
public MyActionWithTableViewResult(String sessionId, MatchOptions options, UUID roomId) {
this.sessionId = sessionId;
this.options = options;
this.roomId = roomId;
}
@Override
public TableView execute() throws MageException {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
Optional<User> _user = UserManager.getInstance().getUser(userId);
if (!_user.isPresent()) {
logger.error("User for session not found. session = " + sessionId);
return null;
}
User user = _user.get();
// check if user can create another table
int notStartedTables = user.getNumberOfNotStartedTables();
if (notStartedTables > 1) {
user.showUserMessage("Create table", "You have already " + notStartedTables + " not started table" + (notStartedTables == 1 ? "" : "s") + ". You can't create another.");
throw new MageException("No message");
}
// check if the user itself satisfies the quitRatio requirement.
int quitRatio = options.getQuitRatio();
if (quitRatio < user.getMatchQuitRatio()) {
user.showUserMessage("Create table", "Your quit ratio " + user.getMatchQuitRatio() + "% is higher than the table requirement " + quitRatio + '%');
throw new MageException("No message");
}
TableView table = GamesRoomManager.getInstance().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()));
}
return table;
}
}
} }

View file

@ -421,7 +421,7 @@ public class Session {
Throwable t = cause; Throwable t = cause;
while (t.getCause() != null) { while (t.getCause() != null) {
t = t.getCause(); t = t.getCause();
if (t == cause) { if (Objects.equals(t, cause)) {
throw new IllegalArgumentException("Infinite cycle detected in causal chain"); throw new IllegalArgumentException("Infinite cycle detected in causal chain");
} }
} }

View file

@ -95,11 +95,7 @@ public class TableController {
if (userId != null) { if (userId != null) {
Optional<User> user = UserManager.getInstance().getUser(userId); Optional<User> user = UserManager.getInstance().getUser(userId);
// TODO: Handle if user == null // TODO: Handle if user == null
if (user.isPresent()) { controllerName = user.map(User::getName).orElse("undefined");
controllerName = user.get().getName();
} else {
controllerName = "undefined";
}
} else { } else {
controllerName = "System"; controllerName = "System";
} }
@ -671,9 +667,7 @@ public class TableController {
if (entry.getValue().equals(playerId)) { if (entry.getValue().equals(playerId)) {
Optional<User> user = UserManager.getInstance().getUser(entry.getKey()); Optional<User> user = UserManager.getInstance().getUser(entry.getKey());
int remaining = (int) futureTimeout.getDelay(TimeUnit.SECONDS); int remaining = (int) futureTimeout.getDelay(TimeUnit.SECONDS);
if (user.isPresent()) { user.ifPresent(user1 -> user1.ccSideboard(deck, table.getId(), remaining, options.isLimited()));
user.get().ccSideboard(deck, table.getId(), remaining, options.isLimited());
}
break; break;
} }
} }
@ -811,10 +805,7 @@ public class TableController {
private synchronized void setupTimeout(int seconds) { private synchronized void setupTimeout(int seconds) {
cancelTimeout(); cancelTimeout();
if (seconds > 0) { if (seconds > 0) {
futureTimeout = timeoutExecutor.schedule( futureTimeout = timeoutExecutor.schedule(this::autoSideboard, seconds, TimeUnit.SECONDS);
() -> autoSideboard(),
seconds, TimeUnit.SECONDS
);
} }
} }

View file

@ -60,7 +60,7 @@ public class UserManager {
} }
private UserManager() { private UserManager() {
expireExecutor.scheduleAtFixedRate(() -> checkExpired(), 60, 60, TimeUnit.SECONDS); expireExecutor.scheduleAtFixedRate(this::checkExpired, 60, 60, TimeUnit.SECONDS);
} }
public User createUser(String userName, String host, AuthorizedUser authorizedUser) { public User createUser(String userName, String host, AuthorizedUser authorizedUser) {

View file

@ -21,7 +21,7 @@ public class ChallengeManager {
} }
public void prepareChallenge(UUID playerId, Match match) { public void prepareChallenge(UUID playerId, Match match) {
Map<Zone, String> commands = new HashMap<Zone, String>(); Map<Zone, String> commands = new HashMap<>();
commands.put(Zone.OUTSIDE, "life:3"); commands.put(Zone.OUTSIDE, "life:3");
match.getGame().cheat(playerId, commands); match.getGame().cheat(playerId, commands);
} }

View file

@ -44,7 +44,7 @@ public class CubeFactory {
private static final CubeFactory INSTANCE = new CubeFactory(); private static final CubeFactory INSTANCE = new CubeFactory();
private static final Logger logger = Logger.getLogger(CubeFactory.class); private static final Logger logger = Logger.getLogger(CubeFactory.class);
private final Map<String, Class> draftCubes = new LinkedHashMap<String, Class>(); private final Map<String, Class> draftCubes = new LinkedHashMap<>();
public static CubeFactory getInstance() { public static CubeFactory getInstance() {
return INSTANCE; return INSTANCE;

View file

@ -151,8 +151,7 @@ public class DraftController {
private synchronized void checkStart() { private synchronized void checkStart() {
if (!draft.isStarted() && allJoined()) { if (!draft.isStarted() && allJoined()) {
draft.setStarted(); draft.setStarted();
ThreadExecutor.getInstance().getCallExecutor().execute( ThreadExecutor.getInstance().getCallExecutor().execute(this::startDraft);
() -> startDraft());
} }
} }

View file

@ -388,8 +388,7 @@ public class GameController implements GameCallback {
private void checkStart() { private void checkStart() {
if (allJoined()) { if (allJoined()) {
joinWaitingExecutor.shutdownNow(); joinWaitingExecutor.shutdownNow();
ThreadExecutor.getInstance().getCallExecutor().execute( ThreadExecutor.getInstance().getCallExecutor().execute(this::startGame);
() -> startGame());
} }
} }

View file

@ -130,7 +130,6 @@ public class GameSessionPlayer extends GameSessionWatcher {
public void getAmount(final String message, final int min, final int max) { public void getAmount(final String message, final int min, final int max) {
if (!killed) { if (!killed) {
UserManager.getInstance().getUser(userId).ifPresent(user -> { UserManager.getInstance().getUser(userId).ifPresent(user -> {
user.fireCallback(new ClientCallback("gameSelectAmount", game.getId(), new GameClientMessage(message, min, max))); user.fireCallback(new ClientCallback("gameSelectAmount", game.getId(), new GameClientMessage(message, min, max)));
}); });
} }

View file

@ -198,8 +198,7 @@ public class TournamentController {
private void checkStart() { private void checkStart() {
if (!started && allJoined()) { if (!started && allJoined()) {
ThreadExecutor.getInstance().getCallExecutor().execute( ThreadExecutor.getInstance().getCallExecutor().execute(this::startTournament);
() -> startTournament());
} }
} }

View file

@ -79,7 +79,7 @@ public class TournamentFactory {
} }
tournament.getOptions().getLimitedOptions().setNumberBoosters(tournament.getTournamentType().getNumBoosters()); tournament.getOptions().getLimitedOptions().setNumberBoosters(tournament.getTournamentType().getNumBoosters());
if (tournament.getTournamentType().isCubeBooster()) { if (tournament.getTournamentType().isCubeBooster()) {
DraftCube draftCube = null; DraftCube draftCube;
if (tournament.getOptions().getLimitedOptions().getCubeFromDeck() != null) { if (tournament.getOptions().getLimitedOptions().getCubeFromDeck() != null) {
draftCube = CubeFactory.getInstance().createDeckDraftCube(tournament.getOptions().getLimitedOptions().getDraftCubeName(), tournament.getOptions().getLimitedOptions().getCubeFromDeck()); draftCube = CubeFactory.getInstance().createDeckDraftCube(tournament.getOptions().getLimitedOptions().getDraftCubeName(), tournament.getOptions().getLimitedOptions().getCubeFromDeck());

View file

@ -74,7 +74,7 @@ public class ServerMessagesUtil {
public ServerMessagesUtil() { public ServerMessagesUtil() {
updateExecutor = Executors.newSingleThreadScheduledExecutor(); updateExecutor = Executors.newSingleThreadScheduledExecutor();
updateExecutor.scheduleAtFixedRate(() -> reloadMessages(), 5, 5 * 60, TimeUnit.SECONDS); updateExecutor.scheduleAtFixedRate(this::reloadMessages, 5, 5 * 60, TimeUnit.SECONDS);
} }
public static ServerMessagesUtil getInstance() { public static ServerMessagesUtil getInstance() {