Make use of Set when checking for contained objects.
This commit is contained in:
		@@ -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,37 +33,38 @@ public class Link implements IBypassHandler
 | 
			
		||||
		"Link"
 | 
			
		||||
	};
 | 
			
		||||
	
 | 
			
		||||
	private static final String[] VALID_LINKS =
 | 
			
		||||
	private static final Set<String> VALID_LINKS = new HashSet<>();
 | 
			
		||||
	static
 | 
			
		||||
	{
 | 
			
		||||
		"common/craft_01.htm",
 | 
			
		||||
		"common/craft_02.htm",
 | 
			
		||||
		"common/runes_01.htm",
 | 
			
		||||
		"common/sealed_runes_01.htm",
 | 
			
		||||
		"common/sealed_runes_02.htm",
 | 
			
		||||
		"common/sealed_runes_03.htm",
 | 
			
		||||
		"common/sealed_runes_04.htm",
 | 
			
		||||
		"common/sealed_runes_05.htm",
 | 
			
		||||
		"common/sealed_runes_06.htm",
 | 
			
		||||
		"common/sealed_runes_07.htm",
 | 
			
		||||
		"common/sealed_runes_08.htm",
 | 
			
		||||
		"common/sealed_runes_09.htm",
 | 
			
		||||
		"common/skill_enchant_help_01.htm",
 | 
			
		||||
		"common/skill_enchant_help_02.htm",
 | 
			
		||||
		"common/skill_enchant_help_03.htm",
 | 
			
		||||
		"default/BlessingOfProtection.htm",
 | 
			
		||||
		"default/SupportMagic.htm",
 | 
			
		||||
		"fisherman/fishing_manual001.htm",
 | 
			
		||||
		"fisherman/fishing_manual002.htm",
 | 
			
		||||
		"fisherman/fishing_manual003.htm",
 | 
			
		||||
		"fisherman/fishing_manual004.htm",
 | 
			
		||||
		"fisherman/fishing_manual005.htm",
 | 
			
		||||
		"fortress/foreman.htm",
 | 
			
		||||
		"petmanager/evolve.htm",
 | 
			
		||||
		"petmanager/exchange.htm",
 | 
			
		||||
		"petmanager/instructions.htm",
 | 
			
		||||
		"warehouse/clanwh.htm",
 | 
			
		||||
		"warehouse/privatewh.htm",
 | 
			
		||||
	};
 | 
			
		||||
		VALID_LINKS.add("common/craft_01.htm");
 | 
			
		||||
		VALID_LINKS.add("common/craft_02.htm");
 | 
			
		||||
		VALID_LINKS.add("common/runes_01.htm");
 | 
			
		||||
		VALID_LINKS.add("common/runes_01.htm");
 | 
			
		||||
		VALID_LINKS.add("common/sealed_runes_02.htm");
 | 
			
		||||
		VALID_LINKS.add("common/sealed_runes_03.htm");
 | 
			
		||||
		VALID_LINKS.add("common/sealed_runes_04.htm");
 | 
			
		||||
		VALID_LINKS.add("common/sealed_runes_05.htm");
 | 
			
		||||
		VALID_LINKS.add("common/sealed_runes_06.htm");
 | 
			
		||||
		VALID_LINKS.add("common/sealed_runes_07.htm");
 | 
			
		||||
		VALID_LINKS.add("common/sealed_runes_08.htm");
 | 
			
		||||
		VALID_LINKS.add("common/sealed_runes_09.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("default/BlessingOfProtection.htm");
 | 
			
		||||
		VALID_LINKS.add("default/SupportMagic.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("fortress/foreman.htm");
 | 
			
		||||
		VALID_LINKS.add("petmanager/evolve.htm");
 | 
			
		||||
		VALID_LINKS.add("petmanager/exchange.htm");
 | 
			
		||||
		VALID_LINKS.add("petmanager/instructions.htm");
 | 
			
		||||
		VALID_LINKS.add("warehouse/clanwh.htm");
 | 
			
		||||
		VALID_LINKS.add("warehouse/privatewh.htm");
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	@Override
 | 
			
		||||
	public boolean useBypass(String command, Player player, Creature target)
 | 
			
		||||
@@ -79,12 +82,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)
 | 
			
		||||
		{
 | 
			
		||||
 
 | 
			
		||||
@@ -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));
 | 
			
		||||
 
 | 
			
		||||
@@ -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");
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -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());
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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());
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	/**
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user