/
tofu
/
l2interlude
Обзор
Документация
Войти
/
tofu
/
l2interlude
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
src/main/java/com/l2jserver/gameserver/engines/DocumentEngine.java
120 строк
4 KB
Zoey76
Copyright Update
01 янв 2025, 07:57
01 янв 2025, 07:57
16130a5
Код
Авторство
О чём код?
/* * Copyright © 2004-2025 L2J Server * * This file is part of L2J Server. * * L2J Server is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * L2J Server is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package com.l2jserver.gameserver.engines; import static com.l2jserver.gameserver.config.Configuration.general; import static com.l2jserver.gameserver.config.Configuration.server; import java.io.File; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.function.Function; import java.util.stream.Collectors; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.l2jserver.gameserver.datatables.SkillData; import com.l2jserver.gameserver.engines.items.DocumentItem; import com.l2jserver.gameserver.engines.skills.DocumentSkill; import com.l2jserver.gameserver.model.items.L2Item; import com.l2jserver.gameserver.model.skills.Skill; import com.l2jserver.gameserver.util.file.filter.XMLFilter; /** * Document Engine. * @author mkizub */ public class DocumentEngine { private static final Logger LOG = LoggerFactory.getLogger(DocumentEngine.class); private final List<File> _itemFiles = new ArrayList<>(); private final List<File> _skillFiles = new ArrayList<>(); public static DocumentEngine getInstance() { return SingletonHolder._instance; } protected DocumentEngine() { hashFiles("data/stats/items", _itemFiles); if (general().customItemsLoad()) { hashFiles("data/stats/items/custom", _itemFiles); } hashFiles("data/stats/skills", _skillFiles); if (general().customSkillsLoad()) { hashFiles("data/stats/skills/custom", _skillFiles); } } private void hashFiles(String dirname, List<File> hash) { final var dir = new File(server().getDatapackRoot(), dirname); if (!dir.exists()) { LOG.warn("Directory {} does not exists!", dir.getAbsolutePath()); return; } final var files = dir.listFiles(new XMLFilter()); if (files != null) { Collections.addAll(hash, files); } } private List<Skill> loadSkills(File file) { if (file == null) { LOG.warn("Skill file not found!"); return null; } DocumentSkill doc = new DocumentSkill(file); doc.parse(); return doc.getSkills(); } public Map<Integer, Skill> loadAllSkills() { return _skillFiles.parallelStream() .map(this::loadSkills) .filter(Objects::nonNull) .flatMap(List::stream) .collect(Collectors.toConcurrentMap(SkillData::getSkillHashCode, Function.identity())); } /** * Return created items * @return List of {@link L2Item} */ public List<L2Item> loadItems() { return _itemFiles.parallelStream() .filter(Objects::nonNull) .map(DocumentItem::new) .map(doc -> { doc.parse(); return doc.getItemList(); }) .flatMap(List::stream) .toList(); } private static class SingletonHolder { protected static final DocumentEngine _instance = new DocumentEngine(); } }