Document parsing classes moved to util.

This commit is contained in:
MobiusDevelopment
2020-11-03 22:11:38 +00:00
parent caf29354ac
commit 9903058be9
158 changed files with 19637 additions and 22684 deletions

View File

@ -18,12 +18,16 @@ package org.l2jmobius.gameserver.datatables;
import static org.l2jmobius.gameserver.model.itemcontainer.Inventory.ADENA_ID;
import java.io.File;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
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.Level;
import java.util.logging.Logger;
@ -31,8 +35,8 @@ import java.util.logging.Logger;
import org.l2jmobius.Config;
import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.commons.util.file.filter.XMLFilter;
import org.l2jmobius.gameserver.data.xml.impl.EnchantItemHPBonusData;
import org.l2jmobius.gameserver.engines.DocumentEngine;
import org.l2jmobius.gameserver.enums.ItemLocation;
import org.l2jmobius.gameserver.instancemanager.IdManager;
import org.l2jmobius.gameserver.model.World;
@ -48,6 +52,7 @@ import org.l2jmobius.gameserver.model.items.EtcItem;
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.util.DocumentItem;
import org.l2jmobius.gameserver.util.GMAudit;
/**
@ -58,12 +63,13 @@ public class ItemTable
private static final Logger LOGGER = Logger.getLogger(ItemTable.class.getName());
private static Logger LOGGER_ITEMS = Logger.getLogger("item");
public static final Map<String, Integer> SLOTS = new HashMap<>();
private Item[] _allTemplates;
private final Map<Integer, EtcItem> _etcItems = new HashMap<>();
private final Map<Integer, Armor> _armors = new HashMap<>();
private final Map<Integer, Weapon> _weapons = new HashMap<>();
private final List<File> _itemFiles = new ArrayList<>();
public static final Map<String, Integer> SLOTS = new HashMap<>();
static
{
SLOTS.put("shirt", Item.SLOT_UNDERWEAR);
@ -106,26 +112,77 @@ public class ItemTable
SLOTS.put("waist", Item.SLOT_BELT);
}
/**
* @return a reference to this ItemTable object
*/
public static ItemTable getInstance()
{
return SingletonHolder.INSTANCE;
}
protected ItemTable()
{
processDirectory("data/stats/items", _itemFiles);
if (Config.CUSTOM_ITEMS_LOAD)
{
processDirectory("data/stats/items/custom", _itemFiles);
}
load();
}
private void processDirectory(String dirName, List<File> list)
{
final File dir = new File(Config.DATAPACK_ROOT, dirName);
if (!dir.exists())
{
LOGGER.warning("Dir " + dir.getAbsolutePath() + " does not exist.");
return;
}
final File[] files = dir.listFiles(new XMLFilter());
for (File file : files)
{
list.add(file);
}
}
private Collection<Item> loadItems()
{
final Collection<Item> list = ConcurrentHashMap.newKeySet();
if (Config.THREADS_FOR_LOADING)
{
final Collection<ScheduledFuture<?>> jobs = ConcurrentHashMap.newKeySet();
for (File file : _itemFiles)
{
jobs.add(ThreadPool.schedule(() ->
{
final DocumentItem document = new DocumentItem(file);
document.parse();
list.addAll(document.getItemList());
}, 0));
}
while (!jobs.isEmpty())
{
for (ScheduledFuture<?> job : jobs)
{
if ((job == null) || job.isDone() || job.isCancelled())
{
jobs.remove(job);
}
}
}
}
else
{
for (File file : _itemFiles)
{
final DocumentItem document = new DocumentItem(file);
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.getId())
{
@ -463,6 +520,11 @@ public class ItemTable
return _allTemplates.length;
}
public static ItemTable getInstance()
{
return SingletonHolder.INSTANCE;
}
private static class SingletonHolder
{
protected static final ItemTable INSTANCE = new ItemTable();

View File

@ -1,75 +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 org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.l2jmobius.gameserver.model.StatSet;
import org.l2jmobius.gameserver.model.conditions.Condition;
/**
* A dummy class designed only to parse conditions
* @author UnAfraid
*/
public class DocumentBaseGeneral extends DocumentBase
{
protected DocumentBaseGeneral(File file)
{
super(file);
}
@Override
protected void parseDocument(Document doc)
{
}
@Override
protected StatSet getStatSet()
{
return null;
}
@Override
protected String getTableValue(String name)
{
return null;
}
@Override
protected String getTableValue(String name, int idx)
{
return null;
}
public Condition parseCondition(Node n)
{
return super.parseCondition(n, null);
}
public static DocumentBaseGeneral getInstance()
{
return SingletonHolder.INSTANCE;
}
private static class SingletonHolder
{
protected static final DocumentBaseGeneral INSTANCE = new DocumentBaseGeneral(null);
}
}

View File

@ -1,117 +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.Collection;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture;
import java.util.logging.Logger;
import org.l2jmobius.Config;
import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.commons.util.file.filter.XMLFilter;
import org.l2jmobius.gameserver.engines.items.DocumentItem;
import org.l2jmobius.gameserver.model.items.Item;
/**
* @author mkizub
*/
public class DocumentEngine
{
private static final Logger LOGGER = Logger.getLogger(DocumentEngine.class.getName());
private final List<File> _itemFiles = new ArrayList<>();
protected DocumentEngine()
{
processDirectory("data/stats/items", _itemFiles);
if (Config.CUSTOM_ITEMS_LOAD)
{
processDirectory("data/stats/items/custom", _itemFiles);
}
}
private void processDirectory(String dirName, List<File> list)
{
final File dir = new File(Config.DATAPACK_ROOT, dirName);
if (!dir.exists())
{
LOGGER.warning("Dir " + dir.getAbsolutePath() + " does not exist.");
return;
}
final File[] files = dir.listFiles(new XMLFilter());
for (File file : files)
{
list.add(file);
}
}
/**
* Return created items
* @return List of {@link Item}
*/
public Collection<Item> loadItems()
{
final Collection<Item> list = ConcurrentHashMap.newKeySet();
if (Config.THREADS_FOR_LOADING)
{
final Collection<ScheduledFuture<?>> jobs = ConcurrentHashMap.newKeySet();
for (File file : _itemFiles)
{
jobs.add(ThreadPool.schedule(() ->
{
final DocumentItem document = new DocumentItem(file);
document.parse();
list.addAll(document.getItemList());
}, 0));
}
while (!jobs.isEmpty())
{
for (ScheduledFuture<?> job : jobs)
{
if ((job == null) || job.isDone() || job.isCancelled())
{
jobs.remove(job);
}
}
}
}
else
{
for (File file : _itemFiles)
{
final DocumentItem document = new DocumentItem(file);
document.parse();
list.addAll(document.getItemList());
}
}
return list;
}
private static class SingletonHolder
{
protected static final DocumentEngine INSTANCE = new DocumentEngine();
}
public static DocumentEngine getInstance()
{
return SingletonHolder.INSTANCE;
}
}

View File

@ -1,30 +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.items;
import org.l2jmobius.gameserver.model.StatSet;
import org.l2jmobius.gameserver.model.items.Item;
public class ItemDataHolder
{
int id;
String type;
String name;
StatSet set;
int currentLevel;
Item item;
}

View File

@ -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;
@ -75,7 +75,6 @@ import org.l2jmobius.gameserver.model.conditions.ConditionPlayerCloakStatus;
import org.l2jmobius.gameserver.model.conditions.ConditionPlayerCp;
import org.l2jmobius.gameserver.model.conditions.ConditionPlayerDualclass;
import org.l2jmobius.gameserver.model.conditions.ConditionPlayerFlyMounted;
import org.l2jmobius.gameserver.model.conditions.ConditionPlayerGrade;
import org.l2jmobius.gameserver.model.conditions.ConditionPlayerHasCastle;
import org.l2jmobius.gameserver.model.conditions.ConditionPlayerHasClanHall;
import org.l2jmobius.gameserver.model.conditions.ConditionPlayerHasFort;
@ -511,12 +510,6 @@ public abstract class DocumentBase
cond = joinAnd(cond, new ConditionPlayerCp(cp));
break;
}
case "grade":
{
final int expIndex = Integer.decode(getValue(a.getNodeValue(), template));
cond = joinAnd(cond, new ConditionPlayerGrade(expIndex));
break;
}
case "pkcount":
{
final int expIndex = Integer.decode(getValue(a.getNodeValue(), template));

View File

@ -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.items;
package org.l2jmobius.gameserver.util;
import java.io.File;
import java.lang.reflect.Constructor;
@ -28,7 +28,6 @@ import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.l2jmobius.commons.util.IXmlReader;
import org.l2jmobius.gameserver.engines.DocumentBase;
import org.l2jmobius.gameserver.enums.ItemSkillType;
import org.l2jmobius.gameserver.model.ExtractableProduct;
import org.l2jmobius.gameserver.model.StatSet;
@ -45,12 +44,18 @@ public class DocumentItem extends DocumentBase implements IXmlReader
{
private static final Logger LOGGER = Logger.getLogger(DocumentItem.class.getName());
private ItemDataHolder _currentItem = null;
private DocumentItemDataHolder _currentItem = null;
private final List<Item> _itemsInFile = new ArrayList<>();
/**
* @param file
*/
private class DocumentItemDataHolder
{
int id;
String type;
StatSet set;
int currentLevel;
Item item;
}
public DocumentItem(File file)
{
super(file);
@ -87,7 +92,7 @@ public class DocumentItem extends DocumentBase implements IXmlReader
{
try
{
_currentItem = new ItemDataHolder();
_currentItem = new DocumentItemDataHolder();
parseItem(d);
_itemsInFile.add(_currentItem.item);
resetTable();
@ -102,7 +107,7 @@ public class DocumentItem extends DocumentBase implements IXmlReader
}
}
protected void parseItem(Node node) throws InvocationTargetException
private void parseItem(Node node) throws InvocationTargetException
{
Node n = node;
final int itemId = Integer.parseInt(n.getAttributes().getNamedItem("id").getNodeValue());
@ -110,7 +115,6 @@ public class DocumentItem extends DocumentBase implements IXmlReader
final String itemName = n.getAttributes().getNamedItem("name").getNodeValue();
final String additionalName = n.getAttributes().getNamedItem("additionalName") != null ? n.getAttributes().getNamedItem("additionalName").getNodeValue() : null;
_currentItem.id = itemId;
_currentItem.name = itemName;
_currentItem.type = className;
_currentItem.set = new StatSet();
_currentItem.set.set("item_id", itemId);