mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 18:28:00 +00:00
Merge pull request #8703 from kevlahnota/master4
fix crash Android 8-13 NoSuchMethodError, prevent crash for missing card
This commit is contained in:
@@ -878,7 +878,7 @@ public class StaticData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// stream().toList() causes crash on Android, use Collectors.toList()
|
// stream().toList() causes crash on Android 8-13, use Collectors.toList()
|
||||||
List<String> NIF = new ArrayList<>(NIF_Q).stream().sorted().collect(Collectors.toList());
|
List<String> NIF = new ArrayList<>(NIF_Q).stream().sorted().collect(Collectors.toList());
|
||||||
List<String> CNI = new ArrayList<>(CNI_Q).stream().sorted().collect(Collectors.toList());
|
List<String> CNI = new ArrayList<>(CNI_Q).stream().sorted().collect(Collectors.toList());
|
||||||
List<String> TOK = new ArrayList<>(TOKEN_Q).stream().sorted().collect(Collectors.toList());
|
List<String> TOK = new ArrayList<>(TOKEN_Q).stream().sorted().collect(Collectors.toList());
|
||||||
|
|||||||
@@ -367,7 +367,7 @@ public class CardState extends GameObject implements IHasSVars, ITranslatable {
|
|||||||
public final FCollectionView<SpellAbility> getManaAbilities() {
|
public final FCollectionView<SpellAbility> getManaAbilities() {
|
||||||
FCollection<SpellAbility> newCol = new FCollection<>();
|
FCollection<SpellAbility> newCol = new FCollection<>();
|
||||||
updateSpellAbilities(newCol, true);
|
updateSpellAbilities(newCol, true);
|
||||||
// stream().toList() causes crash on Android, use Collectors.toList()
|
// stream().toList() causes crash on Android 8-13, use Collectors.toList()
|
||||||
newCol.addAll(abilities.stream().filter(SpellAbility::isManaAbility).collect(Collectors.toList()));
|
newCol.addAll(abilities.stream().filter(SpellAbility::isManaAbility).collect(Collectors.toList()));
|
||||||
card.updateSpellAbilities(newCol, this, true);
|
card.updateSpellAbilities(newCol, this, true);
|
||||||
return newCol;
|
return newCol;
|
||||||
@@ -375,7 +375,7 @@ public class CardState extends GameObject implements IHasSVars, ITranslatable {
|
|||||||
public final FCollectionView<SpellAbility> getNonManaAbilities() {
|
public final FCollectionView<SpellAbility> getNonManaAbilities() {
|
||||||
FCollection<SpellAbility> newCol = new FCollection<>();
|
FCollection<SpellAbility> newCol = new FCollection<>();
|
||||||
updateSpellAbilities(newCol, false);
|
updateSpellAbilities(newCol, false);
|
||||||
// stream().toList() causes crash on Android, use Collectors.toList()
|
// stream().toList() causes crash on Android 8-13, use Collectors.toList()
|
||||||
newCol.addAll(abilities.stream().filter(Predicate.not(SpellAbility::isManaAbility)).collect(Collectors.toList()));
|
newCol.addAll(abilities.stream().filter(Predicate.not(SpellAbility::isManaAbility)).collect(Collectors.toList()));
|
||||||
card.updateSpellAbilities(newCol, this, false);
|
card.updateSpellAbilities(newCol, this, false);
|
||||||
return newCol;
|
return newCol;
|
||||||
@@ -390,7 +390,7 @@ public class CardState extends GameObject implements IHasSVars, ITranslatable {
|
|||||||
if (null != mana) {
|
if (null != mana) {
|
||||||
leftAbilities = leftAbilities.stream()
|
leftAbilities = leftAbilities.stream()
|
||||||
.filter(mana ? SpellAbility::isManaAbility : Predicate.not(SpellAbility::isManaAbility))
|
.filter(mana ? SpellAbility::isManaAbility : Predicate.not(SpellAbility::isManaAbility))
|
||||||
// stream().toList() causes crash on Android, use Collectors.toList()
|
// stream().toList() causes crash on Android 8-13, use Collectors.toList()
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
newCol.addAll(leftAbilities);
|
newCol.addAll(leftAbilities);
|
||||||
@@ -402,7 +402,7 @@ public class CardState extends GameObject implements IHasSVars, ITranslatable {
|
|||||||
if (null != mana) {
|
if (null != mana) {
|
||||||
rightAbilities = rightAbilities.stream()
|
rightAbilities = rightAbilities.stream()
|
||||||
.filter(mana ? SpellAbility::isManaAbility : Predicate.not(SpellAbility::isManaAbility))
|
.filter(mana ? SpellAbility::isManaAbility : Predicate.not(SpellAbility::isManaAbility))
|
||||||
// stream().toList() causes crash on Android, use Collectors.toList()
|
// stream().toList() causes crash on Android 8-13, use Collectors.toList()
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
newCol.addAll(rightAbilities);
|
newCol.addAll(rightAbilities);
|
||||||
|
|||||||
@@ -809,6 +809,11 @@ public class CardUtil {
|
|||||||
return generateBoosterPackAsDeck(edition);
|
return generateBoosterPackAsDeck(edition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static PaperCard getReplacement(String missingCard, String replacementCard) {
|
||||||
|
System.err.println(missingCard + " : Not found in the database.\nReplacement card: " + replacementCard);
|
||||||
|
return FModel.getMagicDb().getCommonCards().getCard(replacementCard);
|
||||||
|
}
|
||||||
|
|
||||||
public static PaperCard getCardByName(String cardName) {
|
public static PaperCard getCardByName(String cardName) {
|
||||||
List<PaperCard> validCards;
|
List<PaperCard> validCards;
|
||||||
//Faster to ask the CardDB for a card name than it is to search the pool.
|
//Faster to ask the CardDB for a card name than it is to search the pool.
|
||||||
@@ -817,6 +822,10 @@ public class CardUtil {
|
|||||||
else
|
else
|
||||||
validCards = FModel.getMagicDb().getCommonCards().getUniqueCardsNoAlt(cardName);
|
validCards = FModel.getMagicDb().getCommonCards().getUniqueCardsNoAlt(cardName);
|
||||||
|
|
||||||
|
if (validCards.isEmpty()) {
|
||||||
|
return getReplacement(cardName, "Wastes");
|
||||||
|
}
|
||||||
|
|
||||||
return validCards.get(Current.world().getRandom().nextInt(validCards.size()));
|
return validCards.get(Current.world().getRandom().nextInt(validCards.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -828,7 +837,7 @@ public class CardUtil {
|
|||||||
.filter(input -> input.getEdition().equals(edition)).collect(Collectors.toList());
|
.filter(input -> input.getEdition().equals(edition)).collect(Collectors.toList());
|
||||||
|
|
||||||
if (validCards.isEmpty()) {
|
if (validCards.isEmpty()) {
|
||||||
System.err.println("Unexpected behavior: tried to call getCardByNameAndEdition for card " + cardName + " from the edition " + edition + ", but didn't find it in the DB. A random existing instance will be returned.");
|
System.err.println("Unexpected behavior: tried to call getCardByNameAndEdition for card " + cardName + " from the edition " + edition + ", but didn't find it in the DB. A random existing instance will be returned if found.");
|
||||||
return getCardByName(cardName);
|
return getCardByName(cardName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import org.apache.commons.lang3.tuple.Pair;
|
|||||||
import java.text.DateFormatSymbols;
|
import java.text.DateFormatSymbols;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class DeckImportController {
|
public class DeckImportController {
|
||||||
public enum ImportBehavior {
|
public enum ImportBehavior {
|
||||||
@@ -516,7 +517,9 @@ public class DeckImportController {
|
|||||||
PaperCard card = token.getCard();
|
PaperCard card = token.getCard();
|
||||||
String cardName = card.getName();
|
String cardName = card.getName();
|
||||||
CardPool substitutes = availableInventory.getFilteredPool(c -> c.getName().equals(cardName));
|
CardPool substitutes = availableInventory.getFilteredPool(c -> c.getName().equals(cardName));
|
||||||
List<Map.Entry<PaperCard, Integer>> sortedSubstitutes = StreamUtil.stream(substitutes).sorted(Comparator.comparingInt(Map.Entry::getValue)).toList();
|
// stream().toList() causes crash on Android 8-13, use Collectors.toList()
|
||||||
|
// ref: https://developer.android.com/reference/java/util/stream/Stream#toList()
|
||||||
|
List<Map.Entry<PaperCard, Integer>> sortedSubstitutes = StreamUtil.stream(substitutes).sorted(Comparator.comparingInt(Map.Entry::getValue)).collect(Collectors.toList());
|
||||||
int neededQuantity = token.getQuantity();
|
int neededQuantity = token.getQuantity();
|
||||||
for(Token found : replacementList) {
|
for(Token found : replacementList) {
|
||||||
//If there's an item in the replacement list already it means we've already found some of the needed copies.
|
//If there's an item in the replacement list already it means we've already found some of the needed copies.
|
||||||
|
|||||||
@@ -437,7 +437,7 @@ public class BoosterDraft implements IBoosterDraft {
|
|||||||
CompletableFuture.allOf(futuresArray).join();
|
CompletableFuture.allOf(futuresArray).join();
|
||||||
futures.clear();
|
futures.clear();
|
||||||
}
|
}
|
||||||
// stream().toList() causes crash on Android, use Collectors.toList()
|
// stream().toList() causes crash on Android 8-13, use Collectors.toList()
|
||||||
customs.addAll(queue.stream().collect(Collectors.toList()));
|
customs.addAll(queue.stream().collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
return customs;
|
return customs;
|
||||||
|
|||||||
Reference in New Issue
Block a user