From b0010879649dce13726a08fb8a6df9ab69a081fc Mon Sep 17 00:00:00 2001 From: MobiusDev <8391001+MobiusDevelopment@users.noreply.github.com> Date: Sat, 30 Apr 2016 20:04:02 +0000 Subject: [PATCH] Some synchronized changes. --- .../gameserver/model/CharEffectList.java | 98 +--------- .../l2jmobius/gameserver/model/L2Object.java | 12 +- .../gameserver/model/actor/L2Attackable.java | 15 +- .../gameserver/model/actor/L2Character.java | 172 +++++------------- .../gameserver/model/actor/L2Npc.java | 14 +- .../instance/L2ClanHallDoormenInstance.java | 11 +- .../instance/L2ControlTowerInstance.java | 33 +--- .../actor/instance/L2MonsterInstance.java | 5 +- .../model/actor/instance/L2PcInstance.java | 108 +++-------- .../model/actor/knownlist/CharKnownList.java | 36 +--- .../actor/knownlist/ObjectKnownList.java | 12 +- .../gameserver/model/entity/Fort.java | 5 +- .../model/events/ListenersContainer.java | 23 +-- .../gameserver/model/quest/Quest.java | 10 +- .../gameserver/model/skills/BuffInfo.java | 30 +-- .../gameserver/model/skills/Skill.java | 25 ++- .../model/zone/type/L2EffectZone.java | 10 +- 17 files changed, 127 insertions(+), 492 deletions(-) diff --git a/trunk/java/com/l2jmobius/gameserver/model/CharEffectList.java b/trunk/java/com/l2jmobius/gameserver/model/CharEffectList.java index 3217b7a237..f0d521efc5 100644 --- a/trunk/java/com/l2jmobius/gameserver/model/CharEffectList.java +++ b/trunk/java/com/l2jmobius/gameserver/model/CharEffectList.java @@ -25,6 +25,7 @@ import java.util.Queue; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.CopyOnWriteArraySet; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Consumer; @@ -64,21 +65,21 @@ public final class CharEffectList { private static final Logger _log = Logger.getLogger(CharEffectList.class.getName()); /** Queue containing all effects from buffs for this effect list. */ - private volatile Queue _buffs; + private volatile Queue _buffs = new ConcurrentLinkedQueue<>(); /** Queue containing all triggered skills for this effect list. */ - private volatile Queue _triggered; + private volatile Queue _triggered = new ConcurrentLinkedQueue<>(); /** Queue containing all dances/songs for this effect list. */ - private volatile Queue _dances; + private volatile Queue _dances = new ConcurrentLinkedQueue<>(); /** Queue containing all toggle for this effect list. */ - private volatile Queue _toggles; + private volatile Queue _toggles = new ConcurrentLinkedQueue<>(); /** Queue containing all debuffs for this effect list. */ - private volatile Queue _debuffs; + private volatile Queue _debuffs = new ConcurrentLinkedQueue<>(); /** Queue containing all passives for this effect list. They bypass most of the actions and they are not included in most operations. */ - private volatile Queue _passives; + private volatile Queue _passives = new ConcurrentLinkedQueue<>(); /** Map containing the all stacked effect in progress for each abnormal type. */ - private volatile Map _stackedEffects; + private volatile Map _stackedEffects = new ConcurrentHashMap<>(); /** Set containing all abnormal types that shouldn't be added to this creature effect list. */ - private volatile Set _blockedBuffSlots = null; + private volatile Set _blockedBuffSlots = new CopyOnWriteArraySet<>(); /** Short buff skill ID. */ private BuffInfo _shortBuff = null; /** If {@code true} this effect list has buffs removed on any action. */ @@ -113,16 +114,6 @@ public final class CharEffectList */ public Queue getBuffs() { - if (_buffs == null) - { - synchronized (this) - { - if (_buffs == null) - { - _buffs = new ConcurrentLinkedQueue<>(); - } - } - } return _buffs; } @@ -132,16 +123,6 @@ public final class CharEffectList */ public Queue getTriggered() { - if (_triggered == null) - { - synchronized (this) - { - if (_triggered == null) - { - _triggered = new ConcurrentLinkedQueue<>(); - } - } - } return _triggered; } @@ -151,16 +132,6 @@ public final class CharEffectList */ public Queue getDances() { - if (_dances == null) - { - synchronized (this) - { - if (_dances == null) - { - _dances = new ConcurrentLinkedQueue<>(); - } - } - } return _dances; } @@ -170,16 +141,6 @@ public final class CharEffectList */ public Queue getToggles() { - if (_toggles == null) - { - synchronized (this) - { - if (_toggles == null) - { - _toggles = new ConcurrentLinkedQueue<>(); - } - } - } return _toggles; } @@ -189,16 +150,6 @@ public final class CharEffectList */ public Queue getDebuffs() { - if (_debuffs == null) - { - synchronized (this) - { - if (_debuffs == null) - { - _debuffs = new ConcurrentLinkedQueue<>(); - } - } - } return _debuffs; } @@ -208,16 +159,6 @@ public final class CharEffectList */ public Queue getPassives() { - if (_passives == null) - { - synchronized (this) - { - if (_passives == null) - { - _passives = new ConcurrentLinkedQueue<>(); - } - } - } return _passives; } @@ -465,16 +406,6 @@ public final class CharEffectList */ public void addBlockedBuffSlots(Set blockedBuffSlots) { - if (_blockedBuffSlots == null) - { - synchronized (this) - { - if (_blockedBuffSlots == null) - { - _blockedBuffSlots = ConcurrentHashMap.newKeySet(blockedBuffSlots.size()); - } - } - } _blockedBuffSlots.addAll(blockedBuffSlots); } @@ -1265,17 +1196,6 @@ public final class CharEffectList // Verify stacked skills. else { - if (_stackedEffects == null) - { - synchronized (this) - { - if (_stackedEffects == null) - { - _stackedEffects = new ConcurrentHashMap<>(); - } - } - } - if (_stackedEffects.containsKey(skill.getAbnormalType())) { BuffInfo stackedInfo = _stackedEffects.get(skill.getAbnormalType()); diff --git a/trunk/java/com/l2jmobius/gameserver/model/L2Object.java b/trunk/java/com/l2jmobius/gameserver/model/L2Object.java index c25f7fc109..d23cae2e30 100644 --- a/trunk/java/com/l2jmobius/gameserver/model/L2Object.java +++ b/trunk/java/com/l2jmobius/gameserver/model/L2Object.java @@ -64,7 +64,7 @@ public abstract class L2Object extends ListenersContainer implements IIdentifiab private L2WorldRegion _worldRegion; /** Instance type */ private InstanceType _instanceType = null; - private volatile Map _scripts; + private volatile Map _scripts = new ConcurrentHashMap<>(); /** X coordinate */ private final AtomicInteger _x = new AtomicInteger(0); /** Y coordinate */ @@ -531,16 +531,6 @@ public abstract class L2Object extends ListenersContainer implements IIdentifiab */ public final T addScript(T script) { - if (_scripts == null) - { - synchronized (this) - { - if (_scripts == null) - { - _scripts = new ConcurrentHashMap<>(); - } - } - } _scripts.put(script.getClass().getName(), script); return script; } diff --git a/trunk/java/com/l2jmobius/gameserver/model/actor/L2Attackable.java b/trunk/java/com/l2jmobius/gameserver/model/actor/L2Attackable.java index ee26a015ab..7c46d8c6aa 100644 --- a/trunk/java/com/l2jmobius/gameserver/model/actor/L2Attackable.java +++ b/trunk/java/com/l2jmobius/gameserver/model/actor/L2Attackable.java @@ -257,16 +257,13 @@ public class L2Attackable extends L2Npc { synchronized (this) { - if (_firstCommandChannelAttacked == null) + _firstCommandChannelAttacked = attacker.getParty().getCommandChannel(); + if (_firstCommandChannelAttacked != null) { - _firstCommandChannelAttacked = attacker.getParty().getCommandChannel(); - if (_firstCommandChannelAttacked != null) - { - _commandChannelTimer = new CommandChannelTimer(this); - _commandChannelLastAttack = System.currentTimeMillis(); - ThreadPoolManager.getInstance().scheduleGeneral(_commandChannelTimer, 10000); // check for last attack - _firstCommandChannelAttacked.broadcastPacket(new CreatureSay(0, ChatType.PARTYROOM_ALL, "", "You have looting rights!")); // TODO: retail msg - } + _commandChannelTimer = new CommandChannelTimer(this); + _commandChannelLastAttack = System.currentTimeMillis(); + ThreadPoolManager.getInstance().scheduleGeneral(_commandChannelTimer, 10000); // check for last attack + _firstCommandChannelAttacked.broadcastPacket(new CreatureSay(0, ChatType.PARTYROOM_ALL, "", "You have looting rights!")); // TODO: retail msg } } } diff --git a/trunk/java/com/l2jmobius/gameserver/model/actor/L2Character.java b/trunk/java/com/l2jmobius/gameserver/model/actor/L2Character.java index 81c2f88ab4..8be30e07d8 100644 --- a/trunk/java/com/l2jmobius/gameserver/model/actor/L2Character.java +++ b/trunk/java/com/l2jmobius/gameserver/model/actor/L2Character.java @@ -29,6 +29,7 @@ import java.util.Objects; import java.util.Queue; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.CopyOnWriteArraySet; import java.util.concurrent.Future; import java.util.concurrent.LinkedBlockingDeque; import java.util.concurrent.TimeUnit; @@ -190,7 +191,7 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe { public static final Logger _log = Logger.getLogger(L2Character.class.getName()); - private volatile Set _attackByList; + private volatile Set _attackByList = new CopyOnWriteArraySet<>(); private volatile boolean _isCastingNow = false; private volatile boolean _isCastingSimultaneouslyNow = false; private Skill _lastSkillCast; @@ -225,11 +226,11 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe /** Map containing all skills of this character. */ private final Map _skills = new ConcurrentHashMap<>(); /** Map containing the skill reuse time stamps. */ - private volatile Map _reuseTimeStampsSkills = null; + private volatile Map _reuseTimeStampsSkills = new ConcurrentHashMap<>(); /** Map containing the item reuse time stamps. */ - private volatile Map _reuseTimeStampsItems = null; + private volatile Map _reuseTimeStampsItems = new ConcurrentHashMap<>(); /** Map containing all the disabled skills. */ - private volatile Map _disabledSkills = null; + private volatile Map _disabledSkills = new ConcurrentHashMap<>(); private boolean _allSkillsDisabled; private final byte[] _zones = new byte[ZoneId.getZoneCount()]; @@ -246,9 +247,9 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe private boolean _lethalable = true; - private volatile Map _triggerSkills; + private volatile Map _triggerSkills = new ConcurrentHashMap<>(); - private volatile Map _invulAgainst; + private volatile Map _invulAgainst = new ConcurrentHashMap<>(); /** Creatures effect list. */ private final CharEffectList _effectList = new CharEffectList(this); /** The character that summons this character. */ @@ -258,8 +259,8 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe private SkillChannelized _channelized = null; - private volatile Set _abnormalVisualEffects; - private volatile Set _currentAbnormalVisualEffects; + private volatile Set _abnormalVisualEffects = new CopyOnWriteArraySet<>(); + private volatile Set _currentAbnormalVisualEffects = new CopyOnWriteArraySet<>(); /** Movement data of this L2Character */ protected MoveData _move; @@ -2135,16 +2136,6 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe */ public final void addTimeStampItem(L2ItemInstance item, long reuse, long systime) { - if (_reuseTimeStampsItems == null) - { - synchronized (this) - { - if (_reuseTimeStampsItems == null) - { - _reuseTimeStampsItems = new ConcurrentHashMap<>(); - } - } - } _reuseTimeStampsItems.put(item.getObjectId(), new TimeStamp(item, reuse, systime)); } @@ -2155,7 +2146,7 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe */ public final synchronized long getItemRemainingReuseTime(int itemObjId) { - final TimeStamp reuseStamp = (_reuseTimeStampsItems != null) ? _reuseTimeStampsItems.get(itemObjId) : null; + final TimeStamp reuseStamp = _reuseTimeStampsItems.get(itemObjId); return reuseStamp != null ? reuseStamp.getRemaining() : -1; } @@ -2166,7 +2157,7 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe */ public final long getReuseDelayOnGroup(int group) { - if ((group > 0) && (_reuseTimeStampsItems != null)) + if (group > 0) { for (TimeStamp ts : _reuseTimeStampsItems.values()) { @@ -2207,16 +2198,6 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe */ public final void addTimeStamp(Skill skill, long reuse, long systime) { - if (_reuseTimeStampsSkills == null) - { - synchronized (this) - { - if (_reuseTimeStampsSkills == null) - { - _reuseTimeStampsSkills = new ConcurrentHashMap<>(); - } - } - } _reuseTimeStampsSkills.put(skill.getReuseHashCode(), new TimeStamp(skill, reuse, systime)); } @@ -2226,10 +2207,7 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe */ public final synchronized void removeTimeStamp(Skill skill) { - if (_reuseTimeStampsSkills != null) - { - _reuseTimeStampsSkills.remove(skill.getReuseHashCode()); - } + _reuseTimeStampsSkills.remove(skill.getReuseHashCode()); } /** @@ -2237,10 +2215,7 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe */ public final synchronized void resetTimeStamps() { - if (_reuseTimeStampsSkills != null) - { - _reuseTimeStampsSkills.clear(); - } + _reuseTimeStampsSkills.clear(); } /** @@ -2250,7 +2225,7 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe */ public final synchronized long getSkillRemainingReuseTime(int hashCode) { - final TimeStamp reuseStamp = (_reuseTimeStampsSkills != null) ? _reuseTimeStampsSkills.get(hashCode) : null; + final TimeStamp reuseStamp = _reuseTimeStampsSkills.get(hashCode); return reuseStamp != null ? reuseStamp.getRemaining() : -1; } @@ -2261,7 +2236,7 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe */ public final synchronized boolean hasSkillReuse(int hashCode) { - final TimeStamp reuseStamp = (_reuseTimeStampsSkills != null) ? _reuseTimeStampsSkills.get(hashCode) : null; + final TimeStamp reuseStamp = _reuseTimeStampsSkills.get(hashCode); return (reuseStamp != null) && reuseStamp.hasNotPassed(); } @@ -2272,7 +2247,7 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe */ public final synchronized TimeStamp getSkillReuseTimeStamp(int hashCode) { - return _reuseTimeStampsSkills != null ? _reuseTimeStampsSkills.get(hashCode) : null; + return _reuseTimeStampsSkills.get(hashCode); } /** @@ -2290,7 +2265,7 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe */ public void enableSkill(Skill skill) { - if ((skill == null) || (_disabledSkills == null)) + if (skill == null) { return; } @@ -2309,18 +2284,6 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe { return; } - - if (_disabledSkills == null) - { - synchronized (this) - { - if (_disabledSkills == null) - { - _disabledSkills = new ConcurrentHashMap<>(); - } - } - } - _disabledSkills.put(skill.getReuseHashCode(), delay > 0 ? System.currentTimeMillis() + delay : Long.MAX_VALUE); } @@ -2329,10 +2292,7 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe */ public final synchronized void resetDisabledSkills() { - if (_disabledSkills != null) - { - _disabledSkills.clear(); - } + _disabledSkills.clear(); } /** @@ -2357,7 +2317,7 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe return true; } - if (_disabledSkills == null) + if (_disabledSkills.isEmpty()) { return false; } @@ -2454,7 +2414,7 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe getWorldRegion().onDeath(this); } - getAttackByList().clear(); + clearAttackByList(); if (isChannelized()) { @@ -2555,12 +2515,9 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe { synchronized (this) { - if (_ai == null) - { - // Return the new AI within the synchronized block - // to avoid being nulled by other threads - return _ai = initAI(); - } + // Return the new AI within the synchronized block + // to avoid being nulled by other threads + return _ai = initAI(); } } return _ai; @@ -2624,19 +2581,14 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe */ public final Set getAttackByList() { - if (_attackByList == null) - { - synchronized (this) - { - if (_attackByList == null) - { - _attackByList = ConcurrentHashMap.newKeySet(); - } - } - } return _attackByList; } + public void clearAttackByList() + { + _attackByList.clear(); + } + public final Skill getLastSimultaneousSkillCast() { return _lastSimultaneousSkillCast; @@ -3135,12 +3087,12 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe .collect(Collectors.toCollection(HashSet::new)); //@formatter:on - if (_abnormalVisualEffects != null) + if (!_abnormalVisualEffects.isEmpty()) { abnormalVisualEffects.addAll(_abnormalVisualEffects); } - if ((_currentAbnormalVisualEffects == null) || !_currentAbnormalVisualEffects.equals(abnormalVisualEffects)) + if ((_currentAbnormalVisualEffects.isEmpty()) || !_currentAbnormalVisualEffects.equals(abnormalVisualEffects)) { _currentAbnormalVisualEffects = abnormalVisualEffects; updateAbnormalVisualEffects(); @@ -3153,7 +3105,7 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe */ public Set getCurrentAbnormalVisualEffects() { - return _currentAbnormalVisualEffects != null ? _currentAbnormalVisualEffects : Collections.emptySet(); + return _currentAbnormalVisualEffects; } /** @@ -3163,7 +3115,7 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe */ public boolean hasAbnormalVisualEffect(AbnormalVisualEffect ave) { - return (_abnormalVisualEffects != null) && _abnormalVisualEffects.contains(ave); + return _abnormalVisualEffects.contains(ave); } /** @@ -3174,16 +3126,6 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe { for (AbnormalVisualEffect ave : aves) { - if (_abnormalVisualEffects == null) - { - synchronized (this) - { - if (_abnormalVisualEffects == null) - { - _abnormalVisualEffects = Collections.newSetFromMap(new ConcurrentHashMap<>()); - } - } - } _abnormalVisualEffects.add(ave); } resetCurrentAbnormalVisualEffects(); @@ -3195,14 +3137,11 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe */ public final void stopAbnormalVisualEffect(AbnormalVisualEffect... aves) { - if (_abnormalVisualEffects != null) + for (AbnormalVisualEffect ave : aves) { - for (AbnormalVisualEffect ave : aves) - { - _abnormalVisualEffects.remove(ave); - } - resetCurrentAbnormalVisualEffects(); + _abnormalVisualEffects.remove(ave); } + resetCurrentAbnormalVisualEffects(); } /** @@ -4953,16 +4892,14 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe target.breakCast(); } - if (_triggerSkills != null) + for (OptionsSkillHolder holder : _triggerSkills.values()) { - for (OptionsSkillHolder holder : _triggerSkills.values()) + if (((!crit && (holder.getSkillType() == OptionsSkillType.ATTACK)) || ((holder.getSkillType() == OptionsSkillType.CRITICAL) && crit)) && (Rnd.get(100) < holder.getChance())) { - if (((!crit && (holder.getSkillType() == OptionsSkillType.ATTACK)) || ((holder.getSkillType() == OptionsSkillType.CRITICAL) && crit)) && (Rnd.get(100) < holder.getChance())) - { - makeTriggerCast(holder.getSkill(), target); - } + makeTriggerCast(holder.getSkill(), target); } } + // Launch weapon onCritical Special ability effect if available if (crit && (weapon != null)) { @@ -5748,14 +5685,11 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe activeWeapon.castOnMagicSkill(this, target, skill); } - if (_triggerSkills != null) + for (OptionsSkillHolder holder : _triggerSkills.values()) { - for (OptionsSkillHolder holder : _triggerSkills.values()) + if (((skill.isMagic() && (holder.getSkillType() == OptionsSkillType.MAGIC)) || (skill.isPhysical() && (holder.getSkillType() == OptionsSkillType.ATTACK))) && (Rnd.get(100) < holder.getChance())) { - if (((skill.isMagic() && (holder.getSkillType() == OptionsSkillType.MAGIC)) || (skill.isPhysical() && (holder.getSkillType() == OptionsSkillType.ATTACK))) && (Rnd.get(100) < holder.getChance())) - { - makeTriggerCast(holder.getSkill(), target); - } + makeTriggerCast(holder.getSkill(), target); } } } @@ -6506,16 +6440,6 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe public Map getTriggerSkills() { - if (_triggerSkills == null) - { - synchronized (this) - { - if (_triggerSkills == null) - { - _triggerSkills = new ConcurrentHashMap<>(); - } - } - } return _triggerSkills; } @@ -6793,7 +6717,7 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe public boolean isInvulAgainst(int skillId, int skillLvl) { - if (_invulAgainst == null) + if (_invulAgainst.isEmpty()) { return false; } @@ -6803,16 +6727,6 @@ public abstract class L2Character extends L2Object implements ISkillsHolder, IDe private Map getInvulAgainstSkills() { - if (_invulAgainst == null) - { - synchronized (this) - { - if (_invulAgainst == null) - { - _invulAgainst = new ConcurrentHashMap<>(); - } - } - } return _invulAgainst; } diff --git a/trunk/java/com/l2jmobius/gameserver/model/actor/L2Npc.java b/trunk/java/com/l2jmobius/gameserver/model/actor/L2Npc.java index b03a9690f9..335a18efcc 100644 --- a/trunk/java/com/l2jmobius/gameserver/model/actor/L2Npc.java +++ b/trunk/java/com/l2jmobius/gameserver/model/actor/L2Npc.java @@ -144,7 +144,7 @@ public class L2Npc extends L2Character private int _shotsMask = 0; private int _killingBlowWeaponId; /** Map of summoned NPCs by this NPC. */ - private volatile Map _summonedNpcs = null; + private volatile Map _summonedNpcs = new ConcurrentHashMap<>(); /** * Creates a NPC. @@ -1685,19 +1685,7 @@ public class L2Npc extends L2Character */ public final void addSummonedNpc(L2Npc npc) { - if (_summonedNpcs == null) - { - synchronized (this) - { - if (_summonedNpcs == null) - { - _summonedNpcs = new ConcurrentHashMap<>(); - } - } - } - _summonedNpcs.put(npc.getObjectId(), npc); - npc.setSummoner(this); } diff --git a/trunk/java/com/l2jmobius/gameserver/model/actor/instance/L2ClanHallDoormenInstance.java b/trunk/java/com/l2jmobius/gameserver/model/actor/instance/L2ClanHallDoormenInstance.java index ee67743118..442ac47462 100644 --- a/trunk/java/com/l2jmobius/gameserver/model/actor/instance/L2ClanHallDoormenInstance.java +++ b/trunk/java/com/l2jmobius/gameserver/model/actor/instance/L2ClanHallDoormenInstance.java @@ -172,15 +172,12 @@ public class L2ClanHallDoormenInstance extends L2DoormenInstance { synchronized (this) { - if (!_init) + _clanHall = ClanHallManager.getInstance().getNearbyClanHall(getX(), getY(), 500); + if (_clanHall != null) { - _clanHall = ClanHallManager.getInstance().getNearbyClanHall(getX(), getY(), 500); - if (_clanHall != null) - { - _hasEvolve = Arrays.binarySearch(CH_WITH_EVOLVE, _clanHall.getId()) >= 0; - } - _init = true; + _hasEvolve = Arrays.binarySearch(CH_WITH_EVOLVE, _clanHall.getId()) >= 0; } + _init = true; } } return _clanHall; diff --git a/trunk/java/com/l2jmobius/gameserver/model/actor/instance/L2ControlTowerInstance.java b/trunk/java/com/l2jmobius/gameserver/model/actor/instance/L2ControlTowerInstance.java index 8a84100fce..2ab067a235 100644 --- a/trunk/java/com/l2jmobius/gameserver/model/actor/instance/L2ControlTowerInstance.java +++ b/trunk/java/com/l2jmobius/gameserver/model/actor/instance/L2ControlTowerInstance.java @@ -31,7 +31,7 @@ import com.l2jmobius.gameserver.model.actor.templates.L2NpcTemplate; */ public class L2ControlTowerInstance extends L2Tower { - private volatile List _guards; + private volatile List _guards = new CopyOnWriteArrayList<>(); /** * Creates a control tower. @@ -50,22 +50,19 @@ public class L2ControlTowerInstance extends L2Tower { getCastle().getSiege().killedCT(this); - if ((_guards != null) && !_guards.isEmpty()) + for (L2Spawn spawn : _guards) { - for (L2Spawn spawn : _guards) + try { - try - { - spawn.stopRespawn(); - // spawn.getLastSpawn().doDie(spawn.getLastSpawn()); - } - catch (Exception e) - { - _log.log(Level.WARNING, "Error at L2ControlTowerInstance", e); - } + spawn.stopRespawn(); + // spawn.getLastSpawn().doDie(spawn.getLastSpawn()); + } + catch (Exception e) + { + _log.log(Level.WARNING, "Error at L2ControlTowerInstance", e); } - _guards.clear(); } + _guards.clear(); } return super.doDie(killer); } @@ -77,16 +74,6 @@ public class L2ControlTowerInstance extends L2Tower private final List getGuards() { - if (_guards == null) - { - synchronized (this) - { - if (_guards == null) - { - _guards = new CopyOnWriteArrayList<>(); - } - } - } return _guards; } } diff --git a/trunk/java/com/l2jmobius/gameserver/model/actor/instance/L2MonsterInstance.java b/trunk/java/com/l2jmobius/gameserver/model/actor/instance/L2MonsterInstance.java index f10d7f40d8..4e4b963ade 100644 --- a/trunk/java/com/l2jmobius/gameserver/model/actor/instance/L2MonsterInstance.java +++ b/trunk/java/com/l2jmobius/gameserver/model/actor/instance/L2MonsterInstance.java @@ -193,10 +193,7 @@ public class L2MonsterInstance extends L2Attackable { synchronized (this) { - if (_minionList == null) - { - _minionList = new MinionList(this); - } + _minionList = new MinionList(this); } } return _minionList; diff --git a/trunk/java/com/l2jmobius/gameserver/model/actor/instance/L2PcInstance.java b/trunk/java/com/l2jmobius/gameserver/model/actor/instance/L2PcInstance.java index 95c647b781..93c23afffd 100644 --- a/trunk/java/com/l2jmobius/gameserver/model/actor/instance/L2PcInstance.java +++ b/trunk/java/com/l2jmobius/gameserver/model/actor/instance/L2PcInstance.java @@ -518,7 +518,7 @@ public final class L2PcInstance extends L2Playable private long _offlineShopStart = 0; private Transform _transformation; - private volatile Map _transformSkills; + private volatile Map _transformSkills = new ConcurrentHashMap<>(); /** The table containing all L2RecipeList of the L2PcInstance */ private final Map _dwarvenRecipeBook = new ConcurrentHashMap<>(); @@ -607,7 +607,7 @@ public final class L2PcInstance extends L2Playable /** The Pet of the L2PcInstance */ private L2Summon _pet = null; /** Servitors of the L2PcInstance */ - private volatile Map _servitors = null; + private volatile Map _servitors = new ConcurrentHashMap<>(); private int _usedSummonPoints = 0; /** The L2Decoy of the L2PcInstance */ private L2Decoy _decoy = null; @@ -693,7 +693,7 @@ public final class L2PcInstance extends L2Playable private L2ItemInstance _lure = null; - private volatile Map _lastCommissionInfos; + private volatile Map _lastCommissionInfos = new ConcurrentHashMap<>(); public boolean isSpawnProtected() { @@ -722,7 +722,7 @@ public final class L2PcInstance extends L2Playable private int _expertiseWeaponPenalty = 0; private int _expertisePenaltyBonus = 0; - private volatile Map, AbstractRequest> _requests; + private volatile Map, AbstractRequest> _requests = new ConcurrentHashMap<>(); protected boolean _inventoryDisable = false; /** Player's cubics. */ @@ -1534,7 +1534,7 @@ public final class L2PcInstance extends L2Playable } /** List of all QuestState instance that needs to be notified of this L2PcInstance's or its pet's death */ - private volatile List _notifyQuestOfDeathList; + private volatile List _notifyQuestOfDeathList = new CopyOnWriteArrayList<>(); /** * Add QuestState instance that is to be notified of L2PcInstance's death. @@ -1559,11 +1559,10 @@ public final class L2PcInstance extends L2Playable */ public void removeNotifyQuestOfDeath(QuestState qs) { - if ((qs == null) || (_notifyQuestOfDeathList == null)) + if (qs == null) { return; } - _notifyQuestOfDeathList.remove(qs); } @@ -1572,23 +1571,12 @@ public final class L2PcInstance extends L2Playable */ public final List getNotifyQuestOfDeath() { - if (_notifyQuestOfDeathList == null) - { - synchronized (this) - { - if (_notifyQuestOfDeathList == null) - { - _notifyQuestOfDeathList = new CopyOnWriteArrayList<>(); - } - } - } - return _notifyQuestOfDeathList; } public final boolean isNotifyQuestOfDeathEmpty() { - return (_notifyQuestOfDeathList == null) || _notifyQuestOfDeathList.isEmpty(); + return _notifyQuestOfDeathList.isEmpty(); } /** @@ -5755,7 +5743,7 @@ public final class L2PcInstance extends L2Playable @Override public Map getServitors() { - return _servitors == null ? Collections.emptyMap() : _servitors; + return _servitors; } public L2Summon getAnyServitor() @@ -5796,16 +5784,6 @@ public final class L2PcInstance extends L2Playable public void addServitor(L2Summon servitor) { - if (_servitors == null) - { - synchronized (this) - { - if (_servitors == null) - { - _servitors = new ConcurrentHashMap<>(1); - } - } - } _servitors.put(servitor.getObjectId(), servitor); } @@ -6036,10 +6014,7 @@ public final class L2PcInstance extends L2Playable { synchronized (this) { - if (_manufactureItems == null) - { - _manufactureItems = Collections.synchronizedMap(new LinkedHashMap()); - } + _manufactureItems = Collections.synchronizedMap(new LinkedHashMap()); } } return _manufactureItems; @@ -11065,10 +11040,7 @@ public final class L2PcInstance extends L2Playable { synchronized (this) { - if (_teleportWatchdog == null) - { - _teleportWatchdog = ThreadPoolManager.getInstance().scheduleGeneral(new TeleportWatchdogTask(this), Config.TELEPORT_WATCHDOG_TIMEOUT * 1000); - } + _teleportWatchdog = ThreadPoolManager.getInstance().scheduleGeneral(new TeleportWatchdogTask(this), Config.TELEPORT_WATCHDOG_TIMEOUT * 1000); } } } @@ -12814,16 +12786,6 @@ public final class L2PcInstance extends L2Playable public void addTransformSkill(Skill sk) { - if (_transformSkills == null) - { - synchronized (this) - { - if (_transformSkills == null) - { - _transformSkills = new ConcurrentHashMap<>(); - } - } - } _transformSkills.put(sk.getId(), sk); if (sk.isPassive()) { @@ -12833,17 +12795,17 @@ public final class L2PcInstance extends L2Playable public Skill getTransformSkill(int id) { - return _transformSkills == null ? null : _transformSkills.get(id); + return _transformSkills.get(id); } public boolean hasTransformSkill(int id) { - return (_transformSkills != null) && _transformSkills.containsKey(id); + return _transformSkills.containsKey(id); } public void removeAllTransformSkills() { - _transformSkills = null; + _transformSkills.clear(); } protected void startFeed(int npcId) @@ -13076,10 +13038,7 @@ public final class L2PcInstance extends L2Playable { synchronized (this) { - if (_chargeTask != null) - { - _chargeTask.cancel(false); - } + _chargeTask.cancel(false); } } _chargeTask = ThreadPoolManager.getInstance().scheduleGeneral(new ResetChargesTask(this), 600000); @@ -14946,22 +14905,12 @@ public final class L2PcInstance extends L2Playable */ public boolean addRequest(AbstractRequest request) { - if (_requests == null) - { - synchronized (this) - { - if (_requests == null) - { - _requests = new ConcurrentHashMap<>(); - } - } - } return canRequest(request) && (_requests.putIfAbsent(request.getClass(), request) == null); } public boolean canRequest(AbstractRequest request) { - return (_requests != null) && _requests.values().stream().allMatch(request::canWorkWith); + return _requests.values().stream().allMatch(request::canWorkWith); } /** @@ -14970,7 +14919,7 @@ public final class L2PcInstance extends L2Playable */ public boolean removeRequest(Class clazz) { - return (_requests != null) && (_requests.remove(clazz) != null); + return (_requests.remove(clazz) != null); } /** @@ -14980,7 +14929,7 @@ public final class L2PcInstance extends L2Playable */ public T getRequest(Class requestClass) { - return _requests != null ? requestClass.cast(_requests.get(requestClass)) : null; + return requestClass.cast(_requests.get(requestClass)); } /** @@ -14988,12 +14937,12 @@ public final class L2PcInstance extends L2Playable */ public boolean hasRequests() { - return (_requests != null) && !_requests.isEmpty(); + return !_requests.isEmpty(); } public boolean hasItemRequest() { - return (_requests != null) && _requests.values().stream().anyMatch(AbstractRequest::isItemRequest); + return _requests.values().stream().anyMatch(AbstractRequest::isItemRequest); } /** @@ -15004,7 +14953,7 @@ public final class L2PcInstance extends L2Playable @SafeVarargs public final boolean hasRequest(Class requestClass, Class... classes) { - if (_requests == null) + if (_requests.isEmpty()) { return false; } @@ -15024,7 +14973,7 @@ public final class L2PcInstance extends L2Playable */ public boolean isProcessingItem(int objectId) { - return (_requests != null) && _requests.values().stream().anyMatch(req -> req.isUsing(objectId)); + return _requests.values().stream().anyMatch(req -> req.isUsing(objectId)); } /** @@ -15033,10 +14982,7 @@ public final class L2PcInstance extends L2Playable */ public void removeRequestsThatProcessesItem(int objectId) { - if (_requests != null) - { - _requests.values().removeIf(req -> req.isUsing(objectId)); - } + _requests.values().removeIf(req -> req.isUsing(objectId)); } /* @@ -15095,16 +15041,6 @@ public final class L2PcInstance extends L2Playable */ public Map getLastCommissionInfos() { - if (_lastCommissionInfos == null) - { - synchronized (this) - { - if (_lastCommissionInfos == null) - { - _lastCommissionInfos = new ConcurrentHashMap<>(); - } - } - } return _lastCommissionInfos; } diff --git a/trunk/java/com/l2jmobius/gameserver/model/actor/knownlist/CharKnownList.java b/trunk/java/com/l2jmobius/gameserver/model/actor/knownlist/CharKnownList.java index 2ebb458f99..6a18287702 100644 --- a/trunk/java/com/l2jmobius/gameserver/model/actor/knownlist/CharKnownList.java +++ b/trunk/java/com/l2jmobius/gameserver/model/actor/knownlist/CharKnownList.java @@ -29,9 +29,9 @@ import com.l2jmobius.gameserver.util.Util; public class CharKnownList extends ObjectKnownList { - private volatile Map _knownPlayers; - private volatile Map _knownSummons; - private volatile Map _knownRelations; + private volatile Map _knownPlayers = new ConcurrentHashMap<>(); + private volatile Map _knownSummons = new ConcurrentHashMap<>(); + private volatile Map _knownRelations = new ConcurrentHashMap<>(); public CharKnownList(L2Character activeChar) { @@ -225,46 +225,16 @@ public class CharKnownList extends ObjectKnownList public final Map getKnownPlayers() { - if (_knownPlayers == null) - { - synchronized (this) - { - if (_knownPlayers == null) - { - _knownPlayers = new ConcurrentHashMap<>(); - } - } - } return _knownPlayers; } public final Map getKnownRelations() { - if (_knownRelations == null) - { - synchronized (this) - { - if (_knownRelations == null) - { - _knownRelations = new ConcurrentHashMap<>(); - } - } - } return _knownRelations; } public final Map getKnownSummons() { - if (_knownSummons == null) - { - synchronized (this) - { - if (_knownSummons == null) - { - _knownSummons = new ConcurrentHashMap<>(); - } - } - } return _knownSummons; } diff --git a/trunk/java/com/l2jmobius/gameserver/model/actor/knownlist/ObjectKnownList.java b/trunk/java/com/l2jmobius/gameserver/model/actor/knownlist/ObjectKnownList.java index 4350e795a3..f8575eadd7 100644 --- a/trunk/java/com/l2jmobius/gameserver/model/actor/knownlist/ObjectKnownList.java +++ b/trunk/java/com/l2jmobius/gameserver/model/actor/knownlist/ObjectKnownList.java @@ -27,7 +27,7 @@ import com.l2jmobius.gameserver.util.Util; public class ObjectKnownList { private final L2Object _activeObject; - private volatile Map _knownObjects; + private volatile Map _knownObjects = new ConcurrentHashMap<>(); public ObjectKnownList(L2Object activeObject) { @@ -193,16 +193,6 @@ public class ObjectKnownList */ public final Map getKnownObjects() { - if (_knownObjects == null) - { - synchronized (this) - { - if (_knownObjects == null) - { - _knownObjects = new ConcurrentHashMap<>(); - } - } - } return _knownObjects; } } diff --git a/trunk/java/com/l2jmobius/gameserver/model/entity/Fort.java b/trunk/java/com/l2jmobius/gameserver/model/entity/Fort.java index c16fdc76d0..2c25e2fec2 100644 --- a/trunk/java/com/l2jmobius/gameserver/model/entity/Fort.java +++ b/trunk/java/com/l2jmobius/gameserver/model/entity/Fort.java @@ -890,10 +890,7 @@ public final class Fort extends AbstractResidence { synchronized (this) { - if (_siege == null) - { - _siege = new FortSiege(this); - } + _siege = new FortSiege(this); } } return _siege; diff --git a/trunk/java/com/l2jmobius/gameserver/model/events/ListenersContainer.java b/trunk/java/com/l2jmobius/gameserver/model/events/ListenersContainer.java index 24e03cbce7..1a34f413b3 100644 --- a/trunk/java/com/l2jmobius/gameserver/model/events/ListenersContainer.java +++ b/trunk/java/com/l2jmobius/gameserver/model/events/ListenersContainer.java @@ -30,7 +30,7 @@ import com.l2jmobius.util.EmptyQueue; */ public class ListenersContainer { - private volatile Map> _listeners = null; + private volatile Map> _listeners = new ConcurrentHashMap<>(); /** * Registers listener for a callback when specified event is executed. @@ -58,10 +58,6 @@ public class ListenersContainer { throw new NullPointerException("Listener cannot be null!"); } - else if (_listeners == null) - { - throw new NullPointerException("Listeners container is not initialized!"); - } else if (!_listeners.containsKey(listener.getType())) { throw new IllegalAccessError("Listeners container doesn't had " + listener.getType() + " event type added!"); @@ -77,7 +73,7 @@ public class ListenersContainer */ public Queue getListeners(EventType type) { - return (_listeners != null) && _listeners.containsKey(type) ? _listeners.get(type) : EmptyQueue.emptyQueue(); + return _listeners.containsKey(type) ? _listeners.get(type) : EmptyQueue.emptyQueue(); } public void removeListenerIf(EventType type, Predicate filter) @@ -87,10 +83,7 @@ public class ListenersContainer public void removeListenerIf(Predicate filter) { - if (_listeners != null) - { - getListeners().values().forEach(queue -> queue.stream().filter(filter).forEach(AbstractEventListener::unregisterMe)); - } + getListeners().values().forEach(queue -> queue.stream().filter(filter).forEach(AbstractEventListener::unregisterMe)); } public boolean hasListener(EventType type) @@ -104,16 +97,6 @@ public class ListenersContainer */ private Map> getListeners() { - if (_listeners == null) - { - synchronized (this) - { - if (_listeners == null) - { - _listeners = new ConcurrentHashMap<>(); - } - } - } return _listeners; } } diff --git a/trunk/java/com/l2jmobius/gameserver/model/quest/Quest.java b/trunk/java/com/l2jmobius/gameserver/model/quest/Quest.java index d204baed14..e4991c3510 100644 --- a/trunk/java/com/l2jmobius/gameserver/model/quest/Quest.java +++ b/trunk/java/com/l2jmobius/gameserver/model/quest/Quest.java @@ -246,10 +246,7 @@ public class Quest extends AbstractScript implements IIdentifiable { synchronized (this) { - if (_questTimers == null) - { - _questTimers = new ConcurrentHashMap<>(1); - } + _questTimers = new ConcurrentHashMap<>(1); } } return _questTimers; @@ -2799,10 +2796,7 @@ public class Quest extends AbstractScript implements IIdentifiable { synchronized (this) { - if (_startCondition == null) - { - _startCondition = new LinkedHashMap<>(1); - } + _startCondition = new LinkedHashMap<>(1); } } return _startCondition; diff --git a/trunk/java/com/l2jmobius/gameserver/model/skills/BuffInfo.java b/trunk/java/com/l2jmobius/gameserver/model/skills/BuffInfo.java index 829d249130..be0401ac5b 100644 --- a/trunk/java/com/l2jmobius/gameserver/model/skills/BuffInfo.java +++ b/trunk/java/com/l2jmobius/gameserver/model/skills/BuffInfo.java @@ -51,7 +51,7 @@ public final class BuffInfo private final List _effects = new ArrayList<>(1); // Tasks /** Effect tasks for ticks. */ - private volatile Map _tasks; + private volatile Map _tasks = new ConcurrentHashMap<>(); /** Scheduled future. */ private ScheduledFuture _scheduledFutureTimeTask; // Time and ticks @@ -106,16 +106,6 @@ public final class BuffInfo */ private void addTask(AbstractEffect effect, EffectTaskInfo effectTaskInfo) { - if (_tasks == null) - { - synchronized (this) - { - if (_tasks == null) - { - _tasks = new ConcurrentHashMap<>(); - } - } - } _tasks.put(effect, effectTaskInfo); } @@ -126,7 +116,7 @@ public final class BuffInfo */ private EffectTaskInfo getEffectTask(AbstractEffect effect) { - return (_tasks == null) ? null : _tasks.get(effect); + return _tasks.get(effect); } /** @@ -318,12 +308,9 @@ public final class BuffInfo public void finishEffects() { // Cancels the ticking task. - if (_tasks != null) + for (EffectTaskInfo effectTask : _tasks.values()) { - for (EffectTaskInfo effectTask : _tasks.values()) - { - effectTask.getScheduledFuture().cancel(true); // Don't allow to finish current run. - } + effectTask.getScheduledFuture().cancel(true); // Don't allow to finish current run. } // Remove stats removeStats(); @@ -405,13 +392,10 @@ public final class BuffInfo */ public int getTickCount(AbstractEffect effect) { - if (_tasks != null) + final EffectTaskInfo effectTaskInfo = _tasks.get(effect); + if (effectTaskInfo != null) { - final EffectTaskInfo effectTaskInfo = _tasks.get(effect); - if (effectTaskInfo != null) - { - return effectTaskInfo.getEffectTask().getTickCount(); - } + return effectTaskInfo.getEffectTask().getTickCount(); } return 0; } diff --git a/trunk/java/com/l2jmobius/gameserver/model/skills/Skill.java b/trunk/java/com/l2jmobius/gameserver/model/skills/Skill.java index baf1cf5fb3..e57e9a5fb8 100644 --- a/trunk/java/com/l2jmobius/gameserver/model/skills/Skill.java +++ b/trunk/java/com/l2jmobius/gameserver/model/skills/Skill.java @@ -1834,28 +1834,25 @@ public final class Skill implements IIdentifiable { synchronized (this) { - if (_effectTypes == null) + final Set effectTypesSet = new HashSet<>(); + for (List effectList : _effectLists.values()) { - final Set effectTypesSet = new HashSet<>(); - for (List effectList : _effectLists.values()) + if (effectList != null) { - if (effectList != null) + for (AbstractEffect effect : effectList) { - for (AbstractEffect effect : effectList) + if (effect == null) { - if (effect == null) - { - continue; - } - effectTypesSet.add((byte) effect.getEffectType().ordinal()); + continue; } + effectTypesSet.add((byte) effect.getEffectType().ordinal()); } } - - final Byte[] effectTypesArray = effectTypesSet.toArray(new Byte[effectTypesSet.size()]); - Arrays.sort(effectTypesArray); - _effectTypes = effectTypesArray; } + + final Byte[] effectTypesArray = effectTypesSet.toArray(new Byte[effectTypesSet.size()]); + Arrays.sort(effectTypesArray); + _effectTypes = effectTypesArray; } } diff --git a/trunk/java/com/l2jmobius/gameserver/model/zone/type/L2EffectZone.java b/trunk/java/com/l2jmobius/gameserver/model/zone/type/L2EffectZone.java index b6011be336..378f843a95 100644 --- a/trunk/java/com/l2jmobius/gameserver/model/zone/type/L2EffectZone.java +++ b/trunk/java/com/l2jmobius/gameserver/model/zone/type/L2EffectZone.java @@ -131,10 +131,7 @@ public class L2EffectZone extends L2ZoneType { synchronized (this) { - if (getSettings().getTask() == null) - { - getSettings().setTask(ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new ApplySkill(), _initialDelay, _reuse)); - } + getSettings().setTask(ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new ApplySkill(), _initialDelay, _reuse)); } } if (!character.isPlayer()) @@ -193,10 +190,7 @@ public class L2EffectZone extends L2ZoneType { synchronized (this) { - if (_skills == null) - { - _skills = new ConcurrentHashMap<>(3); - } + _skills = new ConcurrentHashMap<>(3); } } _skills.put(skillId, skillLvL);