Some refactoring. Replaced all "listeners" list by instances of

CopyOnWriteArrayList, to allow listeners to unregister themselves due to
an event while preventing ConcurrentModificationExceptions.
Modified all GameDataElement.elementChanged concrete implementation to
remove the backlink from the oldOne.An element pointed by an altered
element will not show the game source element in its backlink list
anymore.
This commit is contained in:
Zukero
2017-03-02 13:53:24 +01:00
parent 2a4cfb0684
commit 940996aa30
27 changed files with 81 additions and 54 deletions

View File

@@ -357,16 +357,19 @@ public class NPC extends JSONElement {
@Override
public void elementChanged(GameDataElement oldOne, GameDataElement newOne) {
if (dialogue == oldOne) {
oldOne.removeBacklink(this);
this.dialogue = (Dialogue) newOne;
if (newOne != null) newOne.addBacklink(this);
} else {
if (this.droplist == oldOne) {
oldOne.removeBacklink(this);
this.droplist = (Droplist) newOne;
if (newOne != null) newOne.addBacklink(this);
} else {
if (this.hit_effect != null && this.hit_effect.conditions_source != null) {
for (TimedConditionEffect tce : this.hit_effect.conditions_source) {
if (tce.condition == oldOne) {
oldOne.removeBacklink(this);
tce.condition = (ActorCondition) newOne;
if (newOne != null) newOne.addBacklink(this);
}
@@ -375,6 +378,7 @@ public class NPC extends JSONElement {
if (this.hit_effect != null && this.hit_effect.conditions_target != null) {
for (TimedConditionEffect tce : this.hit_effect.conditions_target) {
if (tce.condition == oldOne) {
oldOne.removeBacklink(this);
tce.condition = (ActorCondition) newOne;
if (newOne != null) newOne.addBacklink(this);
}