From 49071def0597cf6e414fb8198106f508c85b77c7 Mon Sep 17 00:00:00 2001 From: MobiusDev <8391001+MobiusDevelopment@users.noreply.github.com> Date: Sun, 29 Jul 2018 16:33:00 +0000 Subject: [PATCH] Prefer empty over null aggro list. --- .../gameserver/model/actor/L2Attackable.java | 45 +++++++------------ .../gameserver/model/actor/L2Attackable.java | 45 +++++++------------ .../gameserver/model/actor/L2Attackable.java | 45 +++++++------------ .../gameserver/model/actor/L2Attackable.java | 45 +++++++------------ .../gameserver/model/actor/L2Attackable.java | 45 +++++++------------ .../gameserver/model/actor/L2Attackable.java | 45 +++++++------------ .../gameserver/model/actor/L2Attackable.java | 45 +++++++------------ 7 files changed, 119 insertions(+), 196 deletions(-) diff --git a/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/gameserver/model/actor/L2Attackable.java b/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/gameserver/model/actor/L2Attackable.java index 09b4d41a2a..e1ed479252 100644 --- a/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/gameserver/model/actor/L2Attackable.java +++ b/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/gameserver/model/actor/L2Attackable.java @@ -19,7 +19,6 @@ package com.l2jmobius.gameserver.model.actor; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -89,7 +88,7 @@ public class L2Attackable extends L2Npc private boolean _isRaidMinion = false; // private boolean _champion = false; - private volatile Map _aggroList = null; + private volatile Map _aggroList = new ConcurrentHashMap<>(); private boolean _isReturningToSpawnPoint = false; private boolean _canReturnToSpawnPoint = true; private boolean _seeThroughSilentMove = false; @@ -151,7 +150,7 @@ public class L2Attackable extends L2Npc public final Map getAggroList() { - return _aggroList != null ? _aggroList : Collections.emptyMap(); + return _aggroList; } public final boolean isReturningToSpawnPoint() @@ -342,7 +341,7 @@ public class L2Attackable extends L2Npc { try { - if (getAggroList().isEmpty()) + if (_aggroList.isEmpty()) { return; } @@ -355,7 +354,7 @@ public class L2Attackable extends L2Npc long totalDamage = 0; // While Iterating over This Map Removing Object is Not Allowed // Go through the _aggroList of the L2Attackable - for (AggroInfo info : getAggroList().values()) + for (AggroInfo info : _aggroList.values()) { // Get the L2Character corresponding to this attacker 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 - if (_aggroList == null) - { - synchronized (this) - { - if (_aggroList == null) - { - _aggroList = new ConcurrentHashMap<>(); - } - } - } final AggroInfo ai = _aggroList.computeIfAbsent(attacker, AggroInfo::new); ai.addDamage(damage); @@ -773,7 +762,7 @@ public class L2Attackable extends L2Npc return; } - for (AggroInfo ai : getAggroList().values()) + for (AggroInfo ai : _aggroList.values()) { ai.addHate(amount); } @@ -792,7 +781,7 @@ public class L2Attackable extends L2Npc return; } - final AggroInfo ai = getAggroList().get(target); + final AggroInfo ai = _aggroList.get(target); if (ai == null) { LOGGER.info("target " + target + " not present in aggro list of " + this); @@ -823,7 +812,7 @@ public class L2Attackable extends L2Npc return; } - final AggroInfo ai = getAggroList().get(target); + final AggroInfo ai = _aggroList.get(target); if (ai != null) { ai.stopHate(); @@ -867,7 +856,7 @@ public class L2Attackable extends L2Npc */ public List get2MostHated() { - if (getAggroList().isEmpty() || isAlikeDead()) + if (_aggroList.isEmpty() || isAlikeDead()) { return null; } @@ -879,7 +868,7 @@ public class L2Attackable extends L2Npc // While iterating over this map removing objects is not allowed // Go through the aggroList of the L2Attackable - for (AggroInfo ai : getAggroList().values()) + for (AggroInfo ai : _aggroList.values()) { if (ai.checkHate(this) > maxHate) { @@ -905,13 +894,13 @@ public class L2Attackable extends L2Npc public List getHateList() { - if (getAggroList().isEmpty() || isAlikeDead()) + if (_aggroList.isEmpty() || isAlikeDead()) { return null; } final List result = new ArrayList<>(); - for (AggroInfo ai : getAggroList().values()) + for (AggroInfo ai : _aggroList.values()) { ai.checkHate(this); @@ -926,12 +915,12 @@ public class L2Attackable extends L2Npc */ public int getHating(L2Character target) { - if (getAggroList().isEmpty() || (target == null)) + if (_aggroList.isEmpty() || (target == null)) { return 0; } - final AggroInfo ai = getAggroList().get(target); + final AggroInfo ai = _aggroList.get(target); if (ai == null) { return 0; @@ -943,14 +932,14 @@ public class L2Attackable extends L2Npc if (act.isInvisible() || act.isInvul() || act.isSpawnProtected()) { // Remove Object Should Use This Method and Can be Blocked While Interacting - getAggroList().remove(target); + _aggroList.remove(target); return 0; } } if (!ai.getAttacker().isSpawned() || ai.getAttacker().isInvisible()) { - getAggroList().remove(target); + _aggroList.remove(target); return 0; } @@ -1167,7 +1156,7 @@ public class L2Attackable extends L2Npc */ 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() { - _aggroList = null; + _aggroList.clear(); // clear overhit values _overhit = false; diff --git a/L2J_Mobius_2.5_Underground/java/com/l2jmobius/gameserver/model/actor/L2Attackable.java b/L2J_Mobius_2.5_Underground/java/com/l2jmobius/gameserver/model/actor/L2Attackable.java index da32d824d8..3b8c2f3632 100644 --- a/L2J_Mobius_2.5_Underground/java/com/l2jmobius/gameserver/model/actor/L2Attackable.java +++ b/L2J_Mobius_2.5_Underground/java/com/l2jmobius/gameserver/model/actor/L2Attackable.java @@ -19,7 +19,6 @@ package com.l2jmobius.gameserver.model.actor; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -88,7 +87,7 @@ public class L2Attackable extends L2Npc private boolean _isRaidMinion = false; // private boolean _champion = false; - private volatile Map _aggroList = null; + private volatile Map _aggroList = new ConcurrentHashMap<>(); private boolean _isReturningToSpawnPoint = false; private boolean _canReturnToSpawnPoint = true; private boolean _seeThroughSilentMove = false; @@ -147,7 +146,7 @@ public class L2Attackable extends L2Npc public final Map getAggroList() { - return _aggroList != null ? _aggroList : Collections.emptyMap(); + return _aggroList; } public final boolean isReturningToSpawnPoint() @@ -338,7 +337,7 @@ public class L2Attackable extends L2Npc { try { - if (getAggroList().isEmpty()) + if (_aggroList.isEmpty()) { return; } @@ -351,7 +350,7 @@ public class L2Attackable extends L2Npc long totalDamage = 0; // While Iterating over This Map Removing Object is Not Allowed // Go through the _aggroList of the L2Attackable - for (AggroInfo info : getAggroList().values()) + for (AggroInfo info : _aggroList.values()) { // Get the L2Character corresponding to this attacker 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 - if (_aggroList == null) - { - synchronized (this) - { - if (_aggroList == null) - { - _aggroList = new ConcurrentHashMap<>(); - } - } - } final AggroInfo ai = _aggroList.computeIfAbsent(attacker, AggroInfo::new); ai.addDamage(damage); @@ -769,7 +758,7 @@ public class L2Attackable extends L2Npc return; } - for (AggroInfo ai : getAggroList().values()) + for (AggroInfo ai : _aggroList.values()) { ai.addHate(amount); } @@ -788,7 +777,7 @@ public class L2Attackable extends L2Npc return; } - final AggroInfo ai = getAggroList().get(target); + final AggroInfo ai = _aggroList.get(target); if (ai == null) { LOGGER.info("target " + target + " not present in aggro list of " + this); @@ -819,7 +808,7 @@ public class L2Attackable extends L2Npc return; } - final AggroInfo ai = getAggroList().get(target); + final AggroInfo ai = _aggroList.get(target); if (ai != null) { ai.stopHate(); @@ -863,7 +852,7 @@ public class L2Attackable extends L2Npc */ public List get2MostHated() { - if (getAggroList().isEmpty() || isAlikeDead()) + if (_aggroList.isEmpty() || isAlikeDead()) { return null; } @@ -875,7 +864,7 @@ public class L2Attackable extends L2Npc // While iterating over this map removing objects is not allowed // Go through the aggroList of the L2Attackable - for (AggroInfo ai : getAggroList().values()) + for (AggroInfo ai : _aggroList.values()) { if (ai.checkHate(this) > maxHate) { @@ -901,13 +890,13 @@ public class L2Attackable extends L2Npc public List getHateList() { - if (getAggroList().isEmpty() || isAlikeDead()) + if (_aggroList.isEmpty() || isAlikeDead()) { return null; } final List result = new ArrayList<>(); - for (AggroInfo ai : getAggroList().values()) + for (AggroInfo ai : _aggroList.values()) { ai.checkHate(this); @@ -922,12 +911,12 @@ public class L2Attackable extends L2Npc */ public int getHating(L2Character target) { - if (getAggroList().isEmpty() || (target == null)) + if (_aggroList.isEmpty() || (target == null)) { return 0; } - final AggroInfo ai = getAggroList().get(target); + final AggroInfo ai = _aggroList.get(target); if (ai == null) { return 0; @@ -939,14 +928,14 @@ public class L2Attackable extends L2Npc if (act.isInvisible() || act.isInvul() || act.isSpawnProtected()) { // Remove Object Should Use This Method and Can be Blocked While Interacting - getAggroList().remove(target); + _aggroList.remove(target); return 0; } } if (!ai.getAttacker().isSpawned() || ai.getAttacker().isInvisible()) { - getAggroList().remove(target); + _aggroList.remove(target); return 0; } @@ -1163,7 +1152,7 @@ public class L2Attackable extends L2Npc */ 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() { - _aggroList = null; + _aggroList.clear(); // clear overhit values _overhit = false; diff --git a/L2J_Mobius_3.0_Helios/java/com/l2jmobius/gameserver/model/actor/L2Attackable.java b/L2J_Mobius_3.0_Helios/java/com/l2jmobius/gameserver/model/actor/L2Attackable.java index da32d824d8..3b8c2f3632 100644 --- a/L2J_Mobius_3.0_Helios/java/com/l2jmobius/gameserver/model/actor/L2Attackable.java +++ b/L2J_Mobius_3.0_Helios/java/com/l2jmobius/gameserver/model/actor/L2Attackable.java @@ -19,7 +19,6 @@ package com.l2jmobius.gameserver.model.actor; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -88,7 +87,7 @@ public class L2Attackable extends L2Npc private boolean _isRaidMinion = false; // private boolean _champion = false; - private volatile Map _aggroList = null; + private volatile Map _aggroList = new ConcurrentHashMap<>(); private boolean _isReturningToSpawnPoint = false; private boolean _canReturnToSpawnPoint = true; private boolean _seeThroughSilentMove = false; @@ -147,7 +146,7 @@ public class L2Attackable extends L2Npc public final Map getAggroList() { - return _aggroList != null ? _aggroList : Collections.emptyMap(); + return _aggroList; } public final boolean isReturningToSpawnPoint() @@ -338,7 +337,7 @@ public class L2Attackable extends L2Npc { try { - if (getAggroList().isEmpty()) + if (_aggroList.isEmpty()) { return; } @@ -351,7 +350,7 @@ public class L2Attackable extends L2Npc long totalDamage = 0; // While Iterating over This Map Removing Object is Not Allowed // Go through the _aggroList of the L2Attackable - for (AggroInfo info : getAggroList().values()) + for (AggroInfo info : _aggroList.values()) { // Get the L2Character corresponding to this attacker 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 - if (_aggroList == null) - { - synchronized (this) - { - if (_aggroList == null) - { - _aggroList = new ConcurrentHashMap<>(); - } - } - } final AggroInfo ai = _aggroList.computeIfAbsent(attacker, AggroInfo::new); ai.addDamage(damage); @@ -769,7 +758,7 @@ public class L2Attackable extends L2Npc return; } - for (AggroInfo ai : getAggroList().values()) + for (AggroInfo ai : _aggroList.values()) { ai.addHate(amount); } @@ -788,7 +777,7 @@ public class L2Attackable extends L2Npc return; } - final AggroInfo ai = getAggroList().get(target); + final AggroInfo ai = _aggroList.get(target); if (ai == null) { LOGGER.info("target " + target + " not present in aggro list of " + this); @@ -819,7 +808,7 @@ public class L2Attackable extends L2Npc return; } - final AggroInfo ai = getAggroList().get(target); + final AggroInfo ai = _aggroList.get(target); if (ai != null) { ai.stopHate(); @@ -863,7 +852,7 @@ public class L2Attackable extends L2Npc */ public List get2MostHated() { - if (getAggroList().isEmpty() || isAlikeDead()) + if (_aggroList.isEmpty() || isAlikeDead()) { return null; } @@ -875,7 +864,7 @@ public class L2Attackable extends L2Npc // While iterating over this map removing objects is not allowed // Go through the aggroList of the L2Attackable - for (AggroInfo ai : getAggroList().values()) + for (AggroInfo ai : _aggroList.values()) { if (ai.checkHate(this) > maxHate) { @@ -901,13 +890,13 @@ public class L2Attackable extends L2Npc public List getHateList() { - if (getAggroList().isEmpty() || isAlikeDead()) + if (_aggroList.isEmpty() || isAlikeDead()) { return null; } final List result = new ArrayList<>(); - for (AggroInfo ai : getAggroList().values()) + for (AggroInfo ai : _aggroList.values()) { ai.checkHate(this); @@ -922,12 +911,12 @@ public class L2Attackable extends L2Npc */ public int getHating(L2Character target) { - if (getAggroList().isEmpty() || (target == null)) + if (_aggroList.isEmpty() || (target == null)) { return 0; } - final AggroInfo ai = getAggroList().get(target); + final AggroInfo ai = _aggroList.get(target); if (ai == null) { return 0; @@ -939,14 +928,14 @@ public class L2Attackable extends L2Npc if (act.isInvisible() || act.isInvul() || act.isSpawnProtected()) { // Remove Object Should Use This Method and Can be Blocked While Interacting - getAggroList().remove(target); + _aggroList.remove(target); return 0; } } if (!ai.getAttacker().isSpawned() || ai.getAttacker().isInvisible()) { - getAggroList().remove(target); + _aggroList.remove(target); return 0; } @@ -1163,7 +1152,7 @@ public class L2Attackable extends L2Npc */ 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() { - _aggroList = null; + _aggroList.clear(); // clear overhit values _overhit = false; diff --git a/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/gameserver/model/actor/L2Attackable.java b/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/gameserver/model/actor/L2Attackable.java index da32d824d8..3b8c2f3632 100644 --- a/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/gameserver/model/actor/L2Attackable.java +++ b/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/gameserver/model/actor/L2Attackable.java @@ -19,7 +19,6 @@ package com.l2jmobius.gameserver.model.actor; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -88,7 +87,7 @@ public class L2Attackable extends L2Npc private boolean _isRaidMinion = false; // private boolean _champion = false; - private volatile Map _aggroList = null; + private volatile Map _aggroList = new ConcurrentHashMap<>(); private boolean _isReturningToSpawnPoint = false; private boolean _canReturnToSpawnPoint = true; private boolean _seeThroughSilentMove = false; @@ -147,7 +146,7 @@ public class L2Attackable extends L2Npc public final Map getAggroList() { - return _aggroList != null ? _aggroList : Collections.emptyMap(); + return _aggroList; } public final boolean isReturningToSpawnPoint() @@ -338,7 +337,7 @@ public class L2Attackable extends L2Npc { try { - if (getAggroList().isEmpty()) + if (_aggroList.isEmpty()) { return; } @@ -351,7 +350,7 @@ public class L2Attackable extends L2Npc long totalDamage = 0; // While Iterating over This Map Removing Object is Not Allowed // Go through the _aggroList of the L2Attackable - for (AggroInfo info : getAggroList().values()) + for (AggroInfo info : _aggroList.values()) { // Get the L2Character corresponding to this attacker 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 - if (_aggroList == null) - { - synchronized (this) - { - if (_aggroList == null) - { - _aggroList = new ConcurrentHashMap<>(); - } - } - } final AggroInfo ai = _aggroList.computeIfAbsent(attacker, AggroInfo::new); ai.addDamage(damage); @@ -769,7 +758,7 @@ public class L2Attackable extends L2Npc return; } - for (AggroInfo ai : getAggroList().values()) + for (AggroInfo ai : _aggroList.values()) { ai.addHate(amount); } @@ -788,7 +777,7 @@ public class L2Attackable extends L2Npc return; } - final AggroInfo ai = getAggroList().get(target); + final AggroInfo ai = _aggroList.get(target); if (ai == null) { LOGGER.info("target " + target + " not present in aggro list of " + this); @@ -819,7 +808,7 @@ public class L2Attackable extends L2Npc return; } - final AggroInfo ai = getAggroList().get(target); + final AggroInfo ai = _aggroList.get(target); if (ai != null) { ai.stopHate(); @@ -863,7 +852,7 @@ public class L2Attackable extends L2Npc */ public List get2MostHated() { - if (getAggroList().isEmpty() || isAlikeDead()) + if (_aggroList.isEmpty() || isAlikeDead()) { return null; } @@ -875,7 +864,7 @@ public class L2Attackable extends L2Npc // While iterating over this map removing objects is not allowed // Go through the aggroList of the L2Attackable - for (AggroInfo ai : getAggroList().values()) + for (AggroInfo ai : _aggroList.values()) { if (ai.checkHate(this) > maxHate) { @@ -901,13 +890,13 @@ public class L2Attackable extends L2Npc public List getHateList() { - if (getAggroList().isEmpty() || isAlikeDead()) + if (_aggroList.isEmpty() || isAlikeDead()) { return null; } final List result = new ArrayList<>(); - for (AggroInfo ai : getAggroList().values()) + for (AggroInfo ai : _aggroList.values()) { ai.checkHate(this); @@ -922,12 +911,12 @@ public class L2Attackable extends L2Npc */ public int getHating(L2Character target) { - if (getAggroList().isEmpty() || (target == null)) + if (_aggroList.isEmpty() || (target == null)) { return 0; } - final AggroInfo ai = getAggroList().get(target); + final AggroInfo ai = _aggroList.get(target); if (ai == null) { return 0; @@ -939,14 +928,14 @@ public class L2Attackable extends L2Npc if (act.isInvisible() || act.isInvul() || act.isSpawnProtected()) { // Remove Object Should Use This Method and Can be Blocked While Interacting - getAggroList().remove(target); + _aggroList.remove(target); return 0; } } if (!ai.getAttacker().isSpawned() || ai.getAttacker().isInvisible()) { - getAggroList().remove(target); + _aggroList.remove(target); return 0; } @@ -1163,7 +1152,7 @@ public class L2Attackable extends L2Npc */ 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() { - _aggroList = null; + _aggroList.clear(); // clear overhit values _overhit = false; diff --git a/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/gameserver/model/actor/L2Attackable.java b/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/gameserver/model/actor/L2Attackable.java index c91ac6d15b..2274ddffe3 100644 --- a/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/gameserver/model/actor/L2Attackable.java +++ b/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/gameserver/model/actor/L2Attackable.java @@ -19,7 +19,6 @@ package com.l2jmobius.gameserver.model.actor; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -88,7 +87,7 @@ public class L2Attackable extends L2Npc private boolean _isRaidMinion = false; // private boolean _champion = false; - private volatile Map _aggroList = null; + private volatile Map _aggroList = new ConcurrentHashMap<>(); private boolean _isReturningToSpawnPoint = false; private boolean _canReturnToSpawnPoint = true; private boolean _seeThroughSilentMove = false; @@ -147,7 +146,7 @@ public class L2Attackable extends L2Npc public final Map getAggroList() { - return _aggroList != null ? _aggroList : Collections.emptyMap(); + return _aggroList; } public final boolean isReturningToSpawnPoint() @@ -338,7 +337,7 @@ public class L2Attackable extends L2Npc { try { - if (getAggroList().isEmpty()) + if (_aggroList.isEmpty()) { return; } @@ -351,7 +350,7 @@ public class L2Attackable extends L2Npc long totalDamage = 0; // While Iterating over This Map Removing Object is Not Allowed // Go through the _aggroList of the L2Attackable - for (AggroInfo info : getAggroList().values()) + for (AggroInfo info : _aggroList.values()) { // Get the L2Character corresponding to this attacker 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 - if (_aggroList == null) - { - synchronized (this) - { - if (_aggroList == null) - { - _aggroList = new ConcurrentHashMap<>(); - } - } - } final AggroInfo ai = _aggroList.computeIfAbsent(attacker, AggroInfo::new); ai.addDamage(damage); @@ -769,7 +758,7 @@ public class L2Attackable extends L2Npc return; } - for (AggroInfo ai : getAggroList().values()) + for (AggroInfo ai : _aggroList.values()) { ai.addHate(amount); } @@ -788,7 +777,7 @@ public class L2Attackable extends L2Npc return; } - final AggroInfo ai = getAggroList().get(target); + final AggroInfo ai = _aggroList.get(target); if (ai == null) { LOGGER.info("target " + target + " not present in aggro list of " + this); @@ -819,7 +808,7 @@ public class L2Attackable extends L2Npc return; } - final AggroInfo ai = getAggroList().get(target); + final AggroInfo ai = _aggroList.get(target); if (ai != null) { ai.stopHate(); @@ -863,7 +852,7 @@ public class L2Attackable extends L2Npc */ public List get2MostHated() { - if (getAggroList().isEmpty() || isAlikeDead()) + if (_aggroList.isEmpty() || isAlikeDead()) { return null; } @@ -875,7 +864,7 @@ public class L2Attackable extends L2Npc // While iterating over this map removing objects is not allowed // Go through the aggroList of the L2Attackable - for (AggroInfo ai : getAggroList().values()) + for (AggroInfo ai : _aggroList.values()) { if (ai.checkHate(this) > maxHate) { @@ -901,13 +890,13 @@ public class L2Attackable extends L2Npc public List getHateList() { - if (getAggroList().isEmpty() || isAlikeDead()) + if (_aggroList.isEmpty() || isAlikeDead()) { return null; } final List result = new ArrayList<>(); - for (AggroInfo ai : getAggroList().values()) + for (AggroInfo ai : _aggroList.values()) { ai.checkHate(this); @@ -922,12 +911,12 @@ public class L2Attackable extends L2Npc */ public int getHating(L2Character target) { - if (getAggroList().isEmpty() || (target == null)) + if (_aggroList.isEmpty() || (target == null)) { return 0; } - final AggroInfo ai = getAggroList().get(target); + final AggroInfo ai = _aggroList.get(target); if (ai == null) { return 0; @@ -939,14 +928,14 @@ public class L2Attackable extends L2Npc if (act.isInvisible() || act.isInvul() || act.isSpawnProtected()) { // Remove Object Should Use This Method and Can be Blocked While Interacting - getAggroList().remove(target); + _aggroList.remove(target); return 0; } } if (!ai.getAttacker().isSpawned() || ai.getAttacker().isInvisible()) { - getAggroList().remove(target); + _aggroList.remove(target); return 0; } @@ -1163,7 +1152,7 @@ public class L2Attackable extends L2Npc */ 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() { - _aggroList = null; + _aggroList.clear(); // clear overhit values _overhit = false; diff --git a/L2J_Mobius_Classic_2.1_Zaken/java/com/l2jmobius/gameserver/model/actor/L2Attackable.java b/L2J_Mobius_Classic_2.1_Zaken/java/com/l2jmobius/gameserver/model/actor/L2Attackable.java index c91ac6d15b..2274ddffe3 100644 --- a/L2J_Mobius_Classic_2.1_Zaken/java/com/l2jmobius/gameserver/model/actor/L2Attackable.java +++ b/L2J_Mobius_Classic_2.1_Zaken/java/com/l2jmobius/gameserver/model/actor/L2Attackable.java @@ -19,7 +19,6 @@ package com.l2jmobius.gameserver.model.actor; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -88,7 +87,7 @@ public class L2Attackable extends L2Npc private boolean _isRaidMinion = false; // private boolean _champion = false; - private volatile Map _aggroList = null; + private volatile Map _aggroList = new ConcurrentHashMap<>(); private boolean _isReturningToSpawnPoint = false; private boolean _canReturnToSpawnPoint = true; private boolean _seeThroughSilentMove = false; @@ -147,7 +146,7 @@ public class L2Attackable extends L2Npc public final Map getAggroList() { - return _aggroList != null ? _aggroList : Collections.emptyMap(); + return _aggroList; } public final boolean isReturningToSpawnPoint() @@ -338,7 +337,7 @@ public class L2Attackable extends L2Npc { try { - if (getAggroList().isEmpty()) + if (_aggroList.isEmpty()) { return; } @@ -351,7 +350,7 @@ public class L2Attackable extends L2Npc long totalDamage = 0; // While Iterating over This Map Removing Object is Not Allowed // Go through the _aggroList of the L2Attackable - for (AggroInfo info : getAggroList().values()) + for (AggroInfo info : _aggroList.values()) { // Get the L2Character corresponding to this attacker 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 - if (_aggroList == null) - { - synchronized (this) - { - if (_aggroList == null) - { - _aggroList = new ConcurrentHashMap<>(); - } - } - } final AggroInfo ai = _aggroList.computeIfAbsent(attacker, AggroInfo::new); ai.addDamage(damage); @@ -769,7 +758,7 @@ public class L2Attackable extends L2Npc return; } - for (AggroInfo ai : getAggroList().values()) + for (AggroInfo ai : _aggroList.values()) { ai.addHate(amount); } @@ -788,7 +777,7 @@ public class L2Attackable extends L2Npc return; } - final AggroInfo ai = getAggroList().get(target); + final AggroInfo ai = _aggroList.get(target); if (ai == null) { LOGGER.info("target " + target + " not present in aggro list of " + this); @@ -819,7 +808,7 @@ public class L2Attackable extends L2Npc return; } - final AggroInfo ai = getAggroList().get(target); + final AggroInfo ai = _aggroList.get(target); if (ai != null) { ai.stopHate(); @@ -863,7 +852,7 @@ public class L2Attackable extends L2Npc */ public List get2MostHated() { - if (getAggroList().isEmpty() || isAlikeDead()) + if (_aggroList.isEmpty() || isAlikeDead()) { return null; } @@ -875,7 +864,7 @@ public class L2Attackable extends L2Npc // While iterating over this map removing objects is not allowed // Go through the aggroList of the L2Attackable - for (AggroInfo ai : getAggroList().values()) + for (AggroInfo ai : _aggroList.values()) { if (ai.checkHate(this) > maxHate) { @@ -901,13 +890,13 @@ public class L2Attackable extends L2Npc public List getHateList() { - if (getAggroList().isEmpty() || isAlikeDead()) + if (_aggroList.isEmpty() || isAlikeDead()) { return null; } final List result = new ArrayList<>(); - for (AggroInfo ai : getAggroList().values()) + for (AggroInfo ai : _aggroList.values()) { ai.checkHate(this); @@ -922,12 +911,12 @@ public class L2Attackable extends L2Npc */ public int getHating(L2Character target) { - if (getAggroList().isEmpty() || (target == null)) + if (_aggroList.isEmpty() || (target == null)) { return 0; } - final AggroInfo ai = getAggroList().get(target); + final AggroInfo ai = _aggroList.get(target); if (ai == null) { return 0; @@ -939,14 +928,14 @@ public class L2Attackable extends L2Npc if (act.isInvisible() || act.isInvul() || act.isSpawnProtected()) { // Remove Object Should Use This Method and Can be Blocked While Interacting - getAggroList().remove(target); + _aggroList.remove(target); return 0; } } if (!ai.getAttacker().isSpawned() || ai.getAttacker().isInvisible()) { - getAggroList().remove(target); + _aggroList.remove(target); return 0; } @@ -1163,7 +1152,7 @@ public class L2Attackable extends L2Npc */ 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() { - _aggroList = null; + _aggroList.clear(); // clear overhit values _overhit = false; diff --git a/L2J_Mobius_Classic_2.2_Antharas/java/com/l2jmobius/gameserver/model/actor/L2Attackable.java b/L2J_Mobius_Classic_2.2_Antharas/java/com/l2jmobius/gameserver/model/actor/L2Attackable.java index c91ac6d15b..2274ddffe3 100644 --- a/L2J_Mobius_Classic_2.2_Antharas/java/com/l2jmobius/gameserver/model/actor/L2Attackable.java +++ b/L2J_Mobius_Classic_2.2_Antharas/java/com/l2jmobius/gameserver/model/actor/L2Attackable.java @@ -19,7 +19,6 @@ package com.l2jmobius.gameserver.model.actor; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -88,7 +87,7 @@ public class L2Attackable extends L2Npc private boolean _isRaidMinion = false; // private boolean _champion = false; - private volatile Map _aggroList = null; + private volatile Map _aggroList = new ConcurrentHashMap<>(); private boolean _isReturningToSpawnPoint = false; private boolean _canReturnToSpawnPoint = true; private boolean _seeThroughSilentMove = false; @@ -147,7 +146,7 @@ public class L2Attackable extends L2Npc public final Map getAggroList() { - return _aggroList != null ? _aggroList : Collections.emptyMap(); + return _aggroList; } public final boolean isReturningToSpawnPoint() @@ -338,7 +337,7 @@ public class L2Attackable extends L2Npc { try { - if (getAggroList().isEmpty()) + if (_aggroList.isEmpty()) { return; } @@ -351,7 +350,7 @@ public class L2Attackable extends L2Npc long totalDamage = 0; // While Iterating over This Map Removing Object is Not Allowed // Go through the _aggroList of the L2Attackable - for (AggroInfo info : getAggroList().values()) + for (AggroInfo info : _aggroList.values()) { // Get the L2Character corresponding to this attacker 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 - if (_aggroList == null) - { - synchronized (this) - { - if (_aggroList == null) - { - _aggroList = new ConcurrentHashMap<>(); - } - } - } final AggroInfo ai = _aggroList.computeIfAbsent(attacker, AggroInfo::new); ai.addDamage(damage); @@ -769,7 +758,7 @@ public class L2Attackable extends L2Npc return; } - for (AggroInfo ai : getAggroList().values()) + for (AggroInfo ai : _aggroList.values()) { ai.addHate(amount); } @@ -788,7 +777,7 @@ public class L2Attackable extends L2Npc return; } - final AggroInfo ai = getAggroList().get(target); + final AggroInfo ai = _aggroList.get(target); if (ai == null) { LOGGER.info("target " + target + " not present in aggro list of " + this); @@ -819,7 +808,7 @@ public class L2Attackable extends L2Npc return; } - final AggroInfo ai = getAggroList().get(target); + final AggroInfo ai = _aggroList.get(target); if (ai != null) { ai.stopHate(); @@ -863,7 +852,7 @@ public class L2Attackable extends L2Npc */ public List get2MostHated() { - if (getAggroList().isEmpty() || isAlikeDead()) + if (_aggroList.isEmpty() || isAlikeDead()) { return null; } @@ -875,7 +864,7 @@ public class L2Attackable extends L2Npc // While iterating over this map removing objects is not allowed // Go through the aggroList of the L2Attackable - for (AggroInfo ai : getAggroList().values()) + for (AggroInfo ai : _aggroList.values()) { if (ai.checkHate(this) > maxHate) { @@ -901,13 +890,13 @@ public class L2Attackable extends L2Npc public List getHateList() { - if (getAggroList().isEmpty() || isAlikeDead()) + if (_aggroList.isEmpty() || isAlikeDead()) { return null; } final List result = new ArrayList<>(); - for (AggroInfo ai : getAggroList().values()) + for (AggroInfo ai : _aggroList.values()) { ai.checkHate(this); @@ -922,12 +911,12 @@ public class L2Attackable extends L2Npc */ public int getHating(L2Character target) { - if (getAggroList().isEmpty() || (target == null)) + if (_aggroList.isEmpty() || (target == null)) { return 0; } - final AggroInfo ai = getAggroList().get(target); + final AggroInfo ai = _aggroList.get(target); if (ai == null) { return 0; @@ -939,14 +928,14 @@ public class L2Attackable extends L2Npc if (act.isInvisible() || act.isInvul() || act.isSpawnProtected()) { // Remove Object Should Use This Method and Can be Blocked While Interacting - getAggroList().remove(target); + _aggroList.remove(target); return 0; } } if (!ai.getAttacker().isSpawned() || ai.getAttacker().isInvisible()) { - getAggroList().remove(target); + _aggroList.remove(target); return 0; } @@ -1163,7 +1152,7 @@ public class L2Attackable extends L2Npc */ 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() { - _aggroList = null; + _aggroList.clear(); // clear overhit values _overhit = false;