Prefer empty over null aggro list.

This commit is contained in:
MobiusDev
2018-07-29 16:33:00 +00:00
parent b6843b2ec3
commit 49071def05
7 changed files with 119 additions and 196 deletions

View File

@@ -19,7 +19,6 @@ package com.l2jmobius.gameserver.model.actor;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -89,7 +88,7 @@ public class L2Attackable extends L2Npc
private boolean _isRaidMinion = false; private boolean _isRaidMinion = false;
// //
private boolean _champion = false; private boolean _champion = false;
private volatile Map<L2Character, AggroInfo> _aggroList = null; private volatile Map<L2Character, AggroInfo> _aggroList = new ConcurrentHashMap<>();
private boolean _isReturningToSpawnPoint = false; private boolean _isReturningToSpawnPoint = false;
private boolean _canReturnToSpawnPoint = true; private boolean _canReturnToSpawnPoint = true;
private boolean _seeThroughSilentMove = false; private boolean _seeThroughSilentMove = false;
@@ -151,7 +150,7 @@ public class L2Attackable extends L2Npc
public final Map<L2Character, AggroInfo> getAggroList() public final Map<L2Character, AggroInfo> getAggroList()
{ {
return _aggroList != null ? _aggroList : Collections.emptyMap(); return _aggroList;
} }
public final boolean isReturningToSpawnPoint() public final boolean isReturningToSpawnPoint()
@@ -342,7 +341,7 @@ public class L2Attackable extends L2Npc
{ {
try try
{ {
if (getAggroList().isEmpty()) if (_aggroList.isEmpty())
{ {
return; return;
} }
@@ -355,7 +354,7 @@ public class L2Attackable extends L2Npc
long totalDamage = 0; long totalDamage = 0;
// While Iterating over This Map Removing Object is Not Allowed // While Iterating over This Map Removing Object is Not Allowed
// Go through the _aggroList of the L2Attackable // Go through the _aggroList of the L2Attackable
for (AggroInfo info : getAggroList().values()) for (AggroInfo info : _aggroList.values())
{ {
// Get the L2Character corresponding to this attacker // Get the L2Character corresponding to this attacker
final L2PcInstance attacker = info.getAttacker().getActingPlayer(); final L2PcInstance attacker = info.getAttacker().getActingPlayer();
@@ -715,16 +714,6 @@ public class L2Attackable extends L2Npc
} }
// Get the AggroInfo of the attacker L2Character from the _aggroList of the L2Attackable // Get the AggroInfo of the attacker L2Character from the _aggroList of the L2Attackable
if (_aggroList == null)
{
synchronized (this)
{
if (_aggroList == null)
{
_aggroList = new ConcurrentHashMap<>();
}
}
}
final AggroInfo ai = _aggroList.computeIfAbsent(attacker, AggroInfo::new); final AggroInfo ai = _aggroList.computeIfAbsent(attacker, AggroInfo::new);
ai.addDamage(damage); ai.addDamage(damage);
@@ -773,7 +762,7 @@ public class L2Attackable extends L2Npc
return; return;
} }
for (AggroInfo ai : getAggroList().values()) for (AggroInfo ai : _aggroList.values())
{ {
ai.addHate(amount); ai.addHate(amount);
} }
@@ -792,7 +781,7 @@ public class L2Attackable extends L2Npc
return; return;
} }
final AggroInfo ai = getAggroList().get(target); final AggroInfo ai = _aggroList.get(target);
if (ai == null) if (ai == null)
{ {
LOGGER.info("target " + target + " not present in aggro list of " + this); LOGGER.info("target " + target + " not present in aggro list of " + this);
@@ -823,7 +812,7 @@ public class L2Attackable extends L2Npc
return; return;
} }
final AggroInfo ai = getAggroList().get(target); final AggroInfo ai = _aggroList.get(target);
if (ai != null) if (ai != null)
{ {
ai.stopHate(); ai.stopHate();
@@ -867,7 +856,7 @@ public class L2Attackable extends L2Npc
*/ */
public List<L2Character> get2MostHated() public List<L2Character> get2MostHated()
{ {
if (getAggroList().isEmpty() || isAlikeDead()) if (_aggroList.isEmpty() || isAlikeDead())
{ {
return null; return null;
} }
@@ -879,7 +868,7 @@ public class L2Attackable extends L2Npc
// While iterating over this map removing objects is not allowed // While iterating over this map removing objects is not allowed
// Go through the aggroList of the L2Attackable // Go through the aggroList of the L2Attackable
for (AggroInfo ai : getAggroList().values()) for (AggroInfo ai : _aggroList.values())
{ {
if (ai.checkHate(this) > maxHate) if (ai.checkHate(this) > maxHate)
{ {
@@ -905,13 +894,13 @@ public class L2Attackable extends L2Npc
public List<L2Character> getHateList() public List<L2Character> getHateList()
{ {
if (getAggroList().isEmpty() || isAlikeDead()) if (_aggroList.isEmpty() || isAlikeDead())
{ {
return null; return null;
} }
final List<L2Character> result = new ArrayList<>(); final List<L2Character> result = new ArrayList<>();
for (AggroInfo ai : getAggroList().values()) for (AggroInfo ai : _aggroList.values())
{ {
ai.checkHate(this); ai.checkHate(this);
@@ -926,12 +915,12 @@ public class L2Attackable extends L2Npc
*/ */
public int getHating(L2Character target) public int getHating(L2Character target)
{ {
if (getAggroList().isEmpty() || (target == null)) if (_aggroList.isEmpty() || (target == null))
{ {
return 0; return 0;
} }
final AggroInfo ai = getAggroList().get(target); final AggroInfo ai = _aggroList.get(target);
if (ai == null) if (ai == null)
{ {
return 0; return 0;
@@ -943,14 +932,14 @@ public class L2Attackable extends L2Npc
if (act.isInvisible() || act.isInvul() || act.isSpawnProtected()) if (act.isInvisible() || act.isInvul() || act.isSpawnProtected())
{ {
// Remove Object Should Use This Method and Can be Blocked While Interacting // Remove Object Should Use This Method and Can be Blocked While Interacting
getAggroList().remove(target); _aggroList.remove(target);
return 0; return 0;
} }
} }
if (!ai.getAttacker().isSpawned() || ai.getAttacker().isInvisible()) if (!ai.getAttacker().isSpawned() || ai.getAttacker().isInvisible())
{ {
getAggroList().remove(target); _aggroList.remove(target);
return 0; return 0;
} }
@@ -1167,7 +1156,7 @@ public class L2Attackable extends L2Npc
*/ */
public boolean containsTarget(L2Character player) public boolean containsTarget(L2Character player)
{ {
return getAggroList().containsKey(player); return _aggroList.containsKey(player);
} }
/** /**
@@ -1175,7 +1164,7 @@ public class L2Attackable extends L2Npc
*/ */
public void clearAggroList() public void clearAggroList()
{ {
_aggroList = null; _aggroList.clear();
// clear overhit values // clear overhit values
_overhit = false; _overhit = false;

View File

@@ -19,7 +19,6 @@ package com.l2jmobius.gameserver.model.actor;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -88,7 +87,7 @@ public class L2Attackable extends L2Npc
private boolean _isRaidMinion = false; private boolean _isRaidMinion = false;
// //
private boolean _champion = false; private boolean _champion = false;
private volatile Map<L2Character, AggroInfo> _aggroList = null; private volatile Map<L2Character, AggroInfo> _aggroList = new ConcurrentHashMap<>();
private boolean _isReturningToSpawnPoint = false; private boolean _isReturningToSpawnPoint = false;
private boolean _canReturnToSpawnPoint = true; private boolean _canReturnToSpawnPoint = true;
private boolean _seeThroughSilentMove = false; private boolean _seeThroughSilentMove = false;
@@ -147,7 +146,7 @@ public class L2Attackable extends L2Npc
public final Map<L2Character, AggroInfo> getAggroList() public final Map<L2Character, AggroInfo> getAggroList()
{ {
return _aggroList != null ? _aggroList : Collections.emptyMap(); return _aggroList;
} }
public final boolean isReturningToSpawnPoint() public final boolean isReturningToSpawnPoint()
@@ -338,7 +337,7 @@ public class L2Attackable extends L2Npc
{ {
try try
{ {
if (getAggroList().isEmpty()) if (_aggroList.isEmpty())
{ {
return; return;
} }
@@ -351,7 +350,7 @@ public class L2Attackable extends L2Npc
long totalDamage = 0; long totalDamage = 0;
// While Iterating over This Map Removing Object is Not Allowed // While Iterating over This Map Removing Object is Not Allowed
// Go through the _aggroList of the L2Attackable // Go through the _aggroList of the L2Attackable
for (AggroInfo info : getAggroList().values()) for (AggroInfo info : _aggroList.values())
{ {
// Get the L2Character corresponding to this attacker // Get the L2Character corresponding to this attacker
final L2PcInstance attacker = info.getAttacker().getActingPlayer(); final L2PcInstance attacker = info.getAttacker().getActingPlayer();
@@ -711,16 +710,6 @@ public class L2Attackable extends L2Npc
} }
// Get the AggroInfo of the attacker L2Character from the _aggroList of the L2Attackable // Get the AggroInfo of the attacker L2Character from the _aggroList of the L2Attackable
if (_aggroList == null)
{
synchronized (this)
{
if (_aggroList == null)
{
_aggroList = new ConcurrentHashMap<>();
}
}
}
final AggroInfo ai = _aggroList.computeIfAbsent(attacker, AggroInfo::new); final AggroInfo ai = _aggroList.computeIfAbsent(attacker, AggroInfo::new);
ai.addDamage(damage); ai.addDamage(damage);
@@ -769,7 +758,7 @@ public class L2Attackable extends L2Npc
return; return;
} }
for (AggroInfo ai : getAggroList().values()) for (AggroInfo ai : _aggroList.values())
{ {
ai.addHate(amount); ai.addHate(amount);
} }
@@ -788,7 +777,7 @@ public class L2Attackable extends L2Npc
return; return;
} }
final AggroInfo ai = getAggroList().get(target); final AggroInfo ai = _aggroList.get(target);
if (ai == null) if (ai == null)
{ {
LOGGER.info("target " + target + " not present in aggro list of " + this); LOGGER.info("target " + target + " not present in aggro list of " + this);
@@ -819,7 +808,7 @@ public class L2Attackable extends L2Npc
return; return;
} }
final AggroInfo ai = getAggroList().get(target); final AggroInfo ai = _aggroList.get(target);
if (ai != null) if (ai != null)
{ {
ai.stopHate(); ai.stopHate();
@@ -863,7 +852,7 @@ public class L2Attackable extends L2Npc
*/ */
public List<L2Character> get2MostHated() public List<L2Character> get2MostHated()
{ {
if (getAggroList().isEmpty() || isAlikeDead()) if (_aggroList.isEmpty() || isAlikeDead())
{ {
return null; return null;
} }
@@ -875,7 +864,7 @@ public class L2Attackable extends L2Npc
// While iterating over this map removing objects is not allowed // While iterating over this map removing objects is not allowed
// Go through the aggroList of the L2Attackable // Go through the aggroList of the L2Attackable
for (AggroInfo ai : getAggroList().values()) for (AggroInfo ai : _aggroList.values())
{ {
if (ai.checkHate(this) > maxHate) if (ai.checkHate(this) > maxHate)
{ {
@@ -901,13 +890,13 @@ public class L2Attackable extends L2Npc
public List<L2Character> getHateList() public List<L2Character> getHateList()
{ {
if (getAggroList().isEmpty() || isAlikeDead()) if (_aggroList.isEmpty() || isAlikeDead())
{ {
return null; return null;
} }
final List<L2Character> result = new ArrayList<>(); final List<L2Character> result = new ArrayList<>();
for (AggroInfo ai : getAggroList().values()) for (AggroInfo ai : _aggroList.values())
{ {
ai.checkHate(this); ai.checkHate(this);
@@ -922,12 +911,12 @@ public class L2Attackable extends L2Npc
*/ */
public int getHating(L2Character target) public int getHating(L2Character target)
{ {
if (getAggroList().isEmpty() || (target == null)) if (_aggroList.isEmpty() || (target == null))
{ {
return 0; return 0;
} }
final AggroInfo ai = getAggroList().get(target); final AggroInfo ai = _aggroList.get(target);
if (ai == null) if (ai == null)
{ {
return 0; return 0;
@@ -939,14 +928,14 @@ public class L2Attackable extends L2Npc
if (act.isInvisible() || act.isInvul() || act.isSpawnProtected()) if (act.isInvisible() || act.isInvul() || act.isSpawnProtected())
{ {
// Remove Object Should Use This Method and Can be Blocked While Interacting // Remove Object Should Use This Method and Can be Blocked While Interacting
getAggroList().remove(target); _aggroList.remove(target);
return 0; return 0;
} }
} }
if (!ai.getAttacker().isSpawned() || ai.getAttacker().isInvisible()) if (!ai.getAttacker().isSpawned() || ai.getAttacker().isInvisible())
{ {
getAggroList().remove(target); _aggroList.remove(target);
return 0; return 0;
} }
@@ -1163,7 +1152,7 @@ public class L2Attackable extends L2Npc
*/ */
public boolean containsTarget(L2Character player) public boolean containsTarget(L2Character player)
{ {
return getAggroList().containsKey(player); return _aggroList.containsKey(player);
} }
/** /**
@@ -1171,7 +1160,7 @@ public class L2Attackable extends L2Npc
*/ */
public void clearAggroList() public void clearAggroList()
{ {
_aggroList = null; _aggroList.clear();
// clear overhit values // clear overhit values
_overhit = false; _overhit = false;

View File

@@ -19,7 +19,6 @@ package com.l2jmobius.gameserver.model.actor;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -88,7 +87,7 @@ public class L2Attackable extends L2Npc
private boolean _isRaidMinion = false; private boolean _isRaidMinion = false;
// //
private boolean _champion = false; private boolean _champion = false;
private volatile Map<L2Character, AggroInfo> _aggroList = null; private volatile Map<L2Character, AggroInfo> _aggroList = new ConcurrentHashMap<>();
private boolean _isReturningToSpawnPoint = false; private boolean _isReturningToSpawnPoint = false;
private boolean _canReturnToSpawnPoint = true; private boolean _canReturnToSpawnPoint = true;
private boolean _seeThroughSilentMove = false; private boolean _seeThroughSilentMove = false;
@@ -147,7 +146,7 @@ public class L2Attackable extends L2Npc
public final Map<L2Character, AggroInfo> getAggroList() public final Map<L2Character, AggroInfo> getAggroList()
{ {
return _aggroList != null ? _aggroList : Collections.emptyMap(); return _aggroList;
} }
public final boolean isReturningToSpawnPoint() public final boolean isReturningToSpawnPoint()
@@ -338,7 +337,7 @@ public class L2Attackable extends L2Npc
{ {
try try
{ {
if (getAggroList().isEmpty()) if (_aggroList.isEmpty())
{ {
return; return;
} }
@@ -351,7 +350,7 @@ public class L2Attackable extends L2Npc
long totalDamage = 0; long totalDamage = 0;
// While Iterating over This Map Removing Object is Not Allowed // While Iterating over This Map Removing Object is Not Allowed
// Go through the _aggroList of the L2Attackable // Go through the _aggroList of the L2Attackable
for (AggroInfo info : getAggroList().values()) for (AggroInfo info : _aggroList.values())
{ {
// Get the L2Character corresponding to this attacker // Get the L2Character corresponding to this attacker
final L2PcInstance attacker = info.getAttacker().getActingPlayer(); final L2PcInstance attacker = info.getAttacker().getActingPlayer();
@@ -711,16 +710,6 @@ public class L2Attackable extends L2Npc
} }
// Get the AggroInfo of the attacker L2Character from the _aggroList of the L2Attackable // Get the AggroInfo of the attacker L2Character from the _aggroList of the L2Attackable
if (_aggroList == null)
{
synchronized (this)
{
if (_aggroList == null)
{
_aggroList = new ConcurrentHashMap<>();
}
}
}
final AggroInfo ai = _aggroList.computeIfAbsent(attacker, AggroInfo::new); final AggroInfo ai = _aggroList.computeIfAbsent(attacker, AggroInfo::new);
ai.addDamage(damage); ai.addDamage(damage);
@@ -769,7 +758,7 @@ public class L2Attackable extends L2Npc
return; return;
} }
for (AggroInfo ai : getAggroList().values()) for (AggroInfo ai : _aggroList.values())
{ {
ai.addHate(amount); ai.addHate(amount);
} }
@@ -788,7 +777,7 @@ public class L2Attackable extends L2Npc
return; return;
} }
final AggroInfo ai = getAggroList().get(target); final AggroInfo ai = _aggroList.get(target);
if (ai == null) if (ai == null)
{ {
LOGGER.info("target " + target + " not present in aggro list of " + this); LOGGER.info("target " + target + " not present in aggro list of " + this);
@@ -819,7 +808,7 @@ public class L2Attackable extends L2Npc
return; return;
} }
final AggroInfo ai = getAggroList().get(target); final AggroInfo ai = _aggroList.get(target);
if (ai != null) if (ai != null)
{ {
ai.stopHate(); ai.stopHate();
@@ -863,7 +852,7 @@ public class L2Attackable extends L2Npc
*/ */
public List<L2Character> get2MostHated() public List<L2Character> get2MostHated()
{ {
if (getAggroList().isEmpty() || isAlikeDead()) if (_aggroList.isEmpty() || isAlikeDead())
{ {
return null; return null;
} }
@@ -875,7 +864,7 @@ public class L2Attackable extends L2Npc
// While iterating over this map removing objects is not allowed // While iterating over this map removing objects is not allowed
// Go through the aggroList of the L2Attackable // Go through the aggroList of the L2Attackable
for (AggroInfo ai : getAggroList().values()) for (AggroInfo ai : _aggroList.values())
{ {
if (ai.checkHate(this) > maxHate) if (ai.checkHate(this) > maxHate)
{ {
@@ -901,13 +890,13 @@ public class L2Attackable extends L2Npc
public List<L2Character> getHateList() public List<L2Character> getHateList()
{ {
if (getAggroList().isEmpty() || isAlikeDead()) if (_aggroList.isEmpty() || isAlikeDead())
{ {
return null; return null;
} }
final List<L2Character> result = new ArrayList<>(); final List<L2Character> result = new ArrayList<>();
for (AggroInfo ai : getAggroList().values()) for (AggroInfo ai : _aggroList.values())
{ {
ai.checkHate(this); ai.checkHate(this);
@@ -922,12 +911,12 @@ public class L2Attackable extends L2Npc
*/ */
public int getHating(L2Character target) public int getHating(L2Character target)
{ {
if (getAggroList().isEmpty() || (target == null)) if (_aggroList.isEmpty() || (target == null))
{ {
return 0; return 0;
} }
final AggroInfo ai = getAggroList().get(target); final AggroInfo ai = _aggroList.get(target);
if (ai == null) if (ai == null)
{ {
return 0; return 0;
@@ -939,14 +928,14 @@ public class L2Attackable extends L2Npc
if (act.isInvisible() || act.isInvul() || act.isSpawnProtected()) if (act.isInvisible() || act.isInvul() || act.isSpawnProtected())
{ {
// Remove Object Should Use This Method and Can be Blocked While Interacting // Remove Object Should Use This Method and Can be Blocked While Interacting
getAggroList().remove(target); _aggroList.remove(target);
return 0; return 0;
} }
} }
if (!ai.getAttacker().isSpawned() || ai.getAttacker().isInvisible()) if (!ai.getAttacker().isSpawned() || ai.getAttacker().isInvisible())
{ {
getAggroList().remove(target); _aggroList.remove(target);
return 0; return 0;
} }
@@ -1163,7 +1152,7 @@ public class L2Attackable extends L2Npc
*/ */
public boolean containsTarget(L2Character player) public boolean containsTarget(L2Character player)
{ {
return getAggroList().containsKey(player); return _aggroList.containsKey(player);
} }
/** /**
@@ -1171,7 +1160,7 @@ public class L2Attackable extends L2Npc
*/ */
public void clearAggroList() public void clearAggroList()
{ {
_aggroList = null; _aggroList.clear();
// clear overhit values // clear overhit values
_overhit = false; _overhit = false;

View File

@@ -19,7 +19,6 @@ package com.l2jmobius.gameserver.model.actor;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -88,7 +87,7 @@ public class L2Attackable extends L2Npc
private boolean _isRaidMinion = false; private boolean _isRaidMinion = false;
// //
private boolean _champion = false; private boolean _champion = false;
private volatile Map<L2Character, AggroInfo> _aggroList = null; private volatile Map<L2Character, AggroInfo> _aggroList = new ConcurrentHashMap<>();
private boolean _isReturningToSpawnPoint = false; private boolean _isReturningToSpawnPoint = false;
private boolean _canReturnToSpawnPoint = true; private boolean _canReturnToSpawnPoint = true;
private boolean _seeThroughSilentMove = false; private boolean _seeThroughSilentMove = false;
@@ -147,7 +146,7 @@ public class L2Attackable extends L2Npc
public final Map<L2Character, AggroInfo> getAggroList() public final Map<L2Character, AggroInfo> getAggroList()
{ {
return _aggroList != null ? _aggroList : Collections.emptyMap(); return _aggroList;
} }
public final boolean isReturningToSpawnPoint() public final boolean isReturningToSpawnPoint()
@@ -338,7 +337,7 @@ public class L2Attackable extends L2Npc
{ {
try try
{ {
if (getAggroList().isEmpty()) if (_aggroList.isEmpty())
{ {
return; return;
} }
@@ -351,7 +350,7 @@ public class L2Attackable extends L2Npc
long totalDamage = 0; long totalDamage = 0;
// While Iterating over This Map Removing Object is Not Allowed // While Iterating over This Map Removing Object is Not Allowed
// Go through the _aggroList of the L2Attackable // Go through the _aggroList of the L2Attackable
for (AggroInfo info : getAggroList().values()) for (AggroInfo info : _aggroList.values())
{ {
// Get the L2Character corresponding to this attacker // Get the L2Character corresponding to this attacker
final L2PcInstance attacker = info.getAttacker().getActingPlayer(); final L2PcInstance attacker = info.getAttacker().getActingPlayer();
@@ -711,16 +710,6 @@ public class L2Attackable extends L2Npc
} }
// Get the AggroInfo of the attacker L2Character from the _aggroList of the L2Attackable // Get the AggroInfo of the attacker L2Character from the _aggroList of the L2Attackable
if (_aggroList == null)
{
synchronized (this)
{
if (_aggroList == null)
{
_aggroList = new ConcurrentHashMap<>();
}
}
}
final AggroInfo ai = _aggroList.computeIfAbsent(attacker, AggroInfo::new); final AggroInfo ai = _aggroList.computeIfAbsent(attacker, AggroInfo::new);
ai.addDamage(damage); ai.addDamage(damage);
@@ -769,7 +758,7 @@ public class L2Attackable extends L2Npc
return; return;
} }
for (AggroInfo ai : getAggroList().values()) for (AggroInfo ai : _aggroList.values())
{ {
ai.addHate(amount); ai.addHate(amount);
} }
@@ -788,7 +777,7 @@ public class L2Attackable extends L2Npc
return; return;
} }
final AggroInfo ai = getAggroList().get(target); final AggroInfo ai = _aggroList.get(target);
if (ai == null) if (ai == null)
{ {
LOGGER.info("target " + target + " not present in aggro list of " + this); LOGGER.info("target " + target + " not present in aggro list of " + this);
@@ -819,7 +808,7 @@ public class L2Attackable extends L2Npc
return; return;
} }
final AggroInfo ai = getAggroList().get(target); final AggroInfo ai = _aggroList.get(target);
if (ai != null) if (ai != null)
{ {
ai.stopHate(); ai.stopHate();
@@ -863,7 +852,7 @@ public class L2Attackable extends L2Npc
*/ */
public List<L2Character> get2MostHated() public List<L2Character> get2MostHated()
{ {
if (getAggroList().isEmpty() || isAlikeDead()) if (_aggroList.isEmpty() || isAlikeDead())
{ {
return null; return null;
} }
@@ -875,7 +864,7 @@ public class L2Attackable extends L2Npc
// While iterating over this map removing objects is not allowed // While iterating over this map removing objects is not allowed
// Go through the aggroList of the L2Attackable // Go through the aggroList of the L2Attackable
for (AggroInfo ai : getAggroList().values()) for (AggroInfo ai : _aggroList.values())
{ {
if (ai.checkHate(this) > maxHate) if (ai.checkHate(this) > maxHate)
{ {
@@ -901,13 +890,13 @@ public class L2Attackable extends L2Npc
public List<L2Character> getHateList() public List<L2Character> getHateList()
{ {
if (getAggroList().isEmpty() || isAlikeDead()) if (_aggroList.isEmpty() || isAlikeDead())
{ {
return null; return null;
} }
final List<L2Character> result = new ArrayList<>(); final List<L2Character> result = new ArrayList<>();
for (AggroInfo ai : getAggroList().values()) for (AggroInfo ai : _aggroList.values())
{ {
ai.checkHate(this); ai.checkHate(this);
@@ -922,12 +911,12 @@ public class L2Attackable extends L2Npc
*/ */
public int getHating(L2Character target) public int getHating(L2Character target)
{ {
if (getAggroList().isEmpty() || (target == null)) if (_aggroList.isEmpty() || (target == null))
{ {
return 0; return 0;
} }
final AggroInfo ai = getAggroList().get(target); final AggroInfo ai = _aggroList.get(target);
if (ai == null) if (ai == null)
{ {
return 0; return 0;
@@ -939,14 +928,14 @@ public class L2Attackable extends L2Npc
if (act.isInvisible() || act.isInvul() || act.isSpawnProtected()) if (act.isInvisible() || act.isInvul() || act.isSpawnProtected())
{ {
// Remove Object Should Use This Method and Can be Blocked While Interacting // Remove Object Should Use This Method and Can be Blocked While Interacting
getAggroList().remove(target); _aggroList.remove(target);
return 0; return 0;
} }
} }
if (!ai.getAttacker().isSpawned() || ai.getAttacker().isInvisible()) if (!ai.getAttacker().isSpawned() || ai.getAttacker().isInvisible())
{ {
getAggroList().remove(target); _aggroList.remove(target);
return 0; return 0;
} }
@@ -1163,7 +1152,7 @@ public class L2Attackable extends L2Npc
*/ */
public boolean containsTarget(L2Character player) public boolean containsTarget(L2Character player)
{ {
return getAggroList().containsKey(player); return _aggroList.containsKey(player);
} }
/** /**
@@ -1171,7 +1160,7 @@ public class L2Attackable extends L2Npc
*/ */
public void clearAggroList() public void clearAggroList()
{ {
_aggroList = null; _aggroList.clear();
// clear overhit values // clear overhit values
_overhit = false; _overhit = false;

View File

@@ -19,7 +19,6 @@ package com.l2jmobius.gameserver.model.actor;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -88,7 +87,7 @@ public class L2Attackable extends L2Npc
private boolean _isRaidMinion = false; private boolean _isRaidMinion = false;
// //
private boolean _champion = false; private boolean _champion = false;
private volatile Map<L2Character, AggroInfo> _aggroList = null; private volatile Map<L2Character, AggroInfo> _aggroList = new ConcurrentHashMap<>();
private boolean _isReturningToSpawnPoint = false; private boolean _isReturningToSpawnPoint = false;
private boolean _canReturnToSpawnPoint = true; private boolean _canReturnToSpawnPoint = true;
private boolean _seeThroughSilentMove = false; private boolean _seeThroughSilentMove = false;
@@ -147,7 +146,7 @@ public class L2Attackable extends L2Npc
public final Map<L2Character, AggroInfo> getAggroList() public final Map<L2Character, AggroInfo> getAggroList()
{ {
return _aggroList != null ? _aggroList : Collections.emptyMap(); return _aggroList;
} }
public final boolean isReturningToSpawnPoint() public final boolean isReturningToSpawnPoint()
@@ -338,7 +337,7 @@ public class L2Attackable extends L2Npc
{ {
try try
{ {
if (getAggroList().isEmpty()) if (_aggroList.isEmpty())
{ {
return; return;
} }
@@ -351,7 +350,7 @@ public class L2Attackable extends L2Npc
long totalDamage = 0; long totalDamage = 0;
// While Iterating over This Map Removing Object is Not Allowed // While Iterating over This Map Removing Object is Not Allowed
// Go through the _aggroList of the L2Attackable // Go through the _aggroList of the L2Attackable
for (AggroInfo info : getAggroList().values()) for (AggroInfo info : _aggroList.values())
{ {
// Get the L2Character corresponding to this attacker // Get the L2Character corresponding to this attacker
final L2PcInstance attacker = info.getAttacker().getActingPlayer(); final L2PcInstance attacker = info.getAttacker().getActingPlayer();
@@ -711,16 +710,6 @@ public class L2Attackable extends L2Npc
} }
// Get the AggroInfo of the attacker L2Character from the _aggroList of the L2Attackable // Get the AggroInfo of the attacker L2Character from the _aggroList of the L2Attackable
if (_aggroList == null)
{
synchronized (this)
{
if (_aggroList == null)
{
_aggroList = new ConcurrentHashMap<>();
}
}
}
final AggroInfo ai = _aggroList.computeIfAbsent(attacker, AggroInfo::new); final AggroInfo ai = _aggroList.computeIfAbsent(attacker, AggroInfo::new);
ai.addDamage(damage); ai.addDamage(damage);
@@ -769,7 +758,7 @@ public class L2Attackable extends L2Npc
return; return;
} }
for (AggroInfo ai : getAggroList().values()) for (AggroInfo ai : _aggroList.values())
{ {
ai.addHate(amount); ai.addHate(amount);
} }
@@ -788,7 +777,7 @@ public class L2Attackable extends L2Npc
return; return;
} }
final AggroInfo ai = getAggroList().get(target); final AggroInfo ai = _aggroList.get(target);
if (ai == null) if (ai == null)
{ {
LOGGER.info("target " + target + " not present in aggro list of " + this); LOGGER.info("target " + target + " not present in aggro list of " + this);
@@ -819,7 +808,7 @@ public class L2Attackable extends L2Npc
return; return;
} }
final AggroInfo ai = getAggroList().get(target); final AggroInfo ai = _aggroList.get(target);
if (ai != null) if (ai != null)
{ {
ai.stopHate(); ai.stopHate();
@@ -863,7 +852,7 @@ public class L2Attackable extends L2Npc
*/ */
public List<L2Character> get2MostHated() public List<L2Character> get2MostHated()
{ {
if (getAggroList().isEmpty() || isAlikeDead()) if (_aggroList.isEmpty() || isAlikeDead())
{ {
return null; return null;
} }
@@ -875,7 +864,7 @@ public class L2Attackable extends L2Npc
// While iterating over this map removing objects is not allowed // While iterating over this map removing objects is not allowed
// Go through the aggroList of the L2Attackable // Go through the aggroList of the L2Attackable
for (AggroInfo ai : getAggroList().values()) for (AggroInfo ai : _aggroList.values())
{ {
if (ai.checkHate(this) > maxHate) if (ai.checkHate(this) > maxHate)
{ {
@@ -901,13 +890,13 @@ public class L2Attackable extends L2Npc
public List<L2Character> getHateList() public List<L2Character> getHateList()
{ {
if (getAggroList().isEmpty() || isAlikeDead()) if (_aggroList.isEmpty() || isAlikeDead())
{ {
return null; return null;
} }
final List<L2Character> result = new ArrayList<>(); final List<L2Character> result = new ArrayList<>();
for (AggroInfo ai : getAggroList().values()) for (AggroInfo ai : _aggroList.values())
{ {
ai.checkHate(this); ai.checkHate(this);
@@ -922,12 +911,12 @@ public class L2Attackable extends L2Npc
*/ */
public int getHating(L2Character target) public int getHating(L2Character target)
{ {
if (getAggroList().isEmpty() || (target == null)) if (_aggroList.isEmpty() || (target == null))
{ {
return 0; return 0;
} }
final AggroInfo ai = getAggroList().get(target); final AggroInfo ai = _aggroList.get(target);
if (ai == null) if (ai == null)
{ {
return 0; return 0;
@@ -939,14 +928,14 @@ public class L2Attackable extends L2Npc
if (act.isInvisible() || act.isInvul() || act.isSpawnProtected()) if (act.isInvisible() || act.isInvul() || act.isSpawnProtected())
{ {
// Remove Object Should Use This Method and Can be Blocked While Interacting // Remove Object Should Use This Method and Can be Blocked While Interacting
getAggroList().remove(target); _aggroList.remove(target);
return 0; return 0;
} }
} }
if (!ai.getAttacker().isSpawned() || ai.getAttacker().isInvisible()) if (!ai.getAttacker().isSpawned() || ai.getAttacker().isInvisible())
{ {
getAggroList().remove(target); _aggroList.remove(target);
return 0; return 0;
} }
@@ -1163,7 +1152,7 @@ public class L2Attackable extends L2Npc
*/ */
public boolean containsTarget(L2Character player) public boolean containsTarget(L2Character player)
{ {
return getAggroList().containsKey(player); return _aggroList.containsKey(player);
} }
/** /**
@@ -1171,7 +1160,7 @@ public class L2Attackable extends L2Npc
*/ */
public void clearAggroList() public void clearAggroList()
{ {
_aggroList = null; _aggroList.clear();
// clear overhit values // clear overhit values
_overhit = false; _overhit = false;

View File

@@ -19,7 +19,6 @@ package com.l2jmobius.gameserver.model.actor;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -88,7 +87,7 @@ public class L2Attackable extends L2Npc
private boolean _isRaidMinion = false; private boolean _isRaidMinion = false;
// //
private boolean _champion = false; private boolean _champion = false;
private volatile Map<L2Character, AggroInfo> _aggroList = null; private volatile Map<L2Character, AggroInfo> _aggroList = new ConcurrentHashMap<>();
private boolean _isReturningToSpawnPoint = false; private boolean _isReturningToSpawnPoint = false;
private boolean _canReturnToSpawnPoint = true; private boolean _canReturnToSpawnPoint = true;
private boolean _seeThroughSilentMove = false; private boolean _seeThroughSilentMove = false;
@@ -147,7 +146,7 @@ public class L2Attackable extends L2Npc
public final Map<L2Character, AggroInfo> getAggroList() public final Map<L2Character, AggroInfo> getAggroList()
{ {
return _aggroList != null ? _aggroList : Collections.emptyMap(); return _aggroList;
} }
public final boolean isReturningToSpawnPoint() public final boolean isReturningToSpawnPoint()
@@ -338,7 +337,7 @@ public class L2Attackable extends L2Npc
{ {
try try
{ {
if (getAggroList().isEmpty()) if (_aggroList.isEmpty())
{ {
return; return;
} }
@@ -351,7 +350,7 @@ public class L2Attackable extends L2Npc
long totalDamage = 0; long totalDamage = 0;
// While Iterating over This Map Removing Object is Not Allowed // While Iterating over This Map Removing Object is Not Allowed
// Go through the _aggroList of the L2Attackable // Go through the _aggroList of the L2Attackable
for (AggroInfo info : getAggroList().values()) for (AggroInfo info : _aggroList.values())
{ {
// Get the L2Character corresponding to this attacker // Get the L2Character corresponding to this attacker
final L2PcInstance attacker = info.getAttacker().getActingPlayer(); final L2PcInstance attacker = info.getAttacker().getActingPlayer();
@@ -711,16 +710,6 @@ public class L2Attackable extends L2Npc
} }
// Get the AggroInfo of the attacker L2Character from the _aggroList of the L2Attackable // Get the AggroInfo of the attacker L2Character from the _aggroList of the L2Attackable
if (_aggroList == null)
{
synchronized (this)
{
if (_aggroList == null)
{
_aggroList = new ConcurrentHashMap<>();
}
}
}
final AggroInfo ai = _aggroList.computeIfAbsent(attacker, AggroInfo::new); final AggroInfo ai = _aggroList.computeIfAbsent(attacker, AggroInfo::new);
ai.addDamage(damage); ai.addDamage(damage);
@@ -769,7 +758,7 @@ public class L2Attackable extends L2Npc
return; return;
} }
for (AggroInfo ai : getAggroList().values()) for (AggroInfo ai : _aggroList.values())
{ {
ai.addHate(amount); ai.addHate(amount);
} }
@@ -788,7 +777,7 @@ public class L2Attackable extends L2Npc
return; return;
} }
final AggroInfo ai = getAggroList().get(target); final AggroInfo ai = _aggroList.get(target);
if (ai == null) if (ai == null)
{ {
LOGGER.info("target " + target + " not present in aggro list of " + this); LOGGER.info("target " + target + " not present in aggro list of " + this);
@@ -819,7 +808,7 @@ public class L2Attackable extends L2Npc
return; return;
} }
final AggroInfo ai = getAggroList().get(target); final AggroInfo ai = _aggroList.get(target);
if (ai != null) if (ai != null)
{ {
ai.stopHate(); ai.stopHate();
@@ -863,7 +852,7 @@ public class L2Attackable extends L2Npc
*/ */
public List<L2Character> get2MostHated() public List<L2Character> get2MostHated()
{ {
if (getAggroList().isEmpty() || isAlikeDead()) if (_aggroList.isEmpty() || isAlikeDead())
{ {
return null; return null;
} }
@@ -875,7 +864,7 @@ public class L2Attackable extends L2Npc
// While iterating over this map removing objects is not allowed // While iterating over this map removing objects is not allowed
// Go through the aggroList of the L2Attackable // Go through the aggroList of the L2Attackable
for (AggroInfo ai : getAggroList().values()) for (AggroInfo ai : _aggroList.values())
{ {
if (ai.checkHate(this) > maxHate) if (ai.checkHate(this) > maxHate)
{ {
@@ -901,13 +890,13 @@ public class L2Attackable extends L2Npc
public List<L2Character> getHateList() public List<L2Character> getHateList()
{ {
if (getAggroList().isEmpty() || isAlikeDead()) if (_aggroList.isEmpty() || isAlikeDead())
{ {
return null; return null;
} }
final List<L2Character> result = new ArrayList<>(); final List<L2Character> result = new ArrayList<>();
for (AggroInfo ai : getAggroList().values()) for (AggroInfo ai : _aggroList.values())
{ {
ai.checkHate(this); ai.checkHate(this);
@@ -922,12 +911,12 @@ public class L2Attackable extends L2Npc
*/ */
public int getHating(L2Character target) public int getHating(L2Character target)
{ {
if (getAggroList().isEmpty() || (target == null)) if (_aggroList.isEmpty() || (target == null))
{ {
return 0; return 0;
} }
final AggroInfo ai = getAggroList().get(target); final AggroInfo ai = _aggroList.get(target);
if (ai == null) if (ai == null)
{ {
return 0; return 0;
@@ -939,14 +928,14 @@ public class L2Attackable extends L2Npc
if (act.isInvisible() || act.isInvul() || act.isSpawnProtected()) if (act.isInvisible() || act.isInvul() || act.isSpawnProtected())
{ {
// Remove Object Should Use This Method and Can be Blocked While Interacting // Remove Object Should Use This Method and Can be Blocked While Interacting
getAggroList().remove(target); _aggroList.remove(target);
return 0; return 0;
} }
} }
if (!ai.getAttacker().isSpawned() || ai.getAttacker().isInvisible()) if (!ai.getAttacker().isSpawned() || ai.getAttacker().isInvisible())
{ {
getAggroList().remove(target); _aggroList.remove(target);
return 0; return 0;
} }
@@ -1163,7 +1152,7 @@ public class L2Attackable extends L2Npc
*/ */
public boolean containsTarget(L2Character player) public boolean containsTarget(L2Character player)
{ {
return getAggroList().containsKey(player); return _aggroList.containsKey(player);
} }
/** /**
@@ -1171,7 +1160,7 @@ public class L2Attackable extends L2Npc
*/ */
public void clearAggroList() public void clearAggroList()
{ {
_aggroList = null; _aggroList.clear();
// clear overhit values // clear overhit values
_overhit = false; _overhit = false;

View File

@@ -19,7 +19,6 @@ package com.l2jmobius.gameserver.model.actor;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -88,7 +87,7 @@ public class L2Attackable extends L2Npc
private boolean _isRaidMinion = false; private boolean _isRaidMinion = false;
// //
private boolean _champion = false; private boolean _champion = false;
private volatile Map<L2Character, AggroInfo> _aggroList = null; private volatile Map<L2Character, AggroInfo> _aggroList = new ConcurrentHashMap<>();
private boolean _isReturningToSpawnPoint = false; private boolean _isReturningToSpawnPoint = false;
private boolean _canReturnToSpawnPoint = true; private boolean _canReturnToSpawnPoint = true;
private boolean _seeThroughSilentMove = false; private boolean _seeThroughSilentMove = false;
@@ -147,7 +146,7 @@ public class L2Attackable extends L2Npc
public final Map<L2Character, AggroInfo> getAggroList() public final Map<L2Character, AggroInfo> getAggroList()
{ {
return _aggroList != null ? _aggroList : Collections.emptyMap(); return _aggroList;
} }
public final boolean isReturningToSpawnPoint() public final boolean isReturningToSpawnPoint()
@@ -338,7 +337,7 @@ public class L2Attackable extends L2Npc
{ {
try try
{ {
if (getAggroList().isEmpty()) if (_aggroList.isEmpty())
{ {
return; return;
} }
@@ -351,7 +350,7 @@ public class L2Attackable extends L2Npc
long totalDamage = 0; long totalDamage = 0;
// While Iterating over This Map Removing Object is Not Allowed // While Iterating over This Map Removing Object is Not Allowed
// Go through the _aggroList of the L2Attackable // Go through the _aggroList of the L2Attackable
for (AggroInfo info : getAggroList().values()) for (AggroInfo info : _aggroList.values())
{ {
// Get the L2Character corresponding to this attacker // Get the L2Character corresponding to this attacker
final L2PcInstance attacker = info.getAttacker().getActingPlayer(); final L2PcInstance attacker = info.getAttacker().getActingPlayer();
@@ -711,16 +710,6 @@ public class L2Attackable extends L2Npc
} }
// Get the AggroInfo of the attacker L2Character from the _aggroList of the L2Attackable // Get the AggroInfo of the attacker L2Character from the _aggroList of the L2Attackable
if (_aggroList == null)
{
synchronized (this)
{
if (_aggroList == null)
{
_aggroList = new ConcurrentHashMap<>();
}
}
}
final AggroInfo ai = _aggroList.computeIfAbsent(attacker, AggroInfo::new); final AggroInfo ai = _aggroList.computeIfAbsent(attacker, AggroInfo::new);
ai.addDamage(damage); ai.addDamage(damage);
@@ -769,7 +758,7 @@ public class L2Attackable extends L2Npc
return; return;
} }
for (AggroInfo ai : getAggroList().values()) for (AggroInfo ai : _aggroList.values())
{ {
ai.addHate(amount); ai.addHate(amount);
} }
@@ -788,7 +777,7 @@ public class L2Attackable extends L2Npc
return; return;
} }
final AggroInfo ai = getAggroList().get(target); final AggroInfo ai = _aggroList.get(target);
if (ai == null) if (ai == null)
{ {
LOGGER.info("target " + target + " not present in aggro list of " + this); LOGGER.info("target " + target + " not present in aggro list of " + this);
@@ -819,7 +808,7 @@ public class L2Attackable extends L2Npc
return; return;
} }
final AggroInfo ai = getAggroList().get(target); final AggroInfo ai = _aggroList.get(target);
if (ai != null) if (ai != null)
{ {
ai.stopHate(); ai.stopHate();
@@ -863,7 +852,7 @@ public class L2Attackable extends L2Npc
*/ */
public List<L2Character> get2MostHated() public List<L2Character> get2MostHated()
{ {
if (getAggroList().isEmpty() || isAlikeDead()) if (_aggroList.isEmpty() || isAlikeDead())
{ {
return null; return null;
} }
@@ -875,7 +864,7 @@ public class L2Attackable extends L2Npc
// While iterating over this map removing objects is not allowed // While iterating over this map removing objects is not allowed
// Go through the aggroList of the L2Attackable // Go through the aggroList of the L2Attackable
for (AggroInfo ai : getAggroList().values()) for (AggroInfo ai : _aggroList.values())
{ {
if (ai.checkHate(this) > maxHate) if (ai.checkHate(this) > maxHate)
{ {
@@ -901,13 +890,13 @@ public class L2Attackable extends L2Npc
public List<L2Character> getHateList() public List<L2Character> getHateList()
{ {
if (getAggroList().isEmpty() || isAlikeDead()) if (_aggroList.isEmpty() || isAlikeDead())
{ {
return null; return null;
} }
final List<L2Character> result = new ArrayList<>(); final List<L2Character> result = new ArrayList<>();
for (AggroInfo ai : getAggroList().values()) for (AggroInfo ai : _aggroList.values())
{ {
ai.checkHate(this); ai.checkHate(this);
@@ -922,12 +911,12 @@ public class L2Attackable extends L2Npc
*/ */
public int getHating(L2Character target) public int getHating(L2Character target)
{ {
if (getAggroList().isEmpty() || (target == null)) if (_aggroList.isEmpty() || (target == null))
{ {
return 0; return 0;
} }
final AggroInfo ai = getAggroList().get(target); final AggroInfo ai = _aggroList.get(target);
if (ai == null) if (ai == null)
{ {
return 0; return 0;
@@ -939,14 +928,14 @@ public class L2Attackable extends L2Npc
if (act.isInvisible() || act.isInvul() || act.isSpawnProtected()) if (act.isInvisible() || act.isInvul() || act.isSpawnProtected())
{ {
// Remove Object Should Use This Method and Can be Blocked While Interacting // Remove Object Should Use This Method and Can be Blocked While Interacting
getAggroList().remove(target); _aggroList.remove(target);
return 0; return 0;
} }
} }
if (!ai.getAttacker().isSpawned() || ai.getAttacker().isInvisible()) if (!ai.getAttacker().isSpawned() || ai.getAttacker().isInvisible())
{ {
getAggroList().remove(target); _aggroList.remove(target);
return 0; return 0;
} }
@@ -1163,7 +1152,7 @@ public class L2Attackable extends L2Npc
*/ */
public boolean containsTarget(L2Character player) public boolean containsTarget(L2Character player)
{ {
return getAggroList().containsKey(player); return _aggroList.containsKey(player);
} }
/** /**
@@ -1171,7 +1160,7 @@ public class L2Attackable extends L2Npc
*/ */
public void clearAggroList() public void clearAggroList()
{ {
_aggroList = null; _aggroList.clear();
// clear overhit values // clear overhit values
_overhit = false; _overhit = false;