mirror of
https://github.com/correl/mage.git
synced 2024-12-26 19:16:54 +00:00
Sonar cleanups 03032019
This commit is contained in:
parent
f46f321635
commit
45f665eb1d
13 changed files with 37 additions and 41 deletions
|
@ -270,12 +270,14 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
|
||||||
mageCards = new LinkedHashMap<>();
|
mageCards = new LinkedHashMap<>();
|
||||||
|
|
||||||
//Find card view
|
//Find card view
|
||||||
for (UUID uuid : cards.keySet()) {
|
for (Map.Entry<UUID, CardView> view : cards.entrySet()) {
|
||||||
|
UUID uuid = view.getKey();
|
||||||
|
CardView cardView = view.getValue();
|
||||||
if (oldMageCards.containsKey(uuid)) {
|
if (oldMageCards.containsKey(uuid)) {
|
||||||
mageCards.put(uuid, oldMageCards.get(uuid));
|
mageCards.put(uuid, oldMageCards.get(uuid));
|
||||||
oldMageCards.remove(uuid);
|
oldMageCards.remove(uuid);
|
||||||
} else {
|
} else {
|
||||||
mageCards.put(uuid, addCard(cards.get(uuid), bigCard, gameId));
|
mageCards.put(uuid, addCard(cardView, bigCard, gameId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Remove unused cards
|
//Remove unused cards
|
||||||
|
|
|
@ -238,11 +238,7 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane {
|
||||||
cardDimension = new Dimension(Config.dimensions.getFrameWidth(), Config.dimensions.getFrameHeight());
|
cardDimension = new Dimension(Config.dimensions.getFrameWidth(), Config.dimensions.getFrameHeight());
|
||||||
}
|
}
|
||||||
final MagePermanent perm = Plugins.instance.getMagePermanent(permanent, bigCard, cardDimension, gameId, true);
|
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);
|
|
||||||
}
|
|
||||||
permanents.put(permanent.getId(), perm);
|
permanents.put(permanent.getId(), perm);
|
||||||
|
|
||||||
BattlefieldPanel.this.jPanel.add(perm, 10);
|
BattlefieldPanel.this.jPanel.add(perm, 10);
|
||||||
|
|
|
@ -428,7 +428,7 @@ public class CardViewEDHPowerLevelComparator implements Comparator<CardView> {
|
||||||
|| cn.equals("krosan restorer") || cn.equals("laboratory maniac")
|
|| cn.equals("krosan restorer") || cn.equals("laboratory maniac")
|
||||||
|| cn.equals("leovold, emissary of trest")
|
|| cn.equals("leovold, emissary of trest")
|
||||||
|| cn.equals("leonin relic-warder") || cn.equals("leyline of the void")
|
|| cn.equals("leonin relic-warder") || cn.equals("leyline of the void")
|
||||||
|| cn.equals("memnarch") || cn.equals("memnarch")
|
|| cn.equals("memnarch")
|
||||||
|| cn.equals("meren of clan nel toth") || cn.equals("mikaeus, the unhallowed")
|
|| cn.equals("meren of clan nel toth") || cn.equals("mikaeus, the unhallowed")
|
||||||
|| cn.equals("mindcrank") || cn.equals("mindslaver")
|
|| cn.equals("mindcrank") || cn.equals("mindslaver")
|
||||||
|| cn.equals("minion reflector") || cn.equals("mycosynth lattice")
|
|| cn.equals("minion reflector") || cn.equals("mycosynth lattice")
|
||||||
|
@ -446,7 +446,7 @@ public class CardViewEDHPowerLevelComparator implements Comparator<CardView> {
|
||||||
|| cn.equals("sunder")
|
|| cn.equals("sunder")
|
||||||
|| cn.equals("storm cauldron") || cn.equals("teferi's puzzle box")
|
|| cn.equals("storm cauldron") || cn.equals("teferi's puzzle box")
|
||||||
|| cn.equals("tangle wire")
|
|| cn.equals("tangle wire")
|
||||||
|| cn.equals("teferi, mage of zhalfir") || cn.equals("teferi, mage of zhalfir")
|
|| cn.equals("teferi, mage of zhalfir")
|
||||||
|| cn.equals("tezzeret the seeker") || cn.equals("time stretch")
|
|| cn.equals("tezzeret the seeker") || cn.equals("time stretch")
|
||||||
|| cn.equals("time warp") || cn.equals("training grounds")
|
|| cn.equals("time warp") || cn.equals("training grounds")
|
||||||
|| cn.equals("triskelavus") || cn.equals("triskelion")
|
|| cn.equals("triskelavus") || cn.equals("triskelion")
|
||||||
|
|
|
@ -180,7 +180,7 @@ public final class ManaSymbols {
|
||||||
codes = EnumSet.of(Rarity.COMMON, Rarity.UNCOMMON, Rarity.RARE, Rarity.MYTHIC);
|
codes = EnumSet.of(Rarity.COMMON, Rarity.UNCOMMON, Rarity.RARE, Rarity.MYTHIC);
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<Rarity, Image> rarityImages = new HashMap<>();
|
Map<Rarity, Image> rarityImages = new EnumMap<>(Rarity.class);
|
||||||
setImages.put(set, rarityImages);
|
setImages.put(set, rarityImages);
|
||||||
|
|
||||||
// load medium size
|
// load medium size
|
||||||
|
|
|
@ -25,7 +25,7 @@ public enum TokensMtgImageSource implements CardImageSource {
|
||||||
private static final Logger logger = Logger.getLogger(TokensMtgImageSource.class);
|
private static final Logger logger = Logger.getLogger(TokensMtgImageSource.class);
|
||||||
|
|
||||||
// [[EXP/Name, TokenData>
|
// [[EXP/Name, TokenData>
|
||||||
private HashMap<String, ArrayList<TokenData>> tokensData;
|
private HashMap<String, List<TokenData>> tokensData;
|
||||||
private static final Set<String> supportedSets = new LinkedHashSet<String>();
|
private static final Set<String> supportedSets = new LinkedHashSet<String>();
|
||||||
|
|
||||||
private final Object tokensDataSync = new Object();
|
private final Object tokensDataSync = new Object();
|
||||||
|
@ -177,7 +177,7 @@ public enum TokensMtgImageSource implements CardImageSource {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private HashMap<String, ArrayList<TokenData>> getTokensData() throws IOException {
|
private HashMap<String, List<TokenData>> getTokensData() throws IOException {
|
||||||
synchronized (tokensDataSync) {
|
synchronized (tokensDataSync) {
|
||||||
if (tokensData == null) {
|
if (tokensData == null) {
|
||||||
DownloadPicturesService.getInstance().updateAndViewMessage("Find tokens data...");
|
DownloadPicturesService.getInstance().updateAndViewMessage("Find tokens data...");
|
||||||
|
@ -188,7 +188,7 @@ public enum TokensMtgImageSource implements CardImageSource {
|
||||||
List<TokenData> fileTokensData = parseTokensData(inputStream);
|
List<TokenData> fileTokensData = parseTokensData(inputStream);
|
||||||
for (TokenData tokenData : fileTokensData) {
|
for (TokenData tokenData : fileTokensData) {
|
||||||
String key = tokenData.getExpansionSetCode() + "/" + tokenData.getName();
|
String key = tokenData.getExpansionSetCode() + "/" + tokenData.getName();
|
||||||
ArrayList<TokenData> list = tokensData.get(key);
|
List<TokenData> list = tokensData.get(key);
|
||||||
if (list == null) {
|
if (list == null) {
|
||||||
list = new ArrayList<>();
|
list = new ArrayList<>();
|
||||||
tokensData.put(key, list);
|
tokensData.put(key, list);
|
||||||
|
@ -213,7 +213,7 @@ public enum TokensMtgImageSource implements CardImageSource {
|
||||||
// logger.info("TOK: " + siteData.getExpansionSetCode() + "/" + siteData.getName());
|
// logger.info("TOK: " + siteData.getExpansionSetCode() + "/" + siteData.getName());
|
||||||
String key = siteData.getExpansionSetCode() + "/" + siteData.getName();
|
String key = siteData.getExpansionSetCode() + "/" + siteData.getName();
|
||||||
supportedSets.add(siteData.getExpansionSetCode());
|
supportedSets.add(siteData.getExpansionSetCode());
|
||||||
ArrayList<TokenData> list = tokensData.get(key);
|
List<TokenData> list = tokensData.get(key);
|
||||||
if (list == null) {
|
if (list == null) {
|
||||||
list = new ArrayList<>();
|
list = new ArrayList<>();
|
||||||
tokensData.put(key, list);
|
tokensData.put(key, list);
|
||||||
|
@ -249,7 +249,7 @@ public enum TokensMtgImageSource implements CardImageSource {
|
||||||
BufferedReader reader = new BufferedReader(inputReader)) {
|
BufferedReader reader = new BufferedReader(inputReader)) {
|
||||||
// we have to specify encoding to read special comma
|
// we have to specify encoding to read special comma
|
||||||
|
|
||||||
reader.readLine(); // skip header
|
String header = reader.readLine(); // skip header
|
||||||
String line = reader.readLine();
|
String line = reader.readLine();
|
||||||
// states
|
// states
|
||||||
// 0 - wait set name
|
// 0 - wait set name
|
||||||
|
|
|
@ -40,7 +40,7 @@ public enum WizardCardsImageSource implements CardImageSource {
|
||||||
|
|
||||||
WizardCardsImageSource() {
|
WizardCardsImageSource() {
|
||||||
|
|
||||||
languageAliases = new HashMap<>();
|
languageAliases = new EnumMap<>(CardLanguage.class);
|
||||||
languageAliases.put(CardLanguage.ENGLISH, "English");
|
languageAliases.put(CardLanguage.ENGLISH, "English");
|
||||||
languageAliases.put(CardLanguage.SPANISH, "Spanish");
|
languageAliases.put(CardLanguage.SPANISH, "Spanish");
|
||||||
languageAliases.put(CardLanguage.FRENCH, "French");
|
languageAliases.put(CardLanguage.FRENCH, "French");
|
||||||
|
@ -544,9 +544,9 @@ public enum WizardCardsImageSource implements CardImageSource {
|
||||||
getLandVariations(setLinks, cardSet, multiverseId, cardName);
|
getLandVariations(setLinks, cardSet, multiverseId, cardName);
|
||||||
} else {
|
} else {
|
||||||
String numberChar = "";
|
String numberChar = "";
|
||||||
int pos1 = cardName.indexOf("(");
|
int pos1 = cardName.indexOf('(');
|
||||||
if (pos1 > 0) {
|
if (pos1 > 0) {
|
||||||
int pos2 = cardName.indexOf("(", pos1 + 1);
|
int pos2 = cardName.indexOf('(', pos1 + 1);
|
||||||
if (pos2 > 0) {
|
if (pos2 > 0) {
|
||||||
numberChar = cardName.substring(pos2 + 1, pos2 + 2);
|
numberChar = cardName.substring(pos2 + 1, pos2 + 2);
|
||||||
cardName = cardName.substring(0, pos1);
|
cardName = cardName.substring(0, pos1);
|
||||||
|
|
|
@ -119,7 +119,7 @@ public class SessionImpl implements Session {
|
||||||
if (ex.getMessage() != null && ex.getMessage().startsWith("Unable to perform invocation")) {
|
if (ex.getMessage() != null && ex.getMessage().startsWith("Unable to perform invocation")) {
|
||||||
addMessage = "Maybe the server version is not compatible. ";
|
addMessage = "Maybe the server version is not compatible. ";
|
||||||
}
|
}
|
||||||
client.showMessage("Unable connect to server. " + addMessage + ex.getMessage() != null ? ex.getMessage() : "");
|
client.showMessage("Unable connect to server. " + addMessage + (ex.getMessage() != null ? ex.getMessage() : ""));
|
||||||
} catch (MageVersionException ex) {
|
} catch (MageVersionException ex) {
|
||||||
if (!canceled) {
|
if (!canceled) {
|
||||||
client.showMessage("Unable connect to server. " + ex.getMessage());
|
client.showMessage("Unable connect to server. " + ex.getMessage());
|
||||||
|
|
|
@ -121,10 +121,8 @@ public enum ServerMessagesUtil {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
Scanner scanner = null;
|
|
||||||
List<String> newMessages = new ArrayList<>();
|
List<String> newMessages = new ArrayList<>();
|
||||||
try {
|
try(Scanner scanner = new Scanner(is)) {
|
||||||
scanner = new Scanner(is);
|
|
||||||
while (scanner.hasNextLine()) {
|
while (scanner.hasNextLine()) {
|
||||||
String message = scanner.nextLine();
|
String message = scanner.nextLine();
|
||||||
if (!message.trim().isEmpty()) {
|
if (!message.trim().isEmpty()) {
|
||||||
|
@ -134,7 +132,6 @@ public enum ServerMessagesUtil {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error(e, e);
|
log.error(e, e);
|
||||||
} finally {
|
} finally {
|
||||||
StreamUtils.closeQuietly(scanner);
|
|
||||||
StreamUtils.closeQuietly(is);
|
StreamUtils.closeQuietly(is);
|
||||||
}
|
}
|
||||||
return newMessages;
|
return newMessages;
|
||||||
|
|
|
@ -2,8 +2,11 @@
|
||||||
package mage.cards.b;
|
package mage.cards.b;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import mage.MageInt;
|
import mage.MageInt;
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.abilities.common.AttacksTriggeredAbility;
|
import mage.abilities.common.AttacksTriggeredAbility;
|
||||||
|
@ -65,13 +68,10 @@ class BaneOfBalaGedEffect extends OneShotEffect {
|
||||||
if (defendingPlayer != null) {
|
if (defendingPlayer != null) {
|
||||||
Target target = new TargetControlledPermanent(2);
|
Target target = new TargetControlledPermanent(2);
|
||||||
defendingPlayer.chooseTarget(outcome, target, source, game);
|
defendingPlayer.chooseTarget(outcome, target, source, game);
|
||||||
Set<Card> toExile = new HashSet<>();
|
Set<Card> toExile = target.getTargets().stream()
|
||||||
target.getTargets().stream().map((targetId)
|
.map(game::getPermanent)
|
||||||
-> game.getPermanent(targetId)).filter((permanent)
|
.filter(Objects::nonNull)
|
||||||
-> (permanent != null)).forEach((permanent)
|
.collect(Collectors.toSet());
|
||||||
-> {
|
|
||||||
toExile.add(permanent);
|
|
||||||
});
|
|
||||||
defendingPlayer.moveCards(toExile, Zone.EXILED, source, game);
|
defendingPlayer.moveCards(toExile, Zone.EXILED, source, game);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package mage.cards.c;
|
package mage.cards.c;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import mage.MageInt;
|
import mage.MageInt;
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
|
@ -61,12 +62,11 @@ class CentaurMediatorEffect extends OneShotEffect {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Game game, Ability source) {
|
public boolean apply(Game game, Ability source) {
|
||||||
game.getState().getPlayersInRange(
|
game.getState().getPlayersInRange(
|
||||||
source.getControllerId(), game
|
source.getControllerId(), game)
|
||||||
).stream().map((playerId) -> game.getPlayer(playerId)).filter(
|
.stream()
|
||||||
(player) -> (player != null)
|
.map(game::getPlayer)
|
||||||
).forEachOrdered((player) -> {
|
.filter(Objects::nonNull)
|
||||||
player.gainLife(4, game, source);
|
.forEachOrdered(player -> player.gainLife(4, game, source));
|
||||||
});
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,7 +72,7 @@ class KavuPredatorTriggeredAbility extends TriggeredAbilityImpl {
|
||||||
@Override
|
@Override
|
||||||
public boolean checkTrigger(GameEvent event, Game game) {
|
public boolean checkTrigger(GameEvent event, Game game) {
|
||||||
if (game.getOpponents(this.controllerId).contains(event.getPlayerId())) {
|
if (game.getOpponents(this.controllerId).contains(event.getPlayerId())) {
|
||||||
this.getEffects().get(0).setValue("gainedLife", new Integer(event.getAmount()));
|
this.getEffects().get(0).setValue("gainedLife", event.getAmount());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -289,8 +289,9 @@ public final class RateCard {
|
||||||
}
|
}
|
||||||
|
|
||||||
// normalize for the file to [1..100]
|
// normalize for the file to [1..100]
|
||||||
for (String name : thisFileRatings.keySet()) {
|
for (Map.Entry<String, Integer> ratingByName : thisFileRatings.entrySet()) {
|
||||||
int r = thisFileRatings.get(name);
|
int r = ratingByName.getValue();
|
||||||
|
String name = ratingByName.getKey();
|
||||||
int newRating = (int) (100.0f * (r - min) / (max - min));
|
int newRating = (int) (100.0f * (r - min) / (max - min));
|
||||||
int oldRating = baseRatings.getOrDefault(name, 0);
|
int oldRating = baseRatings.getOrDefault(name, 0);
|
||||||
if (newRating > oldRating) {
|
if (newRating > oldRating) {
|
||||||
|
@ -339,7 +340,7 @@ public final class RateCard {
|
||||||
}
|
}
|
||||||
Integer typeCount = singleCount.get(symbol);
|
Integer typeCount = singleCount.get(symbol);
|
||||||
if (typeCount == null) {
|
if (typeCount == null) {
|
||||||
typeCount = new Integer(0);
|
typeCount = 0;
|
||||||
}
|
}
|
||||||
typeCount += 1;
|
typeCount += 1;
|
||||||
singleCount.put(symbol, typeCount);
|
singleCount.put(symbol, typeCount);
|
||||||
|
|
|
@ -28,7 +28,7 @@ public class JarVersion {
|
||||||
String manifestPath;
|
String manifestPath;
|
||||||
if (classPath.startsWith("jar")) {
|
if (classPath.startsWith("jar")) {
|
||||||
// jar source
|
// jar source
|
||||||
manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1) + "/META-INF/MANIFEST.MF";
|
manifestPath = classPath.substring(0, classPath.lastIndexOf('!') + 1) + "/META-INF/MANIFEST.MF";
|
||||||
} else {
|
} else {
|
||||||
// dir source (e.g. IDE's debug)
|
// dir source (e.g. IDE's debug)
|
||||||
// it's can be generated by runtime, but need extra code and performance: https://stackoverflow.com/questions/34674073/how-to-generate-manifest-mf-file-during-compile-phase
|
// it's can be generated by runtime, but need extra code and performance: https://stackoverflow.com/questions/34674073/how-to-generate-manifest-mf-file-during-compile-phase
|
||||||
|
|
Loading…
Reference in a new issue