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,67 +33,68 @@ 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"); | ||||
| 		// Quests | ||||
| 		"teleporter/30006.htm", | ||||
| 		"teleporter/30006-Q561.htm", | ||||
| 		"teleporter/30006-Q561-1.htm", | ||||
| 		"teleporter/30006-Q561-2.htm", | ||||
| 		"teleporter/30134.htm", | ||||
| 		"teleporter/30134-Q562.htm", | ||||
| 		"teleporter/30134-Q562-1.htm", | ||||
| 		"teleporter/30134-Q562-2.htm", | ||||
| 		"teleporter/30256.htm", | ||||
| 		"teleporter/30256-Q562.htm", | ||||
| 		"teleporter/30256-Q562-1.htm", | ||||
| 		"teleporter/30256-Q562-2.htm", | ||||
| 		"teleporter/30848.htm", | ||||
| 		"teleporter/30848-Q561-Q562.htm", | ||||
| 		"teleporter/30848-Q561-Q562-1.htm", | ||||
| 		"teleporter/30848-Q561-Q562-2.htm", | ||||
| 	}; | ||||
| 		VALID_LINKS.add("teleporter/30006.htm"); | ||||
| 		VALID_LINKS.add("teleporter/30006-Q561.htm"); | ||||
| 		VALID_LINKS.add("teleporter/30006-Q561-1.htm"); | ||||
| 		VALID_LINKS.add("teleporter/30006-Q561-2.htm"); | ||||
| 		VALID_LINKS.add("teleporter/30134.htm"); | ||||
| 		VALID_LINKS.add("teleporter/30134-Q562.htm"); | ||||
| 		VALID_LINKS.add("teleporter/30134-Q562-1.htm"); | ||||
| 		VALID_LINKS.add("teleporter/30134-Q562-2.htm"); | ||||
| 		VALID_LINKS.add("teleporter/30256.htm"); | ||||
| 		VALID_LINKS.add("teleporter/30256-Q562.htm"); | ||||
| 		VALID_LINKS.add("teleporter/30256-Q562-1.htm"); | ||||
| 		VALID_LINKS.add("teleporter/30256-Q562-2.htm"); | ||||
| 		VALID_LINKS.add("teleporter/30848.htm"); | ||||
| 		VALID_LINKS.add("teleporter/30848-Q561-Q562.htm"); | ||||
| 		VALID_LINKS.add("teleporter/30848-Q561-Q562-1.htm"); | ||||
| 		VALID_LINKS.add("teleporter/30848-Q561-Q562-2.htm"); | ||||
| 	} | ||||
| 	 | ||||
| 	@Override | ||||
| 	public boolean useBypass(String command, Player player, Creature target) | ||||
| @@ -109,12 +112,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
	 MobiusDevelopment
					MobiusDevelopment