Some synchronized changes.

This commit is contained in:
MobiusDev
2016-04-30 20:04:02 +00:00
parent 15d263a788
commit b001087964
17 changed files with 127 additions and 492 deletions

View File

@ -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<BuffInfo> _buffs;
private volatile Queue<BuffInfo> _buffs = new ConcurrentLinkedQueue<>();
/** Queue containing all triggered skills for this effect list. */
private volatile Queue<BuffInfo> _triggered;
private volatile Queue<BuffInfo> _triggered = new ConcurrentLinkedQueue<>();
/** Queue containing all dances/songs for this effect list. */
private volatile Queue<BuffInfo> _dances;
private volatile Queue<BuffInfo> _dances = new ConcurrentLinkedQueue<>();
/** Queue containing all toggle for this effect list. */
private volatile Queue<BuffInfo> _toggles;
private volatile Queue<BuffInfo> _toggles = new ConcurrentLinkedQueue<>();
/** Queue containing all debuffs for this effect list. */
private volatile Queue<BuffInfo> _debuffs;
private volatile Queue<BuffInfo> _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<BuffInfo> _passives;
private volatile Queue<BuffInfo> _passives = new ConcurrentLinkedQueue<>();
/** Map containing the all stacked effect in progress for each abnormal type. */
private volatile Map<AbnormalType, BuffInfo> _stackedEffects;
private volatile Map<AbnormalType, BuffInfo> _stackedEffects = new ConcurrentHashMap<>();
/** Set containing all abnormal types that shouldn't be added to this creature effect list. */
private volatile Set<AbnormalType> _blockedBuffSlots = null;
private volatile Set<AbnormalType> _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<BuffInfo> getBuffs()
{
if (_buffs == null)
{
synchronized (this)
{
if (_buffs == null)
{
_buffs = new ConcurrentLinkedQueue<>();
}
}
}
return _buffs;
}
@ -132,16 +123,6 @@ public final class CharEffectList
*/
public Queue<BuffInfo> getTriggered()
{
if (_triggered == null)
{
synchronized (this)
{
if (_triggered == null)
{
_triggered = new ConcurrentLinkedQueue<>();
}
}
}
return _triggered;
}
@ -151,16 +132,6 @@ public final class CharEffectList
*/
public Queue<BuffInfo> getDances()
{
if (_dances == null)
{
synchronized (this)
{
if (_dances == null)
{
_dances = new ConcurrentLinkedQueue<>();
}
}
}
return _dances;
}
@ -170,16 +141,6 @@ public final class CharEffectList
*/
public Queue<BuffInfo> getToggles()
{
if (_toggles == null)
{
synchronized (this)
{
if (_toggles == null)
{
_toggles = new ConcurrentLinkedQueue<>();
}
}
}
return _toggles;
}
@ -189,16 +150,6 @@ public final class CharEffectList
*/
public Queue<BuffInfo> getDebuffs()
{
if (_debuffs == null)
{
synchronized (this)
{
if (_debuffs == null)
{
_debuffs = new ConcurrentLinkedQueue<>();
}
}
}
return _debuffs;
}
@ -208,16 +159,6 @@ public final class CharEffectList
*/
public Queue<BuffInfo> 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<AbnormalType> 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());

View File

@ -64,7 +64,7 @@ public abstract class L2Object extends ListenersContainer implements IIdentifiab
private L2WorldRegion _worldRegion;
/** Instance type */
private InstanceType _instanceType = null;
private volatile Map<String, Object> _scripts;
private volatile Map<String, Object> _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> T addScript(T script)
{
if (_scripts == null)
{
synchronized (this)
{
if (_scripts == null)
{
_scripts = new ConcurrentHashMap<>();
}
}
}
_scripts.put(script.getClass().getName(), script);
return script;
}

View File

@ -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
}
}
}

View File

