CreatureStat improvements and Collections removal.

This commit is contained in:
MobiusDevelopment 2020-06-20 09:41:06 +00:00
parent b4bea3d52f
commit 6e9fae1f7b
15 changed files with 630 additions and 240 deletions

View File

@ -16,7 +16,6 @@
*/ */
package org.l2jmobius.gameserver.model.actor.stat; package org.l2jmobius.gameserver.model.actor.stat;
import java.util.Collections;
import java.util.Deque; import java.util.Deque;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.EnumSet; import java.util.EnumSet;
@ -804,7 +803,11 @@ public class CreatureStat
_lock.readLock().lock(); _lock.readLock().lock();
try try
{ {
return _statsAdd.getOrDefault(stat, defaultValue); if (_statsAdd.containsKey(stat))
{
return _statsAdd.get(stat);
}
return defaultValue;
} }
finally finally
{ {
@ -831,7 +834,11 @@ public class CreatureStat
_lock.readLock().lock(); _lock.readLock().lock();
try try
{ {
return _statsMul.getOrDefault(stat, defaultValue); if (_statsMul.containsKey(stat))
{
return _statsMul.get(stat);
}
return defaultValue;
} }
finally finally
{ {
@ -846,8 +853,7 @@ public class CreatureStat
*/ */
public double getValue(Stat stat, double baseValue) public double getValue(Stat stat, double baseValue)
{ {
final Double fixedValue = _fixedValue.get(stat); return _fixedValue.containsKey(stat) ? _fixedValue.get(stat) : stat.finalize(_creature, OptionalDouble.of(baseValue));
return fixedValue != null ? fixedValue : stat.finalize(_creature, OptionalDouble.of(baseValue));
} }
/** /**
@ -856,8 +862,7 @@ public class CreatureStat
*/ */
public double getValue(Stat stat) public double getValue(Stat stat)
{ {
final Double fixedValue = _fixedValue.get(stat); return _fixedValue.containsKey(stat) ? _fixedValue.get(stat) : stat.finalize(_creature, OptionalDouble.empty());
return fixedValue != null ? fixedValue : stat.finalize(_creature, OptionalDouble.empty());
} }
protected void resetStats() protected void resetStats()
@ -887,8 +892,19 @@ public class CreatureStat
public void recalculateStats(boolean broadcast) public void recalculateStats(boolean broadcast)
{ {
// Copy old data before wiping it out // Copy old data before wiping it out
final Map<Stat, Double> adds = !broadcast ? Collections.emptyMap() : new EnumMap<>(_statsAdd); final Map<Stat, Double> adds;
final Map<Stat, Double> muls = !broadcast ? Collections.emptyMap() : new EnumMap<>(_statsMul); final Map<Stat, Double> muls;
if (broadcast)
{
adds = new EnumMap<>(_statsAdd);
muls = new EnumMap<>(_statsMul);
}
else
{
adds = null;
muls = null;
}
_lock.writeLock().lock(); _lock.writeLock().lock();
try try
{ {
@ -980,17 +996,17 @@ public class CreatureStat
// Notify recalculation to child classes // Notify recalculation to child classes
onRecalculateStats(broadcast); onRecalculateStats(broadcast);
if (broadcast) if (broadcast && (adds != null) && (muls != null)) // adds and muls cannot be null when broadcast is true, but Eclipse throws warning bellow.
{ {
// Calculate the difference between old and new stats // Calculate the difference between old and new stats
final Set<Stat> changed = new HashSet<>(); final Set<Stat> changed = new HashSet<>();
for (Stat stat : Stat.values()) for (Stat stat : Stat.values())
{ {
if (_statsAdd.getOrDefault(stat, stat.getResetAddValue()) != adds.getOrDefault(stat, stat.getResetAddValue())) if ((_statsAdd.containsKey(stat) ? _statsAdd.get(stat) : stat.getResetAddValue()) != (adds.containsKey(stat) ? adds.get(stat) : stat.getResetAddValue()))
{ {
changed.add(stat); changed.add(stat);
} }
else if (_statsMul.getOrDefault(stat, stat.getResetMulValue()) != muls.getOrDefault(stat, stat.getResetMulValue())) else if ((_statsMul.containsKey(stat) ? _statsMul.get(stat) : stat.getResetMulValue()) != (muls.containsKey(stat) ? muls.get(stat) : stat.getResetMulValue()))
{ {
changed.add(stat); changed.add(stat);
} }
@ -1019,7 +1035,12 @@ public class CreatureStat
public double getPositionTypeValue(Stat stat, Position position) public double getPositionTypeValue(Stat stat, Position position)
{ {
return _positionStats.getOrDefault(stat, Collections.emptyMap()).getOrDefault(position, 1d); final Map<Position, Double> map = _positionStats.get(stat);
if ((map != null) && map.containsKey(position))
{
return map.get(position);
}
return 1d;
} }
public void mergePositionTypeValue(Stat stat, Position position, double value, BiFunction<? super Double, ? super Double, ? extends Double> func) public void mergePositionTypeValue(Stat stat, Position position, double value, BiFunction<? super Double, ? super Double, ? extends Double> func)
@ -1029,7 +1050,12 @@ public class CreatureStat
public double getMoveTypeValue(Stat stat, MoveType type) public double getMoveTypeValue(Stat stat, MoveType type)
{ {
return _moveTypeStats.getOrDefault(stat, Collections.emptyMap()).getOrDefault(type, 0d); final Map<MoveType, Double> map = _moveTypeStats.get(stat);
if ((map != null) && map.containsKey(type))
{
return map.get(type);
}
return 0d;
} }
public void mergeMoveTypeValue(Stat stat, MoveType type, double value) public void mergeMoveTypeValue(Stat stat, MoveType type, double value)
@ -1039,7 +1065,7 @@ public class CreatureStat
public double getReuseTypeValue(int magicType) public double getReuseTypeValue(int magicType)
{ {
return _reuseStat.getOrDefault(magicType, 1d); return _reuseStat.containsKey(magicType) ? _reuseStat.get(magicType) : 1d;
} }
public void mergeReuseTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func) public void mergeReuseTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func)
@ -1049,7 +1075,7 @@ public class CreatureStat
public double getMpConsumeTypeValue(int magicType) public double getMpConsumeTypeValue(int magicType)
{ {
return _mpConsumeStat.getOrDefault(magicType, 1d); return _mpConsumeStat.containsKey(magicType) ? _mpConsumeStat.get(magicType) : 1d;
} }
public void mergeMpConsumeTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func) public void mergeMpConsumeTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func)

View File

@ -16,7 +16,6 @@
*/ */
package org.l2jmobius.gameserver.model.actor.stat; package org.l2jmobius.gameserver.model.actor.stat;
import java.util.Collections;
import java.util.Deque; import java.util.Deque;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.EnumSet; import java.util.EnumSet;
@ -804,7 +803,11 @@ public class CreatureStat
_lock.readLock().lock(); _lock.readLock().lock();
try try
{ {
return _statsAdd.getOrDefault(stat, defaultValue); if (_statsAdd.containsKey(stat))
{
return _statsAdd.get(stat);
}
return defaultValue;
} }
finally finally
{ {
@ -831,7 +834,11 @@ public class CreatureStat
_lock.readLock().lock(); _lock.readLock().lock();
try try
{ {
return _statsMul.getOrDefault(stat, defaultValue); if (_statsMul.containsKey(stat))
{
return _statsMul.get(stat);
}
return defaultValue;
} }
finally finally
{ {
@ -846,8 +853,7 @@ public class CreatureStat
*/ */
public double getValue(Stat stat, double baseValue) public double getValue(Stat stat, double baseValue)
{ {
final Double fixedValue = _fixedValue.get(stat); return _fixedValue.containsKey(stat) ? _fixedValue.get(stat) : stat.finalize(_creature, OptionalDouble.of(baseValue));
return fixedValue != null ? fixedValue : stat.finalize(_creature, OptionalDouble.of(baseValue));
} }
/** /**
@ -856,8 +862,7 @@ public class CreatureStat
*/ */
public double getValue(Stat stat) public double getValue(Stat stat)
{ {
final Double fixedValue = _fixedValue.get(stat); return _fixedValue.containsKey(stat) ? _fixedValue.get(stat) : stat.finalize(_creature, OptionalDouble.empty());
return fixedValue != null ? fixedValue : stat.finalize(_creature, OptionalDouble.empty());
} }
protected void resetStats() protected void resetStats()
@ -887,8 +892,19 @@ public class CreatureStat
public void recalculateStats(boolean broadcast) public void recalculateStats(boolean broadcast)
{ {
// Copy old data before wiping it out // Copy old data before wiping it out
final Map<Stat, Double> adds = !broadcast ? Collections.emptyMap() : new EnumMap<>(_statsAdd); final Map<Stat, Double> adds;
final Map<Stat, Double> muls = !broadcast ? Collections.emptyMap() : new EnumMap<>(_statsMul); final Map<Stat, Double> muls;
if (broadcast)
{
adds = new EnumMap<>(_statsAdd);
muls = new EnumMap<>(_statsMul);
}
else
{
adds = null;
muls = null;
}
_lock.writeLock().lock(); _lock.writeLock().lock();
try try
{ {
@ -980,17 +996,17 @@ public class CreatureStat
// Notify recalculation to child classes // Notify recalculation to child classes
onRecalculateStats(broadcast); onRecalculateStats(broadcast);
if (broadcast) if (broadcast && (adds != null) && (muls != null)) // adds and muls cannot be null when broadcast is true, but Eclipse throws warning bellow.
{ {
// Calculate the difference between old and new stats // Calculate the difference between old and new stats
final Set<Stat> changed = new HashSet<>(); final Set<Stat> changed = new HashSet<>();
for (Stat stat : Stat.values()) for (Stat stat : Stat.values())
{ {
if (_statsAdd.getOrDefault(stat, stat.getResetAddValue()) != adds.getOrDefault(stat, stat.getResetAddValue())) if ((_statsAdd.containsKey(stat) ? _statsAdd.get(stat) : stat.getResetAddValue()) != (adds.containsKey(stat) ? adds.get(stat) : stat.getResetAddValue()))
{ {
changed.add(stat); changed.add(stat);
} }
else if (_statsMul.getOrDefault(stat, stat.getResetMulValue()) != muls.getOrDefault(stat, stat.getResetMulValue())) else if ((_statsMul.containsKey(stat) ? _statsMul.get(stat) : stat.getResetMulValue()) != (muls.containsKey(stat) ? muls.get(stat) : stat.getResetMulValue()))
{ {
changed.add(stat); changed.add(stat);
} }
@ -1019,7 +1035,12 @@ public class CreatureStat
public double getPositionTypeValue(Stat stat, Position position) public double getPositionTypeValue(Stat stat, Position position)
{ {
return _positionStats.getOrDefault(stat, Collections.emptyMap()).getOrDefault(position, 1d); final Map<Position, Double> map = _positionStats.get(stat);
if ((map != null) && map.containsKey(position))
{
return map.get(position);
}
return 1d;
} }
public void mergePositionTypeValue(Stat stat, Position position, double value, BiFunction<? super Double, ? super Double, ? extends Double> func) public void mergePositionTypeValue(Stat stat, Position position, double value, BiFunction<? super Double, ? super Double, ? extends Double> func)
@ -1029,7 +1050,12 @@ public class CreatureStat
public double getMoveTypeValue(Stat stat, MoveType type) public double getMoveTypeValue(Stat stat, MoveType type)
{ {
return _moveTypeStats.getOrDefault(stat, Collections.emptyMap()).getOrDefault(type, 0d); final Map<MoveType, Double> map = _moveTypeStats.get(stat);
if ((map != null) && map.containsKey(type))
{
return map.get(type);
}
return 0d;
} }
public void mergeMoveTypeValue(Stat stat, MoveType type, double value) public void mergeMoveTypeValue(Stat stat, MoveType type, double value)
@ -1039,7 +1065,7 @@ public class CreatureStat
public double getReuseTypeValue(int magicType) public double getReuseTypeValue(int magicType)
{ {
return _reuseStat.getOrDefault(magicType, 1d); return _reuseStat.containsKey(magicType) ? _reuseStat.get(magicType) : 1d;
} }
public void mergeReuseTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func) public void mergeReuseTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func)
@ -1049,7 +1075,7 @@ public class CreatureStat
public double getMpConsumeTypeValue(int magicType) public double getMpConsumeTypeValue(int magicType)
{ {
return _mpConsumeStat.getOrDefault(magicType, 1d); return _mpConsumeStat.containsKey(magicType) ? _mpConsumeStat.get(magicType) : 1d;
} }
public void mergeMpConsumeTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func) public void mergeMpConsumeTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func)

View File

@ -16,7 +16,6 @@
*/ */
package org.l2jmobius.gameserver.model.actor.stat; package org.l2jmobius.gameserver.model.actor.stat;
import java.util.Collections;
import java.util.Deque; import java.util.Deque;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.EnumSet; import java.util.EnumSet;
@ -804,7 +803,11 @@ public class CreatureStat
_lock.readLock().lock(); _lock.readLock().lock();
try try
{ {
return _statsAdd.getOrDefault(stat, defaultValue); if (_statsAdd.containsKey(stat))
{
return _statsAdd.get(stat);
}
return defaultValue;
} }
finally finally
{ {
@ -831,7 +834,11 @@ public class CreatureStat
_lock.readLock().lock(); _lock.readLock().lock();
try try
{ {
return _statsMul.getOrDefault(stat, defaultValue); if (_statsMul.containsKey(stat))
{
return _statsMul.get(stat);
}
return defaultValue;
} }
finally finally
{ {
@ -846,8 +853,7 @@ public class CreatureStat
*/ */
public double getValue(Stat stat, double baseValue) public double getValue(Stat stat, double baseValue)
{ {
final Double fixedValue = _fixedValue.get(stat); return _fixedValue.containsKey(stat) ? _fixedValue.get(stat) : stat.finalize(_creature, OptionalDouble.of(baseValue));
return fixedValue != null ? fixedValue : stat.finalize(_creature, OptionalDouble.of(baseValue));
} }
/** /**
@ -856,8 +862,7 @@ public class CreatureStat
*/ */
public double getValue(Stat stat) public double getValue(Stat stat)
{ {
final Double fixedValue = _fixedValue.get(stat); return _fixedValue.containsKey(stat) ? _fixedValue.get(stat) : stat.finalize(_creature, OptionalDouble.empty());
return fixedValue != null ? fixedValue : stat.finalize(_creature, OptionalDouble.empty());
} }
protected void resetStats() protected void resetStats()
@ -887,8 +892,19 @@ public class CreatureStat
public void recalculateStats(boolean broadcast) public void recalculateStats(boolean broadcast)
{ {
// Copy old data before wiping it out // Copy old data before wiping it out
final Map<Stat, Double> adds = !broadcast ? Collections.emptyMap() : new EnumMap<>(_statsAdd); final Map<Stat, Double> adds;
final Map<Stat, Double> muls = !broadcast ? Collections.emptyMap() : new EnumMap<>(_statsMul); final Map<Stat, Double> muls;
if (broadcast)
{
adds = new EnumMap<>(_statsAdd);
muls = new EnumMap<>(_statsMul);
}
else
{
adds = null;
muls = null;
}
_lock.writeLock().lock(); _lock.writeLock().lock();
try try
{ {
@ -980,17 +996,17 @@ public class CreatureStat
// Notify recalculation to child classes // Notify recalculation to child classes
onRecalculateStats(broadcast); onRecalculateStats(broadcast);
if (broadcast) if (broadcast && (adds != null) && (muls != null)) // adds and muls cannot be null when broadcast is true, but Eclipse throws warning bellow.
{ {
// Calculate the difference between old and new stats // Calculate the difference between old and new stats
final Set<Stat> changed = new HashSet<>(); final Set<Stat> changed = new HashSet<>();
for (Stat stat : Stat.values()) for (Stat stat : Stat.values())
{ {
if (_statsAdd.getOrDefault(stat, stat.getResetAddValue()) != adds.getOrDefault(stat, stat.getResetAddValue())) if ((_statsAdd.containsKey(stat) ? _statsAdd.get(stat) : stat.getResetAddValue()) != (adds.containsKey(stat) ? adds.get(stat) : stat.getResetAddValue()))
{ {
changed.add(stat); changed.add(stat);
} }
else if (_statsMul.getOrDefault(stat, stat.getResetMulValue()) != muls.getOrDefault(stat, stat.getResetMulValue())) else if ((_statsMul.containsKey(stat) ? _statsMul.get(stat) : stat.getResetMulValue()) != (muls.containsKey(stat) ? muls.get(stat) : stat.getResetMulValue()))
{ {
changed.add(stat); changed.add(stat);
} }
@ -1019,7 +1035,12 @@ public class CreatureStat
public double getPositionTypeValue(Stat stat, Position position) public double getPositionTypeValue(Stat stat, Position position)
{ {
return _positionStats.getOrDefault(stat, Collections.emptyMap()).getOrDefault(position, 1d); final Map<Position, Double> map = _positionStats.get(stat);
if ((map != null) && map.containsKey(position))
{
return map.get(position);
}
return 1d;
} }
public void mergePositionTypeValue(Stat stat, Position position, double value, BiFunction<? super Double, ? super Double, ? extends Double> func) public void mergePositionTypeValue(Stat stat, Position position, double value, BiFunction<? super Double, ? super Double, ? extends Double> func)
@ -1029,7 +1050,12 @@ public class CreatureStat
public double getMoveTypeValue(Stat stat, MoveType type) public double getMoveTypeValue(Stat stat, MoveType type)
{ {
return _moveTypeStats.getOrDefault(stat, Collections.emptyMap()).getOrDefault(type, 0d); final Map<MoveType, Double> map = _moveTypeStats.get(stat);
if ((map != null) && map.containsKey(type))
{
return map.get(type);
}
return 0d;
} }
public void mergeMoveTypeValue(Stat stat, MoveType type, double value) public void mergeMoveTypeValue(Stat stat, MoveType type, double value)
@ -1039,7 +1065,7 @@ public class CreatureStat
public double getReuseTypeValue(int magicType) public double getReuseTypeValue(int magicType)
{ {
return _reuseStat.getOrDefault(magicType, 1d); return _reuseStat.containsKey(magicType) ? _reuseStat.get(magicType) : 1d;
} }
public void mergeReuseTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func) public void mergeReuseTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func)
@ -1049,7 +1075,7 @@ public class CreatureStat
public double getMpConsumeTypeValue(int magicType) public double getMpConsumeTypeValue(int magicType)
{ {
return _mpConsumeStat.getOrDefault(magicType, 1d); return _mpConsumeStat.containsKey(magicType) ? _mpConsumeStat.get(magicType) : 1d;
} }
public void mergeMpConsumeTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func) public void mergeMpConsumeTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func)

View File

@ -16,7 +16,6 @@
*/ */
package org.l2jmobius.gameserver.model.actor.stat; package org.l2jmobius.gameserver.model.actor.stat;
import java.util.Collections;
import java.util.Deque; import java.util.Deque;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.EnumSet; import java.util.EnumSet;
@ -804,7 +803,11 @@ public class CreatureStat
_lock.readLock().lock(); _lock.readLock().lock();
try try
{ {
return _statsAdd.getOrDefault(stat, defaultValue); if (_statsAdd.containsKey(stat))
{
return _statsAdd.get(stat);
}
return defaultValue;
} }
finally finally
{ {
@ -831,7 +834,11 @@ public class CreatureStat
_lock.readLock().lock(); _lock.readLock().lock();
try try
{ {
return _statsMul.getOrDefault(stat, defaultValue); if (_statsMul.containsKey(stat))
{
return _statsMul.get(stat);
}
return defaultValue;
} }
finally finally
{ {
@ -846,8 +853,7 @@ public class CreatureStat
*/ */
public double getValue(Stat stat, double baseValue) public double getValue(Stat stat, double baseValue)
{ {
final Double fixedValue = _fixedValue.get(stat); return _fixedValue.containsKey(stat) ? _fixedValue.get(stat) : stat.finalize(_creature, OptionalDouble.of(baseValue));
return fixedValue != null ? fixedValue : stat.finalize(_creature, OptionalDouble.of(baseValue));
} }
/** /**
@ -856,8 +862,7 @@ public class CreatureStat
*/ */
public double getValue(Stat stat) public double getValue(Stat stat)
{ {
final Double fixedValue = _fixedValue.get(stat); return _fixedValue.containsKey(stat) ? _fixedValue.get(stat) : stat.finalize(_creature, OptionalDouble.empty());
return fixedValue != null ? fixedValue : stat.finalize(_creature, OptionalDouble.empty());
} }
protected void resetStats() protected void resetStats()
@ -887,8 +892,19 @@ public class CreatureStat
public void recalculateStats(boolean broadcast) public void recalculateStats(boolean broadcast)
{ {
// Copy old data before wiping it out // Copy old data before wiping it out
final Map<Stat, Double> adds = !broadcast ? Collections.emptyMap() : new EnumMap<>(_statsAdd); final Map<Stat, Double> adds;
final Map<Stat, Double> muls = !broadcast ? Collections.emptyMap() : new EnumMap<>(_statsMul); final Map<Stat, Double> muls;
if (broadcast)
{
adds = new EnumMap<>(_statsAdd);
muls = new EnumMap<>(_statsMul);
}
else
{
adds = null;
muls = null;
}
_lock.writeLock().lock(); _lock.writeLock().lock();
try try
{ {
@ -980,17 +996,17 @@ public class CreatureStat
// Notify recalculation to child classes // Notify recalculation to child classes
onRecalculateStats(broadcast); onRecalculateStats(broadcast);
if (broadcast) if (broadcast && (adds != null) && (muls != null)) // adds and muls cannot be null when broadcast is true, but Eclipse throws warning bellow.
{ {
// Calculate the difference between old and new stats // Calculate the difference between old and new stats
final Set<Stat> changed = new HashSet<>(); final Set<Stat> changed = new HashSet<>();
for (Stat stat : Stat.values()) for (Stat stat : Stat.values())
{ {
if (_statsAdd.getOrDefault(stat, stat.getResetAddValue()) != adds.getOrDefault(stat, stat.getResetAddValue())) if ((_statsAdd.containsKey(stat) ? _statsAdd.get(stat) : stat.getResetAddValue()) != (adds.containsKey(stat) ? adds.get(stat) : stat.getResetAddValue()))
{ {
changed.add(stat); changed.add(stat);
} }
else if (_statsMul.getOrDefault(stat, stat.getResetMulValue()) != muls.getOrDefault(stat, stat.getResetMulValue())) else if ((_statsMul.containsKey(stat) ? _statsMul.get(stat) : stat.getResetMulValue()) != (muls.containsKey(stat) ? muls.get(stat) : stat.getResetMulValue()))
{ {
changed.add(stat); changed.add(stat);
} }
@ -1019,7 +1035,12 @@ public class CreatureStat
public double getPositionTypeValue(Stat stat, Position position) public double getPositionTypeValue(Stat stat, Position position)
{ {
return _positionStats.getOrDefault(stat, Collections.emptyMap()).getOrDefault(position, 1d); final Map<Position, Double> map = _positionStats.get(stat);
if ((map != null) && map.containsKey(position))
{
return map.get(position);
}
return 1d;
} }
public void mergePositionTypeValue(Stat stat, Position position, double value, BiFunction<? super Double, ? super Double, ? extends Double> func) public void mergePositionTypeValue(Stat stat, Position position, double value, BiFunction<? super Double, ? super Double, ? extends Double> func)
@ -1029,7 +1050,12 @@ public class CreatureStat
public double getMoveTypeValue(Stat stat, MoveType type) public double getMoveTypeValue(Stat stat, MoveType type)
{ {
return _moveTypeStats.getOrDefault(stat, Collections.emptyMap()).getOrDefault(type, 0d); final Map<MoveType, Double> map = _moveTypeStats.get(stat);
if ((map != null) && map.containsKey(type))
{
return map.get(type);
}
return 0d;
} }
public void mergeMoveTypeValue(Stat stat, MoveType type, double value) public void mergeMoveTypeValue(Stat stat, MoveType type, double value)
@ -1039,7 +1065,7 @@ public class CreatureStat
public double getReuseTypeValue(int magicType) public double getReuseTypeValue(int magicType)
{ {
return _reuseStat.getOrDefault(magicType, 1d); return _reuseStat.containsKey(magicType) ? _reuseStat.get(magicType) : 1d;
} }
public void mergeReuseTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func) public void mergeReuseTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func)
@ -1049,7 +1075,7 @@ public class CreatureStat
public double getMpConsumeTypeValue(int magicType) public double getMpConsumeTypeValue(int magicType)
{ {
return _mpConsumeStat.getOrDefault(magicType, 1d); return _mpConsumeStat.containsKey(magicType) ? _mpConsumeStat.get(magicType) : 1d;
} }
public void mergeMpConsumeTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func) public void mergeMpConsumeTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func)

View File

@ -16,7 +16,6 @@
*/ */
package org.l2jmobius.gameserver.model.actor.stat; package org.l2jmobius.gameserver.model.actor.stat;
import java.util.Collections;
import java.util.Deque; import java.util.Deque;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.EnumSet; import java.util.EnumSet;
@ -804,7 +803,11 @@ public class CreatureStat
_lock.readLock().lock(); _lock.readLock().lock();
try try
{ {
return _statsAdd.getOrDefault(stat, defaultValue); if (_statsAdd.containsKey(stat))
{
return _statsAdd.get(stat);
}
return defaultValue;
} }
finally finally
{ {
@ -831,7 +834,11 @@ public class CreatureStat
_lock.readLock().lock(); _lock.readLock().lock();
try try
{ {
return _statsMul.getOrDefault(stat, defaultValue); if (_statsMul.containsKey(stat))
{
return _statsMul.get(stat);
}
return defaultValue;
} }
finally finally
{ {
@ -846,8 +853,7 @@ public class CreatureStat
*/ */
public double getValue(Stat stat, double baseValue) public double getValue(Stat stat, double baseValue)
{ {
final Double fixedValue = _fixedValue.get(stat); return _fixedValue.containsKey(stat) ? _fixedValue.get(stat) : stat.finalize(_creature, OptionalDouble.of(baseValue));
return fixedValue != null ? fixedValue : stat.finalize(_creature, OptionalDouble.of(baseValue));
} }
/** /**
@ -856,8 +862,7 @@ public class CreatureStat
*/ */
public double getValue(Stat stat) public double getValue(Stat stat)
{ {
final Double fixedValue = _fixedValue.get(stat); return _fixedValue.containsKey(stat) ? _fixedValue.get(stat) : stat.finalize(_creature, OptionalDouble.empty());
return fixedValue != null ? fixedValue : stat.finalize(_creature, OptionalDouble.empty());
} }
protected void resetStats() protected void resetStats()
@ -887,8 +892,19 @@ public class CreatureStat
public void recalculateStats(boolean broadcast) public void recalculateStats(boolean broadcast)
{ {
// Copy old data before wiping it out // Copy old data before wiping it out
final Map<Stat, Double> adds = !broadcast ? Collections.emptyMap() : new EnumMap<>(_statsAdd); final Map<Stat, Double> adds;
final Map<Stat, Double> muls = !broadcast ? Collections.emptyMap() : new EnumMap<>(_statsMul); final Map<Stat, Double> muls;
if (broadcast)
{
adds = new EnumMap<>(_statsAdd);
muls = new EnumMap<>(_statsMul);
}
else
{
adds = null;
muls = null;
}
_lock.writeLock().lock(); _lock.writeLock().lock();
try try
{ {
@ -980,17 +996,17 @@ public class CreatureStat
// Notify recalculation to child classes // Notify recalculation to child classes
onRecalculateStats(broadcast); onRecalculateStats(broadcast);
if (broadcast) if (broadcast && (adds != null) && (muls != null)) // adds and muls cannot be null when broadcast is true, but Eclipse throws warning bellow.
{ {
// Calculate the difference between old and new stats // Calculate the difference between old and new stats
final Set<Stat> changed = new HashSet<>(); final Set<Stat> changed = new HashSet<>();
for (Stat stat : Stat.values()) for (Stat stat : Stat.values())
{ {
if (_statsAdd.getOrDefault(stat, stat.getResetAddValue()) != adds.getOrDefault(stat, stat.getResetAddValue())) if ((_statsAdd.containsKey(stat) ? _statsAdd.get(stat) : stat.getResetAddValue()) != (adds.containsKey(stat) ? adds.get(stat) : stat.getResetAddValue()))
{ {
changed.add(stat); changed.add(stat);
} }
else if (_statsMul.getOrDefault(stat, stat.getResetMulValue()) != muls.getOrDefault(stat, stat.getResetMulValue())) else if ((_statsMul.containsKey(stat) ? _statsMul.get(stat) : stat.getResetMulValue()) != (muls.containsKey(stat) ? muls.get(stat) : stat.getResetMulValue()))
{ {
changed.add(stat); changed.add(stat);
} }
@ -1019,7 +1035,12 @@ public class CreatureStat
public double getPositionTypeValue(Stat stat, Position position) public double getPositionTypeValue(Stat stat, Position position)
{ {
return _positionStats.getOrDefault(stat, Collections.emptyMap()).getOrDefault(position, 1d); final Map<Position, Double> map = _positionStats.get(stat);
if ((map != null) && map.containsKey(position))
{
return map.get(position);
}
return 1d;
} }
public void mergePositionTypeValue(Stat stat, Position position, double value, BiFunction<? super Double, ? super Double, ? extends Double> func) public void mergePositionTypeValue(Stat stat, Position position, double value, BiFunction<? super Double, ? super Double, ? extends Double> func)
@ -1029,7 +1050,12 @@ public class CreatureStat
public double getMoveTypeValue(Stat stat, MoveType type) public double getMoveTypeValue(Stat stat, MoveType type)
{ {
return _moveTypeStats.getOrDefault(stat, Collections.emptyMap()).getOrDefault(type, 0d); final Map<MoveType, Double> map = _moveTypeStats.get(stat);
if ((map != null) && map.containsKey(type))
{
return map.get(type);
}
return 0d;
} }
public void mergeMoveTypeValue(Stat stat, MoveType type, double value) public void mergeMoveTypeValue(Stat stat, MoveType type, double value)
@ -1039,7 +1065,7 @@ public class CreatureStat
public double getReuseTypeValue(int magicType) public double getReuseTypeValue(int magicType)
{ {
return _reuseStat.getOrDefault(magicType, 1d); return _reuseStat.containsKey(magicType) ? _reuseStat.get(magicType) : 1d;
} }
public void mergeReuseTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func) public void mergeReuseTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func)
@ -1049,7 +1075,7 @@ public class CreatureStat
public double getMpConsumeTypeValue(int magicType) public double getMpConsumeTypeValue(int magicType)
{ {
return _mpConsumeStat.getOrDefault(magicType, 1d); return _mpConsumeStat.containsKey(magicType) ? _mpConsumeStat.get(magicType) : 1d;
} }
public void mergeMpConsumeTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func) public void mergeMpConsumeTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func)

View File

@ -16,7 +16,6 @@
*/ */
package org.l2jmobius.gameserver.model.actor.stat; package org.l2jmobius.gameserver.model.actor.stat;
import java.util.Collections;
import java.util.Deque; import java.util.Deque;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.EnumSet; import java.util.EnumSet;
@ -804,7 +803,11 @@ public class CreatureStat
_lock.readLock().lock(); _lock.readLock().lock();
try try
{ {
return _statsAdd.getOrDefault(stat, defaultValue); if (_statsAdd.containsKey(stat))
{
return _statsAdd.get(stat);
}
return defaultValue;
} }
finally finally
{ {
@ -831,7 +834,11 @@ public class CreatureStat
_lock.readLock().lock(); _lock.readLock().lock();
try try
{ {
return _statsMul.getOrDefault(stat, defaultValue); if (_statsMul.containsKey(stat))
{
return _statsMul.get(stat);
}
return defaultValue;
} }
finally finally
{ {
@ -846,8 +853,7 @@ public class CreatureStat
*/ */
public double getValue(Stat stat, double baseValue) public double getValue(Stat stat, double baseValue)
{ {
final Double fixedValue = _fixedValue.get(stat); return _fixedValue.containsKey(stat) ? _fixedValue.get(stat) : stat.finalize(_creature, OptionalDouble.of(baseValue));
return fixedValue != null ? fixedValue : stat.finalize(_creature, OptionalDouble.of(baseValue));
} }
/** /**
@ -856,8 +862,7 @@ public class CreatureStat
*/ */
public double getValue(Stat stat) public double getValue(Stat stat)
{ {
final Double fixedValue = _fixedValue.get(stat); return _fixedValue.containsKey(stat) ? _fixedValue.get(stat) : stat.finalize(_creature, OptionalDouble.empty());
return fixedValue != null ? fixedValue : stat.finalize(_creature, OptionalDouble.empty());
} }
protected void resetStats() protected void resetStats()
@ -887,8 +892,19 @@ public class CreatureStat
public void recalculateStats(boolean broadcast) public void recalculateStats(boolean broadcast)
{ {
// Copy old data before wiping it out // Copy old data before wiping it out
final Map<Stat, Double> adds = !broadcast ? Collections.emptyMap() : new EnumMap<>(_statsAdd); final Map<Stat, Double> adds;
final Map<Stat, Double> muls = !broadcast ? Collections.emptyMap() : new EnumMap<>(_statsMul); final Map<Stat, Double> muls;
if (broadcast)
{
adds = new EnumMap<>(_statsAdd);
muls = new EnumMap<>(_statsMul);
}
else
{
adds = null;
muls = null;
}
_lock.writeLock().lock(); _lock.writeLock().lock();
try try
{ {
@ -980,17 +996,17 @@ public class CreatureStat
// Notify recalculation to child classes // Notify recalculation to child classes
onRecalculateStats(broadcast); onRecalculateStats(broadcast);
if (broadcast) if (broadcast && (adds != null) && (muls != null)) // adds and muls cannot be null when broadcast is true, but Eclipse throws warning bellow.
{ {
// Calculate the difference between old and new stats // Calculate the difference between old and new stats
final Set<Stat> changed = new HashSet<>(); final Set<Stat> changed = new HashSet<>();
for (Stat stat : Stat.values()) for (Stat stat : Stat.values())
{ {
if (_statsAdd.getOrDefault(stat, stat.getResetAddValue()) != adds.getOrDefault(stat, stat.getResetAddValue())) if ((_statsAdd.containsKey(stat) ? _statsAdd.get(stat) : stat.getResetAddValue()) != (adds.containsKey(stat) ? adds.get(stat) : stat.getResetAddValue()))
{ {
changed.add(stat); changed.add(stat);
} }
else if (_statsMul.getOrDefault(stat, stat.getResetMulValue()) != muls.getOrDefault(stat, stat.getResetMulValue())) else if ((_statsMul.containsKey(stat) ? _statsMul.get(stat) : stat.getResetMulValue()) != (muls.containsKey(stat) ? muls.get(stat) : stat.getResetMulValue()))
{ {
changed.add(stat); changed.add(stat);
} }
@ -1019,7 +1035,12 @@ public class CreatureStat
public double getPositionTypeValue(Stat stat, Position position) public double getPositionTypeValue(Stat stat, Position position)
{ {
return _positionStats.getOrDefault(stat, Collections.emptyMap()).getOrDefault(position, 1d); final Map<Position, Double> map = _positionStats.get(stat);
if ((map != null) && map.containsKey(position))
{
return map.get(position);
}
return 1d;
} }
public void mergePositionTypeValue(Stat stat, Position position, double value, BiFunction<? super Double, ? super Double, ? extends Double> func) public void mergePositionTypeValue(Stat stat, Position position, double value, BiFunction<? super Double, ? super Double, ? extends Double> func)
@ -1029,7 +1050,12 @@ public class CreatureStat
public double getMoveTypeValue(Stat stat, MoveType type) public double getMoveTypeValue(Stat stat, MoveType type)
{ {
return _moveTypeStats.getOrDefault(stat, Collections.emptyMap()).getOrDefault(type, 0d); final Map<MoveType, Double> map = _moveTypeStats.get(stat);
if ((map != null) && map.containsKey(type))
{
return map.get(type);
}
return 0d;
} }
public void mergeMoveTypeValue(Stat stat, MoveType type, double value) public void mergeMoveTypeValue(Stat stat, MoveType type, double value)
@ -1039,7 +1065,7 @@ public class CreatureStat
public double getReuseTypeValue(int magicType) public double getReuseTypeValue(int magicType)
{ {
return _reuseStat.getOrDefault(magicType, 1d); return _reuseStat.containsKey(magicType) ? _reuseStat.get(magicType) : 1d;
} }
public void mergeReuseTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func) public void mergeReuseTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func)
@ -1049,7 +1075,7 @@ public class CreatureStat
public double getMpConsumeTypeValue(int magicType) public double getMpConsumeTypeValue(int magicType)
{ {
return _mpConsumeStat.getOrDefault(magicType, 1d); return _mpConsumeStat.containsKey(magicType) ? _mpConsumeStat.get(magicType) : 1d;
} }
public void mergeMpConsumeTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func) public void mergeMpConsumeTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func)

View File

@ -16,7 +16,6 @@
*/ */
package org.l2jmobius.gameserver.model.actor.stat; package org.l2jmobius.gameserver.model.actor.stat;
import java.util.Collections;
import java.util.Deque; import java.util.Deque;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.EnumSet; import java.util.EnumSet;
@ -804,7 +803,11 @@ public class CreatureStat
_lock.readLock().lock(); _lock.readLock().lock();
try try
{ {
return _statsAdd.getOrDefault(stat, defaultValue); if (_statsAdd.containsKey(stat))
{
return _statsAdd.get(stat);
}
return defaultValue;
} }
finally finally
{ {
@ -831,7 +834,11 @@ public class CreatureStat
_lock.readLock().lock(); _lock.readLock().lock();
try try
{ {
return _statsMul.getOrDefault(stat, defaultValue); if (_statsMul.containsKey(stat))
{
return _statsMul.get(stat);
}
return defaultValue;
} }
finally finally
{ {
@ -846,8 +853,7 @@ public class CreatureStat
*/ */
public double getValue(Stat stat, double baseValue) public double getValue(Stat stat, double baseValue)
{ {
final Double fixedValue = _fixedValue.get(stat); return _fixedValue.containsKey(stat) ? _fixedValue.get(stat) : stat.finalize(_creature, OptionalDouble.of(baseValue));
return fixedValue != null ? fixedValue : stat.finalize(_creature, OptionalDouble.of(baseValue));
} }
/** /**
@ -856,8 +862,7 @@ public class CreatureStat
*/ */
public double getValue(Stat stat) public double getValue(Stat stat)
{ {
final Double fixedValue = _fixedValue.get(stat); return _fixedValue.containsKey(stat) ? _fixedValue.get(stat) : stat.finalize(_creature, OptionalDouble.empty());
return fixedValue != null ? fixedValue : stat.finalize(_creature, OptionalDouble.empty());
} }
protected void resetStats() protected void resetStats()
@ -887,8 +892,19 @@ public class CreatureStat
public void recalculateStats(boolean broadcast) public void recalculateStats(boolean broadcast)
{ {
// Copy old data before wiping it out // Copy old data before wiping it out
final Map<Stat, Double> adds = !broadcast ? Collections.emptyMap() : new EnumMap<>(_statsAdd); final Map<Stat, Double> adds;
final Map<Stat, Double> muls = !broadcast ? Collections.emptyMap() : new EnumMap<>(_statsMul); final Map<Stat, Double> muls;
if (broadcast)
{
adds = new EnumMap<>(_statsAdd);
muls = new EnumMap<>(_statsMul);
}
else
{
adds = null;
muls = null;
}
_lock.writeLock().lock(); _lock.writeLock().lock();
try try
{ {
@ -980,17 +996,17 @@ public class CreatureStat
// Notify recalculation to child classes // Notify recalculation to child classes
onRecalculateStats(broadcast); onRecalculateStats(broadcast);
if (broadcast) if (broadcast && (adds != null) && (muls != null)) // adds and muls cannot be null when broadcast is true, but Eclipse throws warning bellow.
{ {
// Calculate the difference between old and new stats // Calculate the difference between old and new stats
final Set<Stat> changed = new HashSet<>(); final Set<Stat> changed = new HashSet<>();
for (Stat stat : Stat.values()) for (Stat stat : Stat.values())
{ {
if (_statsAdd.getOrDefault(stat, stat.getResetAddValue()) != adds.getOrDefault(stat, stat.getResetAddValue())) if ((_statsAdd.containsKey(stat) ? _statsAdd.get(stat) : stat.getResetAddValue()) != (adds.containsKey(stat) ? adds.get(stat) : stat.getResetAddValue()))
{ {
changed.add(stat); changed.add(stat);
} }
else if (_statsMul.getOrDefault(stat, stat.getResetMulValue()) != muls.getOrDefault(stat, stat.getResetMulValue())) else if ((_statsMul.containsKey(stat) ? _statsMul.get(stat) : stat.getResetMulValue()) != (muls.containsKey(stat) ? muls.get(stat) : stat.getResetMulValue()))
{ {
changed.add(stat); changed.add(stat);
} }
@ -1019,7 +1035,12 @@ public class CreatureStat
public double getPositionTypeValue(Stat stat, Position position) public double getPositionTypeValue(Stat stat, Position position)
{ {
return _positionStats.getOrDefault(stat, Collections.emptyMap()).getOrDefault(position, 1d); final Map<Position, Double> map = _positionStats.get(stat);
if ((map != null) && map.containsKey(position))
{
return map.get(position);
}
return 1d;
} }
public void mergePositionTypeValue(Stat stat, Position position, double value, BiFunction<? super Double, ? super Double, ? extends Double> func) public void mergePositionTypeValue(Stat stat, Position position, double value, BiFunction<? super Double, ? super Double, ? extends Double> func)
@ -1029,7 +1050,12 @@ public class CreatureStat
public double getMoveTypeValue(Stat stat, MoveType type) public double getMoveTypeValue(Stat stat, MoveType type)
{ {
return _moveTypeStats.getOrDefault(stat, Collections.emptyMap()).getOrDefault(type, 0d); final Map<MoveType, Double> map = _moveTypeStats.get(stat);
if ((map != null) && map.containsKey(type))
{
return map.get(type);
}
return 0d;
} }
public void mergeMoveTypeValue(Stat stat, MoveType type, double value) public void mergeMoveTypeValue(Stat stat, MoveType type, double value)
@ -1039,7 +1065,7 @@ public class CreatureStat
public double getReuseTypeValue(int magicType) public double getReuseTypeValue(int magicType)
{ {
return _reuseStat.getOrDefault(magicType, 1d); return _reuseStat.containsKey(magicType) ? _reuseStat.get(magicType) : 1d;
} }
public void mergeReuseTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func) public void mergeReuseTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func)
@ -1049,7 +1075,7 @@ public class CreatureStat
public double getMpConsumeTypeValue(int magicType) public double getMpConsumeTypeValue(int magicType)
{ {
return _mpConsumeStat.getOrDefault(magicType, 1d); return _mpConsumeStat.containsKey(magicType) ? _mpConsumeStat.get(magicType) : 1d;
} }
public void mergeMpConsumeTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func) public void mergeMpConsumeTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func)

View File

@ -16,7 +16,6 @@
*/ */
package org.l2jmobius.gameserver.model.actor.stat; package org.l2jmobius.gameserver.model.actor.stat;
import java.util.Collections;
import java.util.Deque; import java.util.Deque;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.EnumSet; import java.util.EnumSet;
@ -804,7 +803,11 @@ public class CreatureStat
_lock.readLock().lock(); _lock.readLock().lock();
try try
{ {
return _statsAdd.getOrDefault(stat, defaultValue); if (_statsAdd.containsKey(stat))
{
return _statsAdd.get(stat);
}
return defaultValue;
} }
finally finally
{ {
@ -831,7 +834,11 @@ public class CreatureStat
_lock.readLock().lock(); _lock.readLock().lock();
try try
{ {
return _statsMul.getOrDefault(stat, defaultValue); if (_statsMul.containsKey(stat))
{
return _statsMul.get(stat);
}
return defaultValue;
} }
finally finally
{ {
@ -846,8 +853,7 @@ public class CreatureStat
*/ */
public double getValue(Stat stat, double baseValue) public double getValue(Stat stat, double baseValue)
{ {
final Double fixedValue = _fixedValue.get(stat); return _fixedValue.containsKey(stat) ? _fixedValue.get(stat) : stat.finalize(_creature, OptionalDouble.of(baseValue));
return fixedValue != null ? fixedValue : stat.finalize(_creature, OptionalDouble.of(baseValue));
} }
/** /**
@ -856,8 +862,7 @@ public class CreatureStat
*/ */
public double getValue(Stat stat) public double getValue(Stat stat)
{ {
final Double fixedValue = _fixedValue.get(stat); return _fixedValue.containsKey(stat) ? _fixedValue.get(stat) : stat.finalize(_creature, OptionalDouble.empty());
return fixedValue != null ? fixedValue : stat.finalize(_creature, OptionalDouble.empty());
} }
protected void resetStats() protected void resetStats()
@ -887,8 +892,19 @@ public class CreatureStat
public void recalculateStats(boolean broadcast) public void recalculateStats(boolean broadcast)
{ {
// Copy old data before wiping it out // Copy old data before wiping it out
final Map<Stat, Double> adds = !broadcast ? Collections.emptyMap() : new EnumMap<>(_statsAdd); final Map<Stat, Double> adds;
final Map<Stat, Double> muls = !broadcast ? Collections.emptyMap() : new EnumMap<>(_statsMul); final Map<Stat, Double> muls;
if (broadcast)
{
adds = new EnumMap<>(_statsAdd);
muls = new EnumMap<>(_statsMul);
}
else
{
adds = null;
muls = null;
}
_lock.writeLock().lock(); _lock.writeLock().lock();
try try
{ {
@ -980,17 +996,17 @@ public class CreatureStat
// Notify recalculation to child classes // Notify recalculation to child classes
onRecalculateStats(broadcast); onRecalculateStats(broadcast);
if (broadcast) if (broadcast && (adds != null) && (muls != null)) // adds and muls cannot be null when broadcast is true, but Eclipse throws warning bellow.
{ {
// Calculate the difference between old and new stats // Calculate the difference between old and new stats
final Set<Stat> changed = new HashSet<>(); final Set<Stat> changed = new HashSet<>();
for (Stat stat : Stat.values()) for (Stat stat : Stat.values())
{ {
if (_statsAdd.getOrDefault(stat, stat.getResetAddValue()) != adds.getOrDefault(stat, stat.getResetAddValue())) if ((_statsAdd.containsKey(stat) ? _statsAdd.get(stat) : stat.getResetAddValue()) != (adds.containsKey(stat) ? adds.get(stat) : stat.getResetAddValue()))
{ {
changed.add(stat); changed.add(stat);
} }
else if (_statsMul.getOrDefault(stat, stat.getResetMulValue()) != muls.getOrDefault(stat, stat.getResetMulValue())) else if ((_statsMul.containsKey(stat) ? _statsMul.get(stat) : stat.getResetMulValue()) != (muls.containsKey(stat) ? muls.get(stat) : stat.getResetMulValue()))
{ {
changed.add(stat); changed.add(stat);
} }
@ -1019,7 +1035,12 @@ public class CreatureStat
public double getPositionTypeValue(Stat stat, Position position) public double getPositionTypeValue(Stat stat, Position position)
{ {
return _positionStats.getOrDefault(stat, Collections.emptyMap()).getOrDefault(position, 1d); final Map<Position, Double> map = _positionStats.get(stat);
if ((map != null) && map.containsKey(position))
{
return map.get(position);
}
return 1d;
} }
public void mergePositionTypeValue(Stat stat, Position position, double value, BiFunction<? super Double, ? super Double, ? extends Double> func) public void mergePositionTypeValue(Stat stat, Position position, double value, BiFunction<? super Double, ? super Double, ? extends Double> func)
@ -1029,7 +1050,12 @@ public class CreatureStat
public double getMoveTypeValue(Stat stat, MoveType type) public double getMoveTypeValue(Stat stat, MoveType type)
{ {
return _moveTypeStats.getOrDefault(stat, Collections.emptyMap()).getOrDefault(type, 0d); final Map<MoveType, Double> map = _moveTypeStats.get(stat);
if ((map != null) && map.containsKey(type))
{
return map.get(type);
}
return 0d;
} }
public void mergeMoveTypeValue(Stat stat, MoveType type, double value) public void mergeMoveTypeValue(Stat stat, MoveType type, double value)
@ -1039,7 +1065,7 @@ public class CreatureStat
public double getReuseTypeValue(int magicType) public double getReuseTypeValue(int magicType)
{ {
return _reuseStat.getOrDefault(magicType, 1d); return _reuseStat.containsKey(magicType) ? _reuseStat.get(magicType) : 1d;
} }
public void mergeReuseTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func) public void mergeReuseTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func)
@ -1049,7 +1075,7 @@ public class CreatureStat
public double getMpConsumeTypeValue(int magicType) public double getMpConsumeTypeValue(int magicType)
{ {
return _mpConsumeStat.getOrDefault(magicType, 1d); return _mpConsumeStat.containsKey(magicType) ? _mpConsumeStat.get(magicType) : 1d;
} }
public void mergeMpConsumeTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func) public void mergeMpConsumeTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func)

View File

@ -16,7 +16,6 @@
*/ */
package org.l2jmobius.gameserver.model.actor.stat; package org.l2jmobius.gameserver.model.actor.stat;
import java.util.Collections;
import java.util.Deque; import java.util.Deque;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.EnumSet; import java.util.EnumSet;
@ -794,7 +793,11 @@ public class CreatureStat
_lock.readLock().lock(); _lock.readLock().lock();
try try
{ {
return _statsAdd.getOrDefault(stat, defaultValue); if (_statsAdd.containsKey(stat))
{
return _statsAdd.get(stat);
}
return defaultValue;
} }
finally finally
{ {
@ -821,7 +824,11 @@ public class CreatureStat
_lock.readLock().lock(); _lock.readLock().lock();
try try
{ {
return _statsMul.getOrDefault(stat, defaultValue); if (_statsMul.containsKey(stat))
{
return _statsMul.get(stat);
}
return defaultValue;
} }
finally finally
{ {
@ -836,8 +843,7 @@ public class CreatureStat
*/ */
public double getValue(Stat stat, double baseValue) public double getValue(Stat stat, double baseValue)
{ {
final Double fixedValue = _fixedValue.get(stat); return _fixedValue.containsKey(stat) ? _fixedValue.get(stat) : stat.finalize(_creature, OptionalDouble.of(baseValue));
return fixedValue != null ? fixedValue : stat.finalize(_creature, OptionalDouble.of(baseValue));
} }
/** /**
@ -846,8 +852,7 @@ public class CreatureStat
*/ */
public double getValue(Stat stat) public double getValue(Stat stat)
{ {
final Double fixedValue = _fixedValue.get(stat); return _fixedValue.containsKey(stat) ? _fixedValue.get(stat) : stat.finalize(_creature, OptionalDouble.empty());
return fixedValue != null ? fixedValue : stat.finalize(_creature, OptionalDouble.empty());
} }
protected void resetStats() protected void resetStats()
@ -877,8 +882,19 @@ public class CreatureStat
public void recalculateStats(boolean broadcast) public void recalculateStats(boolean broadcast)
{ {
// Copy old data before wiping it out // Copy old data before wiping it out
final Map<Stat, Double> adds = !broadcast ? Collections.emptyMap() : new EnumMap<>(_statsAdd); final Map<Stat, Double> adds;
final Map<Stat, Double> muls = !broadcast ? Collections.emptyMap() : new EnumMap<>(_statsMul); final Map<Stat, Double> muls;
if (broadcast)
{
adds = new EnumMap<>(_statsAdd);
muls = new EnumMap<>(_statsMul);
}
else
{
adds = null;
muls = null;
}
_lock.writeLock().lock(); _lock.writeLock().lock();
try try
{ {
@ -970,17 +986,17 @@ public class CreatureStat
// Notify recalculation to child classes // Notify recalculation to child classes
onRecalculateStats(broadcast); onRecalculateStats(broadcast);
if (broadcast) if (broadcast && (adds != null) && (muls != null)) // adds and muls cannot be null when broadcast is true, but Eclipse throws warning bellow.
{ {
// Calculate the difference between old and new stats // Calculate the difference between old and new stats
final Set<Stat> changed = new HashSet<>(); final Set<Stat> changed = new HashSet<>();
for (Stat stat : Stat.values()) for (Stat stat : Stat.values())
{ {
if (_statsAdd.getOrDefault(stat, stat.getResetAddValue()) != adds.getOrDefault(stat, stat.getResetAddValue())) if ((_statsAdd.containsKey(stat) ? _statsAdd.get(stat) : stat.getResetAddValue()) != (adds.containsKey(stat) ? adds.get(stat) : stat.getResetAddValue()))
{ {
changed.add(stat); changed.add(stat);
} }
else if (_statsMul.getOrDefault(stat, stat.getResetMulValue()) != muls.getOrDefault(stat, stat.getResetMulValue())) else if ((_statsMul.containsKey(stat) ? _statsMul.get(stat) : stat.getResetMulValue()) != (muls.containsKey(stat) ? muls.get(stat) : stat.getResetMulValue()))
{ {
changed.add(stat); changed.add(stat);
} }
@ -1009,7 +1025,12 @@ public class CreatureStat
public double getPositionTypeValue(Stat stat, Position position) public double getPositionTypeValue(Stat stat, Position position)
{ {
return _positionStats.getOrDefault(stat, Collections.emptyMap()).getOrDefault(position, 1d); final Map<Position, Double> map = _positionStats.get(stat);
if ((map != null) && map.containsKey(position))
{
return map.get(position);
}
return 1d;
} }
public void mergePositionTypeValue(Stat stat, Position position, double value, BiFunction<? super Double, ? super Double, ? extends Double> func) public void mergePositionTypeValue(Stat stat, Position position, double value, BiFunction<? super Double, ? super Double, ? extends Double> func)
@ -1019,7 +1040,12 @@ public class CreatureStat
public double getMoveTypeValue(Stat stat, MoveType type) public double getMoveTypeValue(Stat stat, MoveType type)
{ {
return _moveTypeStats.getOrDefault(stat, Collections.emptyMap()).getOrDefault(type, 0d); final Map<MoveType, Double> map = _moveTypeStats.get(stat);
if ((map != null) && map.containsKey(type))
{
return map.get(type);
}
return 0d;
} }
public void mergeMoveTypeValue(Stat stat, MoveType type, double value) public void mergeMoveTypeValue(Stat stat, MoveType type, double value)
@ -1029,7 +1055,7 @@ public class CreatureStat
public double getReuseTypeValue(int magicType) public double getReuseTypeValue(int magicType)
{ {
return _reuseStat.getOrDefault(magicType, 1d); return _reuseStat.containsKey(magicType) ? _reuseStat.get(magicType) : 1d;
} }
public void mergeReuseTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func) public void mergeReuseTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func)
@ -1039,7 +1065,7 @@ public class CreatureStat
public double getMpConsumeTypeValue(int magicType) public double getMpConsumeTypeValue(int magicType)
{ {
return _mpConsumeStat.getOrDefault(magicType, 1d); return _mpConsumeStat.containsKey(magicType) ? _mpConsumeStat.get(magicType) : 1d;
} }
public void mergeMpConsumeTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func) public void mergeMpConsumeTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func)

View File

@ -16,7 +16,6 @@
*/ */
package org.l2jmobius.gameserver.model.actor.stat; package org.l2jmobius.gameserver.model.actor.stat;
import java.util.Collections;
import java.util.Deque; import java.util.Deque;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.EnumSet; import java.util.EnumSet;
@ -794,7 +793,11 @@ public class CreatureStat
_lock.readLock().lock(); _lock.readLock().lock();
try try
{ {
return _statsAdd.getOrDefault(stat, defaultValue); if (_statsAdd.containsKey(stat))
{
return _statsAdd.get(stat);
}
return defaultValue;
} }
finally finally
{ {
@ -821,7 +824,11 @@ public class CreatureStat
_lock.readLock().lock(); _lock.readLock().lock();
try try
{ {
return _statsMul.getOrDefault(stat, defaultValue); if (_statsMul.containsKey(stat))
{
return _statsMul.get(stat);
}
return defaultValue;
} }
finally finally
{ {
@ -836,8 +843,7 @@ public class CreatureStat
*/ */
public double getValue(Stat stat, double baseValue) public double getValue(Stat stat, double baseValue)
{ {
final Double fixedValue = _fixedValue.get(stat); return _fixedValue.containsKey(stat) ? _fixedValue.get(stat) : stat.finalize(_creature, OptionalDouble.of(baseValue));
return fixedValue != null ? fixedValue : stat.finalize(_creature, OptionalDouble.of(baseValue));
} }
/** /**
@ -846,8 +852,7 @@ public class CreatureStat
*/ */
public double getValue(Stat stat) public double getValue(Stat stat)
{ {
final Double fixedValue = _fixedValue.get(stat); return _fixedValue.containsKey(stat) ? _fixedValue.get(stat) : stat.finalize(_creature, OptionalDouble.empty());
return fixedValue != null ? fixedValue : stat.finalize(_creature, OptionalDouble.empty());
} }
protected void resetStats() protected void resetStats()
@ -877,8 +882,19 @@ public class CreatureStat
public void recalculateStats(boolean broadcast) public void recalculateStats(boolean broadcast)
{ {
// Copy old data before wiping it out // Copy old data before wiping it out
final Map<Stat, Double> adds = !broadcast ? Collections.emptyMap() : new EnumMap<>(_statsAdd); final Map<Stat, Double> adds;
final Map<Stat, Double> muls = !broadcast ? Collections.emptyMap() : new EnumMap<>(_statsMul); final Map<Stat, Double> muls;
if (broadcast)
{
adds = new EnumMap<>(_statsAdd);
muls = new EnumMap<>(_statsMul);
}
else
{
adds = null;
muls = null;
}
_lock.writeLock().lock(); _lock.writeLock().lock();
try try
{ {
@ -970,17 +986,17 @@ public class CreatureStat
// Notify recalculation to child classes // Notify recalculation to child classes
onRecalculateStats(broadcast); onRecalculateStats(broadcast);
if (broadcast) if (broadcast && (adds != null) && (muls != null)) // adds and muls cannot be null when broadcast is true, but Eclipse throws warning bellow.
{ {
// Calculate the difference between old and new stats // Calculate the difference between old and new stats
final Set<Stat> changed = new HashSet<>(); final Set<Stat> changed = new HashSet<>();
for (Stat stat : Stat.values()) for (Stat stat : Stat.values())
{ {
if (_statsAdd.getOrDefault(stat, stat.getResetAddValue()) != adds.getOrDefault(stat, stat.getResetAddValue())) if ((_statsAdd.containsKey(stat) ? _statsAdd.get(stat) : stat.getResetAddValue()) != (adds.containsKey(stat) ? adds.get(stat) : stat.getResetAddValue()))
{ {
changed.add(stat); changed.add(stat);
} }
else if (_statsMul.getOrDefault(stat, stat.getResetMulValue()) != muls.getOrDefault(stat, stat.getResetMulValue())) else if ((_statsMul.containsKey(stat) ? _statsMul.get(stat) : stat.getResetMulValue()) != (muls.containsKey(stat) ? muls.get(stat) : stat.getResetMulValue()))
{ {
changed.add(stat); changed.add(stat);
} }
@ -1009,7 +1025,12 @@ public class CreatureStat
public double getPositionTypeValue(Stat stat, Position position) public double getPositionTypeValue(Stat stat, Position position)
{ {
return _positionStats.getOrDefault(stat, Collections.emptyMap()).getOrDefault(position, 1d); final Map<Position, Double> map = _positionStats.get(stat);
if ((map != null) && map.containsKey(position))
{
return map.get(position);
}
return 1d;
} }
public void mergePositionTypeValue(Stat stat, Position position, double value, BiFunction<? super Double, ? super Double, ? extends Double> func) public void mergePositionTypeValue(Stat stat, Position position, double value, BiFunction<? super Double, ? super Double, ? extends Double> func)
@ -1019,7 +1040,12 @@ public class CreatureStat
public double getMoveTypeValue(Stat stat, MoveType type) public double getMoveTypeValue(Stat stat, MoveType type)
{ {
return _moveTypeStats.getOrDefault(stat, Collections.emptyMap()).getOrDefault(type, 0d); final Map<MoveType, Double> map = _moveTypeStats.get(stat);
if ((map != null) && map.containsKey(type))
{
return map.get(type);
}
return 0d;
} }
public void mergeMoveTypeValue(Stat stat, MoveType type, double value) public void mergeMoveTypeValue(Stat stat, MoveType type, double value)
@ -1029,7 +1055,7 @@ public class CreatureStat
public double getReuseTypeValue(int magicType) public double getReuseTypeValue(int magicType)
{ {
return _reuseStat.getOrDefault(magicType, 1d); return _reuseStat.containsKey(magicType) ? _reuseStat.get(magicType) : 1d;
} }
public void mergeReuseTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func) public void mergeReuseTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func)
@ -1039,7 +1065,7 @@ public class CreatureStat
public double getMpConsumeTypeValue(int magicType) public double getMpConsumeTypeValue(int magicType)
{ {
return _mpConsumeStat.getOrDefault(magicType, 1d); return _mpConsumeStat.containsKey(magicType) ? _mpConsumeStat.get(magicType) : 1d;
} }
public void mergeMpConsumeTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func) public void mergeMpConsumeTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func)

View File

@ -16,7 +16,6 @@
*/ */
package org.l2jmobius.gameserver.model.actor.stat; package org.l2jmobius.gameserver.model.actor.stat;
import java.util.Collections;
import java.util.Deque; import java.util.Deque;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.EnumSet; import java.util.EnumSet;
@ -794,7 +793,11 @@ public class CreatureStat
_lock.readLock().lock(); _lock.readLock().lock();
try try
{ {
return _statsAdd.getOrDefault(stat, defaultValue); if (_statsAdd.containsKey(stat))
{
return _statsAdd.get(stat);
}
return defaultValue;
} }
finally finally
{ {
@ -821,7 +824,11 @@ public class CreatureStat
_lock.readLock().lock(); _lock.readLock().lock();
try try
{ {
return _statsMul.getOrDefault(stat, defaultValue); if (_statsMul.containsKey(stat))
{
return _statsMul.get(stat);
}
return defaultValue;
} }
finally finally
{ {
@ -836,8 +843,7 @@ public class CreatureStat
*/ */
public double getValue(Stat stat, double baseValue) public double getValue(Stat stat, double baseValue)
{ {
final Double fixedValue = _fixedValue.get(stat); return _fixedValue.containsKey(stat) ? _fixedValue.get(stat) : stat.finalize(_creature, OptionalDouble.of(baseValue));
return fixedValue != null ? fixedValue : stat.finalize(_creature, OptionalDouble.of(baseValue));
} }
/** /**
@ -846,8 +852,7 @@ public class CreatureStat
*/ */
public double getValue(Stat stat) public double getValue(Stat stat)
{ {
final Double fixedValue = _fixedValue.get(stat); return _fixedValue.containsKey(stat) ? _fixedValue.get(stat) : stat.finalize(_creature, OptionalDouble.empty());
return fixedValue != null ? fixedValue : stat.finalize(_creature, OptionalDouble.empty());
} }
protected void resetStats() protected void resetStats()
@ -877,8 +882,19 @@ public class CreatureStat
public void recalculateStats(boolean broadcast) public void recalculateStats(boolean broadcast)
{ {
// Copy old data before wiping it out // Copy old data before wiping it out
final Map<Stat, Double> adds = !broadcast ? Collections.emptyMap() : new EnumMap<>(_statsAdd); final Map<Stat, Double> adds;
final Map<Stat, Double> muls = !broadcast ? Collections.emptyMap() : new EnumMap<>(_statsMul); final Map<Stat, Double> muls;
if (broadcast)
{
adds = new EnumMap<>(_statsAdd);
muls = new EnumMap<>(_statsMul);
}
else
{
adds = null;
muls = null;
}
_lock.writeLock().lock(); _lock.writeLock().lock();
try try
{ {
@ -970,17 +986,17 @@ public class CreatureStat
// Notify recalculation to child classes // Notify recalculation to child classes
onRecalculateStats(broadcast); onRecalculateStats(broadcast);
if (broadcast) if (broadcast && (adds != null) && (muls != null)) // adds and muls cannot be null when broadcast is true, but Eclipse throws warning bellow.
{ {
// Calculate the difference between old and new stats // Calculate the difference between old and new stats
final Set<Stat> changed = new HashSet<>(); final Set<Stat> changed = new HashSet<>();
for (Stat stat : Stat.values()) for (Stat stat : Stat.values())
{ {
if (_statsAdd.getOrDefault(stat, stat.getResetAddValue()) != adds.getOrDefault(stat, stat.getResetAddValue())) if ((_statsAdd.containsKey(stat) ? _statsAdd.get(stat) : stat.getResetAddValue()) != (adds.containsKey(stat) ? adds.get(stat) : stat.getResetAddValue()))
{ {
changed.add(stat); changed.add(stat);
} }
else if (_statsMul.getOrDefault(stat, stat.getResetMulValue()) != muls.getOrDefault(stat, stat.getResetMulValue())) else if ((_statsMul.containsKey(stat) ? _statsMul.get(stat) : stat.getResetMulValue()) != (muls.containsKey(stat) ? muls.get(stat) : stat.getResetMulValue()))
{ {
changed.add(stat); changed.add(stat);
} }
@ -1009,7 +1025,12 @@ public class CreatureStat
public double getPositionTypeValue(Stat stat, Position position) public double getPositionTypeValue(Stat stat, Position position)
{ {
return _positionStats.getOrDefault(stat, Collections.emptyMap()).getOrDefault(position, 1d); final Map<Position, Double> map = _positionStats.get(stat);
if ((map != null) && map.containsKey(position))
{
return map.get(position);
}
return 1d;
} }
public void mergePositionTypeValue(Stat stat, Position position, double value, BiFunction<? super Double, ? super Double, ? extends Double> func) public void mergePositionTypeValue(Stat stat, Position position, double value, BiFunction<? super Double, ? super Double, ? extends Double> func)
@ -1019,7 +1040,12 @@ public class CreatureStat
public double getMoveTypeValue(Stat stat, MoveType type) public double getMoveTypeValue(Stat stat, MoveType type)
{ {
return _moveTypeStats.getOrDefault(stat, Collections.emptyMap()).getOrDefault(type, 0d); final Map<MoveType, Double> map = _moveTypeStats.get(stat);
if ((map != null) && map.containsKey(type))
{
return map.get(type);
}
return 0d;
} }
public void mergeMoveTypeValue(Stat stat, MoveType type, double value) public void mergeMoveTypeValue(Stat stat, MoveType type, double value)
@ -1029,7 +1055,7 @@ public class CreatureStat
public double getReuseTypeValue(int magicType) public double getReuseTypeValue(int magicType)
{ {
return _reuseStat.getOrDefault(magicType, 1d); return _reuseStat.containsKey(magicType) ? _reuseStat.get(magicType) : 1d;
} }
public void mergeReuseTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func) public void mergeReuseTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func)
@ -1039,7 +1065,7 @@ public class CreatureStat
public double getMpConsumeTypeValue(int magicType) public double getMpConsumeTypeValue(int magicType)
{ {
return _mpConsumeStat.getOrDefault(magicType, 1d); return _mpConsumeStat.containsKey(magicType) ? _mpConsumeStat.get(magicType) : 1d;
} }
public void mergeMpConsumeTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func) public void mergeMpConsumeTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func)

View File

@ -16,7 +16,6 @@
*/ */
package org.l2jmobius.gameserver.model.actor.stat; package org.l2jmobius.gameserver.model.actor.stat;
import java.util.Collections;
import java.util.Deque; import java.util.Deque;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.EnumSet; import java.util.EnumSet;
@ -794,7 +793,11 @@ public class CreatureStat
_lock.readLock().lock(); _lock.readLock().lock();
try try
{ {
return _statsAdd.getOrDefault(stat, defaultValue); if (_statsAdd.containsKey(stat))
{
return _statsAdd.get(stat);
}
return defaultValue;
} }
finally finally
{ {
@ -821,7 +824,11 @@ public class CreatureStat
_lock.readLock().lock(); _lock.readLock().lock();
try try
{ {
return _statsMul.getOrDefault(stat, defaultValue); if (_statsMul.containsKey(stat))
{
return _statsMul.get(stat);
}
return defaultValue;
} }
finally finally
{ {
@ -836,8 +843,7 @@ public class CreatureStat
*/ */
public double getValue(Stat stat, double baseValue) public double getValue(Stat stat, double baseValue)
{ {
final Double fixedValue = _fixedValue.get(stat); return _fixedValue.containsKey(stat) ? _fixedValue.get(stat) : stat.finalize(_creature, OptionalDouble.of(baseValue));
return fixedValue != null ? fixedValue : stat.finalize(_creature, OptionalDouble.of(baseValue));
} }
/** /**
@ -846,8 +852,7 @@ public class CreatureStat
*/ */
public double getValue(Stat stat) public double getValue(Stat stat)
{ {
final Double fixedValue = _fixedValue.get(stat); return _fixedValue.containsKey(stat) ? _fixedValue.get(stat) : stat.finalize(_creature, OptionalDouble.empty());
return fixedValue != null ? fixedValue : stat.finalize(_creature, OptionalDouble.empty());
} }
protected void resetStats() protected void resetStats()
@ -877,8 +882,19 @@ public class CreatureStat
public void recalculateStats(boolean broadcast) public void recalculateStats(boolean broadcast)
{ {
// Copy old data before wiping it out // Copy old data before wiping it out
final Map<Stat, Double> adds = !broadcast ? Collections.emptyMap() : new EnumMap<>(_statsAdd); final Map<Stat, Double> adds;
final Map<Stat, Double> muls = !broadcast ? Collections.emptyMap() : new EnumMap<>(_statsMul); final Map<Stat, Double> muls;
if (broadcast)
{
adds = new EnumMap<>(_statsAdd);
muls = new EnumMap<>(_statsMul);
}
else
{
adds = null;
muls = null;
}
_lock.writeLock().lock(); _lock.writeLock().lock();
try try
{ {
@ -970,17 +986,17 @@ public class CreatureStat
// Notify recalculation to child classes // Notify recalculation to child classes
onRecalculateStats(broadcast); onRecalculateStats(broadcast);
if (broadcast) if (broadcast && (adds != null) && (muls != null)) // adds and muls cannot be null when broadcast is true, but Eclipse throws warning bellow.
{ {
// Calculate the difference between old and new stats // Calculate the difference between old and new stats
final Set<Stat> changed = new HashSet<>(); final Set<Stat> changed = new HashSet<>();
for (Stat stat : Stat.values()) for (Stat stat : Stat.values())
{ {
if (_statsAdd.getOrDefault(stat, stat.getResetAddValue()) != adds.getOrDefault(stat, stat.getResetAddValue())) if ((_statsAdd.containsKey(stat) ? _statsAdd.get(stat) : stat.getResetAddValue()) != (adds.containsKey(stat) ? adds.get(stat) : stat.getResetAddValue()))
{ {
changed.add(stat); changed.add(stat);
} }
else if (_statsMul.getOrDefault(stat, stat.getResetMulValue()) != muls.getOrDefault(stat, stat.getResetMulValue())) else if ((_statsMul.containsKey(stat) ? _statsMul.get(stat) : stat.getResetMulValue()) != (muls.containsKey(stat) ? muls.get(stat) : stat.getResetMulValue()))
{ {
changed.add(stat); changed.add(stat);
} }
@ -1009,7 +1025,12 @@ public class CreatureStat
public double getPositionTypeValue(Stat stat, Position position) public double getPositionTypeValue(Stat stat, Position position)
{ {
return _positionStats.getOrDefault(stat, Collections.emptyMap()).getOrDefault(position, 1d); final Map<Position, Double> map = _positionStats.get(stat);
if ((map != null) && map.containsKey(position))
{
return map.get(position);
}
return 1d;
} }
public void mergePositionTypeValue(Stat stat, Position position, double value, BiFunction<? super Double, ? super Double, ? extends Double> func) public void mergePositionTypeValue(Stat stat, Position position, double value, BiFunction<? super Double, ? super Double, ? extends Double> func)
@ -1019,7 +1040,12 @@ public class CreatureStat
public double getMoveTypeValue(Stat stat, MoveType type) public double getMoveTypeValue(Stat stat, MoveType type)
{ {
return _moveTypeStats.getOrDefault(stat, Collections.emptyMap()).getOrDefault(type, 0d); final Map<MoveType, Double> map = _moveTypeStats.get(stat);
if ((map != null) && map.containsKey(type))
{
return map.get(type);
}
return 0d;
} }
public void mergeMoveTypeValue(Stat stat, MoveType type, double value) public void mergeMoveTypeValue(Stat stat, MoveType type, double value)
@ -1029,7 +1055,7 @@ public class CreatureStat
public double getReuseTypeValue(int magicType) public double getReuseTypeValue(int magicType)
{ {
return _reuseStat.getOrDefault(magicType, 1d); return _reuseStat.containsKey(magicType) ? _reuseStat.get(magicType) : 1d;
} }
public void mergeReuseTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func) public void mergeReuseTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func)
@ -1039,7 +1065,7 @@ public class CreatureStat
public double getMpConsumeTypeValue(int magicType) public double getMpConsumeTypeValue(int magicType)
{ {
return _mpConsumeStat.getOrDefault(magicType, 1d); return _mpConsumeStat.containsKey(magicType) ? _mpConsumeStat.get(magicType) : 1d;
} }
public void mergeMpConsumeTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func) public void mergeMpConsumeTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func)

View File

@ -16,7 +16,6 @@
*/ */
package org.l2jmobius.gameserver.model.actor.stat; package org.l2jmobius.gameserver.model.actor.stat;
import java.util.Collections;
import java.util.Deque; import java.util.Deque;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.EnumSet; import java.util.EnumSet;
@ -794,7 +793,11 @@ public class CreatureStat
_lock.readLock().lock(); _lock.readLock().lock();
try try
{ {
return _statsAdd.getOrDefault(stat, defaultValue); if (_statsAdd.containsKey(stat))
{
return _statsAdd.get(stat);
}
return defaultValue;
} }
finally finally
{ {
@ -821,7 +824,11 @@ public class CreatureStat
_lock.readLock().lock(); _lock.readLock().lock();
try try
{ {
return _statsMul.getOrDefault(stat, defaultValue); if (_statsMul.containsKey(stat))
{
return _statsMul.get(stat);
}
return defaultValue;
} }
finally finally
{ {
@ -836,8 +843,7 @@ public class CreatureStat
*/ */
public double getValue(Stat stat, double baseValue) public double getValue(Stat stat, double baseValue)
{ {
final Double fixedValue = _fixedValue.get(stat); return _fixedValue.containsKey(stat) ? _fixedValue.get(stat) : stat.finalize(_creature, OptionalDouble.of(baseValue));
return fixedValue != null ? fixedValue : stat.finalize(_creature, OptionalDouble.of(baseValue));
} }
/** /**
@ -846,8 +852,7 @@ public class CreatureStat
*/ */
public double getValue(Stat stat) public double getValue(Stat stat)
{ {
final Double fixedValue = _fixedValue.get(stat); return _fixedValue.containsKey(stat) ? _fixedValue.get(stat) : stat.finalize(_creature, OptionalDouble.empty());
return fixedValue != null ? fixedValue : stat.finalize(_creature, OptionalDouble.empty());
} }
protected void resetStats() protected void resetStats()
@ -877,8 +882,19 @@ public class CreatureStat
public void recalculateStats(boolean broadcast) public void recalculateStats(boolean broadcast)
{ {
// Copy old data before wiping it out // Copy old data before wiping it out
final Map<Stat, Double> adds = !broadcast ? Collections.emptyMap() : new EnumMap<>(_statsAdd); final Map<Stat, Double> adds;
final Map<Stat, Double> muls = !broadcast ? Collections.emptyMap() : new EnumMap<>(_statsMul); final Map<Stat, Double> muls;
if (broadcast)
{
adds = new EnumMap<>(_statsAdd);
muls = new EnumMap<>(_statsMul);
}
else
{
adds = null;
muls = null;
}
_lock.writeLock().lock(); _lock.writeLock().lock();
try try
{ {
@ -970,17 +986,17 @@ public class CreatureStat
// Notify recalculation to child classes // Notify recalculation to child classes
onRecalculateStats(broadcast); onRecalculateStats(broadcast);
if (broadcast) if (broadcast && (adds != null) && (muls != null)) // adds and muls cannot be null when broadcast is true, but Eclipse throws warning bellow.
{ {
// Calculate the difference between old and new stats // Calculate the difference between old and new stats
final Set<Stat> changed = new HashSet<>(); final Set<Stat> changed = new HashSet<>();
for (Stat stat : Stat.values()) for (Stat stat : Stat.values())
{ {
if (_statsAdd.getOrDefault(stat, stat.getResetAddValue()) != adds.getOrDefault(stat, stat.getResetAddValue())) if ((_statsAdd.containsKey(stat) ? _statsAdd.get(stat) : stat.getResetAddValue()) != (adds.containsKey(stat) ? adds.get(stat) : stat.getResetAddValue()))
{ {
changed.add(stat); changed.add(stat);
} }
else if (_statsMul.getOrDefault(stat, stat.getResetMulValue()) != muls.getOrDefault(stat, stat.getResetMulValue())) else if ((_statsMul.containsKey(stat) ? _statsMul.get(stat) : stat.getResetMulValue()) != (muls.containsKey(stat) ? muls.get(stat) : stat.getResetMulValue()))
{ {
changed.add(stat); changed.add(stat);
} }
@ -1009,7 +1025,12 @@ public class CreatureStat
public double getPositionTypeValue(Stat stat, Position position) public double getPositionTypeValue(Stat stat, Position position)
{ {
return _positionStats.getOrDefault(stat, Collections.emptyMap()).getOrDefault(position, 1d); final Map<Position, Double> map = _positionStats.get(stat);
if ((map != null) && map.containsKey(position))
{
return map.get(position);
}
return 1d;
} }
public void mergePositionTypeValue(Stat stat, Position position, double value, BiFunction<? super Double, ? super Double, ? extends Double> func) public void mergePositionTypeValue(Stat stat, Position position, double value, BiFunction<? super Double, ? super Double, ? extends Double> func)
@ -1019,7 +1040,12 @@ public class CreatureStat
public double getMoveTypeValue(Stat stat, MoveType type) public double getMoveTypeValue(Stat stat, MoveType type)
{ {
return _moveTypeStats.getOrDefault(stat, Collections.emptyMap()).getOrDefault(type, 0d); final Map<MoveType, Double> map = _moveTypeStats.get(stat);
if ((map != null) && map.containsKey(type))
{
return map.get(type);
}
return 0d;
} }
public void mergeMoveTypeValue(Stat stat, MoveType type, double value) public void mergeMoveTypeValue(Stat stat, MoveType type, double value)
@ -1029,7 +1055,7 @@ public class CreatureStat
public double getReuseTypeValue(int magicType) public double getReuseTypeValue(int magicType)
{ {
return _reuseStat.getOrDefault(magicType, 1d); return _reuseStat.containsKey(magicType) ? _reuseStat.get(magicType) : 1d;
} }
public void mergeReuseTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func) public void mergeReuseTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func)
@ -1039,7 +1065,7 @@ public class CreatureStat
public double getMpConsumeTypeValue(int magicType) public double getMpConsumeTypeValue(int magicType)
{ {
return _mpConsumeStat.getOrDefault(magicType, 1d); return _mpConsumeStat.containsKey(magicType) ? _mpConsumeStat.get(magicType) : 1d;
} }
public void mergeMpConsumeTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func) public void mergeMpConsumeTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func)

View File

@ -16,7 +16,6 @@
*/ */
package org.l2jmobius.gameserver.model.actor.stat; package org.l2jmobius.gameserver.model.actor.stat;
import java.util.Collections;
import java.util.Deque; import java.util.Deque;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.EnumSet; import java.util.EnumSet;
@ -794,7 +793,11 @@ public class CreatureStat
_lock.readLock().lock(); _lock.readLock().lock();
try try
{ {
return _statsAdd.getOrDefault(stat, defaultValue); if (_statsAdd.containsKey(stat))
{
return _statsAdd.get(stat);
}
return defaultValue;
} }
finally finally
{ {
@ -821,7 +824,11 @@ public class CreatureStat
_lock.readLock().lock(); _lock.readLock().lock();
try try
{ {
return _statsMul.getOrDefault(stat, defaultValue); if (_statsMul.containsKey(stat))
{
return _statsMul.get(stat);
}
return defaultValue;
} }
finally finally
{ {
@ -836,8 +843,7 @@ public class CreatureStat
*/ */
public double getValue(Stat stat, double baseValue) public double getValue(Stat stat, double baseValue)
{ {
final Double fixedValue = _fixedValue.get(stat); return _fixedValue.containsKey(stat) ? _fixedValue.get(stat) : stat.finalize(_creature, OptionalDouble.of(baseValue));
return fixedValue != null ? fixedValue : stat.finalize(_creature, OptionalDouble.of(baseValue));
} }
/** /**
@ -846,8 +852,7 @@ public class CreatureStat
*/ */
public double getValue(Stat stat) public double getValue(Stat stat)
{ {
final Double fixedValue = _fixedValue.get(stat); return _fixedValue.containsKey(stat) ? _fixedValue.get(stat) : stat.finalize(_creature, OptionalDouble.empty());
return fixedValue != null ? fixedValue : stat.finalize(_creature, OptionalDouble.empty());
} }
protected void resetStats() protected void resetStats()
@ -877,8 +882,19 @@ public class CreatureStat
public void recalculateStats(boolean broadcast) public void recalculateStats(boolean broadcast)
{ {
// Copy old data before wiping it out // Copy old data before wiping it out
final Map<Stat, Double> adds = !broadcast ? Collections.emptyMap() : new EnumMap<>(_statsAdd); final Map<Stat, Double> adds;
final Map<Stat, Double> muls = !broadcast ? Collections.emptyMap() : new EnumMap<>(_statsMul); final Map<Stat, Double> muls;
if (broadcast)
{
adds = new EnumMap<>(_statsAdd);
muls = new EnumMap<>(_statsMul);
}
else
{
adds = null;
muls = null;
}
_lock.writeLock().lock(); _lock.writeLock().lock();
try try
{ {
@ -970,17 +986,17 @@ public class CreatureStat
// Notify recalculation to child classes // Notify recalculation to child classes
onRecalculateStats(broadcast); onRecalculateStats(broadcast);
if (broadcast) if (broadcast && (adds != null) && (muls != null)) // adds and muls cannot be null when broadcast is true, but Eclipse throws warning bellow.
{ {
// Calculate the difference between old and new stats // Calculate the difference between old and new stats
final Set<Stat> changed = new HashSet<>(); final Set<Stat> changed = new HashSet<>();
for (Stat stat : Stat.values()) for (Stat stat : Stat.values())
{ {
if (_statsAdd.getOrDefault(stat, stat.getResetAddValue()) != adds.getOrDefault(stat, stat.getResetAddValue())) if ((_statsAdd.containsKey(stat) ? _statsAdd.get(stat) : stat.getResetAddValue()) != (adds.containsKey(stat) ? adds.get(stat) : stat.getResetAddValue()))
{ {
changed.add(stat); changed.add(stat);
} }
else if (_statsMul.getOrDefault(stat, stat.getResetMulValue()) != muls.getOrDefault(stat, stat.getResetMulValue())) else if ((_statsMul.containsKey(stat) ? _statsMul.get(stat) : stat.getResetMulValue()) != (muls.containsKey(stat) ? muls.get(stat) : stat.getResetMulValue()))
{ {
changed.add(stat); changed.add(stat);
} }
@ -1009,7 +1025,12 @@ public class CreatureStat
public double getPositionTypeValue(Stat stat, Position position) public double getPositionTypeValue(Stat stat, Position position)
{ {
return _positionStats.getOrDefault(stat, Collections.emptyMap()).getOrDefault(position, 1d); final Map<Position, Double> map = _positionStats.get(stat);
if ((map != null) && map.containsKey(position))
{
return map.get(position);
}
return 1d;
} }
public void mergePositionTypeValue(Stat stat, Position position, double value, BiFunction<? super Double, ? super Double, ? extends Double> func) public void mergePositionTypeValue(Stat stat, Position position, double value, BiFunction<? super Double, ? super Double, ? extends Double> func)
@ -1019,7 +1040,12 @@ public class CreatureStat
public double getMoveTypeValue(Stat stat, MoveType type) public double getMoveTypeValue(Stat stat, MoveType type)
{ {
return _moveTypeStats.getOrDefault(stat, Collections.emptyMap()).getOrDefault(type, 0d); final Map<MoveType, Double> map = _moveTypeStats.get(stat);
if ((map != null) && map.containsKey(type))
{
return map.get(type);
}
return 0d;
} }
public void mergeMoveTypeValue(Stat stat, MoveType type, double value) public void mergeMoveTypeValue(Stat stat, MoveType type, double value)
@ -1029,7 +1055,7 @@ public class CreatureStat
public double getReuseTypeValue(int magicType) public double getReuseTypeValue(int magicType)
{ {
return _reuseStat.getOrDefault(magicType, 1d); return _reuseStat.containsKey(magicType) ? _reuseStat.get(magicType) : 1d;
} }
public void mergeReuseTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func) public void mergeReuseTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func)
@ -1039,7 +1065,7 @@ public class CreatureStat
public double getMpConsumeTypeValue(int magicType) public double getMpConsumeTypeValue(int magicType)
{ {
return _mpConsumeStat.getOrDefault(magicType, 1d); return _mpConsumeStat.containsKey(magicType) ? _mpConsumeStat.get(magicType) : 1d;
} }
public void mergeMpConsumeTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func) public void mergeMpConsumeTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func)

View File

@ -16,7 +16,6 @@
*/ */
package org.l2jmobius.gameserver.model.actor.stat; package org.l2jmobius.gameserver.model.actor.stat;
import java.util.Collections;
import java.util.Deque; import java.util.Deque;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.EnumSet; import java.util.EnumSet;
@ -794,7 +793,11 @@ public class CreatureStat
_lock.readLock().lock(); _lock.readLock().lock();
try try
{ {
return _statsAdd.getOrDefault(stat, defaultValue); if (_statsAdd.containsKey(stat))
{
return _statsAdd.get(stat);
}
return defaultValue;
} }
finally finally
{ {
@ -821,7 +824,11 @@ public class CreatureStat
_lock.readLock().lock(); _lock.readLock().lock();
try try
{ {
return _statsMul.getOrDefault(stat, defaultValue); if (_statsMul.containsKey(stat))
{
return _statsMul.get(stat);
}
return defaultValue;
} }
finally finally
{ {
@ -836,8 +843,7 @@ public class CreatureStat
*/ */
public double getValue(Stat stat, double baseValue) public double getValue(Stat stat, double baseValue)
{ {
final Double fixedValue = _fixedValue.get(stat); return _fixedValue.containsKey(stat) ? _fixedValue.get(stat) : stat.finalize(_creature, OptionalDouble.of(baseValue));
return fixedValue != null ? fixedValue : stat.finalize(_creature, OptionalDouble.of(baseValue));
} }
/** /**
@ -846,8 +852,7 @@ public class CreatureStat
*/ */
public double getValue(Stat stat) public double getValue(Stat stat)
{ {
final Double fixedValue = _fixedValue.get(stat); return _fixedValue.containsKey(stat) ? _fixedValue.get(stat) : stat.finalize(_creature, OptionalDouble.empty());
return fixedValue != null ? fixedValue : stat.finalize(_creature, OptionalDouble.empty());
} }
protected void resetStats() protected void resetStats()
@ -877,8 +882,19 @@ public class CreatureStat
public void recalculateStats(boolean broadcast) public void recalculateStats(boolean broadcast)
{ {
// Copy old data before wiping it out // Copy old data before wiping it out
final Map<Stat, Double> adds = !broadcast ? Collections.emptyMap() : new EnumMap<>(_statsAdd); final Map<Stat, Double> adds;
final Map<Stat, Double> muls = !broadcast ? Collections.emptyMap() : new EnumMap<>(_statsMul); final Map<Stat, Double> muls;
if (broadcast)
{
adds = new EnumMap<>(_statsAdd);
muls = new EnumMap<>(_statsMul);
}
else
{
adds = null;
muls = null;
}
_lock.writeLock().lock(); _lock.writeLock().lock();
try try
{ {
@ -970,17 +986,17 @@ public class CreatureStat
// Notify recalculation to child classes // Notify recalculation to child classes
onRecalculateStats(broadcast); onRecalculateStats(broadcast);
if (broadcast) if (broadcast && (adds != null) && (muls != null)) // adds and muls cannot be null when broadcast is true, but Eclipse throws warning bellow.
{ {
// Calculate the difference between old and new stats // Calculate the difference between old and new stats
final Set<Stat> changed = new HashSet<>(); final Set<Stat> changed = new HashSet<>();
for (Stat stat : Stat.values()) for (Stat stat : Stat.values())
{ {
if (_statsAdd.getOrDefault(stat, stat.getResetAddValue()) != adds.getOrDefault(stat, stat.getResetAddValue())) if ((_statsAdd.containsKey(stat) ? _statsAdd.get(stat) : stat.getResetAddValue()) != (adds.containsKey(stat) ? adds.get(stat) : stat.getResetAddValue()))
{ {
changed.add(stat); changed.add(stat);
} }
else if (_statsMul.getOrDefault(stat, stat.getResetMulValue()) != muls.getOrDefault(stat, stat.getResetMulValue())) else if ((_statsMul.containsKey(stat) ? _statsMul.get(stat) : stat.getResetMulValue()) != (muls.containsKey(stat) ? muls.get(stat) : stat.getResetMulValue()))
{ {
changed.add(stat); changed.add(stat);
} }
@ -1009,7 +1025,12 @@ public class CreatureStat
public double getPositionTypeValue(Stat stat, Position position) public double getPositionTypeValue(Stat stat, Position position)
{ {
return _positionStats.getOrDefault(stat, Collections.emptyMap()).getOrDefault(position, 1d); final Map<Position, Double> map = _positionStats.get(stat);
if ((map != null) && map.containsKey(position))
{
return map.get(position);
}
return 1d;
} }
public void mergePositionTypeValue(Stat stat, Position position, double value, BiFunction<? super Double, ? super Double, ? extends Double> func) public void mergePositionTypeValue(Stat stat, Position position, double value, BiFunction<? super Double, ? super Double, ? extends Double> func)
@ -1019,7 +1040,12 @@ public class CreatureStat
public double getMoveTypeValue(Stat stat, MoveType type) public double getMoveTypeValue(Stat stat, MoveType type)
{ {
return _moveTypeStats.getOrDefault(stat, Collections.emptyMap()).getOrDefault(type, 0d); final Map<MoveType, Double> map = _moveTypeStats.get(stat);
if ((map != null) && map.containsKey(type))
{
return map.get(type);
}
return 0d;
} }
public void mergeMoveTypeValue(Stat stat, MoveType type, double value) public void mergeMoveTypeValue(Stat stat, MoveType type, double value)
@ -1029,7 +1055,7 @@ public class CreatureStat
public double getReuseTypeValue(int magicType) public double getReuseTypeValue(int magicType)
{ {
return _reuseStat.getOrDefault(magicType, 1d); return _reuseStat.containsKey(magicType) ? _reuseStat.get(magicType) : 1d;
} }
public void mergeReuseTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func) public void mergeReuseTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func)
@ -1039,7 +1065,7 @@ public class CreatureStat
public double getMpConsumeTypeValue(int magicType) public double getMpConsumeTypeValue(int magicType)
{ {
return _mpConsumeStat.getOrDefault(magicType, 1d); return _mpConsumeStat.containsKey(magicType) ? _mpConsumeStat.get(magicType) : 1d;
} }
public void mergeMpConsumeTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func) public void mergeMpConsumeTypeValue(int magicType, double value, BiFunction<? super Double, ? super Double, ? extends Double> func)