mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 12:18:00 +00:00
Prevent crash when canceling prompt for card or player
This commit is contained in:
@@ -92,12 +92,16 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
|||||||
public class Card extends GameEntity implements Comparable<Card>, IIdentifiable {
|
public class Card extends GameEntity implements Comparable<Card>, IIdentifiable {
|
||||||
private static HashMap<Integer, Card> cardCache = new HashMap<Integer, Card>();
|
private static HashMap<Integer, Card> cardCache = new HashMap<Integer, Card>();
|
||||||
public static Card get(CardView cardView) {
|
public static Card get(CardView cardView) {
|
||||||
|
if (cardView == null) { return null; }
|
||||||
return cardCache.get(cardView.getId());
|
return cardCache.get(cardView.getId());
|
||||||
}
|
}
|
||||||
public static CardCollection getList(Iterable<CardView> cardViews) {
|
public static CardCollection getList(Iterable<CardView> cardViews) {
|
||||||
CardCollection list = new CardCollection();
|
CardCollection list = new CardCollection();
|
||||||
for (CardView cv : cardViews) {
|
for (CardView cv : cardViews) {
|
||||||
list.add(get(cv));
|
Card c = get(cv);
|
||||||
|
if (c != null) {
|
||||||
|
list.add(c);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,12 +83,16 @@ public class Player extends GameEntity implements Comparable<Player> {
|
|||||||
|
|
||||||
private static HashMap<Integer, Player> playerCache = new HashMap<Integer, Player>();
|
private static HashMap<Integer, Player> playerCache = new HashMap<Integer, Player>();
|
||||||
public static Player get(PlayerView playerView) {
|
public static Player get(PlayerView playerView) {
|
||||||
|
if (playerView == null) { return null; }
|
||||||
return playerCache.get(playerView.getId());
|
return playerCache.get(playerView.getId());
|
||||||
}
|
}
|
||||||
public static List<Player> getList(Iterable<PlayerView> playerViews) {
|
public static List<Player> getList(Iterable<PlayerView> playerViews) {
|
||||||
List<Player> list = new ArrayList<Player>();
|
List<Player> list = new ArrayList<Player>();
|
||||||
for (PlayerView pv : playerViews) {
|
for (PlayerView pv : playerViews) {
|
||||||
list.add(get(pv));
|
Player p = get(pv);
|
||||||
|
if (p != null) {
|
||||||
|
list.add(p);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user