@ -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<L2Character> _attackByList;
private volatile Set<L2Character> _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<Integer, Skill> _skills = new ConcurrentHashMap<>();
/** Map containing the skill reuse time stamps. */
private volatile Map<Integer, TimeStamp> _reuseTimeStampsSkills = null;
private volatile Map<Integer, TimeStamp> _reuseTimeStampsSkills = new ConcurrentHashMap<>();
/** Map containing the item reuse time stamps. */
private volatile Map<Integer, TimeStamp> _reuseTimeStampsItems = null;
private volatile Map<Integer, TimeStamp> _reuseTimeStampsItems = new ConcurrentHashMap<>();
/** Map containing all the disabled skills. */
private volatile Map<Integer, Long> _disabledSkills = null;
private volatile Map<Integer, Long> _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<Integer, OptionsSkillHolder> _triggerSkills;
private volatile Map<Integer, OptionsSkillHolder> _triggerSkills = new ConcurrentHashMap<>();
private volatile Map<Integer, InvulSkillHolder> _invulAgainst;
private volatile Map<Integer, InvulSkillHolder> _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<AbnormalVisualEffect> _abnormalVisualEffects;
private volatile Set<AbnormalVisualEffect> _currentAbnormalVisualEffects;
private volatile Set<AbnormalVisualEffect> _abnormalVisualEffects = new CopyOnWriteArraySet<>();
private volatile Set<AbnormalVisualEffect> _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<L2Character> 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<AbnormalVisualEffect> 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<Integer, OptionsSkillHolder> 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<Integer, InvulSkillHolder> getInvulAgainstSkills()
{
if (_invulAgainst == null)
{
synchronized (this)
{
if (_invulAgainst == null)
{
_invulAgainst = new ConcurrentHashMap<>();
}
}
}
return _invulAgainst;
}

View File

@ -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<Integer, L2Npc> _summonedNpcs = null;
private volatile Map<Integer, L2Npc> _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);
}

View File

@ -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;

View File

@ -31,7 +31,7 @@ import com.l2jmobius.gameserver.model.actor.templates.L2NpcTemplate;
*/
public class L2ControlTowerInstance extends L2Tower
{
private volatile List<L2Spawn> _guards;
private volatile List<L2Spawn> _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<L2Spawn> getGuards()
{
if (_guards == null)
{
synchronized (this)
{
if (_guards == null)
{
_guards = new CopyOnWriteArrayList<>();
}
}
}
return _guards;
}
}

View File

@ -193,10 +193,7 @@ public class L2MonsterInstance extends L2Attackable
{
synchronized (this)
{
if (_minionList == null)
{
_minionList = new MinionList(this);
}
_minionList = new MinionList(this);
}
}
return _minionList;

View File

