mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 19:28:01 +00:00
Merge branch 'sonarqubefixes02' into 'master'
More SonarQube detected bugs fixed See merge request core-developers/forge!2021
This commit is contained in:
@@ -150,6 +150,8 @@ public class AiCardMemory {
|
|||||||
*/
|
*/
|
||||||
public boolean isRememberedCardByName(String cardName, MemorySet set) {
|
public boolean isRememberedCardByName(String cardName, MemorySet set) {
|
||||||
Set<Card> memorySet = getMemorySet(set);
|
Set<Card> memorySet = getMemorySet(set);
|
||||||
|
|
||||||
|
if (memorySet != null) {
|
||||||
Iterator<Card> it = memorySet.iterator();
|
Iterator<Card> it = memorySet.iterator();
|
||||||
|
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
@@ -158,6 +160,7 @@ public class AiCardMemory {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -174,6 +177,8 @@ public class AiCardMemory {
|
|||||||
*/
|
*/
|
||||||
public boolean isRememberedCardByName(String cardName, MemorySet set, Player owner) {
|
public boolean isRememberedCardByName(String cardName, MemorySet set, Player owner) {
|
||||||
Set<Card> memorySet = getMemorySet(set);
|
Set<Card> memorySet = getMemorySet(set);
|
||||||
|
|
||||||
|
if (memorySet != null) {
|
||||||
Iterator<Card> it = memorySet.iterator();
|
Iterator<Card> it = memorySet.iterator();
|
||||||
|
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
@@ -182,6 +187,7 @@ public class AiCardMemory {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -197,7 +203,12 @@ public class AiCardMemory {
|
|||||||
if (c == null)
|
if (c == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
getMemorySet(set).add(c);
|
Set<Card> memorySet = getMemorySet(set);
|
||||||
|
|
||||||
|
if (memorySet != null) {
|
||||||
|
memorySet.add(c);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,7 +227,12 @@ public class AiCardMemory {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
getMemorySet(set).remove(c);
|
Set<Card> memorySet = getMemorySet(set);
|
||||||
|
|
||||||
|
if (memorySet != null) {
|
||||||
|
memorySet.remove(c);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -229,6 +245,8 @@ public class AiCardMemory {
|
|||||||
*/
|
*/
|
||||||
public boolean forgetAnyCardWithName(String cardName, MemorySet set) {
|
public boolean forgetAnyCardWithName(String cardName, MemorySet set) {
|
||||||
Set<Card> memorySet = getMemorySet(set);
|
Set<Card> memorySet = getMemorySet(set);
|
||||||
|
|
||||||
|
if (memorySet != null) {
|
||||||
Iterator<Card> it = memorySet.iterator();
|
Iterator<Card> it = memorySet.iterator();
|
||||||
|
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
@@ -237,6 +255,7 @@ public class AiCardMemory {
|
|||||||
return forgetCard(c, set);
|
return forgetCard(c, set);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -251,6 +270,8 @@ public class AiCardMemory {
|
|||||||
*/
|
*/
|
||||||
public boolean forgetAnyCardWithName(String cardName, MemorySet set, Player owner) {
|
public boolean forgetAnyCardWithName(String cardName, MemorySet set, Player owner) {
|
||||||
Set<Card> memorySet = getMemorySet(set);
|
Set<Card> memorySet = getMemorySet(set);
|
||||||
|
|
||||||
|
if (memorySet != null) {
|
||||||
Iterator<Card> it = memorySet.iterator();
|
Iterator<Card> it = memorySet.iterator();
|
||||||
|
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
@@ -259,6 +280,7 @@ public class AiCardMemory {
|
|||||||
return forgetCard(c, set);
|
return forgetCard(c, set);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -269,15 +291,17 @@ public class AiCardMemory {
|
|||||||
* @return true, if the given memory set contains no remembered cards.
|
* @return true, if the given memory set contains no remembered cards.
|
||||||
*/
|
*/
|
||||||
public boolean isMemorySetEmpty(MemorySet set) {
|
public boolean isMemorySetEmpty(MemorySet set) {
|
||||||
return getMemorySet(set).isEmpty();
|
return set == null ? true : getMemorySet(set).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears the given memory set.
|
* Clears the given memory set.
|
||||||
*/
|
*/
|
||||||
public void clearMemorySet(MemorySet set) {
|
public void clearMemorySet(MemorySet set) {
|
||||||
|
if (set != null) {
|
||||||
getMemorySet(set).clear();
|
getMemorySet(set).clear();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears all memory sets stored in this card memory for the given player.
|
* Clears all memory sets stored in this card memory for the given player.
|
||||||
|
|||||||
@@ -655,10 +655,10 @@ public class AiController {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
AiCardMemory.MemorySet memSet;
|
AiCardMemory.MemorySet memSet = null;
|
||||||
if (phaseType == null && forNextSpell) {
|
if (phaseType == null && forNextSpell) {
|
||||||
memSet = AiCardMemory.MemorySet.HELD_MANA_SOURCES_FOR_NEXT_SPELL;
|
memSet = AiCardMemory.MemorySet.HELD_MANA_SOURCES_FOR_NEXT_SPELL;
|
||||||
} else {
|
} else if (phaseType != null) {
|
||||||
switch (phaseType) {
|
switch (phaseType) {
|
||||||
case MAIN2:
|
case MAIN2:
|
||||||
memSet = AiCardMemory.MemorySet.HELD_MANA_SOURCES_FOR_MAIN2;
|
memSet = AiCardMemory.MemorySet.HELD_MANA_SOURCES_FOR_MAIN2;
|
||||||
|
|||||||
@@ -1612,7 +1612,7 @@ public class ComputerUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (saviourApi == ApiType.PutCounter || saviourApi == ApiType.PutCounterAll) {
|
if (saviourApi == ApiType.PutCounter || saviourApi == ApiType.PutCounterAll) {
|
||||||
if (saviour.getParam("CounterType").equals("P1P1")) {
|
if (saviour != null && saviour.getParam("CounterType").equals("P1P1")) {
|
||||||
toughness = AbilityUtils.calculateAmount(saviour.getHostCard(), saviour.getParam("CounterNum"), saviour);
|
toughness = AbilityUtils.calculateAmount(saviour.getHostCard(), saviour.getParam("CounterNum"), saviour);
|
||||||
} else {
|
} else {
|
||||||
return threatened;
|
return threatened;
|
||||||
|
|||||||
@@ -926,7 +926,7 @@ public class ComputerUtilCard {
|
|||||||
}
|
}
|
||||||
else if (logic.equals("MostProminentInComputerDeckButGreen")) {
|
else if (logic.equals("MostProminentInComputerDeckButGreen")) {
|
||||||
List<String> prominence = ComputerUtilCard.getColorByProminence(CardLists.filterControlledBy(game.getCardsInGame(), ai));
|
List<String> prominence = ComputerUtilCard.getColorByProminence(CardLists.filterControlledBy(game.getCardsInGame(), ai));
|
||||||
if (prominence.get(0) == MagicColor.Constant.GREEN) {
|
if (prominence.get(0).equals(MagicColor.Constant.GREEN)) {
|
||||||
chosen.add(prominence.get(1));
|
chosen.add(prominence.get(1));
|
||||||
} else {
|
} else {
|
||||||
chosen.add(prominence.get(0));
|
chosen.add(prominence.get(0));
|
||||||
@@ -1878,7 +1878,7 @@ public class ComputerUtilCard {
|
|||||||
|
|
||||||
// A special case which checks that this creature will attack if it's the AI's turn
|
// A special case which checks that this creature will attack if it's the AI's turn
|
||||||
if (needsToPlay.equalsIgnoreCase("WillAttack")) {
|
if (needsToPlay.equalsIgnoreCase("WillAttack")) {
|
||||||
if (game.getPhaseHandler().isPlayerTurn(sa.getActivatingPlayer())) {
|
if (sa != null && game.getPhaseHandler().isPlayerTurn(sa.getActivatingPlayer())) {
|
||||||
return ComputerUtilCard.doesSpecifiedCreatureAttackAI(sa.getActivatingPlayer(), card) ?
|
return ComputerUtilCard.doesSpecifiedCreatureAttackAI(sa.getActivatingPlayer(), card) ?
|
||||||
AiPlayDecision.WillPlay : AiPlayDecision.BadEtbEffects;
|
AiPlayDecision.WillPlay : AiPlayDecision.BadEtbEffects;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -631,8 +631,10 @@ public abstract class GameState {
|
|||||||
// Note: triggers may fire during combat declarations ("whenever X attacks, ...", etc.)
|
// Note: triggers may fire during combat declarations ("whenever X attacks, ...", etc.)
|
||||||
if (newPhase == PhaseType.COMBAT_DECLARE_ATTACKERS || newPhase == PhaseType.COMBAT_DECLARE_BLOCKERS) {
|
if (newPhase == PhaseType.COMBAT_DECLARE_ATTACKERS || newPhase == PhaseType.COMBAT_DECLARE_BLOCKERS) {
|
||||||
boolean toDeclareBlockers = newPhase == PhaseType.COMBAT_DECLARE_BLOCKERS;
|
boolean toDeclareBlockers = newPhase == PhaseType.COMBAT_DECLARE_BLOCKERS;
|
||||||
|
if (newPlayerTurn != null) {
|
||||||
handleCombat(game, newPlayerTurn, newPlayerTurn.getSingleOpponent(), toDeclareBlockers);
|
handleCombat(game, newPlayerTurn, newPlayerTurn.getSingleOpponent(), toDeclareBlockers);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
game.getStack().setResolving(false);
|
game.getStack().setResolving(false);
|
||||||
|
|
||||||
@@ -891,7 +893,9 @@ public abstract class GameState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (sa != null) {
|
||||||
sa.setActivatingPlayer(c.getController());
|
sa.setActivatingPlayer(c.getController());
|
||||||
|
}
|
||||||
handleScriptedTargetingForSA(game, sa, tgtID);
|
handleScriptedTargetingForSA(game, sa, tgtID);
|
||||||
|
|
||||||
if (putOnStack) {
|
if (putOnStack) {
|
||||||
|
|||||||
@@ -733,6 +733,7 @@ public class PlayerControllerAi extends PlayerController {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
case "BetterTgtThanRemembered":
|
case "BetterTgtThanRemembered":
|
||||||
if (source.getRememberedCount() > 0) {
|
if (source.getRememberedCount() > 0) {
|
||||||
Card rem = (Card) source.getFirstRemembered();
|
Card rem = (Card) source.getFirstRemembered();
|
||||||
@@ -746,6 +747,7 @@ public class PlayerControllerAi extends PlayerController {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -172,7 +172,7 @@ public class SpecialCardAi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return best.getName();
|
return best != null ? best.getName() : "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1231,7 +1231,7 @@ public class SpecialCardAi {
|
|||||||
// no options with smaller CMC, so discard the one that is harder to cast for the one that is
|
// no options with smaller CMC, so discard the one that is harder to cast for the one that is
|
||||||
// easier to cast right now, but only if the best card in the library is at least CMC 3
|
// easier to cast right now, but only if the best card in the library is at least CMC 3
|
||||||
// (probably not worth it to grab low mana cost cards this way)
|
// (probably not worth it to grab low mana cost cards this way)
|
||||||
if (maxCMC != null && maxCMC.getCMC() < bestInLib.getCMC() && bestInLib.getCMC() >= 3) {
|
if (maxCMC != null && bestInLib != null && maxCMC.getCMC() < bestInLib.getCMC() && bestInLib.getCMC() >= 3) {
|
||||||
return maxCMC;
|
return maxCMC;
|
||||||
}
|
}
|
||||||
// We appear to be playing Reanimator (or we have a reanimator card in hand already), so it's
|
// We appear to be playing Reanimator (or we have a reanimator card in hand already), so it's
|
||||||
|
|||||||
@@ -311,6 +311,7 @@ public final class GameActionUtil {
|
|||||||
break;
|
break;
|
||||||
case Flash:
|
case Flash:
|
||||||
result.getRestrictions().setInstantSpeed(true);
|
result.getRestrictions().setInstantSpeed(true);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ public class SaveOpenDialog extends JPanel {
|
|||||||
RetFile = fc.getSelectedFile();
|
RetFile = fc.getSelectedFile();
|
||||||
|
|
||||||
/* Adds extension if it is known and not given */
|
/* Adds extension if it is known and not given */
|
||||||
if (type != null & !(RetFile.getAbsolutePath().endsWith(type.TypeExtension))) {
|
if (type != null && !(RetFile.getAbsolutePath().endsWith(type.TypeExtension))) {
|
||||||
RetFile = new File(RetFile.getAbsolutePath() + "." + type.TypeExtension);
|
RetFile = new File(RetFile.getAbsolutePath() + "." + type.TypeExtension);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -214,13 +214,13 @@ public class GuiDownloadZipService extends GuiDownloadService {
|
|||||||
protected void copyInputStream(final InputStream in, final String outPath) throws IOException {
|
protected void copyInputStream(final InputStream in, final String outPath) throws IOException {
|
||||||
final byte[] buffer = new byte[1024];
|
final byte[] buffer = new byte[1024];
|
||||||
int len;
|
int len;
|
||||||
final BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(outPath));
|
|
||||||
|
|
||||||
while((len = in.read(buffer)) >= 0) {
|
try (BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(outPath))) {
|
||||||
|
while ((len = in.read(buffer)) >= 0) {
|
||||||
out.write(buffer, 0, len);
|
out.write(buffer, 0, len);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
in.close();
|
in.close();
|
||||||
out.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -218,7 +218,7 @@ public final class FServerManager {
|
|||||||
// https://stackoverflow.com/a/34873630
|
// https://stackoverflow.com/a/34873630
|
||||||
// https://stackoverflow.com/a/901943
|
// https://stackoverflow.com/a/901943
|
||||||
private String getRoutableAddress(boolean preferIpv4, boolean preferIPv6) throws SocketException, UnknownHostException {
|
private String getRoutableAddress(boolean preferIpv4, boolean preferIPv6) throws SocketException, UnknownHostException {
|
||||||
DatagramSocket s = new DatagramSocket();
|
try (DatagramSocket s = new DatagramSocket()) {
|
||||||
s.connect(InetAddress.getByAddress(this.externalAddress), 0);
|
s.connect(InetAddress.getByAddress(this.externalAddress), 0);
|
||||||
NetworkInterface n = NetworkInterface.getByInetAddress(s.getLocalAddress());
|
NetworkInterface n = NetworkInterface.getByInetAddress(s.getLocalAddress());
|
||||||
Enumeration<InetAddress> en = n.getInetAddresses();
|
Enumeration<InetAddress> en = n.getInetAddresses();
|
||||||
@@ -228,18 +228,16 @@ public final class FServerManager {
|
|||||||
if (preferIPv6) {
|
if (preferIPv6) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
s.close();
|
|
||||||
return addr.getHostAddress();
|
return addr.getHostAddress();
|
||||||
}
|
}
|
||||||
if (addr instanceof Inet6Address) {
|
if (addr instanceof Inet6Address) {
|
||||||
if (preferIpv4) {
|
if (preferIpv4) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
s.close();
|
|
||||||
return addr.getHostAddress();
|
return addr.getHostAddress();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
s.close();
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2040,9 +2040,9 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
|
|||||||
final File f = GuiBase.getInterface().getSaveFile(new File(ForgeConstants.USER_GAMES_DIR, "state.txt"));
|
final File f = GuiBase.getInterface().getSaveFile(new File(ForgeConstants.USER_GAMES_DIR, "state.txt"));
|
||||||
if (f != null
|
if (f != null
|
||||||
&& (!f.exists() || getGui().showConfirmDialog("Overwrite existing file?", "File exists!"))) {
|
&& (!f.exists() || getGui().showConfirmDialog("Overwrite existing file?", "File exists!"))) {
|
||||||
final BufferedWriter bw = new BufferedWriter(new FileWriter(f));
|
try (BufferedWriter bw = new BufferedWriter(new FileWriter(f))) {
|
||||||
bw.write(state.toString());
|
bw.write(state.toString());
|
||||||
bw.close();
|
}
|
||||||
}
|
}
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
String err = e.getClass().getName();
|
String err = e.getClass().getName();
|
||||||
|
|||||||
Reference in New Issue
Block a user