Document parsing classes moved to util.
This commit is contained in:
@ -16,9 +16,12 @@
|
||||
*/
|
||||
package org.l2jmobius.gameserver.datatables;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
@ -30,8 +33,6 @@ import org.l2jmobius.Config;
|
||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||
import org.l2jmobius.commons.database.DatabaseFactory;
|
||||
import org.l2jmobius.gameserver.datatables.sql.PetDataTable;
|
||||
import org.l2jmobius.gameserver.engines.DocumentEngine;
|
||||
import org.l2jmobius.gameserver.engines.ItemDataHolder;
|
||||
import org.l2jmobius.gameserver.instancemanager.IdManager;
|
||||
import org.l2jmobius.gameserver.model.World;
|
||||
import org.l2jmobius.gameserver.model.WorldObject;
|
||||
@ -45,6 +46,7 @@ import org.l2jmobius.gameserver.model.items.Item;
|
||||
import org.l2jmobius.gameserver.model.items.Weapon;
|
||||
import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
||||
import org.l2jmobius.gameserver.model.items.instance.ItemInstance.ItemLocation;
|
||||
import org.l2jmobius.gameserver.util.DocumentItem;
|
||||
|
||||
/**
|
||||
* @version $Revision: 1.9.2.6.2.9 $ $Date: 2005/04/02 15:57:34 $
|
||||
@ -58,6 +60,7 @@ public class ItemTable
|
||||
private final Map<Integer, EtcItem> _etcItems;
|
||||
private final Map<Integer, Armor> _armors;
|
||||
private final Map<Integer, Weapon> _weapons;
|
||||
private final List<File> _itemFiles = new ArrayList<>();
|
||||
|
||||
private static final Map<String, Integer> _crystalTypes = new HashMap<>();
|
||||
static
|
||||
@ -70,33 +73,57 @@ public class ItemTable
|
||||
_crystalTypes.put("none", Item.CRYSTAL_NONE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new object Item
|
||||
* @return
|
||||
*/
|
||||
public ItemDataHolder newItem()
|
||||
{
|
||||
return new ItemDataHolder();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
private ItemTable()
|
||||
{
|
||||
hashFiles("data/stats/items", _itemFiles);
|
||||
_etcItems = new HashMap<>();
|
||||
_armors = new HashMap<>();
|
||||
_weapons = new HashMap<>();
|
||||
load();
|
||||
}
|
||||
|
||||
private void hashFiles(String dirname, List<File> hash)
|
||||
{
|
||||
final File dir = new File(Config.DATAPACK_ROOT, dirname);
|
||||
if (!dir.exists())
|
||||
{
|
||||
LOGGER.info("Dir " + dir.getAbsolutePath() + " not exists");
|
||||
return;
|
||||
}
|
||||
final File[] files = dir.listFiles();
|
||||
for (File f : files)
|
||||
{
|
||||
if (f.getName().endsWith(".xml") && !f.getName().startsWith("custom"))
|
||||
{
|
||||
hash.add(f);
|
||||
}
|
||||
}
|
||||
final File customfile = new File(Config.DATAPACK_ROOT, dirname + "/custom.xml");
|
||||
if (customfile.exists())
|
||||
{
|
||||
hash.add(customfile);
|
||||
}
|
||||
}
|
||||
|
||||
public List<Item> loadItems()
|
||||
{
|
||||
final List<Item> list = new ArrayList<>();
|
||||
for (File f : _itemFiles)
|
||||
{
|
||||
final DocumentItem document = new DocumentItem(f);
|
||||
document.parse();
|
||||
list.addAll(document.getItemList());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private void load()
|
||||
{
|
||||
int highest = 0;
|
||||
_armors.clear();
|
||||
_etcItems.clear();
|
||||
_weapons.clear();
|
||||
for (Item item : DocumentEngine.getInstance().loadItems())
|
||||
for (Item item : loadItems())
|
||||
{
|
||||
if (highest < item.getItemId())
|
||||
{
|
||||
|
@ -16,27 +16,91 @@
|
||||
*/
|
||||
package org.l2jmobius.gameserver.datatables;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.l2jmobius.gameserver.engines.DocumentEngine;
|
||||
import org.l2jmobius.Config;
|
||||
import org.l2jmobius.gameserver.model.Skill;
|
||||
import org.l2jmobius.gameserver.model.items.type.WeaponType;
|
||||
import org.l2jmobius.gameserver.util.DocumentSkill;
|
||||
|
||||
public class SkillTable
|
||||
{
|
||||
protected static final Logger LOGGER = Logger.getLogger(SkillTable.class.getName());
|
||||
|
||||
private final List<File> _skillFiles = new ArrayList<>();
|
||||
private final Map<Integer, Skill> _skills = new HashMap<>();
|
||||
private final boolean _initialized = true;
|
||||
|
||||
private SkillTable()
|
||||
{
|
||||
hashFiles("data/stats/skills", _skillFiles);
|
||||
|
||||
reload();
|
||||
}
|
||||
|
||||
private void hashFiles(String dirname, List<File> hash)
|
||||
{
|
||||
final File dir = new File(Config.DATAPACK_ROOT, dirname);
|
||||
if (!dir.exists())
|
||||
{
|
||||
LOGGER.info("Dir " + dir.getAbsolutePath() + " not exists");
|
||||
return;
|
||||
}
|
||||
final File[] files = dir.listFiles();
|
||||
for (File f : files)
|
||||
{
|
||||
if (f.getName().endsWith(".xml") && !f.getName().startsWith("custom"))
|
||||
{
|
||||
hash.add(f);
|
||||
}
|
||||
}
|
||||
final File customfile = new File(Config.DATAPACK_ROOT, dirname + "/custom.xml");
|
||||
if (customfile.exists())
|
||||
{
|
||||
hash.add(customfile);
|
||||
}
|
||||
}
|
||||
|
||||
public List<Skill> loadSkills(File file)
|
||||
{
|
||||
if (file == null)
|
||||
{
|
||||
LOGGER.warning("Skill file not found.");
|
||||
return null;
|
||||
}
|
||||
final DocumentSkill doc = new DocumentSkill(file);
|
||||
doc.parse();
|
||||
return doc.getSkills();
|
||||
}
|
||||
|
||||
public void loadAllSkills(Map<Integer, Skill> allSkills)
|
||||
{
|
||||
int count = 0;
|
||||
for (File file : _skillFiles)
|
||||
{
|
||||
final List<Skill> s = loadSkills(file);
|
||||
if (s == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
for (Skill skill : s)
|
||||
{
|
||||
allSkills.put(SkillTable.getSkillHashCode(skill), skill);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
LOGGER.info("SkillsEngine: Loaded " + count + " skill templates.");
|
||||
}
|
||||
|
||||
public void reload()
|
||||
{
|
||||
_skills.clear();
|
||||
DocumentEngine.getInstance().loadAllSkills(_skills);
|
||||
loadAllSkills(_skills);
|
||||
}
|
||||
|
||||
public boolean isInitialized()
|
||||
|
@ -1,125 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 org.l2jmobius.gameserver.engines;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.l2jmobius.Config;
|
||||
import org.l2jmobius.gameserver.datatables.SkillTable;
|
||||
import org.l2jmobius.gameserver.model.Skill;
|
||||
import org.l2jmobius.gameserver.model.items.Item;
|
||||
|
||||
/**
|
||||
* @author mkizub
|
||||
*/
|
||||
public class DocumentEngine
|
||||
{
|
||||
protected static final Logger LOGGER = Logger.getLogger(DocumentEngine.class.getName());
|
||||
|
||||
private final List<File> _itemFiles = new ArrayList<>();
|
||||
private final List<File> _skillFiles = new ArrayList<>();
|
||||
|
||||
public static DocumentEngine getInstance()
|
||||
{
|
||||
return SingletonHolder.INSTANCE;
|
||||
}
|
||||
|
||||
private DocumentEngine()
|
||||
{
|
||||
hashFiles("data/stats/items", _itemFiles);
|
||||
hashFiles("data/stats/skills", _skillFiles);
|
||||
}
|
||||
|
||||
private void hashFiles(String dirname, List<File> hash)
|
||||
{
|
||||
final File dir = new File(Config.DATAPACK_ROOT, dirname);
|
||||
if (!dir.exists())
|
||||
{
|
||||
LOGGER.info("Dir " + dir.getAbsolutePath() + " not exists");
|
||||
return;
|
||||
}
|
||||
final File[] files = dir.listFiles();
|
||||
for (File f : files)
|
||||
{
|
||||
if (f.getName().endsWith(".xml") && !f.getName().startsWith("custom"))
|
||||
{
|
||||
hash.add(f);
|
||||
}
|
||||
}
|
||||
final File customfile = new File(Config.DATAPACK_ROOT, dirname + "/custom.xml");
|
||||
if (customfile.exists())
|
||||
{
|
||||
hash.add(customfile);
|
||||
}
|
||||
}
|
||||
|
||||
public List<Skill> loadSkills(File file)
|
||||
{
|
||||
if (file == null)
|
||||
{
|
||||
LOGGER.warning("Skill file not found.");
|
||||
return null;
|
||||
}
|
||||
final DocumentSkill doc = new DocumentSkill(file);
|
||||
doc.parse();
|
||||
return doc.getSkills();
|
||||
}
|
||||
|
||||
public void loadAllSkills(Map<Integer, Skill> allSkills)
|
||||
{
|
||||
int count = 0;
|
||||
for (File file : _skillFiles)
|
||||
{
|
||||
final List<Skill> s = loadSkills(file);
|
||||
if (s == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
for (Skill skill : s)
|
||||
{
|
||||
allSkills.put(SkillTable.getSkillHashCode(skill), skill);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
LOGGER.info("SkillsEngine: Loaded " + count + " skill templates.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Return created items
|
||||
* @return List of {@link Item}
|
||||
*/
|
||||
public List<Item> loadItems()
|
||||
{
|
||||
final List<Item> list = new ArrayList<>();
|
||||
for (File f : _itemFiles)
|
||||
{
|
||||
final DocumentItem document = new DocumentItem(f);
|
||||
document.parse();
|
||||
list.addAll(document.getItemList());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final DocumentEngine INSTANCE = new DocumentEngine();
|
||||
}
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 org.l2jmobius.gameserver.engines;
|
||||
|
||||
import org.l2jmobius.gameserver.model.StatSet;
|
||||
import org.l2jmobius.gameserver.model.items.Item;
|
||||
|
||||
/**
|
||||
* @author luisantonioa
|
||||
* @version $Revision: 1.2 $ $Date: 2004/06/27 08:12:59 $
|
||||
*/
|
||||
public class ItemDataHolder
|
||||
{
|
||||
public int id;
|
||||
public Enum<?> type;
|
||||
public String name;
|
||||
public StatSet set;
|
||||
public int currentLevel;
|
||||
public Item item;
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 org.l2jmobius.gameserver.engines;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.l2jmobius.gameserver.model.Skill;
|
||||
import org.l2jmobius.gameserver.model.StatSet;
|
||||
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class SkillDataHolder
|
||||
{
|
||||
public int id;
|
||||
public String name;
|
||||
public StatSet[] sets;
|
||||
public StatSet[] enchsets1;
|
||||
public StatSet[] enchsets2;
|
||||
public int currentLevel;
|
||||
public List<Skill> skills = new ArrayList<>();
|
||||
public List<Skill> currentSkills = new ArrayList<>();
|
||||
}
|
@ -14,7 +14,7 @@
|
||||
* 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 org.l2jmobius.gameserver.engines;
|
||||
package org.l2jmobius.gameserver.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
@ -93,7 +93,7 @@ public abstract class DocumentBase
|
||||
_tables = new HashMap<>();
|
||||
}
|
||||
|
||||
Document parse()
|
||||
public Document parse()
|
||||
{
|
||||
Document doc;
|
||||
try
|
@ -14,7 +14,7 @@
|
||||
* 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 org.l2jmobius.gameserver.engines;
|
||||
package org.l2jmobius.gameserver.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
@ -38,11 +38,20 @@ import org.l2jmobius.gameserver.model.items.type.WeaponType;
|
||||
/**
|
||||
* @author mkizub, JIV
|
||||
*/
|
||||
final class DocumentItem extends DocumentBase
|
||||
public class DocumentItem extends DocumentBase
|
||||
{
|
||||
private ItemDataHolder _currentItem = null;
|
||||
private DocumentItemDataHolder _currentItem = null;
|
||||
private final List<Item> _itemsInFile = new ArrayList<>();
|
||||
|
||||
private class DocumentItemDataHolder
|
||||
{
|
||||
public int id;
|
||||
public Enum<?> type;
|
||||
public StatSet set;
|
||||
public int currentLevel;
|
||||
public Item item;
|
||||
}
|
||||
|
||||
private static final Map<String, Integer> _slots = new HashMap<>();
|
||||
static
|
||||
{
|
||||
@ -134,7 +143,7 @@ final class DocumentItem extends DocumentBase
|
||||
{
|
||||
try
|
||||
{
|
||||
_currentItem = new ItemDataHolder();
|
||||
_currentItem = new DocumentItemDataHolder();
|
||||
parseItem(d);
|
||||
_itemsInFile.add(_currentItem.item);
|
||||
resetTable();
|
||||
@ -149,7 +158,7 @@ final class DocumentItem extends DocumentBase
|
||||
}
|
||||
}
|
||||
|
||||
protected void parseItem(Node node)
|
||||
private void parseItem(Node node)
|
||||
{
|
||||
Node n = node;
|
||||
final int itemId = Integer.parseInt(n.getAttributes().getNamedItem("id").getNodeValue());
|
||||
@ -157,7 +166,6 @@ final class DocumentItem extends DocumentBase
|
||||
final String itemName = n.getAttributes().getNamedItem("name").getNodeValue();
|
||||
|
||||
_currentItem.id = itemId;
|
||||
_currentItem.name = itemName;
|
||||
_currentItem.set = new StatSet();
|
||||
_currentItem.set.set("item_id", itemId);
|
||||
_currentItem.set.set("name", itemName);
|
@ -14,7 +14,7 @@
|
||||
* 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 org.l2jmobius.gameserver.engines;
|
||||
package org.l2jmobius.gameserver.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
@ -32,17 +32,29 @@ import org.l2jmobius.gameserver.model.skills.conditions.Condition;
|
||||
/**
|
||||
* @author mkizub
|
||||
*/
|
||||
final class DocumentSkill extends DocumentBase
|
||||
public class DocumentSkill extends DocumentBase
|
||||
{
|
||||
private SkillDataHolder _currentSkill;
|
||||
private DocumentSkillDataHolder _currentSkill;
|
||||
private final List<Skill> _skillsInFile = new ArrayList<>();
|
||||
|
||||
DocumentSkill(File file)
|
||||
private class DocumentSkillDataHolder
|
||||
{
|
||||
public int id;
|
||||
public String name;
|
||||
public StatSet[] sets;
|
||||
public StatSet[] enchsets1;
|
||||
public StatSet[] enchsets2;
|
||||
public int currentLevel;
|
||||
public List<Skill> skills = new ArrayList<>();
|
||||
public List<Skill> currentSkills = new ArrayList<>();
|
||||
}
|
||||
|
||||
public DocumentSkill(File file)
|
||||
{
|
||||
super(file);
|
||||
}
|
||||
|
||||
private void setCurrentSkill(SkillDataHolder skill)
|
||||
private void setCurrentSkill(DocumentSkillDataHolder skill)
|
||||
{
|
||||
_currentSkill = skill;
|
||||
}
|
||||
@ -53,11 +65,6 @@ final class DocumentSkill extends DocumentBase
|
||||
return _currentSkill.sets[_currentSkill.currentLevel];
|
||||
}
|
||||
|
||||
protected List<Skill> getSkills()
|
||||
{
|
||||
return _skillsInFile;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTableValue(String name)
|
||||
{
|
||||
@ -97,7 +104,7 @@ final class DocumentSkill extends DocumentBase
|
||||
{
|
||||
if ("skill".equalsIgnoreCase(d.getNodeName()))
|
||||
{
|
||||
setCurrentSkill(new SkillDataHolder());
|
||||
setCurrentSkill(new DocumentSkillDataHolder());
|
||||
parseSkill(d);
|
||||
_skillsInFile.addAll(_currentSkill.skills);
|
||||
resetTable();
|
||||
@ -106,14 +113,14 @@ final class DocumentSkill extends DocumentBase
|
||||
}
|
||||
else if ("skill".equalsIgnoreCase(n.getNodeName()))
|
||||
{
|
||||
setCurrentSkill(new SkillDataHolder());
|
||||
setCurrentSkill(new DocumentSkillDataHolder());
|
||||
parseSkill(n);
|
||||
_skillsInFile.addAll(_currentSkill.skills);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void parseSkill(Node node)
|
||||
private void parseSkill(Node node)
|
||||
{
|
||||
Node n = node;
|
||||
final NamedNodeMap attrs = n.getAttributes();
|
||||
@ -402,4 +409,9 @@ final class DocumentSkill extends DocumentBase
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<Skill> getSkills()
|
||||
{
|
||||
return _skillsInFile;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user