Make use of Set when checking for contained objects.

This commit is contained in:
MobiusDevelopment
2022-02-26 08:51:56 +00:00
parent 8955a8cb24
commit 278fb0e193
839 changed files with 6926 additions and 5782 deletions

View File

@@ -16,7 +16,9 @@
*/
package handlers.bypasshandlers;
import org.l2jmobius.commons.util.CommonUtil;
import java.util.HashSet;
import java.util.Set;
import org.l2jmobius.gameserver.cache.HtmCache;
import org.l2jmobius.gameserver.handler.IBypassHandler;
import org.l2jmobius.gameserver.model.actor.Creature;
@@ -31,50 +33,51 @@ public class Link implements IBypassHandler
"Link"
};
private static final String[] VALID_LINKS =
private static final Set<String> VALID_LINKS = new HashSet<>();
static
{
"common/attribute_info.htm",
"common/augmentation_01.htm",
"common/augmentation_02.htm",
"common/augmentation_exchange.htm",
"common/crafting_01.htm",
"common/crafting_02.htm",
"common/crafting_03.htm",
"common/cursed_to_unidentified.htm",
"common/duals_01.htm",
"common/duals_02.htm",
"common/duals_03.htm",
"common/g_cube_warehouse001.htm",
"common/skill_enchant_help.htm",
"common/skill_enchant_help_01.htm",
"common/skill_enchant_help_02.htm",
"common/skill_enchant_help_03.htm",
"common/smelting_trade001.htm",
"common/weapon_sa_01.htm",
"common/welcomeback002.htm",
"common/welcomeback003.htm",
"default/BlessingOfProtection.htm",
"default/SupportMagic.htm",
"default/SupportMagicServitor.htm",
"fisherman/exchange_old_items.htm",
"fisherman/fish_appearance_exchange.htm",
"fisherman/fishing_manual001.htm",
"fisherman/fishing_manual002.htm",
"fisherman/fishing_manual003.htm",
"fisherman/fishing_manual004.htm",
"fisherman/fishing_manual008.htm",
"fisherman/fishing_manual009.htm",
"fisherman/fishing_manual010.htm",
"fortress/foreman.htm",
"guard/kamaloka_help.htm",
"guard/kamaloka_level.htm",
"petmanager/evolve.htm",
"petmanager/exchange.htm",
"petmanager/instructions.htm",
"teleporter/separatedsoul.htm",
"warehouse/clanwh.htm",
"warehouse/privatewh.htm",
};
VALID_LINKS.add("common/attribute_info.htm");
VALID_LINKS.add("common/augmentation_01.htm");
VALID_LINKS.add("common/augmentation_02.htm");
VALID_LINKS.add("common/augmentation_exchange.htm");
VALID_LINKS.add("common/crafting_01.htm");
VALID_LINKS.add("common/crafting_02.htm");
VALID_LINKS.add("common/crafting_03.htm");
VALID_LINKS.add("common/cursed_to_unidentified.htm");
VALID_LINKS.add("common/duals_01.htm");
VALID_LINKS.add("common/duals_02.htm");
VALID_LINKS.add("common/duals_03.htm");
VALID_LINKS.add("common/g_cube_warehouse001.htm");
VALID_LINKS.add("common/skill_enchant_help.htm");
VALID_LINKS.add("common/skill_enchant_help_01.htm");
VALID_LINKS.add("common/skill_enchant_help_02.htm");
VALID_LINKS.add("common/skill_enchant_help_03.htm");
VALID_LINKS.add("common/smelting_trade001.htm");
VALID_LINKS.add("common/weapon_sa_01.htm");
VALID_LINKS.add("common/welcomeback002.htm");
VALID_LINKS.add("common/welcomeback003.htm");
VALID_LINKS.add("default/BlessingOfProtection.htm");
VALID_LINKS.add("default/SupportMagic.htm");
VALID_LINKS.add("default/SupportMagicServitor.htm");
VALID_LINKS.add("fisherman/exchange_old_items.htm");
VALID_LINKS.add("fisherman/fish_appearance_exchange.htm");
VALID_LINKS.add("fisherman/fishing_manual001.htm");
VALID_LINKS.add("fisherman/fishing_manual002.htm");
VALID_LINKS.add("fisherman/fishing_manual003.htm");
VALID_LINKS.add("fisherman/fishing_manual004.htm");
VALID_LINKS.add("fisherman/fishing_manual008.htm");
VALID_LINKS.add("fisherman/fishing_manual009.htm");
VALID_LINKS.add("fisherman/fishing_manual010.htm");
VALID_LINKS.add("fortress/foreman.htm");
VALID_LINKS.add("guard/kamaloka_help.htm");
VALID_LINKS.add("guard/kamaloka_level.htm");
VALID_LINKS.add("petmanager/evolve.htm");
VALID_LINKS.add("petmanager/exchange.htm");
VALID_LINKS.add("petmanager/instructions.htm");
VALID_LINKS.add("teleporter/separatedsoul.htm");
VALID_LINKS.add("warehouse/clanwh.htm");
VALID_LINKS.add("warehouse/privatewh.htm");
}
@Override
public boolean useBypass(String command, Player player, Creature target)
@@ -92,12 +95,13 @@ public class Link implements IBypassHandler
return false;
}
String content = CommonUtil.contains(VALID_LINKS, htmlPath) ? HtmCache.getInstance().getHtm(player, "data/html/" + htmlPath) : null;
String content = VALID_LINKS.contains(htmlPath) ? HtmCache.getInstance().getHtm(player, "data/html/" + htmlPath) : null;
// Precaution.
if (htmlPath.startsWith("teleporter/") && !(player.getTarget() instanceof Teleporter))
{
content = null;
}
final NpcHtmlMessage html = new NpcHtmlMessage(target != null ? target.getObjectId() : 0);
if (content != null)
{

View File

@@ -17,6 +17,7 @@
package handlers.itemhandlers;
import java.util.List;
import java.util.Set;
import org.l2jmobius.gameserver.data.xml.PetDataTable;
import org.l2jmobius.gameserver.data.xml.SkillData;
@@ -79,7 +80,7 @@ public class PetFood implements IItemHandler
final Player player = activeChar.getActingPlayer();
if (player.isMounted())
{
final List<Integer> foodIds = PetDataTable.getInstance().getPetData(player.getMountNpcId()).getFood();
final Set<Integer> foodIds = PetDataTable.getInstance().getPetData(player.getMountNpcId()).getFood();
if (foodIds.contains(item.getId()) && player.destroyItem("Consume", item.getObjectId(), 1, null, false))
{
player.broadcastPacket(new MagicSkillUse(player, player, skillId, skillLevel, 0, 0));

View File

@@ -16,7 +16,8 @@
*/
package handlers.skillconditionhandlers;
import java.util.List;
import java.util.HashSet;
import java.util.Set;
import org.l2jmobius.gameserver.data.xml.ClanHallData;
import org.l2jmobius.gameserver.model.StatSet;
@@ -32,12 +33,12 @@ import org.l2jmobius.gameserver.model.skill.Skill;
*/
public class OpCheckResidenceSkillCondition implements ISkillCondition
{
private final List<Integer> _residencesId;
private final Set<Integer> _residencesId = new HashSet<>();
private final boolean _isWithin;
public OpCheckResidenceSkillCondition(StatSet params)
{
_residencesId = params.getList("residencesId", Integer.class);
_residencesId.addAll(params.getList("residencesId", Integer.class));
_isWithin = params.getBoolean("isWithin");
}

View File

@@ -16,9 +16,9 @@
*/
package handlers.skillconditionhandlers;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.l2jmobius.gameserver.model.StatSet;
import org.l2jmobius.gameserver.model.WorldObject;
@@ -28,18 +28,18 @@ import org.l2jmobius.gameserver.model.skill.ISkillCondition;
import org.l2jmobius.gameserver.model.skill.Skill;
/**
* @author UnAfraid
* @author UnAfraid, Mobius
*/
public class OpNeedSummonOrPetSkillCondition implements ISkillCondition
{
private final List<Integer> _npcIds = new ArrayList<>();
private final Set<Integer> _npcIds = new HashSet<>();
public OpNeedSummonOrPetSkillCondition(StatSet params)
{
final List<String> npcIds = params.getList("npcIds", String.class);
final List<Integer> npcIds = params.getList("npcIds", Integer.class);
if (npcIds != null)
{
npcIds.stream().map(Integer::valueOf).forEach(_npcIds::add);
_npcIds.addAll(npcIds);
}
}
@@ -47,7 +47,19 @@ public class OpNeedSummonOrPetSkillCondition implements ISkillCondition
public boolean canUse(Creature caster, Skill skill, WorldObject target)
{
final Summon pet = caster.getPet();
final Collection<Summon> summons = caster.getServitors().values();
return ((pet != null) && _npcIds.stream().anyMatch(npcId -> npcId == pet.getId())) || summons.stream().anyMatch(summon -> _npcIds.contains(summon.getId()));
if ((pet != null) && _npcIds.contains(pet.getId()))
{
return true;
}
for (Summon summon : caster.getServitors().values())
{
if (_npcIds.contains(summon.getId()))
{
return true;
}
}
return false;
}
}

View File

@@ -16,7 +16,8 @@
*/
package handlers.skillconditionhandlers;
import java.util.List;
import java.util.HashSet;
import java.util.Set;
import org.l2jmobius.gameserver.model.StatSet;
import org.l2jmobius.gameserver.model.WorldObject;
@@ -29,11 +30,11 @@ import org.l2jmobius.gameserver.model.skill.Skill;
*/
public class OpTargetDoorSkillCondition implements ISkillCondition
{
private final List<Integer> _doorIds;
private final Set<Integer> _doorIds = new HashSet<>();
public OpTargetDoorSkillCondition(StatSet params)
{
_doorIds = params.getList("doorIds", Integer.class);
_doorIds.addAll(params.getList("doorIds", Integer.class));
}
@Override

View File

@@ -16,7 +16,8 @@
*/
package handlers.skillconditionhandlers;
import java.util.List;
import java.util.HashSet;
import java.util.Set;
import org.l2jmobius.gameserver.model.StatSet;
import org.l2jmobius.gameserver.model.WorldObject;
@@ -29,17 +30,17 @@ import org.l2jmobius.gameserver.model.skill.Skill;
*/
public class OpTargetNpcSkillCondition implements ISkillCondition
{
private final List<Integer> _npcId;
private final Set<Integer> _npcIds = new HashSet<>();
public OpTargetNpcSkillCondition(StatSet params)
{
_npcId = params.getList("npcIds", Integer.class);
_npcIds.addAll(params.getList("npcIds", Integer.class));
}
@Override
public boolean canUse(Creature caster, Skill skill, WorldObject target)
{
final WorldObject actualTarget = (caster == null) || !caster.isPlayer() ? target : caster.getTarget();
return (actualTarget != null) && (actualTarget.isNpc() || actualTarget.isDoor()) && _npcId.contains(actualTarget.getId());
return (actualTarget != null) && (actualTarget.isNpc() || actualTarget.isDoor()) && _npcIds.contains(actualTarget.getId());
}
}

View File

@@ -16,9 +16,10 @@
*/
package instances;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.l2jmobius.commons.util.CommonUtil;
import org.l2jmobius.gameserver.enums.InstanceReenterType;
import org.l2jmobius.gameserver.enums.PlayerCondOverride;
import org.l2jmobius.gameserver.instancemanager.InstanceManager;
@@ -40,25 +41,29 @@ import ai.AbstractNpcAI;
*/
public abstract class AbstractInstance extends AbstractNpcAI
{
private final int[] _templateIds;
private final Set<Integer> _templateIds = new HashSet<>();
public AbstractInstance(int... templateId)
public AbstractInstance(int... templateIds)
{
if (templateId.length == 0)
if (templateIds.length == 0)
{
throw new IllegalStateException("No template ids were provided!");
}
_templateIds = templateId;
for (int templateId : templateIds)
{
_templateIds.add(templateId);
}
}
public int[] getTemplateId()
public Set<Integer> getTemplateId()
{
return _templateIds;
}
public boolean isInInstance(Instance instance)
{
return (instance != null) && CommonUtil.contains(_templateIds, instance.getTemplateId());
return (instance != null) && _templateIds.contains(instance.getTemplateId());
}
/**