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
{
"adventurer_guildsman/AboutHighLevelGuilds.htm",
"adventurer_guildsman/AboutNewLifeCrystals.htm",
"clanHallDoorman/evolve.htm",
"common/augmentation_01.htm",
"common/augmentation_02.htm",
"common/crafting_01.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/weapon_sa_01.htm",
"common/welcomeback002.htm",
"common/welcomeback003.htm",
"default/BlessingOfProtection.htm",
"default/SupportMagic.htm",
"default/SupportMagicServitor.htm",
"fisherman/fishing_championship.htm",
"fortress/foreman.htm",
"guard/kamaloka_help.htm",
"guard/kamaloka_level.htm",
"olympiad/hero_main2.htm",
"petmanager/evolve.htm",
"petmanager/exchange.htm",
"petmanager/instructions.htm",
"seven_signs/blkmrkt_1.htm",
"seven_signs/blkmrkt_2.htm",
"seven_signs/mammblack_1a.htm",
"seven_signs/mammblack_1b.htm",
"seven_signs/mammblack_1c.htm",
"seven_signs/mammblack_2a.htm",
"seven_signs/mammblack_2b.htm",
"seven_signs/mammmerch_1.htm",
"seven_signs/mammmerch_1a.htm",
"seven_signs/mammmerch_1b.htm",
"teleporter/separatedsoul.htm",
"warehouse/clanwh.htm",
"warehouse/privatewh.htm",
};
VALID_LINKS.add("adventurer_guildsman/AboutHighLevelGuilds.htm");
VALID_LINKS.add("adventurer_guildsman/AboutNewLifeCrystals.htm");
VALID_LINKS.add("clanHallDoorman/evolve.htm");
VALID_LINKS.add("common/augmentation_01.htm");
VALID_LINKS.add("common/augmentation_02.htm");
VALID_LINKS.add("common/crafting_01.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/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/fishing_championship.htm");
VALID_LINKS.add("fortress/foreman.htm");
VALID_LINKS.add("guard/kamaloka_help.htm");
VALID_LINKS.add("guard/kamaloka_level.htm");
VALID_LINKS.add("olympiad/hero_main2.htm");
VALID_LINKS.add("petmanager/evolve.htm");
VALID_LINKS.add("petmanager/exchange.htm");
VALID_LINKS.add("petmanager/instructions.htm");
VALID_LINKS.add("seven_signs/blkmrkt_1.htm");
VALID_LINKS.add("seven_signs/blkmrkt_2.htm");
VALID_LINKS.add("seven_signs/mammblack_1a.htm");
VALID_LINKS.add("seven_signs/mammblack_1b.htm");
VALID_LINKS.add("seven_signs/mammblack_1c.htm");
VALID_LINKS.add("seven_signs/mammblack_2a.htm");
VALID_LINKS.add("seven_signs/mammblack_2b.htm");
VALID_LINKS.add("seven_signs/mammmerch_1.htm");
VALID_LINKS.add("seven_signs/mammmerch_1a.htm");
VALID_LINKS.add("seven_signs/mammmerch_1b.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

@@ -16,7 +16,7 @@
*/
package handlers.itemhandlers;
import java.util.List;
import java.util.Set;
import org.l2jmobius.Config;
import org.l2jmobius.gameserver.data.xml.PetDataTable;
@@ -82,15 +82,12 @@ public class PetFood implements IItemHandler
final Player player = activeChar.getActingPlayer();
if (player.isMounted())
{
final List<Integer> foodIds = PetDataTable.getInstance().getPetData(player.getMountNpcId()).getFood();
if (foodIds.contains(item.getId()))
final Set<Integer> foodIds = PetDataTable.getInstance().getPetData(player.getMountNpcId()).getFood();
if (foodIds.contains(item.getId()) && player.destroyItem("Consume", item.getObjectId(), 1, null, false))
{
if (player.destroyItem("Consume", item.getObjectId(), 1, null, false))
{
player.broadcastPacket(new MagicSkillUse(player, player, skillId, skillLevel, 0, 0));
player.setCurrentFeed(player.getCurrentFeed() + skill.getFeed());
return true;
}
player.broadcastPacket(new MagicSkillUse(player, player, skillId, skillLevel, 0, 0));
player.setCurrentFeed(player.getCurrentFeed() + skill.getFeed());
return true;
}
}
final SystemMessage sm = new SystemMessage(SystemMessageId.S1_CANNOT_BE_USED_DUE_TO_UNSUITABLE_TERMS);

View File

@@ -277,7 +277,7 @@ public class Config
public static boolean AUTO_LOOT_SLOT_LIMIT;
public static int LOOT_RAIDS_PRIVILEGE_INTERVAL;
public static int LOOT_RAIDS_PRIVILEGE_CC_SIZE;
public static List<Integer> AUTO_LOOT_ITEM_IDS;
public static Set<Integer> AUTO_LOOT_ITEM_IDS;
public static boolean ENABLE_KEYBOARD_MOVEMENT;
public static int UNSTUCK_INTERVAL;
public static int TELEPORT_WATCHDOG_TIMEOUT;
@@ -521,7 +521,7 @@ public class Config
public static boolean ALLOW_DISCARDITEM;
public static int AUTODESTROY_ITEM_AFTER;
public static int HERB_AUTO_DESTROY_TIME;
public static List<Integer> LIST_PROTECTED_ITEMS;
public static Set<Integer> LIST_PROTECTED_ITEMS;
public static boolean DATABASE_CLEAN_UP;
public static int CHAR_DATA_STORE_INTERVAL;
public static boolean LAZY_ITEMS_UPDATE;
@@ -617,7 +617,7 @@ public class Config
public static boolean ALT_OLY_LOG_FIGHTS;
public static boolean ALT_OLY_SHOW_MONTHLY_WINNERS;
public static boolean ALT_OLY_ANNOUNCE_GAMES;
public static List<Integer> LIST_OLY_RESTRICTED_ITEMS = new ArrayList<>();
public static Set<Integer> LIST_OLY_RESTRICTED_ITEMS = new HashSet<>();
public static int ALT_OLY_ENCHANT_LIMIT;
public static int ALT_OLY_WAIT_TIME;
public static boolean ALT_OLY_USE_CUSTOM_PERIOD_SETTINGS;
@@ -1232,9 +1232,9 @@ public class Config
public static int AUTO_CP_PERCENTAGE;
public static int AUTO_HP_PERCENTAGE;
public static int AUTO_MP_PERCENTAGE;
public static List<Integer> AUTO_CP_ITEM_IDS;
public static List<Integer> AUTO_HP_ITEM_IDS;
public static List<Integer> AUTO_MP_ITEM_IDS;
public static Set<Integer> AUTO_CP_ITEM_IDS;
public static Set<Integer> AUTO_HP_ITEM_IDS;
public static Set<Integer> AUTO_MP_ITEM_IDS;
public static boolean CUSTOM_STARTING_LOC;
public static int CUSTOM_STARTING_LOC_X;
public static int CUSTOM_STARTING_LOC_Y;
@@ -1244,7 +1244,7 @@ public class Config
public static boolean ENABLE_RANDOM_MONSTER_SPAWNS;
public static int MOB_MIN_SPAWN_RANGE;
public static int MOB_MAX_SPAWN_RANGE;
public static List<Integer> MOBS_LIST_NOT_RANDOM;
public static Set<Integer> MOBS_LIST_NOT_RANDOM;
public static boolean CUSTOM_CB_ENABLED;
public static int COMMUNITYBOARD_CURRENCY;
public static boolean COMMUNITYBOARD_ENABLE_MULTISELLS;
@@ -1262,7 +1262,7 @@ public class Config
public static boolean COMMUNITY_PREMIUM_SYSTEM_ENABLED;
public static int COMMUNITY_PREMIUM_COIN_ID;
public static int COMMUNITY_PREMIUM_PRICE_PER_DAY;
public static List<Integer> COMMUNITY_AVAILABLE_BUFFS;
public static Set<Integer> COMMUNITY_AVAILABLE_BUFFS;
public static Map<String, Location> COMMUNITY_AVAILABLE_TELEPORTS;
public static boolean CUSTOM_MAIL_MANAGER_ENABLED;
public static int CUSTOM_MAIL_MANAGER_DELAY;
@@ -1934,7 +1934,7 @@ public class Config
LOOT_RAIDS_PRIVILEGE_INTERVAL = characterConfig.getInt("RaidLootRightsInterval", 900) * 1000;
LOOT_RAIDS_PRIVILEGE_CC_SIZE = characterConfig.getInt("RaidLootRightsCCSize", 45);
final String[] autoLootItemIds = characterConfig.getString("AutoLootItemIds", "0").split(",");
AUTO_LOOT_ITEM_IDS = new ArrayList<>(autoLootItemIds.length);
AUTO_LOOT_ITEM_IDS = new HashSet<>(autoLootItemIds.length);
for (String item : autoLootItemIds)
{
Integer itm = 0;
@@ -2049,7 +2049,7 @@ public class Config
AUTODESTROY_ITEM_AFTER = generalConfig.getInt("AutoDestroyDroppedItemAfter", 600);
HERB_AUTO_DESTROY_TIME = generalConfig.getInt("AutoDestroyHerbTime", 60) * 1000;
final String[] split = generalConfig.getString("ListOfProtectedItems", "0").split(",");
LIST_PROTECTED_ITEMS = new ArrayList<>(split.length);
LIST_PROTECTED_ITEMS = new HashSet<>(split.length);
for (String id : split)
{
LIST_PROTECTED_ITEMS.add(Integer.parseInt(id));
@@ -2490,7 +2490,7 @@ public class Config
if (!olyRestrictedItems.isEmpty())
{
final String[] olyRestrictedItemsSplit = olyRestrictedItems.split(",");
LIST_OLY_RESTRICTED_ITEMS = new ArrayList<>(olyRestrictedItemsSplit.length);
LIST_OLY_RESTRICTED_ITEMS = new HashSet<>(olyRestrictedItemsSplit.length);
for (String id : olyRestrictedItemsSplit)
{
LIST_OLY_RESTRICTED_ITEMS.add(Integer.parseInt(id));
@@ -2632,17 +2632,17 @@ public class Config
AUTO_CP_PERCENTAGE = autoPotionsConfig.getInt("AutoCpPercentage", 70);
AUTO_HP_PERCENTAGE = autoPotionsConfig.getInt("AutoHpPercentage", 70);
AUTO_MP_PERCENTAGE = autoPotionsConfig.getInt("AutoMpPercentage", 70);
AUTO_CP_ITEM_IDS = new ArrayList<>();
AUTO_CP_ITEM_IDS = new HashSet<>();
for (String s : autoPotionsConfig.getString("AutoCpItemIds", "0").split(","))
{
AUTO_CP_ITEM_IDS.add(Integer.parseInt(s));
}
AUTO_HP_ITEM_IDS = new ArrayList<>();
AUTO_HP_ITEM_IDS = new HashSet<>();
for (String s : autoPotionsConfig.getString("AutoHpItemIds", "0").split(","))
{
AUTO_HP_ITEM_IDS.add(Integer.parseInt(s));
}
AUTO_MP_ITEM_IDS = new ArrayList<>();
AUTO_MP_ITEM_IDS = new HashSet<>();
for (String s : autoPotionsConfig.getString("AutoMpItemIds", "0").split(","))
{
AUTO_MP_ITEM_IDS.add(Integer.parseInt(s));
@@ -2746,7 +2746,7 @@ public class Config
COMMUNITY_PREMIUM_COIN_ID = communityBoardConfig.getInt("CommunityPremiumBuyCoinId", 57);
COMMUNITY_PREMIUM_PRICE_PER_DAY = communityBoardConfig.getInt("CommunityPremiumPricePerDay", 1000000);
final String[] allowedBuffs = communityBoardConfig.getString("CommunityAvailableBuffs", "").split(",");
COMMUNITY_AVAILABLE_BUFFS = new ArrayList<>(allowedBuffs.length);
COMMUNITY_AVAILABLE_BUFFS = new HashSet<>(allowedBuffs.length);
for (String s : allowedBuffs)
{
COMMUNITY_AVAILABLE_BUFFS.add(Integer.parseInt(s));
@@ -3015,7 +3015,7 @@ public class Config
if (ENABLE_RANDOM_MONSTER_SPAWNS)
{
final String[] mobsIds = randomSpawnsConfig.getString("MobsSpawnNotRandom", "18812,18813,18814,22138").split(",");
MOBS_LIST_NOT_RANDOM = new ArrayList<>(mobsIds.length);
MOBS_LIST_NOT_RANDOM = new HashSet<>(mobsIds.length);
for (String id : mobsIds)
{
MOBS_LIST_NOT_RANDOM.add(Integer.parseInt(id));

View File

@@ -17,10 +17,10 @@
package org.l2jmobius.gameserver.data.xml;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.logging.Logger;
import org.w3c.dom.Document;
@@ -42,7 +42,7 @@ public class FakePlayerData implements IXmlReader
private final Map<Integer, FakePlayerHolder> _fakePlayerInfos = new HashMap<>();
private final Map<String, String> _fakePlayerNames = new HashMap<>();
private final Map<String, Integer> _fakePlayerIds = new HashMap<>();
private final List<String> _talkableFakePlayerNames = new ArrayList<>();
private final Set<String> _talkableFakePlayerNames = new HashSet<>();
protected FakePlayerData()
{

View File

@@ -41,8 +41,8 @@ import org.l2jmobius.gameserver.enums.Race;
import org.l2jmobius.gameserver.enums.SocialClass;
import org.l2jmobius.gameserver.model.SkillLearn;
import org.l2jmobius.gameserver.model.SkillLearn.SubClassData;
import org.l2jmobius.gameserver.model.actor.Player;
import org.l2jmobius.gameserver.model.StatSet;
import org.l2jmobius.gameserver.model.actor.Player;
import org.l2jmobius.gameserver.model.clan.Clan;
import org.l2jmobius.gameserver.model.holders.ItemHolder;
import org.l2jmobius.gameserver.model.holders.PlayerSkillHolder;

View File

@@ -18,7 +18,9 @@ package org.l2jmobius.gameserver.instancemanager;
import java.io.File;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.logging.Logger;
import org.w3c.dom.Document;
@@ -49,7 +51,7 @@ import org.l2jmobius.gameserver.util.Util;
public class SellBuffsManager implements IXmlReader
{
private static final Logger LOGGER = Logger.getLogger(SellBuffsManager.class.getName());
private static final List<Integer> ALLOWED_BUFFS = new ArrayList<>();
private static final Set<Integer> ALLOWED_BUFFS = new HashSet<>();
private static final String HTML_FOLDER = "data/html/mods/SellBuffs/";
protected SellBuffsManager()
@@ -76,11 +78,7 @@ public class SellBuffsManager implements IXmlReader
{
final Element elem = (Element) node.item(i);
final int skillId = Integer.parseInt(elem.getAttribute("id"));
if (!ALLOWED_BUFFS.contains(skillId))
{
ALLOWED_BUFFS.add(skillId);
}
ALLOWED_BUFFS.add(skillId);
}
}

View File

@@ -19,8 +19,10 @@ package org.l2jmobius.gameserver.instancemanager;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture;
import java.util.logging.Logger;
@@ -67,7 +69,7 @@ public class WalkingManager implements IXmlReader
public static final byte REPEAT_TELE_FIRST = 2;
public static final byte REPEAT_RANDOM = 3;
private final List<Integer> _targetedNpcIds = new ArrayList<>();
private final Set<Integer> _targetedNpcIds = new HashSet<>();
private final Map<String, WalkRoute> _routes = new HashMap<>(); // all available routes
private final Map<Integer, WalkInfo> _activeRoutes = new HashMap<>(); // each record represents NPC, moving by predefined route from _routes, and moving progress
private final Map<Integer, NpcRoutesHolder> _routesToAttach = new HashMap<>(); // each record represents NPC and all available routes for it

View File

@@ -19,9 +19,9 @@ package org.l2jmobius.gameserver.model;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -35,10 +35,11 @@ import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
public class BlockList
{
private static final Logger LOGGER = Logger.getLogger(BlockList.class.getName());
private static final Map<Integer, List<Integer>> OFFLINE_LIST = new ConcurrentHashMap<>();
private static final Map<Integer, Set<Integer>> OFFLINE_LIST = new ConcurrentHashMap<>();
private final Player _owner;
private List<Integer> _blockList;
private Set<Integer> _blockList;
public BlockList(Player owner)
{
@@ -67,9 +68,9 @@ public class BlockList
OFFLINE_LIST.put(_owner.getObjectId(), _blockList);
}
private static List<Integer> loadList(int objId)
private static Set<Integer> loadList(int objId)
{
final List<Integer> list = new ArrayList<>();
final Set<Integer> list = new HashSet<>();
try (Connection con = DatabaseFactory.getConnection();
PreparedStatement statement = con.prepareStatement("SELECT friendId FROM character_friends WHERE charId=? AND relation=1"))
{
@@ -157,7 +158,7 @@ public class BlockList
_owner.setMessageRefusal(value);
}
private List<Integer> getBlockList()
private Set<Integer> getBlockList()
{
return _blockList;
}

View File

@@ -18,8 +18,10 @@ package org.l2jmobius.gameserver.model;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.l2jmobius.gameserver.data.xml.SkillData;
import org.l2jmobius.gameserver.model.holders.SkillHolder;
@@ -39,7 +41,7 @@ public class PetData
private int _hungryLimit = 1;
private int _minLevel = Byte.MAX_VALUE;
private boolean _syncLevel = false;
private final List<Integer> _food = new ArrayList<>();
private final Set<Integer> _food = new HashSet<>();
public PetData(int npcId, int itemId)
{
@@ -120,7 +122,7 @@ public class PetData
/**
* @return the pet's food list.
*/
public List<Integer> getFood()
public Set<Integer> getFood()
{
return _food;
}

View File

@@ -17,7 +17,10 @@
package org.l2jmobius.gameserver.model;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.l2jmobius.Config;
import org.l2jmobius.gameserver.enums.ClassId;
@@ -37,13 +40,13 @@ public class SkillLearn
private final int _getLevel;
private final boolean _autoGet;
private final int _levelUpSp;
private final List<ItemHolder> _requiredItems = new ArrayList<>();
private final List<Race> _races = new ArrayList<>();
private final List<SkillHolder> _preReqSkills = new ArrayList<>();
private final Set<ItemHolder> _requiredItems = new HashSet<>(1);
private final Set<Race> _races = EnumSet.noneOf(Race.class);
private final Set<SkillHolder> _preReqSkills = new HashSet<>(1);
private SocialClass _socialClass;
private final boolean _residenceSkill;
private final List<Integer> _residenceIds = new ArrayList<>();
private final List<SubClassData> _subClassLvlNumber = new ArrayList<>();
private final Set<Integer> _residenceIds = new HashSet<>(1);
private final List<SubClassData> _subClassLvlNumber = new ArrayList<>(1);
private final boolean _learnedByNpc;
private final boolean _learnedByFS;
@@ -141,9 +144,9 @@ public class SkillLearn
}
/**
* @return the list with the item holders required to acquire this skill.
* @return the set with the item holders required to acquire this skill.
*/
public List<ItemHolder> getRequiredItems()
public Set<ItemHolder> getRequiredItems()
{
return _requiredItems;
}
@@ -158,9 +161,9 @@ public class SkillLearn
}
/**
* @return a list with the races that can acquire this skill.
* @return a set with the races that can acquire this skill.
*/
public List<Race> getRaces()
public Set<Race> getRaces()
{
return _races;
}
@@ -175,9 +178,9 @@ public class SkillLearn
}
/**
* @return the list of skill holders required to acquire this skill.
* @return the set of skill holders required to acquire this skill.
*/
public List<SkillHolder> getPreReqSkills()
public Set<SkillHolder> getPreReqSkills()
{
return _preReqSkills;
}
@@ -220,9 +223,9 @@ public class SkillLearn
}
/**
* @return a list with the Ids where this skill is available.
* @return a set with the Ids where this skill is available.
*/
public List<Integer> getResidenceIds()
public Set<Integer> getResidenceIds()
{
return _residenceIds;
}

View File

@@ -21,6 +21,7 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.Future;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -172,7 +173,7 @@ public class Pet extends Summon
setCurrentFed(_curFed > getFeedConsume() ? _curFed - getFeedConsume() : 0);
broadcastStatusUpdate();
final List<Integer> foodIds = getPetData().getFood();
final Set<Integer> foodIds = getPetData().getFood();
if (foodIds.isEmpty())
{
if (isUncontrollable())

View File

@@ -16,8 +16,8 @@
*/
package org.l2jmobius.gameserver.model.actor.instance;
import java.util.ArrayList;
import java.util.List;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.ScheduledFuture;
import org.l2jmobius.commons.threads.ThreadPool;
@@ -57,7 +57,7 @@ public class Trap extends Npc
private boolean _isTriggered;
private final int _lifeTime;
private Player _owner;
private final List<Integer> _playersWhoDetectedMe = new ArrayList<>();
private final Set<Integer> _playersWhoDetectedMe = new HashSet<>();
private final SkillHolder _skill;
private int _remainingTime;
// Tasks

View File

@@ -16,7 +16,7 @@
*/
package org.l2jmobius.gameserver.model.actor.tasks.player;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -69,7 +69,7 @@ public class PetFeedTask implements Runnable
return;
}
final List<Integer> foodIds = PetDataTable.getInstance().getPetData(_player.getMountNpcId()).getFood();
final Set<Integer> foodIds = PetDataTable.getInstance().getPetData(_player.getMountNpcId()).getFood();
if (foodIds.isEmpty())
{
return;

View File

@@ -16,7 +16,7 @@
*/
package org.l2jmobius.gameserver.model.conditions;
import java.util.List;
import java.util.Set;
import org.l2jmobius.gameserver.instancemanager.ZoneManager;
import org.l2jmobius.gameserver.model.actor.Creature;
@@ -29,9 +29,9 @@ import org.l2jmobius.gameserver.model.zone.ZoneType;
*/
public class ConditionPlayerInsideZoneId extends Condition
{
private final List<Integer> _zones;
private final Set<Integer> _zones;
public ConditionPlayerInsideZoneId(List<Integer> zones)
public ConditionPlayerInsideZoneId(Set<Integer> zones)
{
_zones = zones;
}

View File

@@ -16,7 +16,7 @@
*/
package org.l2jmobius.gameserver.model.conditions;
import java.util.List;
import java.util.Set;
import org.l2jmobius.gameserver.instancemanager.InstanceManager;
import org.l2jmobius.gameserver.model.actor.Creature;
@@ -29,13 +29,13 @@ import org.l2jmobius.gameserver.model.skill.Skill;
*/
public class ConditionPlayerInstanceId extends Condition
{
private final List<Integer> _instanceIds;
private final Set<Integer> _instanceIds;
/**
* Instantiates a new condition player instance id.
* @param instanceIds the instance ids
*/
public ConditionPlayerInstanceId(List<Integer> instanceIds)
public ConditionPlayerInstanceId(Set<Integer> instanceIds)
{
_instanceIds = instanceIds;
}

View File

@@ -16,7 +16,8 @@
*/
package org.l2jmobius.gameserver.model.conditions;
import org.l2jmobius.commons.util.CommonUtil;
import java.util.Set;
import org.l2jmobius.gameserver.enums.Race;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.item.ItemTemplate;
@@ -28,13 +29,13 @@ import org.l2jmobius.gameserver.model.skill.Skill;
*/
public class ConditionPlayerRace extends Condition
{
private final Race[] _races;
private final Set<Race> _races;
/**
* Instantiates a new condition player race.
* @param races the list containing the allowed races.
*/
public ConditionPlayerRace(Race[] races)
public ConditionPlayerRace(Set<Race> races)
{
_races = races;
}
@@ -42,6 +43,10 @@ public class ConditionPlayerRace extends Condition
@Override
public boolean testImpl(Creature effector, Creature effected, Skill skill, ItemTemplate item)
{
return (effector != null) && effector.isPlayer() && CommonUtil.contains(_races, effector.getActingPlayer().getRace());
if ((effector == null) || !effector.isPlayer())
{
return false;
}
return _races.contains(effector.getActingPlayer().getRace());
}
}

View File

@@ -16,7 +16,8 @@
*/
package org.l2jmobius.gameserver.model.conditions;
import org.l2jmobius.commons.util.CommonUtil;
import java.util.Set;
import org.l2jmobius.gameserver.model.World;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.actor.Npc;
@@ -30,13 +31,13 @@ import org.l2jmobius.gameserver.model.skill.Skill;
public class ConditionPlayerRangeFromNpc extends Condition
{
/** NPC Ids. */
private final int[] _npcIds;
private final Set<Integer> _npcIds;
/** Radius to check. */
private final int _radius;
/** Expected value. */
private final boolean _value;
public ConditionPlayerRangeFromNpc(int[] npcIds, int radius, boolean value)
public ConditionPlayerRangeFromNpc(Set<Integer> npcIds, int radius, boolean value)
{
_npcIds = npcIds;
_radius = radius;
@@ -47,11 +48,11 @@ public class ConditionPlayerRangeFromNpc extends Condition
public boolean testImpl(Creature effector, Creature effected, Skill skill, ItemTemplate item)
{
boolean existNpc = false;
if ((_npcIds != null) && (_npcIds.length > 0) && (_radius > 0))
if (!_npcIds.isEmpty() && (_radius > 0))
{
for (Npc target : World.getInstance().getVisibleObjectsInRange(effector, Npc.class, _radius))
{
if (CommonUtil.contains(_npcIds, target.getId()))
if (_npcIds.contains(target.getId()))
{
existNpc = true;
break;

View File

@@ -16,7 +16,7 @@
*/
package org.l2jmobius.gameserver.model.conditions;
import java.util.List;
import java.util.Set;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.item.ItemTemplate;
@@ -27,13 +27,13 @@ import org.l2jmobius.gameserver.model.skill.Skill;
*/
public class ConditionTargetClassIdRestriction extends Condition
{
private final List<Integer> _classIds;
private final Set<Integer> _classIds;
/**
* Instantiates a new condition target class id restriction.
* @param classId the class id
*/
public ConditionTargetClassIdRestriction(List<Integer> classId)
public ConditionTargetClassIdRestriction(Set<Integer> classId)
{
_classIds = classId;
}

View File

@@ -16,7 +16,7 @@
*/
package org.l2jmobius.gameserver.model.conditions;
import java.util.List;
import java.util.Set;
import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.actor.Creature;
@@ -28,13 +28,13 @@ import org.l2jmobius.gameserver.model.skill.Skill;
*/
public class ConditionTargetNpcId extends Condition
{
private final List<Integer> _npcIds;
private final Set<Integer> _npcIds;
/**
* Instantiates a new condition target npc id.
* @param npcIds the npc ids
*/
public ConditionTargetNpcId(List<Integer> npcIds)
public ConditionTargetNpcId(Set<Integer> npcIds)
{
_npcIds = npcIds;
}

View File

@@ -16,7 +16,7 @@
*/
package org.l2jmobius.gameserver.model.holders;
import java.util.Collection;
import java.util.Set;
/**
* @author Mobius
@@ -25,9 +25,9 @@ public class EventDropHolder extends DropHolder
{
private final int _minLevel;
private final int _maxLevel;
private final Collection<Integer> _monsterIds;
private final Set<Integer> _monsterIds;
public EventDropHolder(int itemId, long min, long max, double chance, int minLevel, int maxLevel, Collection<Integer> monsterIds)
public EventDropHolder(int itemId, long min, long max, double chance, int minLevel, int maxLevel, Set<Integer> monsterIds)
{
super(null, itemId, min, max, chance);
_minLevel = minLevel;
@@ -45,7 +45,7 @@ public class EventDropHolder extends DropHolder
return _maxLevel;
}
public Collection<Integer> getMonsterIds()
public Set<Integer> getMonsterIds()
{
return _monsterIds;
}

View File

@@ -16,8 +16,9 @@
*/
package org.l2jmobius.gameserver.model.item;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;
import org.l2jmobius.gameserver.enums.ClassId;
import org.l2jmobius.gameserver.model.StatSet;
@@ -40,7 +41,7 @@ public class Henna
private final int _wearCount;
private final int _cancelFee;
private final int _cancelCount;
private final List<ClassId> _wearClass;
private final Set<ClassId> _wearClass;
public Henna(StatSet set)
{
@@ -56,7 +57,7 @@ public class Henna
_wearCount = set.getInt("wear_count");
_cancelFee = set.getInt("cancel_fee");
_cancelCount = set.getInt("cancel_count");
_wearClass = new ArrayList<>();
_wearClass = EnumSet.noneOf(ClassId.class);
}
/**
@@ -158,7 +159,7 @@ public class Henna
/**
* @return the list with the allowed classes to wear this dye.
*/
public List<ClassId> getAllowedWearClass()
public Set<ClassId> getAllowedWearClass()
{
return _wearClass;
}

View File

@@ -16,16 +16,16 @@
*/
package org.l2jmobius.gameserver.model.item.enchant;
import java.util.EnumSet;
import java.util.Set;
import java.util.logging.Logger;
import org.l2jmobius.commons.util.CommonUtil;
import org.l2jmobius.gameserver.data.ItemTable;
import org.l2jmobius.gameserver.model.StatSet;
import org.l2jmobius.gameserver.model.item.ItemTemplate;
import org.l2jmobius.gameserver.model.item.instance.Item;
import org.l2jmobius.gameserver.model.item.type.CrystalType;
import org.l2jmobius.gameserver.model.item.type.EtcItemType;
import org.l2jmobius.gameserver.model.item.type.ItemType;
/**
* @author UnAfraid
@@ -34,17 +34,18 @@ public abstract class AbstractEnchantItem
{
protected static final Logger LOGGER = Logger.getLogger(AbstractEnchantItem.class.getName());
private static final ItemType[] ENCHANT_TYPES = new ItemType[]
private static final Set<EtcItemType> ENCHANT_TYPES = EnumSet.noneOf(EtcItemType.class);
static
{
EtcItemType.ANCIENT_CRYSTAL_ENCHANT_AM,
EtcItemType.ANCIENT_CRYSTAL_ENCHANT_WP,
EtcItemType.BLESS_SCRL_ENCHANT_AM,
EtcItemType.BLESS_SCRL_ENCHANT_WP,
EtcItemType.SCRL_ENCHANT_AM,
EtcItemType.SCRL_ENCHANT_WP,
EtcItemType.SCRL_INC_ENCHANT_PROP_AM,
EtcItemType.SCRL_INC_ENCHANT_PROP_WP,
};
ENCHANT_TYPES.add(EtcItemType.ANCIENT_CRYSTAL_ENCHANT_AM);
ENCHANT_TYPES.add(EtcItemType.ANCIENT_CRYSTAL_ENCHANT_WP);
ENCHANT_TYPES.add(EtcItemType.BLESS_SCRL_ENCHANT_AM);
ENCHANT_TYPES.add(EtcItemType.BLESS_SCRL_ENCHANT_WP);
ENCHANT_TYPES.add(EtcItemType.SCRL_ENCHANT_AM);
ENCHANT_TYPES.add(EtcItemType.SCRL_ENCHANT_WP);
ENCHANT_TYPES.add(EtcItemType.SCRL_INC_ENCHANT_PROP_AM);
ENCHANT_TYPES.add(EtcItemType.SCRL_INC_ENCHANT_PROP_WP);
}
private final int _id;
private final CrystalType _grade;
@@ -58,7 +59,7 @@ public abstract class AbstractEnchantItem
{
throw new NullPointerException();
}
else if (!CommonUtil.contains(ENCHANT_TYPES, getItem().getItemType()))
else if (!ENCHANT_TYPES.contains(getItem().getItemType()))
{
throw new IllegalAccessError();
}
@@ -146,7 +147,7 @@ public abstract class AbstractEnchantItem
* @param type2
* @return {@code true} if current type2 is valid to be enchanted, {@code false} otherwise
*/
private final boolean isValidItemType(int type2)
private boolean isValidItemType(int type2)
{
if (type2 == ItemTemplate.TYPE2_WEAPON)
{

View File

@@ -24,8 +24,10 @@ import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.logging.Level;
import javax.xml.parsers.DocumentBuilder;
@@ -175,7 +177,7 @@ public class LongTimeEvent extends Quest
final Node maxLevelNode = d.getAttributes().getNamedItem("maxLevel");
final int maxLevel = maxLevelNode == null ? Integer.MAX_VALUE : Integer.parseInt(maxLevelNode.getNodeValue());
final Node monsterIdsNode = d.getAttributes().getNamedItem("monsterIds");
final List<Integer> monsterIds = new ArrayList<>();
final Set<Integer> monsterIds = new HashSet<>();
if (monsterIdsNode != null)
{
for (String id : monsterIdsNode.getNodeValue().split(","))

View File

@@ -21,8 +21,10 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -78,8 +80,8 @@ public class Castle extends AbstractResidence
private SiegeZone _zone = null;
private ResidenceTeleportZone _teleZone;
private Clan _formerOwner = null;
private final List<Artefact> _artefacts = new ArrayList<>(1);
private final Map<Integer, CastleFunction> _function;
private final Set<Artefact> _artefacts = new HashSet<>(1);
private final Map<Integer, CastleFunction> _function = new ConcurrentHashMap<>();
private int _ticketBuyCount = 0;
private boolean _isFirstMidVictory = false;
@@ -237,10 +239,6 @@ public class Castle extends AbstractResidence
{
super(castleId);
load();
/*
* if (getResidenceId() == 7 || castleId == 9) // Goddard and Schuttgart _nbArtifact = 2;
*/
_function = new ConcurrentHashMap<>();
initResidenceZone();
if (_ownerId != 0)
{
@@ -1075,7 +1073,7 @@ public class Castle extends AbstractResidence
_artefacts.add(artefact);
}
public List<Artefact> getArtefacts()
public Set<Artefact> getArtefacts()
{
return _artefacts;
}

View File

@@ -18,6 +18,7 @@ package org.l2jmobius.gameserver.util;
import java.io.File;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -476,12 +477,12 @@ public abstract class DocumentBase
case "races":
{
final String[] racesVal = a.getNodeValue().split(",");
final Race[] races = new Race[racesVal.length];
final Set<Race> races = EnumSet.noneOf(Race.class);
for (int r = 0; r < racesVal.length; r++)
{
if (racesVal[r] != null)
{
races[r] = Race.valueOf(racesVal[r]);
races.add(Race.valueOf(racesVal[r]));
}
}
cond = joinAnd(cond, new ConditionPlayerRace(races));
@@ -752,13 +753,13 @@ public abstract class DocumentBase
case "instanceid":
{
final StringTokenizer st = new StringTokenizer(a.getNodeValue(), ",");
final List<Integer> array = new ArrayList<>(st.countTokens());
final Set<Integer> set = new HashSet<>(st.countTokens());
while (st.hasMoreTokens())
{
final String item = st.nextToken().trim();
array.add(Integer.decode(getValue(item, null)));
set.add(Integer.decode(getValue(item, null)));
}
cond = joinAnd(cond, new ConditionPlayerInstanceId(array));
cond = joinAnd(cond, new ConditionPlayerInstanceId(set));
break;
}
case "agathionid":
@@ -803,10 +804,10 @@ public abstract class DocumentBase
if (st.countTokens() == 3)
{
final String[] ids = st.nextToken().split(";");
final int[] npcIds = new int[ids.length];
final Set<Integer> npcIds = new HashSet<>(ids.length);
for (int index = 0; index < ids.length; index++)
{
npcIds[index] = Integer.parseInt(getValue(ids[index], template));
npcIds.add(Integer.parseInt(getValue(ids[index], template)));
}
final int radius = Integer.parseInt(st.nextToken());
final boolean val = Boolean.parseBoolean(st.nextToken());
@@ -882,13 +883,13 @@ public abstract class DocumentBase
case "insidezoneid":
{
final StringTokenizer st = new StringTokenizer(a.getNodeValue(), ",");
final List<Integer> array = new ArrayList<>(st.countTokens());
final Set<Integer> set = new HashSet<>(st.countTokens());
while (st.hasMoreTokens())
{
final String item = st.nextToken().trim();
array.add(Integer.decode(getValue(item, null)));
set.add(Integer.decode(getValue(item, null)));
}
cond = joinAnd(cond, new ConditionPlayerInsideZoneId(array));
cond = joinAnd(cond, new ConditionPlayerInsideZoneId(set));
break;
}
case "checkabnormal":
@@ -978,13 +979,13 @@ public abstract class DocumentBase
case "class_id_restriction":
{
final StringTokenizer st = new StringTokenizer(a.getNodeValue(), ",");
final List<Integer> array = new ArrayList<>(st.countTokens());
final Set<Integer> set = new HashSet<>(st.countTokens());
while (st.hasMoreTokens())
{
final String item = st.nextToken().trim();
array.add(Integer.decode(getValue(item, null)));
set.add(Integer.decode(getValue(item, null)));
}
cond = joinAnd(cond, new ConditionTargetClassIdRestriction(array));
cond = joinAnd(cond, new ConditionTargetClassIdRestriction(set));
break;
}
case "active_effect_id":
@@ -1062,13 +1063,13 @@ public abstract class DocumentBase
case "npcid":
{
final StringTokenizer st = new StringTokenizer(a.getNodeValue(), ",");
final List<Integer> array = new ArrayList<>(st.countTokens());
final Set<Integer> set = new HashSet<>(st.countTokens());
while (st.hasMoreTokens())
{
final String item = st.nextToken().trim();
array.add(Integer.decode(getValue(item, null)));
set.add(Integer.decode(getValue(item, null)));
}
cond = joinAnd(cond, new ConditionTargetNpcId(array));
cond = joinAnd(cond, new ConditionTargetNpcId(set));
break;
}
case "npctype":