-Misc clean up/refactor.
-Removed unnecessary Map.containsKey calls
-Using java 8 methods where possible to avoid external checks.
Source L2J HighFive branch:
9d0fee8537
This commit is contained in:
parent
2dd69863cc
commit
f9a65fe3c1
@ -153,11 +153,7 @@ public class UIData implements IXmlReader
|
|||||||
*/
|
*/
|
||||||
public static void addCategory(Map<Integer, List<Integer>> map, int cat, int cmd)
|
public static void addCategory(Map<Integer, List<Integer>> map, int cat, int cmd)
|
||||||
{
|
{
|
||||||
if (!map.containsKey(cat))
|
map.computeIfAbsent(cat, k -> new ArrayList<>()).add(cmd);
|
||||||
{
|
|
||||||
map.put(cat, new ArrayList<Integer>());
|
|
||||||
}
|
|
||||||
map.get(cat).add(cmd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -168,11 +164,7 @@ public class UIData implements IXmlReader
|
|||||||
*/
|
*/
|
||||||
public static void addKey(Map<Integer, List<ActionKey>> map, int cat, ActionKey akey)
|
public static void addKey(Map<Integer, List<ActionKey>> map, int cat, ActionKey akey)
|
||||||
{
|
{
|
||||||
if (!map.containsKey(cat))
|
map.computeIfAbsent(cat, k -> new ArrayList<>()).add(akey);
|
||||||
{
|
|
||||||
map.put(cat, new ArrayList<ActionKey>());
|
|
||||||
}
|
|
||||||
map.get(cat).add(akey);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -154,15 +154,9 @@ public final class AntiFeedManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
final Integer addrHash = Integer.valueOf(client.getConnectionAddress().hashCode());
|
final Integer addrHash = Integer.valueOf(client.getConnectionAddress().hashCode());
|
||||||
int limit = max;
|
|
||||||
if (Config.L2JMOD_DUALBOX_CHECK_WHITELIST.containsKey(addrHash))
|
|
||||||
{
|
|
||||||
limit += Config.L2JMOD_DUALBOX_CHECK_WHITELIST.get(addrHash);
|
|
||||||
}
|
|
||||||
|
|
||||||
final AtomicInteger connectionCount = event.computeIfAbsent(addrHash, k -> new AtomicInteger());
|
final AtomicInteger connectionCount = event.computeIfAbsent(addrHash, k -> new AtomicInteger());
|
||||||
|
|
||||||
return connectionCount.getAndIncrement() < limit;
|
return connectionCount.getAndIncrement() < (max + Config.L2JMOD_DUALBOX_CHECK_WHITELIST.getOrDefault(addrHash, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -95,22 +95,8 @@ public class RaidBossPointsManager
|
|||||||
|
|
||||||
public final void addPoints(L2PcInstance player, int bossId, int points)
|
public final void addPoints(L2PcInstance player, int bossId, int points)
|
||||||
{
|
{
|
||||||
int ownerId = player.getObjectId();
|
final Map<Integer, Integer> tmpPoint = _list.computeIfAbsent(player.getObjectId(), k -> new HashMap<>());
|
||||||
Map<Integer, Integer> tmpPoint = _list.get(ownerId);
|
updatePointsInDB(player, bossId, tmpPoint.merge(bossId, points, Integer::sum));
|
||||||
if (tmpPoint == null)
|
|
||||||
{
|
|
||||||
tmpPoint = new HashMap<>();
|
|
||||||
tmpPoint.put(bossId, points);
|
|
||||||
updatePointsInDB(player, bossId, points);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
int currentPoins = tmpPoint.containsKey(bossId) ? tmpPoint.get(bossId) : 0;
|
|
||||||
currentPoins += points;
|
|
||||||
tmpPoint.put(bossId, currentPoins);
|
|
||||||
updatePointsInDB(player, bossId, currentPoins);
|
|
||||||
}
|
|
||||||
_list.put(ownerId, tmpPoint);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public final int getPointsByOwnerId(int ownerId)
|
public final int getPointsByOwnerId(int ownerId)
|
||||||
|
@ -176,13 +176,12 @@ public class RaidBossSpawnManager
|
|||||||
*/
|
*/
|
||||||
public void updateStatus(L2RaidBossInstance boss, boolean isBossDead)
|
public void updateStatus(L2RaidBossInstance boss, boolean isBossDead)
|
||||||
{
|
{
|
||||||
if (!_storedInfo.containsKey(boss.getId()))
|
final StatsSet info = _storedInfo.get(boss.getId());
|
||||||
|
if (info == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final StatsSet info = _storedInfo.get(boss.getId());
|
|
||||||
|
|
||||||
if (isBossDead)
|
if (isBossDead)
|
||||||
{
|
{
|
||||||
boss.setRaidStatus(StatusEnum.DEAD);
|
boss.setRaidStatus(StatusEnum.DEAD);
|
||||||
|
@ -333,10 +333,10 @@ public final class WalkingManager implements IXmlReader
|
|||||||
* @param npc NPC to cancel
|
* @param npc NPC to cancel
|
||||||
*/
|
*/
|
||||||
public synchronized void cancelMoving(L2Npc npc)
|
public synchronized void cancelMoving(L2Npc npc)
|
||||||
{
|
|
||||||
if (_activeRoutes.containsKey(npc.getObjectId()))
|
|
||||||
{
|
{
|
||||||
final WalkInfo walk = _activeRoutes.remove(npc.getObjectId());
|
final WalkInfo walk = _activeRoutes.remove(npc.getObjectId());
|
||||||
|
if (walk != null)
|
||||||
|
{
|
||||||
walk.getWalkCheckTask().cancel(true);
|
walk.getWalkCheckTask().cancel(true);
|
||||||
npc.getKnownList().stopTrackingTask();
|
npc.getKnownList().stopTrackingTask();
|
||||||
}
|
}
|
||||||
@ -348,16 +348,14 @@ public final class WalkingManager implements IXmlReader
|
|||||||
*/
|
*/
|
||||||
public void resumeMoving(final L2Npc npc)
|
public void resumeMoving(final L2Npc npc)
|
||||||
{
|
{
|
||||||
if (!_activeRoutes.containsKey(npc.getObjectId()))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final WalkInfo walk = _activeRoutes.get(npc.getObjectId());
|
final WalkInfo walk = _activeRoutes.get(npc.getObjectId());
|
||||||
|
if (walk != null)
|
||||||
|
{
|
||||||
walk.setSuspended(false);
|
walk.setSuspended(false);
|
||||||
walk.setStoppedByAttack(false);
|
walk.setStoppedByAttack(false);
|
||||||
startMoving(npc, walk.getRoute().getName());
|
startMoving(npc, walk.getRoute().getName());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pause NPC moving until it will be resumed
|
* Pause NPC moving until it will be resumed
|
||||||
|
@ -28,10 +28,9 @@ public final class DamageDoneInfo
|
|||||||
private final L2PcInstance _attacker;
|
private final L2PcInstance _attacker;
|
||||||
private int _damage = 0;
|
private int _damage = 0;
|
||||||
|
|
||||||
public DamageDoneInfo(L2PcInstance attacker, int damage)
|
public DamageDoneInfo(L2PcInstance attacker)
|
||||||
{
|
{
|
||||||
_attacker = attacker;
|
_attacker = attacker;
|
||||||
_damage = damage;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public L2PcInstance getAttacker()
|
public L2PcInstance getAttacker()
|
||||||
|
@ -426,16 +426,8 @@ public class L2Attackable extends L2Npc
|
|||||||
totalDamage += damage;
|
totalDamage += damage;
|
||||||
|
|
||||||
// Calculate real damages (Summoners should get own damage plus summon's damage)
|
// Calculate real damages (Summoners should get own damage plus summon's damage)
|
||||||
DamageDoneInfo reward = rewards.get(attacker);
|
final DamageDoneInfo reward = rewards.computeIfAbsent(attacker, DamageDoneInfo::new);
|
||||||
if (reward == null)
|
|
||||||
{
|
|
||||||
reward = new DamageDoneInfo(attacker, damage);
|
|
||||||
rewards.put(attacker, reward);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
reward.addDamage(damage);
|
reward.addDamage(damage);
|
||||||
}
|
|
||||||
|
|
||||||
if (reward.getDamage() > maxDamage)
|
if (reward.getDamage() > maxDamage)
|
||||||
{
|
{
|
||||||
@ -710,12 +702,7 @@ public class L2Attackable extends L2Npc
|
|||||||
|
|
||||||
final L2PcInstance targetPlayer = attacker.getActingPlayer();
|
final L2PcInstance targetPlayer = attacker.getActingPlayer();
|
||||||
// Get the AggroInfo of the attacker L2Character from the _aggroList of the L2Attackable
|
// Get the AggroInfo of the attacker L2Character from the _aggroList of the L2Attackable
|
||||||
AggroInfo ai = getAggroList().get(attacker);
|
final AggroInfo ai = getAggroList().computeIfAbsent(attacker, AggroInfo::new);
|
||||||
if (ai == null)
|
|
||||||
{
|
|
||||||
ai = new AggroInfo(attacker);
|
|
||||||
getAggroList().put(attacker, ai);
|
|
||||||
}
|
|
||||||
ai.addDamage(damage);
|
ai.addDamage(damage);
|
||||||
// traps does not cause aggro
|
// traps does not cause aggro
|
||||||
// making this hack because not possible to determine if damage made by trap
|
// making this hack because not possible to determine if damage made by trap
|
||||||
|
@ -22,6 +22,7 @@ import java.sql.Connection;
|
|||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
@ -1015,10 +1016,7 @@ public class L2PetInstance extends L2Summon
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Clear list for overwrite
|
// Clear list for overwrite
|
||||||
if (SummonEffectsTable.getInstance().getPetEffects().containsKey(getControlObjectId()))
|
SummonEffectsTable.getInstance().getPetEffects().getOrDefault(getControlObjectId(), Collections.emptyList()).clear();
|
||||||
{
|
|
||||||
SummonEffectsTable.getInstance().getPetEffects().get(getControlObjectId()).clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
try (Connection con = L2DatabaseFactory.getInstance().getConnection();
|
try (Connection con = L2DatabaseFactory.getInstance().getConnection();
|
||||||
PreparedStatement ps1 = con.prepareStatement(DELETE_SKILL_SAVE);
|
PreparedStatement ps1 = con.prepareStatement(DELETE_SKILL_SAVE);
|
||||||
|
@ -22,6 +22,7 @@ import java.sql.Connection;
|
|||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -282,9 +283,9 @@ public class L2ServitorInstance extends L2Summon implements Runnable
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Clear list for overwrite
|
// Clear list for overwrite
|
||||||
if (SummonEffectsTable.getInstance().getServitorEffectsOwner().containsKey(getOwner().getObjectId()) && SummonEffectsTable.getInstance().getServitorEffectsOwner().get(getOwner().getObjectId()).containsKey(getOwner().getClassIndex()) && SummonEffectsTable.getInstance().getServitorEffects(getOwner()).containsKey(getReferenceSkill()))
|
if (SummonEffectsTable.getInstance().getServitorEffectsOwner().getOrDefault(getOwner().getObjectId(), Collections.emptyMap()).containsKey(getOwner().getClassIndex()))
|
||||||
{
|
{
|
||||||
SummonEffectsTable.getInstance().getServitorEffects(getOwner()).get(getReferenceSkill()).clear();
|
SummonEffectsTable.getInstance().getServitorEffects(getOwner()).getOrDefault(getReferenceSkill(), Collections.emptyList()).clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
try (Connection con = L2DatabaseFactory.getInstance().getConnection();
|
try (Connection con = L2DatabaseFactory.getInstance().getConnection();
|
||||||
|
@ -840,8 +840,6 @@ public final class Instance
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void cancelEjectDeadPlayer(L2PcInstance player)
|
public void cancelEjectDeadPlayer(L2PcInstance player)
|
||||||
{
|
|
||||||
if (_ejectDeadTasks.containsKey(player.getObjectId()))
|
|
||||||
{
|
{
|
||||||
final ScheduledFuture<?> task = _ejectDeadTasks.remove(player.getObjectId());
|
final ScheduledFuture<?> task = _ejectDeadTasks.remove(player.getObjectId());
|
||||||
if (task != null)
|
if (task != null)
|
||||||
@ -849,7 +847,6 @@ public final class Instance
|
|||||||
task.cancel(true);
|
task.cancel(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void addEjectDeadTask(L2PcInstance player)
|
public void addEjectDeadTask(L2PcInstance player)
|
||||||
{
|
{
|
||||||
|
@ -39,12 +39,8 @@ public final class PunishmentHolder
|
|||||||
{
|
{
|
||||||
if (!task.isExpired())
|
if (!task.isExpired())
|
||||||
{
|
{
|
||||||
String key = String.valueOf(task.getKey());
|
final String key = String.valueOf(task.getKey());
|
||||||
if (!_holder.containsKey(key))
|
_holder.computeIfAbsent(key, k -> new ConcurrentHashMap<>()).put(task.getType(), task);
|
||||||
{
|
|
||||||
_holder.put(key, new ConcurrentHashMap<PunishmentType, PunishmentTask>());
|
|
||||||
}
|
|
||||||
_holder.get(key).put(task.getType(), task);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -238,7 +238,7 @@ public abstract class ItemContainer
|
|||||||
item = olditem;
|
item = olditem;
|
||||||
|
|
||||||
// Updates database
|
// Updates database
|
||||||
float adenaRate = Config.RATE_DROP_AMOUNT_MULTIPLIER.containsKey(Inventory.ADENA_ID) ? Config.RATE_DROP_AMOUNT_MULTIPLIER.get(Inventory.ADENA_ID) : 1;
|
float adenaRate = Config.RATE_DROP_AMOUNT_MULTIPLIER.getOrDefault(Inventory.ADENA_ID, 1f);
|
||||||
if (actor.hasPremiumStatus() && Config.PREMIUM_RATE_DROP_AMOUNT_BY_ID.containsKey(Inventory.ADENA_ID))
|
if (actor.hasPremiumStatus() && Config.PREMIUM_RATE_DROP_AMOUNT_BY_ID.containsKey(Inventory.ADENA_ID))
|
||||||
{
|
{
|
||||||
adenaRate *= Config.PREMIUM_RATE_DROP_AMOUNT_BY_ID.get(Inventory.ADENA_ID);
|
adenaRate *= Config.PREMIUM_RATE_DROP_AMOUNT_BY_ID.get(Inventory.ADENA_ID);
|
||||||
@ -294,7 +294,7 @@ public abstract class ItemContainer
|
|||||||
item.setLastChange(L2ItemInstance.MODIFIED);
|
item.setLastChange(L2ItemInstance.MODIFIED);
|
||||||
// Updates database
|
// Updates database
|
||||||
// If Adena drop rate is not present it will be x1.
|
// If Adena drop rate is not present it will be x1.
|
||||||
float adenaRate = Config.RATE_DROP_AMOUNT_MULTIPLIER.containsKey(Inventory.ADENA_ID) ? Config.RATE_DROP_AMOUNT_MULTIPLIER.get(Inventory.ADENA_ID) : 1;
|
float adenaRate = Config.RATE_DROP_AMOUNT_MULTIPLIER.getOrDefault(Inventory.ADENA_ID, 1f);
|
||||||
if (actor.hasPremiumStatus() && Config.PREMIUM_RATE_DROP_AMOUNT_BY_ID.containsKey(Inventory.ADENA_ID))
|
if (actor.hasPremiumStatus() && Config.PREMIUM_RATE_DROP_AMOUNT_BY_ID.containsKey(Inventory.ADENA_ID))
|
||||||
{
|
{
|
||||||
adenaRate *= Config.PREMIUM_RATE_DROP_AMOUNT_BY_ID.get(Inventory.ADENA_ID);
|
adenaRate *= Config.PREMIUM_RATE_DROP_AMOUNT_BY_ID.get(Inventory.ADENA_ID);
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.l2jserver.gameserver.model.skills;
|
package com.l2jserver.gameserver.model.skills;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
@ -32,33 +33,22 @@ public final class SkillChannelized
|
|||||||
|
|
||||||
public void addChannelizer(int skillId, L2Character channelizer)
|
public void addChannelizer(int skillId, L2Character channelizer)
|
||||||
{
|
{
|
||||||
if (!_channelizers.containsKey(skillId))
|
_channelizers.computeIfAbsent(skillId, k -> new ConcurrentHashMap<>()).put(channelizer.getObjectId(), channelizer);
|
||||||
{
|
|
||||||
_channelizers.put(skillId, new ConcurrentHashMap<Integer, L2Character>());
|
|
||||||
}
|
|
||||||
_channelizers.get(skillId).put(channelizer.getObjectId(), channelizer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeChannelizer(int skillId, L2Character channelizer)
|
public void removeChannelizer(int skillId, L2Character channelizer)
|
||||||
{
|
{
|
||||||
if (_channelizers.containsKey(skillId))
|
getChannelizers(skillId).remove(channelizer.getObjectId());
|
||||||
{
|
|
||||||
_channelizers.get(skillId).remove(channelizer.getObjectId());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getChannerlizersSize(int skillId)
|
public int getChannerlizersSize(int skillId)
|
||||||
{
|
{
|
||||||
if (_channelizers.containsKey(skillId))
|
return getChannelizers(skillId).size();
|
||||||
{
|
|
||||||
return _channelizers.get(skillId).size();
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<Integer, L2Character> getChannelizers(int skillId)
|
public Map<Integer, L2Character> getChannelizers(int skillId)
|
||||||
{
|
{
|
||||||
return _channelizers.get(skillId);
|
return _channelizers.getOrDefault(skillId, Collections.emptyMap());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void abortChannelization()
|
public void abortChannelization()
|
||||||
|
Loading…
Reference in New Issue
Block a user