mirror of
https://github.com/magefree/mage.git
synced 2025-12-24 12:31:59 -08:00
Merge pull request #2891 from kubikrubikvkube/master
Nulls to optional. Also there was bug with AetherChaser
This commit is contained in:
commit
afbf5ce2b6
131 changed files with 188 additions and 183 deletions
|
|
@ -37,7 +37,7 @@ import java.util.Scanner;
|
|||
/**
|
||||
* @author Lymia
|
||||
*/
|
||||
public class ExtensionPackageLoader {
|
||||
public final class ExtensionPackageLoader {
|
||||
public static ExtensionPackage loadExtension(File directory) throws IOException {
|
||||
if(!directory.exists ()) throw new RuntimeException("File not found "+directory);
|
||||
if(!directory.isDirectory()) throw new RuntimeException(directory+" is not a directory");
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ import javax.mail.internet.MimeMessage;
|
|||
import mage.server.util.ConfigSettings;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
public class GmailClient {
|
||||
public final class GmailClient {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(Main.class);
|
||||
private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import javax.mail.internet.MimeMessage;
|
|||
import mage.server.util.ConfigSettings;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
public class MailClient {
|
||||
public final class MailClient {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(Main.class);
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import javax.ws.rs.core.MediaType;
|
|||
import mage.server.util.ConfigSettings;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
public class MailgunClient {
|
||||
public final class MailgunClient {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(Main.class);
|
||||
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ import java.util.*;
|
|||
/**
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class Main {
|
||||
public final class Main {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(Main.class);
|
||||
private static final MageVersion version = new MageVersion(MageVersion.MAGE_VERSION_MAJOR, MageVersion.MAGE_VERSION_MINOR, MageVersion.MAGE_VERSION_PATCH, MageVersion.MAGE_VERSION_MINOR_PATCH, MageVersion.MAGE_VERSION_INFO);
|
||||
|
|
|
|||
|
|
@ -27,14 +27,6 @@
|
|||
*/
|
||||
package mage.server;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import mage.MageException;
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
|
|
@ -68,6 +60,15 @@ import mage.server.util.ThreadExecutor;
|
|||
import mage.view.ChatMessage;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
|
|
@ -195,8 +196,9 @@ public class TableController {
|
|||
return false;
|
||||
}
|
||||
|
||||
Player player = createPlayer(name, seat.getPlayerType(), skill);
|
||||
if (player != null) {
|
||||
Optional<Player> playerOptional = createPlayer(name, seat.getPlayerType(), skill);
|
||||
if (playerOptional.isPresent()) {
|
||||
Player player = playerOptional.get();
|
||||
if (!player.canJoinTable(table)) {
|
||||
user.showUserMessage("Join Table", new StringBuilder("A ").append(seat.getPlayerType()).append(" player can't join this table.").toString());
|
||||
return false;
|
||||
|
|
@ -227,10 +229,11 @@ public class TableController {
|
|||
}
|
||||
|
||||
public synchronized boolean replaceDraftPlayer(Player oldPlayer, String name, String playerType, int skill) {
|
||||
Player newPlayer = createPlayer(name, playerType, skill);
|
||||
if (newPlayer == null || table.getState() != TableState.DRAFTING) {
|
||||
Optional<Player> newPlayerOpt = createPlayer(name, playerType, skill);
|
||||
if (!newPlayerOpt.isPresent() || table.getState() != TableState.DRAFTING) {
|
||||
return false;
|
||||
}
|
||||
Player newPlayer = newPlayerOpt.get();
|
||||
TournamentPlayer oldTournamentPlayer = tournament.getPlayer(oldPlayer.getId());
|
||||
tournament.removePlayer(oldPlayer.getId());
|
||||
tournament.addPlayer(newPlayer, playerType);
|
||||
|
|
@ -331,13 +334,14 @@ public class TableController {
|
|||
}
|
||||
}
|
||||
|
||||
Player player = createPlayer(name, seat.getPlayerType(), skill);
|
||||
if (player == null) {
|
||||
Optional<Player> playerOpt = createPlayer(name, seat.getPlayerType(), skill);
|
||||
if (!playerOpt.isPresent()) {
|
||||
String message = new StringBuilder("Could not create player ").append(name).append(" of type ").append(seat.getPlayerType()).toString();
|
||||
logger.warn(new StringBuilder("User: ").append(user.getName()).append(" => ").append(message).toString());
|
||||
user.showUserMessage("Join Table", message);
|
||||
return false;
|
||||
}
|
||||
Player player = playerOpt.get();
|
||||
logger.debug("DECK validated: " + table.getValidator().getName() + ' ' + player.getName() + ' ' + deck.getName());
|
||||
if (!player.canJoinTable(table)) {
|
||||
user.showUserMessage("Join Table", new StringBuilder("A ").append(seat.getPlayerType()).append(" player can't join this table.").toString());
|
||||
|
|
@ -468,17 +472,18 @@ public class TableController {
|
|||
// ReplayManager.getInstance().replayGame(table.getId(), userId);
|
||||
// return true;
|
||||
// }
|
||||
private Player createPlayer(String name, String playerType, int skill) {
|
||||
Player player;
|
||||
private Optional<Player> createPlayer(String name, String playerType, int skill) {
|
||||
Optional<Player> playerOpt;
|
||||
if (options == null) {
|
||||
player = PlayerFactory.getInstance().createPlayer(playerType, name, RangeOfInfluence.ALL, skill);
|
||||
playerOpt = PlayerFactory.getInstance().createPlayer(playerType, name, RangeOfInfluence.ALL, skill);
|
||||
} else {
|
||||
player = PlayerFactory.getInstance().createPlayer(playerType, name, options.getRange(), skill);
|
||||
playerOpt = PlayerFactory.getInstance().createPlayer(playerType, name, options.getRange(), skill);
|
||||
}
|
||||
if (player != null) {
|
||||
if (playerOpt.isPresent()) {
|
||||
Player player = playerOpt.get();
|
||||
logger.trace("Player " + player.getName() + " created id: " + player.getId());
|
||||
}
|
||||
return player;
|
||||
return playerOpt;
|
||||
}
|
||||
|
||||
public void leaveTableAll() {
|
||||
|
|
|
|||
|
|
@ -28,14 +28,16 @@
|
|||
|
||||
package mage.server.game;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import mage.constants.RangeOfInfluence;
|
||||
import mage.players.Player;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
|
|
@ -53,14 +55,14 @@ public class PlayerFactory {
|
|||
|
||||
private PlayerFactory() {}
|
||||
|
||||
public Player createPlayer(String playerType, String name, RangeOfInfluence range, int skill) {
|
||||
public Optional<Player> createPlayer(String playerType, String name, RangeOfInfluence range, int skill) {
|
||||
try {
|
||||
Class playerTypeClass = playerTypes.get(playerType);
|
||||
if (playerTypeClass != null) {
|
||||
Constructor<?> con = playerTypeClass.getConstructor(String.class, RangeOfInfluence.class, int.class);
|
||||
Player player = (Player) con.newInstance(name, range, skill);
|
||||
logger.trace("Player created: " + name + " - " + player.getId());
|
||||
return player;
|
||||
return Optional.of(player);
|
||||
}
|
||||
else {
|
||||
logger.fatal("Unknown player type: " + playerType);
|
||||
|
|
@ -68,7 +70,7 @@ public class PlayerFactory {
|
|||
} catch (Exception ex) {
|
||||
logger.fatal("PlayerFactory error ", ex);
|
||||
}
|
||||
return null;
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public Set<String> getPlayerTypes() {
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ import org.apache.log4j.Logger;
|
|||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class Config {
|
||||
public final class Config {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(Config.class);
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import mage.players.Player;
|
|||
/**
|
||||
* @author nantuko
|
||||
*/
|
||||
public class Splitter {
|
||||
public final class Splitter {
|
||||
|
||||
public static List<UUID> split(Game game, UUID playerId) {
|
||||
List<UUID> players = new ArrayList<>();
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ import java.util.regex.Pattern;
|
|||
/**
|
||||
* @author nantuko
|
||||
*/
|
||||
public class SystemUtil {
|
||||
public final class SystemUtil {
|
||||
|
||||
public static final DateFormat dateFormat = new SimpleDateFormat("yy-M-dd HH:mm:ss");
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue