mirror of
https://github.com/correl/mage.git
synced 2024-11-15 19:19:33 +00:00
Made CardScanner classloader aware.
This commit is contained in:
parent
3c2dd8d335
commit
ad5b23aa06
1 changed files with 18 additions and 10 deletions
|
@ -29,7 +29,10 @@
|
||||||
package mage.cards.repository;
|
package mage.cards.repository;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import mage.cards.Card;
|
import mage.cards.Card;
|
||||||
import mage.cards.CardImpl;
|
import mage.cards.CardImpl;
|
||||||
import mage.cards.ExpansionSet;
|
import mage.cards.ExpansionSet;
|
||||||
|
@ -55,23 +58,28 @@ public class CardScanner {
|
||||||
scanned = true;
|
scanned = true;
|
||||||
|
|
||||||
List<CardInfo> cardsToAdd = new ArrayList<>();
|
List<CardInfo> cardsToAdd = new ArrayList<>();
|
||||||
List<String> packages = new ArrayList<>();
|
Map<ClassLoader, List<String>> packageMap = new HashMap<>();
|
||||||
|
|
||||||
for (ExpansionSet set : Sets.getInstance().values()) {
|
for (ExpansionSet set : Sets.getInstance().values()) {
|
||||||
|
ClassLoader cl = set.getClass().getClassLoader();
|
||||||
|
if(!packageMap.containsKey(cl)) packageMap.put(cl, new ArrayList<String>());
|
||||||
|
List<String> packages = packageMap.get(cl);
|
||||||
packages.add(set.getPackageName());
|
packages.add(set.getPackageName());
|
||||||
ExpansionRepository.instance.add(new ExpansionInfo(set));
|
ExpansionRepository.instance.add(new ExpansionInfo(set));
|
||||||
}
|
}
|
||||||
ExpansionRepository.instance.setContentVersion(ExpansionRepository.instance.getContentVersionConstant());
|
ExpansionRepository.instance.setContentVersion(ExpansionRepository.instance.getContentVersionConstant());
|
||||||
|
|
||||||
for (Class c : ClassScanner.findClasses(null, packages, CardImpl.class)) {
|
for (ClassLoader cl : packageMap.keySet()) {
|
||||||
if (!CardRepository.instance.cardExists(c.getCanonicalName())) {
|
for (Class c : ClassScanner.findClasses(cl, packageMap.get(cl), CardImpl.class)) {
|
||||||
Card card = CardImpl.createCard(c);
|
if (!CardRepository.instance.cardExists(c.getCanonicalName())) {
|
||||||
if (card != null) {
|
Card card = CardImpl.createCard(c);
|
||||||
cardsToAdd.add(new CardInfo(card));
|
if (card != null) {
|
||||||
if (card instanceof SplitCard) {
|
cardsToAdd.add(new CardInfo(card));
|
||||||
SplitCard splitCard = (SplitCard) card;
|
if (card instanceof SplitCard) {
|
||||||
cardsToAdd.add(new CardInfo(splitCard.getLeftHalfCard()));
|
SplitCard splitCard = (SplitCard) card;
|
||||||
cardsToAdd.add(new CardInfo(splitCard.getRightHalfCard()));
|
cardsToAdd.add(new CardInfo(splitCard.getLeftHalfCard()));
|
||||||
|
cardsToAdd.add(new CardInfo(splitCard.getRightHalfCard()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue