mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 03:38:01 +00:00
Prevent some possible concurrency exceptions in views
This commit is contained in:
@@ -3,10 +3,11 @@ package forge.game.combat;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
import forge.game.GameEntityView;
|
import forge.game.GameEntityView;
|
||||||
import forge.game.card.CardView;
|
import forge.game.card.CardView;
|
||||||
@@ -15,7 +16,6 @@ import forge.trackable.TrackableProperty;
|
|||||||
import forge.trackable.Tracker;
|
import forge.trackable.Tracker;
|
||||||
import forge.util.FCollection;
|
import forge.util.FCollection;
|
||||||
|
|
||||||
|
|
||||||
public class CombatView extends TrackableObject {
|
public class CombatView extends TrackableObject {
|
||||||
private static final long serialVersionUID = 68085618912864941L;
|
private static final long serialVersionUID = 68085618912864941L;
|
||||||
|
|
||||||
@@ -68,11 +68,15 @@ public class CombatView extends TrackableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isBlocking(final CardView card) {
|
public boolean isBlocking(final CardView card) {
|
||||||
for (final FCollection<CardView> blockers : getAttackersWithBlockers().values()) {
|
final List<FCollection<CardView>> allBlockers;
|
||||||
|
synchronized (this) {
|
||||||
|
allBlockers = Lists.newArrayList(getAttackersWithBlockers().values());
|
||||||
|
}
|
||||||
|
for (final FCollection<CardView> blockers : allBlockers) {
|
||||||
if (blockers == null) {
|
if (blockers == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (Iterables.contains(blockers, card)) {
|
if (blockers.contains(card)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -122,8 +126,12 @@ public class CombatView extends TrackableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public FCollection<CardView> getAttackersOf(final GameEntityView defender) {
|
public FCollection<CardView> getAttackersOf(final GameEntityView defender) {
|
||||||
FCollection<CardView> views = new FCollection<CardView>();
|
final List<Entry<CardView, GameEntityView>> attackersWithDefenders;
|
||||||
for (Entry<CardView, GameEntityView> entry : getAttackersWithDefenders().entrySet()) {
|
synchronized (this) {
|
||||||
|
attackersWithDefenders = Lists.newArrayList(getAttackersWithDefenders().entrySet());
|
||||||
|
}
|
||||||
|
final FCollection<CardView> views = new FCollection<CardView>();
|
||||||
|
for (final Entry<CardView, GameEntityView> entry : attackersWithDefenders) {
|
||||||
if (entry.getValue().equals(defender)) {
|
if (entry.getValue().equals(defender)) {
|
||||||
views.add(entry.getKey());
|
views.add(entry.getKey());
|
||||||
}
|
}
|
||||||
@@ -131,8 +139,12 @@ public class CombatView extends TrackableObject {
|
|||||||
return views;
|
return views;
|
||||||
}
|
}
|
||||||
public Iterable<FCollection<CardView>> getAttackingBandsOf(final GameEntityView defender) {
|
public Iterable<FCollection<CardView>> getAttackingBandsOf(final GameEntityView defender) {
|
||||||
ArrayList<FCollection<CardView>> views = new ArrayList<FCollection<CardView>>();
|
final List<Entry<FCollection<CardView>, GameEntityView>> bandsWithDefenders;
|
||||||
for (Entry<FCollection<CardView>, GameEntityView> entry : getBandsWithDefenders().entrySet()) {
|
synchronized (this) {
|
||||||
|
bandsWithDefenders = Lists.newArrayList(getBandsWithDefenders().entrySet());
|
||||||
|
}
|
||||||
|
final List<FCollection<CardView>> views = new ArrayList<FCollection<CardView>>();
|
||||||
|
for (final Entry<FCollection<CardView>, GameEntityView> entry : bandsWithDefenders) {
|
||||||
if (entry.getValue().equals(defender)) {
|
if (entry.getValue().equals(defender)) {
|
||||||
views.add(entry.getKey());
|
views.add(entry.getKey());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -187,8 +187,9 @@ public class PlayerView extends GameEntityView {
|
|||||||
}
|
}
|
||||||
public List<String> getDisplayableKeywords() {
|
public List<String> getDisplayableKeywords() {
|
||||||
final List<String> allKws;
|
final List<String> allKws;
|
||||||
synchronized (this) {
|
final KeywordCollectionView kws = getKeywords();
|
||||||
allKws = Lists.newArrayList(getKeywords());
|
synchronized (kws) {
|
||||||
|
allKws = Lists.newArrayList(kws);
|
||||||
}
|
}
|
||||||
while (allKws.remove("CanSeeOpponentsFaceDownCards")) {
|
while (allKws.remove("CanSeeOpponentsFaceDownCards")) {
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user