@ -518,7 +518,7 @@ public final class L2PcInstance extends L2Playable
private long _offlineShopStart = 0;
private Transform _transformation;
private volatile Map<Integer, Skill> _transformSkills;
private volatile Map<Integer, Skill> _transformSkills = new ConcurrentHashMap<>();
/** The table containing all L2RecipeList of the L2PcInstance */
private final Map<Integer, L2RecipeList> _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<Integer, L2Summon> _servitors = null;
private volatile Map<Integer, L2Summon> _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<Integer, ExResponseCommissionInfo> _lastCommissionInfos;
private volatile Map<Integer, ExResponseCommissionInfo> _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<Class<? extends AbstractRequest>, AbstractRequest> _requests;
private volatile Map<Class<? extends AbstractRequest>, 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<QuestState> _notifyQuestOfDeathList;
private volatile List<QuestState> _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<QuestState> 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<Integer, L2Summon> 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<Integer, L2ManufactureItem>());
}
_manufactureItems = Collections.synchronizedMap(new LinkedHashMap<Integer, L2ManufactureItem>());
}
}
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<? extends AbstractRequest> 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 extends AbstractRequest> T getRequest(Class<T> 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<? extends AbstractRequest> requestClass, Class<? extends AbstractRequest>... 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<Integer, ExResponseCommissionInfo> getLastCommissionInfos()
{
if (_lastCommissionInfos == null)
{
synchronized (this)
{
if (_lastCommissionInfos == null)
{
_lastCommissionInfos = new ConcurrentHashMap<>();
}
}
}
return _lastCommissionInfos;
}

View File

@ -29,9 +29,9 @@ import com.l2jmobius.gameserver.util.Util;
public class CharKnownList extends ObjectKnownList
{
private volatile Map<Integer, L2PcInstance> _knownPlayers;
private volatile Map<Integer, L2Summon> _knownSummons;
private volatile Map<Integer, Integer> _knownRelations;
private volatile Map<Integer, L2PcInstance> _knownPlayers = new ConcurrentHashMap<>();
private volatile Map<Integer, L2Summon> _knownSummons = new ConcurrentHashMap<>();
private volatile Map<Integer, Integer> _knownRelations = new ConcurrentHashMap<>();
public CharKnownList(L2Character activeChar)
{
@ -225,46 +225,16 @@ public class CharKnownList extends ObjectKnownList
public final Map<Integer, L2PcInstance> getKnownPlayers()
{
if (_knownPlayers == null)
{
synchronized (this)
{
if (_knownPlayers == null)
{
_knownPlayers = new ConcurrentHashMap<>();
}
}
}
return _knownPlayers;
}
public final Map<Integer, Integer> getKnownRelations()
{
if (_knownRelations == null)
{
synchronized (this)
{
if (_knownRelations == null)
{
_knownRelations = new ConcurrentHashMap<>();
}
}
}
return _knownRelations;
}
public final Map<Integer, L2Summon> getKnownSummons()
{
if (_knownSummons == null)
{
synchronized (this)
{
if (_knownSummons == null)
{
_knownSummons = new ConcurrentHashMap<>();
}
}
}
return _knownSummons;
}

View File

@ -27,7 +27,7 @@ import com.l2jmobius.gameserver.util.Util;
public class ObjectKnownList
{
private final L2Object _activeObject;
private volatile Map<Integer, L2Object> _knownObjects;
private volatile Map<Integer, L2Object> _knownObjects = new ConcurrentHashMap<>();
public ObjectKnownList(L2Object activeObject)
{
@ -193,16 +193,6 @@ public class ObjectKnownList
*/
public final Map<Integer, L2Object> getKnownObjects()
{
if (_knownObjects == null)
{
synchronized (this)
{
if (_knownObjects == null)
{
_knownObjects = new ConcurrentHashMap<>();
}
}
}
return _knownObjects;
}
}

View File

@ -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;

View File

@ -30,7 +30,7 @@ import com.l2jmobius.util.EmptyQueue;
*/
public class ListenersContainer
{
private volatile Map<EventType, Queue<AbstractEventListener>> _listeners = null;
private volatile Map<EventType, Queue<AbstractEventListener>> _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<AbstractEventListener> 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<? super AbstractEventListener> filter)
@ -87,10 +83,7 @@ public class ListenersContainer
public void removeListenerIf(Predicate<? super AbstractEventListener> 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<EventType, Queue<AbstractEventListener>> getListeners()
{
if (_listeners == null)
{
synchronized (this)
{
if (_listeners == null)
{
_listeners = new ConcurrentHashMap<>();
}
}
}
return _listeners;
}
}

View File

@ -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;

View File

@ -51,7 +51,7 @@ public final class BuffInfo
private final List<AbstractEffect> _effects = new ArrayList<>(1);
// Tasks
/** Effect tasks for ticks. */
private volatile Map<AbstractEffect, EffectTaskInfo> _tasks;
private volatile Map<AbstractEffect, EffectTaskInfo> _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;
}

View File

@ -1834,28 +1834,25 @@ public final class Skill implements IIdentifiable
{
synchronized (this)
{
if (_effectTypes == null)
final Set<Byte> effectTypesSet = new HashSet<>();
for (List<AbstractEffect> effectList : _effectLists.values())
{
final Set<Byte> effectTypesSet = new HashSet<>();
for (List<AbstractEffect> 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;
}
}

View File

@ -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);