mirror of
https://github.com/correl/mage.git
synced 2024-11-28 19:19:55 +00:00
Narrowed variables scope.
This commit is contained in:
parent
09da478b38
commit
f1ef3bf68b
20 changed files with 42 additions and 60 deletions
|
@ -240,12 +240,9 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
||||||
|
|
||||||
private static List<CardDownloadData> getNeededCards(List<CardInfo> allCards) {
|
private static List<CardDownloadData> getNeededCards(List<CardInfo> allCards) {
|
||||||
|
|
||||||
List<CardDownloadData> cardsToDownload = Collections.synchronizedList(new ArrayList<>());
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* read all card names and urls
|
* read all card names and urls
|
||||||
*/
|
*/
|
||||||
List<CardDownloadData> allCardsUrls = Collections.synchronizedList(new ArrayList<>());
|
|
||||||
HashSet<String> ignoreUrls = SettingsManager.getIntance().getIgnoreUrls();
|
HashSet<String> ignoreUrls = SettingsManager.getIntance().getIgnoreUrls();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -261,6 +258,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
||||||
|
|
||||||
int numberCardImages = allCards.size();
|
int numberCardImages = allCards.size();
|
||||||
int numberWithoutTokens = 0;
|
int numberWithoutTokens = 0;
|
||||||
|
List<CardDownloadData> allCardsUrls = Collections.synchronizedList(new ArrayList<>());
|
||||||
try {
|
try {
|
||||||
offlineMode = true;
|
offlineMode = true;
|
||||||
allCards.parallelStream().forEach(card -> {
|
allCards.parallelStream().forEach(card -> {
|
||||||
|
@ -290,11 +288,11 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
||||||
if (card.getFlipCardName() == null || card.getFlipCardName().trim().isEmpty()) {
|
if (card.getFlipCardName() == null || card.getFlipCardName().trim().isEmpty()) {
|
||||||
throw new IllegalStateException("Flipped card can't have empty name.");
|
throw new IllegalStateException("Flipped card can't have empty name.");
|
||||||
}
|
}
|
||||||
url = new CardDownloadData(card.getFlipCardName(), card.getSetCode(), card.getCardNumber(), card.usesVariousArt(), 0, "", "", false, card.isDoubleFaced(), card.isNightCard());
|
CardDownloadData cardDownloadData = new CardDownloadData(card.getFlipCardName(), card.getSetCode(), card.getCardNumber(), card.usesVariousArt(), 0, "", "", false, card.isDoubleFaced(), card.isNightCard());
|
||||||
url.setFlipCard(true);
|
cardDownloadData.setFlipCard(true);
|
||||||
url.setFlippedSide(true);
|
cardDownloadData.setFlippedSide(true);
|
||||||
url.setType2(isType2);
|
cardDownloadData.setType2(isType2);
|
||||||
allCardsUrls.add(url);
|
allCardsUrls.add(cardDownloadData);
|
||||||
}
|
}
|
||||||
} else if (card.getCardNumber().isEmpty() || "0".equals(card.getCardNumber())) {
|
} else if (card.getCardNumber().isEmpty() || "0".equals(card.getCardNumber())) {
|
||||||
System.err.println("There was a critical error!");
|
System.err.println("There was a critical error!");
|
||||||
|
@ -315,6 +313,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
||||||
/**
|
/**
|
||||||
* check to see which cards we already have
|
* check to see which cards we already have
|
||||||
*/
|
*/
|
||||||
|
List<CardDownloadData> cardsToDownload = Collections.synchronizedList(new ArrayList<>());
|
||||||
allCardsUrls.parallelStream().forEach(card -> {
|
allCardsUrls.parallelStream().forEach(card -> {
|
||||||
TFile file = new TFile(CardImageUtils.generateImagePath(card));
|
TFile file = new TFile(CardImageUtils.generateImagePath(card));
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
|
@ -348,19 +347,18 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
||||||
|
|
||||||
try(InputStreamReader input = new InputStreamReader(in);
|
try(InputStreamReader input = new InputStreamReader(in);
|
||||||
BufferedReader reader = new BufferedReader(input)) {
|
BufferedReader reader = new BufferedReader(input)) {
|
||||||
String line;
|
|
||||||
|
|
||||||
line = reader.readLine();
|
String line = reader.readLine();
|
||||||
while (line != null) {
|
while (line != null) {
|
||||||
line = line.trim();
|
line = line.trim();
|
||||||
if (line.startsWith("|")) { // new format
|
if (line.startsWith("|")) { // new format
|
||||||
String[] params = line.split("\\|", -1);
|
String[] params = line.split("\\|", -1);
|
||||||
if (params.length >= 5) {
|
if (params.length >= 5) {
|
||||||
int type = 0;
|
int type = 0;
|
||||||
String fileName = "";
|
|
||||||
if (params[4] != null && !params[4].isEmpty()) {
|
if (params[4] != null && !params[4].isEmpty()) {
|
||||||
type = Integer.parseInt(params[4].trim());
|
type = Integer.parseInt(params[4].trim());
|
||||||
}
|
}
|
||||||
|
String fileName = "";
|
||||||
if (params.length > 5 && params[5] != null && !params[5].isEmpty()) {
|
if (params.length > 5 && params[5] != null && !params[5].isEmpty()) {
|
||||||
fileName = params[5].trim();
|
fileName = params[5].trim();
|
||||||
}
|
}
|
||||||
|
@ -516,7 +514,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
||||||
private final String actualFilename;
|
private final String actualFilename;
|
||||||
private final boolean useSpecifiedPaths;
|
private final boolean useSpecifiedPaths;
|
||||||
|
|
||||||
public DownloadTask(CardDownloadData card, URL url, int count) {
|
DownloadTask(CardDownloadData card, URL url, int count) {
|
||||||
this.card = card;
|
this.card = card;
|
||||||
this.url = url;
|
this.url = url;
|
||||||
this.count = count;
|
this.count = count;
|
||||||
|
@ -524,7 +522,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
||||||
useSpecifiedPaths = false;
|
useSpecifiedPaths = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DownloadTask(CardDownloadData card, URL url, String actualFilename, int count) {
|
DownloadTask(CardDownloadData card, URL url, String actualFilename, int count) {
|
||||||
this.card = card;
|
this.card = card;
|
||||||
this.url = url;
|
this.url = url;
|
||||||
this.count = count;
|
this.count = count;
|
||||||
|
@ -583,7 +581,6 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
BufferedOutputStream out;
|
|
||||||
|
|
||||||
// Logger.getLogger(this.getClass()).info(url.toString());
|
// Logger.getLogger(this.getClass()).info(url.toString());
|
||||||
boolean useTempFile = false;
|
boolean useTempFile = false;
|
||||||
|
@ -602,6 +599,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
||||||
|
|
||||||
if (responseCode == 200 || useTempFile) {
|
if (responseCode == 200 || useTempFile) {
|
||||||
if (!useTempFile) {
|
if (!useTempFile) {
|
||||||
|
BufferedOutputStream out;
|
||||||
try (BufferedInputStream in = new BufferedInputStream(httpConn.getInputStream())) {
|
try (BufferedInputStream in = new BufferedInputStream(httpConn.getInputStream())) {
|
||||||
//try (BufferedInputStream in = new BufferedInputStream(url.openConnection(p).getInputStream())) {
|
//try (BufferedInputStream in = new BufferedInputStream(url.openConnection(p).getInputStream())) {
|
||||||
out = new BufferedOutputStream(new TFileOutputStream(temporaryFile));
|
out = new BufferedOutputStream(new TFileOutputStream(temporaryFile));
|
||||||
|
|
|
@ -39,7 +39,7 @@ import org.mage.plugins.card.utils.CardImageUtils;
|
||||||
* look</li>
|
* look</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
*/
|
*/
|
||||||
public class ImageCache {
|
public final class ImageCache {
|
||||||
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(ImageCache.class);
|
private static final Logger LOGGER = Logger.getLogger(ImageCache.class);
|
||||||
|
|
||||||
|
@ -157,6 +157,9 @@ public class ImageCache {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ImageCache() {
|
||||||
|
}
|
||||||
|
|
||||||
public static BufferedImage getMorphImage() {
|
public static BufferedImage getMorphImage() {
|
||||||
CardDownloadData info = new CardDownloadData("Morph", "KTK", "0", false, 0, "KTK", "");
|
CardDownloadData info = new CardDownloadData("Morph", "KTK", "0", false, 0, "KTK", "");
|
||||||
info.setToken(true);
|
info.setToken(true);
|
||||||
|
@ -222,8 +225,7 @@ public class ImageCache {
|
||||||
*/
|
*/
|
||||||
private static BufferedImage getImage(String key) {
|
private static BufferedImage getImage(String key) {
|
||||||
try {
|
try {
|
||||||
BufferedImage image = IMAGE_CACHE.get(key);
|
return IMAGE_CACHE.get(key);
|
||||||
return image;
|
|
||||||
} catch (NullPointerException ex) {
|
} catch (NullPointerException ex) {
|
||||||
// unfortunately NullOutputException, thrown when apply() returns
|
// unfortunately NullOutputException, thrown when apply() returns
|
||||||
// null, is not public
|
// null, is not public
|
||||||
|
@ -244,11 +246,7 @@ public class ImageCache {
|
||||||
* the cache.
|
* the cache.
|
||||||
*/
|
*/
|
||||||
private static BufferedImage tryGetImage(String key) {
|
private static BufferedImage tryGetImage(String key) {
|
||||||
if (IMAGE_CACHE.containsKey(key)) {
|
return IMAGE_CACHE.containsKey(key) ? IMAGE_CACHE.get(key) : null;
|
||||||
return IMAGE_CACHE.get(key);
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -279,11 +277,11 @@ public class ImageCache {
|
||||||
if (file == null) {
|
if (file == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
BufferedImage image = null;
|
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
LOGGER.debug("File does not exist: " + file.toString());
|
LOGGER.debug("File does not exist: " + file.toString());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
BufferedImage image = null;
|
||||||
try {
|
try {
|
||||||
try (TFileInputStream inputStream = new TFileInputStream(file)) {
|
try (TFileInputStream inputStream = new TFileInputStream(file)) {
|
||||||
image = ImageIO.read(inputStream);
|
image = ImageIO.read(inputStream);
|
||||||
|
@ -395,8 +393,7 @@ public class ImageCache {
|
||||||
|
|
||||||
public static TFile getTFile(String path) {
|
public static TFile getTFile(String path) {
|
||||||
try {
|
try {
|
||||||
TFile file = new TFile(path);
|
return new TFile(path);
|
||||||
return file;
|
|
||||||
} catch (NullPointerException ex) {
|
} catch (NullPointerException ex) {
|
||||||
LOGGER.warn("Imagefile does not exist: " + path);
|
LOGGER.warn("Imagefile does not exist: " + path);
|
||||||
}
|
}
|
||||||
|
|
|
@ -271,8 +271,7 @@ public class ChatManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<ChatSession> getChatSessions() {
|
public ArrayList<ChatSession> getChatSessions() {
|
||||||
ArrayList<ChatSession> chatSessionList = new ArrayList<>(chatSessions.values());
|
return new ArrayList<>(chatSessions.values());
|
||||||
return chatSessionList;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,6 @@
|
||||||
package mage.server;
|
package mage.server;
|
||||||
|
|
||||||
import mage.interfaces.callback.ClientCallback;
|
import mage.interfaces.callback.ClientCallback;
|
||||||
import mage.server.exceptions.UserNotFoundException;
|
|
||||||
import mage.view.ChatMessage;
|
import mage.view.ChatMessage;
|
||||||
import mage.view.ChatMessage.MessageColor;
|
import mage.view.ChatMessage.MessageColor;
|
||||||
import mage.view.ChatMessage.MessageType;
|
import mage.view.ChatMessage.MessageType;
|
||||||
|
@ -36,7 +35,6 @@ import mage.view.ChatMessage.SoundToPlay;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
|
@ -227,13 +227,13 @@ public class MageServerImpl implements MageServer {
|
||||||
// check AI players max
|
// check AI players max
|
||||||
String maxAiOpponents = ConfigSettings.getInstance().getMaxAiOpponents();
|
String maxAiOpponents = ConfigSettings.getInstance().getMaxAiOpponents();
|
||||||
if (maxAiOpponents != null) {
|
if (maxAiOpponents != null) {
|
||||||
int max = Integer.parseInt(maxAiOpponents);
|
|
||||||
int aiPlayers = 0;
|
int aiPlayers = 0;
|
||||||
for (String playerType : options.getPlayerTypes()) {
|
for (String playerType : options.getPlayerTypes()) {
|
||||||
if (!playerType.equals("Human")) {
|
if (!playerType.equals("Human")) {
|
||||||
aiPlayers++;
|
aiPlayers++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
int max = Integer.parseInt(maxAiOpponents);
|
||||||
if (aiPlayers > max) {
|
if (aiPlayers > max) {
|
||||||
user.showUserMessage("Create tournament", "It's only allowed to use a maximum of " + max + " AI players.");
|
user.showUserMessage("Create tournament", "It's only allowed to use a maximum of " + max + " AI players.");
|
||||||
throw new MageException("No message");
|
throw new MageException("No message");
|
||||||
|
|
|
@ -37,8 +37,7 @@ public class MailClient {
|
||||||
message.setSubject(subject);
|
message.setSubject(subject);
|
||||||
message.setText(text);
|
message.setText(text);
|
||||||
|
|
||||||
Transport trnsport;
|
Transport trnsport = session.getTransport("smtps");
|
||||||
trnsport = session.getTransport("smtps");
|
|
||||||
trnsport.connect(null, properties.getProperty("mail.password"));
|
trnsport.connect(null, properties.getProperty("mail.password"));
|
||||||
message.saveChanges();
|
message.saveChanges();
|
||||||
trnsport.sendMessage(message, message.getAllRecipients());
|
trnsport.sendMessage(message, message.getAllRecipients());
|
||||||
|
|
|
@ -116,13 +116,13 @@ public class Main {
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("Loading extension packages...");
|
logger.info("Loading extension packages...");
|
||||||
List<ExtensionPackage> extensions = new ArrayList<>();
|
|
||||||
if (!extensionFolder.exists()) {
|
if (!extensionFolder.exists()) {
|
||||||
if (!extensionFolder.mkdirs()) {
|
if (!extensionFolder.mkdirs()) {
|
||||||
logger.error("Could not create extensions directory.");
|
logger.error("Could not create extensions directory.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
File[] extensionDirectories = extensionFolder.listFiles();
|
File[] extensionDirectories = extensionFolder.listFiles();
|
||||||
|
List<ExtensionPackage> extensions = new ArrayList<>();
|
||||||
if (extensionDirectories != null) {
|
if (extensionDirectories != null) {
|
||||||
for (File f : extensionDirectories) {
|
for (File f : extensionDirectories) {
|
||||||
if (f.isDirectory()) {
|
if (f.isDirectory()) {
|
||||||
|
|
|
@ -101,11 +101,11 @@ public class Session {
|
||||||
return returnMessage;
|
return returnMessage;
|
||||||
}
|
}
|
||||||
AuthorizedUserRepository.instance.add(userName, password, email);
|
AuthorizedUserRepository.instance.add(userName, password, email);
|
||||||
String subject = "XMage Registration Completed";
|
|
||||||
String text = "You are successfully registered as " + userName + '.';
|
String text = "You are successfully registered as " + userName + '.';
|
||||||
text += " Your initial, generated password is: " + password;
|
text += " Your initial, generated password is: " + password;
|
||||||
|
|
||||||
boolean success;
|
boolean success;
|
||||||
|
String subject = "XMage Registration Completed";
|
||||||
if (!ConfigSettings.getInstance().getMailUser().isEmpty()) {
|
if (!ConfigSettings.getInstance().getMailUser().isEmpty()) {
|
||||||
success = MailClient.sendMessage(email, subject, text);
|
success = MailClient.sendMessage(email, subject, text);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -173,8 +173,9 @@ public class SessionManager {
|
||||||
*/
|
*/
|
||||||
public void disconnectUser(String sessionId, String userSessionId) {
|
public void disconnectUser(String sessionId, String userSessionId) {
|
||||||
if (isAdmin(sessionId)) {
|
if (isAdmin(sessionId)) {
|
||||||
User userAdmin, user;
|
User userAdmin;
|
||||||
if ((userAdmin = getUserFromSession(sessionId)) != null) {
|
if ((userAdmin = getUserFromSession(sessionId)) != null) {
|
||||||
|
User user;
|
||||||
if ((user = getUserFromSession(userSessionId)) != null) {
|
if ((user = getUserFromSession(userSessionId)) != null) {
|
||||||
user.showUserMessage("Admin operation", "Your session was disconnected by Admin.");
|
user.showUserMessage("Admin operation", "Your session was disconnected by Admin.");
|
||||||
userAdmin.showUserMessage("Admin action", "User" + user.getName() + " was disconnected.");
|
userAdmin.showUserMessage("Admin action", "User" + user.getName() + " was disconnected.");
|
||||||
|
|
|
@ -911,9 +911,6 @@ public class TableController {
|
||||||
public boolean isMatchTableStillValid() {
|
public boolean isMatchTableStillValid() {
|
||||||
// check only normal match table with state != Finished
|
// check only normal match table with state != Finished
|
||||||
if (!table.isTournament()) {
|
if (!table.isTournament()) {
|
||||||
int humanPlayers = 0;
|
|
||||||
int aiPlayers = 0;
|
|
||||||
int validHumanPlayers = 0;
|
|
||||||
if (!(table.getState() == TableState.WAITING || table.getState() == TableState.STARTING || table.getState() == TableState.READY_TO_START)) {
|
if (!(table.getState() == TableState.WAITING || table.getState() == TableState.STARTING || table.getState() == TableState.READY_TO_START)) {
|
||||||
if (match == null) {
|
if (match == null) {
|
||||||
logger.debug("- Match table with no match:");
|
logger.debug("- Match table with no match:");
|
||||||
|
@ -927,6 +924,9 @@ public class TableController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// check for active players
|
// check for active players
|
||||||
|
int validHumanPlayers = 0;
|
||||||
|
int aiPlayers = 0;
|
||||||
|
int humanPlayers = 0;
|
||||||
for (Map.Entry<UUID, UUID> userPlayerEntry : userPlayerMap.entrySet()) {
|
for (Map.Entry<UUID, UUID> userPlayerEntry : userPlayerMap.entrySet()) {
|
||||||
MatchPlayer matchPlayer = match.getPlayer(userPlayerEntry.getValue());
|
MatchPlayer matchPlayer = match.getPlayer(userPlayerEntry.getValue());
|
||||||
if (matchPlayer == null) {
|
if (matchPlayer == null) {
|
||||||
|
|
|
@ -55,9 +55,8 @@ public class CubeFactory {
|
||||||
public DraftCube createDraftCube(String draftCubeName) {
|
public DraftCube createDraftCube(String draftCubeName) {
|
||||||
|
|
||||||
DraftCube draftCube;
|
DraftCube draftCube;
|
||||||
Constructor<?> con;
|
|
||||||
try {
|
try {
|
||||||
con = draftCubes.get(draftCubeName).getConstructor();
|
Constructor<?> con = draftCubes.get(draftCubeName).getConstructor();
|
||||||
draftCube = (DraftCube)con.newInstance();
|
draftCube = (DraftCube)con.newInstance();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
logger.fatal("CubeFactory error", ex);
|
logger.fatal("CubeFactory error", ex);
|
||||||
|
@ -71,9 +70,8 @@ public class CubeFactory {
|
||||||
public DraftCube createDeckDraftCube(String draftCubeName, Deck cubeFromDeck) {
|
public DraftCube createDeckDraftCube(String draftCubeName, Deck cubeFromDeck) {
|
||||||
|
|
||||||
DraftCube draftCube;
|
DraftCube draftCube;
|
||||||
Constructor<?> con;
|
|
||||||
try {
|
try {
|
||||||
con = draftCubes.get(draftCubeName).getConstructor(Deck.class);
|
Constructor<?> con = draftCubes.get(draftCubeName).getConstructor(Deck.class);
|
||||||
draftCube = (DraftCube)con.newInstance(cubeFromDeck);
|
draftCube = (DraftCube)con.newInstance(cubeFromDeck);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
logger.fatal("CubeFactory error", ex);
|
logger.fatal("CubeFactory error", ex);
|
||||||
|
|
|
@ -55,9 +55,8 @@ public class DeckValidatorFactory {
|
||||||
public DeckValidator createDeckValidator(String deckType) {
|
public DeckValidator createDeckValidator(String deckType) {
|
||||||
|
|
||||||
DeckValidator validator;
|
DeckValidator validator;
|
||||||
Constructor<?> con;
|
|
||||||
try {
|
try {
|
||||||
con = deckTypes.get(deckType).getConstructor();
|
Constructor<?> con = deckTypes.get(deckType).getConstructor();
|
||||||
validator = (DeckValidator)con.newInstance();
|
validator = (DeckValidator)con.newInstance();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
logger.fatal("DeckValidatorFactory error", ex);
|
logger.fatal("DeckValidatorFactory error", ex);
|
||||||
|
|
|
@ -621,9 +621,8 @@ public class GameController implements GameCallback {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cheat(UUID userId, UUID playerId, DeckCardLists deckList) {
|
public void cheat(UUID userId, UUID playerId, DeckCardLists deckList) {
|
||||||
Deck deck;
|
|
||||||
try {
|
try {
|
||||||
deck = Deck.load(deckList, false, false);
|
Deck deck = Deck.load(deckList, false, false);
|
||||||
game.loadCards(deck.getCards(), playerId);
|
game.loadCards(deck.getCards(), playerId);
|
||||||
for (Card card : deck.getCards()) {
|
for (Card card : deck.getCards()) {
|
||||||
card.putOntoBattlefield(game, Zone.OUTSIDE, null, playerId);
|
card.putOntoBattlefield(game, Zone.OUTSIDE, null, playerId);
|
||||||
|
|
|
@ -62,9 +62,8 @@ public class GameFactory {
|
||||||
public Match createMatch(String gameType, MatchOptions options) {
|
public Match createMatch(String gameType, MatchOptions options) {
|
||||||
|
|
||||||
Match match;
|
Match match;
|
||||||
Constructor<Match> con;
|
|
||||||
try {
|
try {
|
||||||
con = games.get(gameType).getConstructor(MatchOptions.class);
|
Constructor<Match> con = games.get(gameType).getConstructor(MatchOptions.class);
|
||||||
match = con.newInstance(options);
|
match = con.newInstance(options);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
logger.fatal("Error creating match - " + gameType, ex);
|
logger.fatal("Error creating match - " + gameType, ex);
|
||||||
|
|
|
@ -29,7 +29,6 @@ package mage.server.game;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
@ -89,10 +88,10 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void update() {
|
private void update() {
|
||||||
ArrayList<TableView> tableList = new ArrayList<>();
|
|
||||||
ArrayList<MatchView> matchList = new ArrayList<>();
|
|
||||||
List<Table> allTables = new ArrayList<>(tables.values());
|
List<Table> allTables = new ArrayList<>(tables.values());
|
||||||
allTables.sort(new TableListSorter());
|
allTables.sort(new TableListSorter());
|
||||||
|
ArrayList<MatchView> matchList = new ArrayList<>();
|
||||||
|
ArrayList<TableView> tableList = new ArrayList<>();
|
||||||
for (Table table : allTables) {
|
for (Table table : allTables) {
|
||||||
if (table.getState() != TableState.FINISHED) {
|
if (table.getState() != TableState.FINISHED) {
|
||||||
tableList.add(new TableView(table));
|
tableList.add(new TableView(table));
|
||||||
|
|
|
@ -54,13 +54,11 @@ public class PlayerFactory {
|
||||||
private PlayerFactory() {}
|
private PlayerFactory() {}
|
||||||
|
|
||||||
public Player createPlayer(String playerType, String name, RangeOfInfluence range, int skill) {
|
public Player createPlayer(String playerType, String name, RangeOfInfluence range, int skill) {
|
||||||
Player player;
|
|
||||||
Constructor<?> con;
|
|
||||||
try {
|
try {
|
||||||
Class playerTypeClass = playerTypes.get(playerType);
|
Class playerTypeClass = playerTypes.get(playerType);
|
||||||
if (playerTypeClass != null) {
|
if (playerTypeClass != null) {
|
||||||
con = playerTypeClass.getConstructor(String.class, RangeOfInfluence.class, int.class);
|
Constructor<?> con = playerTypeClass.getConstructor(String.class, RangeOfInfluence.class, int.class);
|
||||||
player = (Player)con.newInstance(name, range, skill);
|
Player player = (Player) con.newInstance(name, range, skill);
|
||||||
logger.trace("Player created: " + name + " - " + player.getId());
|
logger.trace("Player created: " + name + " - " + player.getId());
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,6 @@ import java.util.UUID;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.GameState;
|
import mage.game.GameState;
|
||||||
import mage.interfaces.callback.ClientCallback;
|
import mage.interfaces.callback.ClientCallback;
|
||||||
import mage.server.User;
|
|
||||||
import mage.server.UserManager;
|
import mage.server.UserManager;
|
||||||
import mage.view.GameView;
|
import mage.view.GameView;
|
||||||
|
|
||||||
|
|
|
@ -418,10 +418,10 @@ public class TournamentController {
|
||||||
}
|
}
|
||||||
// replace player that quits with draft bot
|
// replace player that quits with draft bot
|
||||||
if (humans > 1) {
|
if (humans > 1) {
|
||||||
String replacePlayerName = "Draftbot";
|
|
||||||
Optional<User> user = UserManager.getInstance().getUser(userId);
|
Optional<User> user = UserManager.getInstance().getUser(userId);
|
||||||
TableController tableController = TableManager.getInstance().getController(tableId);
|
TableController tableController = TableManager.getInstance().getController(tableId);
|
||||||
if (tableController != null) {
|
if (tableController != null) {
|
||||||
|
String replacePlayerName = "Draftbot";
|
||||||
if (user.isPresent()) {
|
if (user.isPresent()) {
|
||||||
replacePlayerName = "Draftbot (" + user.get().getName() + ')';
|
replacePlayerName = "Draftbot (" + user.get().getName() + ')';
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,9 +64,8 @@ public class TournamentFactory {
|
||||||
public Tournament createTournament(String tournamentType, TournamentOptions options) {
|
public Tournament createTournament(String tournamentType, TournamentOptions options) {
|
||||||
|
|
||||||
Tournament tournament;
|
Tournament tournament;
|
||||||
Constructor<Tournament> con;
|
|
||||||
try {
|
try {
|
||||||
con = tournaments.get(tournamentType).getConstructor(TournamentOptions.class);
|
Constructor<Tournament> con = tournaments.get(tournamentType).getConstructor(TournamentOptions.class);
|
||||||
tournament = con.newInstance(options);
|
tournament = con.newInstance(options);
|
||||||
// transfer set information, create short info string for included sets
|
// transfer set information, create short info string for included sets
|
||||||
tournament.setTournamentType(tournamentTypes.get(tournamentType));
|
tournament.setTournamentType(tournamentTypes.get(tournamentType));
|
||||||
|
|
|
@ -45,7 +45,6 @@ public class SystemUtil {
|
||||||
public static void addCardsForTesting(Game game) {
|
public static void addCardsForTesting(Game game) {
|
||||||
try {
|
try {
|
||||||
File f = new File(INIT_FILE_PATH);
|
File f = new File(INIT_FILE_PATH);
|
||||||
Pattern pattern = Pattern.compile("([a-zA-Z]+):([\\w]+):([a-zA-Z ,\\/\\-.!'\\d:]+?):(\\d+)");
|
|
||||||
if (!f.exists()) {
|
if (!f.exists()) {
|
||||||
logger.warn("Couldn't find init file: " + INIT_FILE_PATH);
|
logger.warn("Couldn't find init file: " + INIT_FILE_PATH);
|
||||||
return;
|
return;
|
||||||
|
@ -54,6 +53,7 @@ public class SystemUtil {
|
||||||
logger.info("Parsing init.txt... ");
|
logger.info("Parsing init.txt... ");
|
||||||
|
|
||||||
try (Scanner scanner = new Scanner(f)) {
|
try (Scanner scanner = new Scanner(f)) {
|
||||||
|
Pattern pattern = Pattern.compile("([a-zA-Z]+):([\\w]+):([a-zA-Z ,\\/\\-.!'\\d:]+?):(\\d+)");
|
||||||
while (scanner.hasNextLine()) {
|
while (scanner.hasNextLine()) {
|
||||||
String line = scanner.nextLine().trim();
|
String line = scanner.nextLine().trim();
|
||||||
if (line.isEmpty() || line.startsWith("#")) {
|
if (line.isEmpty() || line.startsWith("#")) {
|
||||||
|
|
Loading…
Reference in a new issue