Prevent crash when canceling prompt for card or player

This commit is contained in:
drdev
2014-10-13 23:13:13 +00:00
parent 1b70875b40
commit 8d71ae5cbf
3 changed files with 19 additions and 11 deletions

View File

@@ -92,12 +92,16 @@ import java.util.concurrent.CopyOnWriteArrayList;
public class Card extends GameEntity implements Comparable<Card>, IIdentifiable {
private static HashMap<Integer, Card> cardCache = new HashMap<Integer, Card>();
public static Card get(CardView cardView) {
if (cardView == null) { return null; }
return cardCache.get(cardView.getId());
}
public static CardCollection getList(Iterable<CardView> cardViews) {
CardCollection list = new CardCollection();
for (CardView cv : cardViews) {
list.add(get(cv));
Card c = get(cv);
if (c != null) {
list.add(c);
}
}
return list;
}

View File

@@ -83,12 +83,16 @@ public class Player extends GameEntity implements Comparable<Player> {
private static HashMap<Integer, Player> playerCache = new HashMap<Integer, Player>();
public static Player get(PlayerView playerView) {
if (playerView == null) { return null; }
return playerCache.get(playerView.getId());
}
public static List<Player> getList(Iterable<PlayerView> playerViews) {
List<Player> list = new ArrayList<Player>();
for (PlayerView pv : playerViews) {
list.add(get(pv));
Player p = get(pv);
if (p != null) {
list.add(p);
}
}
return list;
}