From 7b64bbb7a213f74e172d13ff7de0e999d5cc8cd0 Mon Sep 17 00:00:00 2001 From: Mads Boddum Date: Tue, 18 Oct 2016 15:55:07 +0200 Subject: [PATCH] Moved a couple of method bodies from CreatureObject into CREO06 --- .../objects/creature/CreatureObject.java | 27 ++--------- .../creature/CreatureObjectSharedNP.java | 47 ++++++++++++++++++- 2 files changed, 49 insertions(+), 25 deletions(-) diff --git a/src/resources/objects/creature/CreatureObject.java b/src/resources/objects/creature/CreatureObject.java index 105cdc39d..395a02091 100644 --- a/src/resources/objects/creature/CreatureObject.java +++ b/src/resources/objects/creature/CreatureObject.java @@ -595,40 +595,21 @@ public class CreatureObject extends TangibleObject { } public void addBuff(CRC buffCrc, Buff buff) { - SWGMap buffs = creo6.getBuffs(); - if(!buffs.containsKey(buffCrc)) { - buffs.put(buffCrc, buff); - buffs.sendDeltaMessage(this); - } + creo6.addBuff(buffCrc, buff, this); } public void removeBuff(CRC buffCrc) { - SWGMap buffs = creo6.getBuffs(); - // If a value was associated with the key, then send a delta. - if(buffs.containsKey(buffCrc)) { - buffs.remove(buffCrc); - buffs.sendDeltaMessage(this); - } + creo6.removeBuff(buffCrc, this); } public Buff getBuffByCrc(CRC buffCrc) { - return creo6.getBuffs().get(buffCrc); + return creo6.getBuffByCrc(buffCrc); } public void adjustBuffStackCount(CRC buffCrc, int adjustment) { - SWGMap buffs = creo6.getBuffs(); - Buff buff = buffs.get(buffCrc); - buff.adjustStackCount(adjustment); // Adjust the stack count - // TODO reset time remaining? - buffs.update(buffCrc, this); // Send deltas for this key. + creo6.adjustBuffStackCount(buffCrc, adjustment, this); } - /** - * @return a copy of the buffs map. Removing and adding entries in this - * map will not affect the internal {@code SWGMap}. Do not edit the - * {@code Buff} values in the belief that deltas will be sent because - * they won't - this is incorrect usage. - */ public Map getBuffs() { return new HashMap<>(creo6.getBuffs()); } diff --git a/src/resources/objects/creature/CreatureObjectSharedNP.java b/src/resources/objects/creature/CreatureObjectSharedNP.java index bd960b7f5..8ef5405ac 100644 --- a/src/resources/objects/creature/CreatureObjectSharedNP.java +++ b/src/resources/objects/creature/CreatureObjectSharedNP.java @@ -27,6 +27,8 @@ ***********************************************************************************/ package resources.objects.creature; +import java.util.HashMap; +import java.util.Map; import resources.HologramColour; import resources.collections.SWGList; import resources.collections.SWGMap; @@ -456,8 +458,49 @@ class CreatureObjectSharedNP implements Persistable { } } - public SWGMap getBuffs() { - return buffs; + /** + * @return a copy of the buffs map. Removing and adding entries in this + * map will not affect the internal {@code SWGMap}. Do not edit the + * {@code Buff} values in the belief that deltas will be sent because + * they won't - this is incorrect usage. + */ + public Map getBuffs() { + synchronized (buffs) { + return new HashMap<>(buffs); + } + } + + public void addBuff(CRC buffCrc, Buff buff, SWGObject target) { + synchronized (buffs) { + if(!buffs.containsKey(buffCrc)) { + buffs.put(buffCrc, buff); + buffs.sendDeltaMessage(target); + } + } + } + + public void removeBuff(CRC buffCrc, SWGObject target) { + synchronized (buffs) { + if(buffs.containsKey(buffCrc)) { + buffs.remove(buffCrc); + buffs.sendDeltaMessage(target); + } + } + } + + public Buff getBuffByCrc(CRC buffCrc) { + synchronized (buffs) { + return buffs.get(buffCrc); + } + } + + public void adjustBuffStackCount(CRC buffCrc, int adjustment, SWGObject target) { + synchronized (buffs) { + Buff buff = buffs.get(buffCrc); + buff.adjustStackCount(adjustment); // Adjust the stack count + // TODO reset time remaining + buffs.update(buffCrc, target); // Send deltas for this key. + } } private void initMaxAttributes() {