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 static org.l2jmobius.gameserver.model.itemcontainer.Inventory.ADENA_ID;
import java.io.File;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -31,8 +35,8 @@ import java.util.logging.Logger;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.commons.database.DatabaseFactory; 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.data.xml.impl.EnchantItemHPBonusData;
import org.l2jmobius.gameserver.engines.DocumentEngine;
import org.l2jmobius.gameserver.enums.ItemLocation; import org.l2jmobius.gameserver.enums.ItemLocation;
import org.l2jmobius.gameserver.instancemanager.IdManager; import org.l2jmobius.gameserver.instancemanager.IdManager;
import org.l2jmobius.gameserver.model.World; 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.Item;
import org.l2jmobius.gameserver.model.items.Weapon; import org.l2jmobius.gameserver.model.items.Weapon;
import org.l2jmobius.gameserver.model.items.instance.ItemInstance; import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
import org.l2jmobius.gameserver.util.DocumentItem;
import org.l2jmobius.gameserver.util.GMAudit; 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 final Logger LOGGER = Logger.getLogger(ItemTable.class.getName());
private static Logger LOGGER_ITEMS = Logger.getLogger("item"); private static Logger LOGGER_ITEMS = Logger.getLogger("item");
public static final Map<String, Integer> SLOTS = new HashMap<>();
private Item[] _allTemplates; private Item[] _allTemplates;
private final Map<Integer, EtcItem> _etcItems = new HashMap<>(); private final Map<Integer, EtcItem> _etcItems = new HashMap<>();
private final Map<Integer, Armor> _armors = new HashMap<>(); private final Map<Integer, Armor> _armors = new HashMap<>();
private final Map<Integer, Weapon> _weapons = 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 static
{ {
SLOTS.put("shirt", Item.SLOT_UNDERWEAR); SLOTS.put("shirt", Item.SLOT_UNDERWEAR);
@ -106,26 +112,77 @@ public class ItemTable
SLOTS.put("waist", Item.SLOT_BELT); SLOTS.put("waist", Item.SLOT_BELT);
} }
/**
* @return a reference to this ItemTable object
*/
public static ItemTable getInstance()
{
return SingletonHolder.INSTANCE;
}
protected ItemTable() protected ItemTable()
{ {
processDirectory("data/stats/items", _itemFiles);
if (Config.CUSTOM_ITEMS_LOAD)
{
processDirectory("data/stats/items/custom", _itemFiles);
}
load(); 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() private void load()
{ {
int highest = 0; int highest = 0;
_armors.clear(); _armors.clear();
_etcItems.clear(); _etcItems.clear();
_weapons.clear(); _weapons.clear();
for (Item item : DocumentEngine.getInstance().loadItems()) for (Item item : loadItems())
{ {
if (highest < item.getId()) if (highest < item.getId())
{ {
@ -463,6 +520,11 @@ public class ItemTable
return _allTemplates.length; return _allTemplates.length;
} }
public static ItemTable getInstance()
{
return SingletonHolder.INSTANCE;
}
private static class SingletonHolder private static class SingletonHolder
{ {
protected static final ItemTable INSTANCE = new ItemTable(); 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 * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * 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.io.File;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * 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.io.File;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
@ -28,7 +28,6 @@ import org.w3c.dom.Document;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.l2jmobius.commons.util.IXmlReader; import org.l2jmobius.commons.util.IXmlReader;
import org.l2jmobius.gameserver.engines.DocumentBase;
import org.l2jmobius.gameserver.enums.ItemSkillType; import org.l2jmobius.gameserver.enums.ItemSkillType;
import org.l2jmobius.gameserver.model.ExtractableProduct; import org.l2jmobius.gameserver.model.ExtractableProduct;
import org.l2jmobius.gameserver.model.StatSet; 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 static final Logger LOGGER = Logger.getLogger(DocumentItem.class.getName());
private ItemDataHolder _currentItem = null; private DocumentItemDataHolder _currentItem = null;
private final List<Item> _itemsInFile = new ArrayList<>(); private final List<Item> _itemsInFile = new ArrayList<>();
/** private class DocumentItemDataHolder
* @param file {
*/ int id;
String type;
StatSet set;
int currentLevel;
Item item;
}
public DocumentItem(File file) public DocumentItem(File file)
{ {
super(file); super(file);
@ -87,7 +92,7 @@ public class DocumentItem extends DocumentBase implements IXmlReader
{ {
try try
{ {
_currentItem = new ItemDataHolder(); _currentItem = new DocumentItemDataHolder();
parseItem(d); parseItem(d);
_itemsInFile.add(_currentItem.item); _itemsInFile.add(_currentItem.item);
resetTable(); 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; Node n = node;
final int itemId = Integer.parseInt(n.getAttributes().getNamedItem("id").getNodeValue()); 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 itemName = n.getAttributes().getNamedItem("name").getNodeValue();
final String additionalName = n.getAttributes().getNamedItem("additionalName") != null ? n.getAttributes().getNamedItem("additionalName").getNodeValue() : null; final String additionalName = n.getAttributes().getNamedItem("additionalName") != null ? n.getAttributes().getNamedItem("additionalName").getNodeValue() : null;
_currentItem.id = itemId; _currentItem.id = itemId;
_currentItem.name = itemName;
_currentItem.type = className; _currentItem.type = className;
_currentItem.set = new StatSet(); _currentItem.set = new StatSet();
_currentItem.set.set("item_id", itemId); _currentItem.set.set("item_id", itemId);

View File

@ -18,12 +18,16 @@ package org.l2jmobius.gameserver.datatables;
import static org.l2jmobius.gameserver.model.itemcontainer.Inventory.ADENA_ID; import static org.l2jmobius.gameserver.model.itemcontainer.Inventory.ADENA_ID;
import java.io.File;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -31,8 +35,8 @@ import java.util.logging.Logger;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.commons.database.DatabaseFactory; 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.data.xml.impl.EnchantItemHPBonusData;
import org.l2jmobius.gameserver.engines.DocumentEngine;
import org.l2jmobius.gameserver.enums.ItemLocation; import org.l2jmobius.gameserver.enums.ItemLocation;
import org.l2jmobius.gameserver.instancemanager.IdManager; import org.l2jmobius.gameserver.instancemanager.IdManager;
import org.l2jmobius.gameserver.model.World; 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.Item;
import org.l2jmobius.gameserver.model.items.Weapon; import org.l2jmobius.gameserver.model.items.Weapon;
import org.l2jmobius.gameserver.model.items.instance.ItemInstance; import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
import org.l2jmobius.gameserver.util.DocumentItem;
import org.l2jmobius.gameserver.util.GMAudit; 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 final Logger LOGGER = Logger.getLogger(ItemTable.class.getName());
private static Logger LOGGER_ITEMS = Logger.getLogger("item"); private static Logger LOGGER_ITEMS = Logger.getLogger("item");
public static final Map<String, Integer> SLOTS = new HashMap<>();
private Item[] _allTemplates; private Item[] _allTemplates;
private final Map<Integer, EtcItem> _etcItems = new HashMap<>(); private final Map<Integer, EtcItem> _etcItems = new HashMap<>();
private final Map<Integer, Armor> _armors = new HashMap<>(); private final Map<Integer, Armor> _armors = new HashMap<>();
private final Map<Integer, Weapon> _weapons = 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 static
{ {
SLOTS.put("shirt", Item.SLOT_UNDERWEAR); SLOTS.put("shirt", Item.SLOT_UNDERWEAR);
@ -106,26 +112,77 @@ public class ItemTable
SLOTS.put("waist", Item.SLOT_BELT); SLOTS.put("waist", Item.SLOT_BELT);
} }
/**
* @return a reference to this ItemTable object
*/
public static ItemTable getInstance()
{
return SingletonHolder.INSTANCE;
}
protected ItemTable() protected ItemTable()
{ {
processDirectory("data/stats/items", _itemFiles);
if (Config.CUSTOM_ITEMS_LOAD)
{
processDirectory("data/stats/items/custom", _itemFiles);
}
load(); 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() private void load()
{ {
int highest = 0; int highest = 0;
_armors.clear(); _armors.clear();
_etcItems.clear(); _etcItems.clear();
_weapons.clear(); _weapons.clear();
for (Item item : DocumentEngine.getInstance().loadItems()) for (Item item : loadItems())
{ {
if (highest < item.getId()) if (highest < item.getId())
{ {
@ -463,6 +520,11 @@ public class ItemTable
return _allTemplates.length; return _allTemplates.length;
} }
public static ItemTable getInstance()
{
return SingletonHolder.INSTANCE;
}
private static class SingletonHolder private static class SingletonHolder
{ {
protected static final ItemTable INSTANCE = new ItemTable(); 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 * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * 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.io.File;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * 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.io.File;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
@ -28,7 +28,6 @@ import org.w3c.dom.Document;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.l2jmobius.commons.util.IXmlReader; import org.l2jmobius.commons.util.IXmlReader;
import org.l2jmobius.gameserver.engines.DocumentBase;
import org.l2jmobius.gameserver.enums.ItemSkillType; import org.l2jmobius.gameserver.enums.ItemSkillType;
import org.l2jmobius.gameserver.model.ExtractableProduct; import org.l2jmobius.gameserver.model.ExtractableProduct;
import org.l2jmobius.gameserver.model.StatSet; 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 static final Logger LOGGER = Logger.getLogger(DocumentItem.class.getName());
private ItemDataHolder _currentItem = null; private DocumentItemDataHolder _currentItem = null;
private final List<Item> _itemsInFile = new ArrayList<>(); private final List<Item> _itemsInFile = new ArrayList<>();
/** private class DocumentItemDataHolder
* @param file {
*/ int id;
String type;
StatSet set;
int currentLevel;
Item item;
}
public DocumentItem(File file) public DocumentItem(File file)
{ {
super(file); super(file);
@ -87,7 +92,7 @@ public class DocumentItem extends DocumentBase implements IXmlReader
{ {
try try
{ {
_currentItem = new ItemDataHolder(); _currentItem = new DocumentItemDataHolder();
parseItem(d); parseItem(d);
_itemsInFile.add(_currentItem.item); _itemsInFile.add(_currentItem.item);
resetTable(); 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; Node n = node;
final int itemId = Integer.parseInt(n.getAttributes().getNamedItem("id").getNodeValue()); 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 itemName = n.getAttributes().getNamedItem("name").getNodeValue();
final String additionalName = n.getAttributes().getNamedItem("additionalName") != null ? n.getAttributes().getNamedItem("additionalName").getNodeValue() : null; final String additionalName = n.getAttributes().getNamedItem("additionalName") != null ? n.getAttributes().getNamedItem("additionalName").getNodeValue() : null;
_currentItem.id = itemId; _currentItem.id = itemId;
_currentItem.name = itemName;
_currentItem.type = className; _currentItem.type = className;
_currentItem.set = new StatSet(); _currentItem.set = new StatSet();
_currentItem.set.set("item_id", itemId); _currentItem.set.set("item_id", itemId);

View File

@ -18,12 +18,16 @@ package org.l2jmobius.gameserver.datatables;
import static org.l2jmobius.gameserver.model.itemcontainer.Inventory.ADENA_ID; import static org.l2jmobius.gameserver.model.itemcontainer.Inventory.ADENA_ID;
import java.io.File;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -31,8 +35,8 @@ import java.util.logging.Logger;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.commons.database.DatabaseFactory; 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.data.xml.impl.EnchantItemHPBonusData;
import org.l2jmobius.gameserver.engines.DocumentEngine;
import org.l2jmobius.gameserver.enums.ItemLocation; import org.l2jmobius.gameserver.enums.ItemLocation;
import org.l2jmobius.gameserver.instancemanager.IdManager; import org.l2jmobius.gameserver.instancemanager.IdManager;
import org.l2jmobius.gameserver.model.World; 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.Item;
import org.l2jmobius.gameserver.model.items.Weapon; import org.l2jmobius.gameserver.model.items.Weapon;
import org.l2jmobius.gameserver.model.items.instance.ItemInstance; import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
import org.l2jmobius.gameserver.util.DocumentItem;
import org.l2jmobius.gameserver.util.GMAudit; 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 final Logger LOGGER = Logger.getLogger(ItemTable.class.getName());
private static Logger LOGGER_ITEMS = Logger.getLogger("item"); private static Logger LOGGER_ITEMS = Logger.getLogger("item");
public static final Map<String, Integer> SLOTS = new HashMap<>();
private Item[] _allTemplates; private Item[] _allTemplates;
private final Map<Integer, EtcItem> _etcItems = new HashMap<>(); private final Map<Integer, EtcItem> _etcItems = new HashMap<>();
private final Map<Integer, Armor> _armors = new HashMap<>(); private final Map<Integer, Armor> _armors = new HashMap<>();
private final Map<Integer, Weapon> _weapons = 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 static
{ {
SLOTS.put("shirt", Item.SLOT_UNDERWEAR); SLOTS.put("shirt", Item.SLOT_UNDERWEAR);
@ -106,26 +112,77 @@ public class ItemTable
SLOTS.put("waist", Item.SLOT_BELT); SLOTS.put("waist", Item.SLOT_BELT);
} }
/**
* @return a reference to this ItemTable object
*/
public static ItemTable getInstance()
{
return SingletonHolder.INSTANCE;
}
protected ItemTable() protected ItemTable()
{ {
processDirectory("data/stats/items", _itemFiles);
if (Config.CUSTOM_ITEMS_LOAD)
{
processDirectory("data/stats/items/custom", _itemFiles);
}
load(); 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() private void load()
{ {
int highest = 0; int highest = 0;
_armors.clear(); _armors.clear();
_etcItems.clear(); _etcItems.clear();
_weapons.clear(); _weapons.clear();
for (Item item : DocumentEngine.getInstance().loadItems()) for (Item item : loadItems())
{ {
if (highest < item.getId()) if (highest < item.getId())
{ {
@ -463,6 +520,11 @@ public class ItemTable
return _allTemplates.length; return _allTemplates.length;
} }
public static ItemTable getInstance()
{
return SingletonHolder.INSTANCE;
}
private static class SingletonHolder private static class SingletonHolder
{ {
protected static final ItemTable INSTANCE = new ItemTable(); 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 * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * 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.io.File;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * 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.io.File;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
@ -28,7 +28,6 @@ import org.w3c.dom.Document;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.l2jmobius.commons.util.IXmlReader; import org.l2jmobius.commons.util.IXmlReader;
import org.l2jmobius.gameserver.engines.DocumentBase;
import org.l2jmobius.gameserver.enums.ItemSkillType; import org.l2jmobius.gameserver.enums.ItemSkillType;
import org.l2jmobius.gameserver.model.ExtractableProduct; import org.l2jmobius.gameserver.model.ExtractableProduct;
import org.l2jmobius.gameserver.model.StatSet; 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 static final Logger LOGGER = Logger.getLogger(DocumentItem.class.getName());
private ItemDataHolder _currentItem = null; private DocumentItemDataHolder _currentItem = null;
private final List<Item> _itemsInFile = new ArrayList<>(); private final List<Item> _itemsInFile = new ArrayList<>();
/** private class DocumentItemDataHolder
* @param file {
*/ int id;
String type;
StatSet set;
int currentLevel;
Item item;
}
public DocumentItem(File file) public DocumentItem(File file)
{ {
super(file); super(file);
@ -87,7 +92,7 @@ public class DocumentItem extends DocumentBase implements IXmlReader
{ {
try try
{ {
_currentItem = new ItemDataHolder(); _currentItem = new DocumentItemDataHolder();
parseItem(d); parseItem(d);
_itemsInFile.add(_currentItem.item); _itemsInFile.add(_currentItem.item);
resetTable(); 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; Node n = node;
final int itemId = Integer.parseInt(n.getAttributes().getNamedItem("id").getNodeValue()); 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 itemName = n.getAttributes().getNamedItem("name").getNodeValue();
final String additionalName = n.getAttributes().getNamedItem("additionalName") != null ? n.getAttributes().getNamedItem("additionalName").getNodeValue() : null; final String additionalName = n.getAttributes().getNamedItem("additionalName") != null ? n.getAttributes().getNamedItem("additionalName").getNodeValue() : null;
_currentItem.id = itemId; _currentItem.id = itemId;
_currentItem.name = itemName;
_currentItem.type = className; _currentItem.type = className;
_currentItem.set = new StatSet(); _currentItem.set = new StatSet();
_currentItem.set.set("item_id", itemId); _currentItem.set.set("item_id", itemId);

View File

@ -18,12 +18,16 @@ package org.l2jmobius.gameserver.datatables;
import static org.l2jmobius.gameserver.model.itemcontainer.Inventory.ADENA_ID; import static org.l2jmobius.gameserver.model.itemcontainer.Inventory.ADENA_ID;
import java.io.File;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -31,8 +35,8 @@ import java.util.logging.Logger;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.commons.database.DatabaseFactory; 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.data.xml.impl.EnchantItemHPBonusData;
import org.l2jmobius.gameserver.engines.DocumentEngine;
import org.l2jmobius.gameserver.enums.ItemLocation; import org.l2jmobius.gameserver.enums.ItemLocation;
import org.l2jmobius.gameserver.instancemanager.IdManager; import org.l2jmobius.gameserver.instancemanager.IdManager;
import org.l2jmobius.gameserver.model.World; 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.Item;
import org.l2jmobius.gameserver.model.items.Weapon; import org.l2jmobius.gameserver.model.items.Weapon;
import org.l2jmobius.gameserver.model.items.instance.ItemInstance; import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
import org.l2jmobius.gameserver.util.DocumentItem;
import org.l2jmobius.gameserver.util.GMAudit; 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 final Logger LOGGER = Logger.getLogger(ItemTable.class.getName());
private static Logger LOGGER_ITEMS = Logger.getLogger("item"); private static Logger LOGGER_ITEMS = Logger.getLogger("item");
public static final Map<String, Integer> SLOTS = new HashMap<>();
private Item[] _allTemplates; private Item[] _allTemplates;
private final Map<Integer, EtcItem> _etcItems = new HashMap<>(); private final Map<Integer, EtcItem> _etcItems = new HashMap<>();
private final Map<Integer, Armor> _armors = new HashMap<>(); private final Map<Integer, Armor> _armors = new HashMap<>();
private final Map<Integer, Weapon> _weapons = 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 static
{ {
SLOTS.put("shirt", Item.SLOT_UNDERWEAR); SLOTS.put("shirt", Item.SLOT_UNDERWEAR);
@ -106,26 +112,77 @@ public class ItemTable
SLOTS.put("waist", Item.SLOT_BELT); SLOTS.put("waist", Item.SLOT_BELT);
} }
/**
* @return a reference to this ItemTable object
*/
public static ItemTable getInstance()
{
return SingletonHolder.INSTANCE;
}
protected ItemTable() protected ItemTable()
{ {
processDirectory("data/stats/items", _itemFiles);
if (Config.CUSTOM_ITEMS_LOAD)
{
processDirectory("data/stats/items/custom", _itemFiles);
}
load(); 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() private void load()
{ {
int highest = 0; int highest = 0;
_armors.clear(); _armors.clear();
_etcItems.clear(); _etcItems.clear();
_weapons.clear(); _weapons.clear();
for (Item item : DocumentEngine.getInstance().loadItems()) for (Item item : loadItems())
{ {
if (highest < item.getId()) if (highest < item.getId())
{ {
@ -463,6 +520,11 @@ public class ItemTable
return _allTemplates.length; return _allTemplates.length;
} }
public static ItemTable getInstance()
{
return SingletonHolder.INSTANCE;
}
private static class SingletonHolder private static class SingletonHolder
{ {
protected static final ItemTable INSTANCE = new ItemTable(); 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 * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * 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.io.File;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * 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.io.File;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
@ -28,7 +28,6 @@ import org.w3c.dom.Document;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.l2jmobius.commons.util.IXmlReader; import org.l2jmobius.commons.util.IXmlReader;
import org.l2jmobius.gameserver.engines.DocumentBase;
import org.l2jmobius.gameserver.enums.ItemSkillType; import org.l2jmobius.gameserver.enums.ItemSkillType;
import org.l2jmobius.gameserver.model.ExtractableProduct; import org.l2jmobius.gameserver.model.ExtractableProduct;
import org.l2jmobius.gameserver.model.StatSet; 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 static final Logger LOGGER = Logger.getLogger(DocumentItem.class.getName());
private ItemDataHolder _currentItem = null; private DocumentItemDataHolder _currentItem = null;
private final List<Item> _itemsInFile = new ArrayList<>(); private final List<Item> _itemsInFile = new ArrayList<>();
/** private class DocumentItemDataHolder
* @param file {
*/ int id;
String type;
StatSet set;
int currentLevel;
Item item;
}
public DocumentItem(File file) public DocumentItem(File file)
{ {
super(file); super(file);
@ -87,7 +92,7 @@ public class DocumentItem extends DocumentBase implements IXmlReader
{ {
try try
{ {
_currentItem = new ItemDataHolder(); _currentItem = new DocumentItemDataHolder();
parseItem(d); parseItem(d);
_itemsInFile.add(_currentItem.item); _itemsInFile.add(_currentItem.item);
resetTable(); 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; Node n = node;
final int itemId = Integer.parseInt(n.getAttributes().getNamedItem("id").getNodeValue()); 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 itemName = n.getAttributes().getNamedItem("name").getNodeValue();
final String additionalName = n.getAttributes().getNamedItem("additionalName") != null ? n.getAttributes().getNamedItem("additionalName").getNodeValue() : null; final String additionalName = n.getAttributes().getNamedItem("additionalName") != null ? n.getAttributes().getNamedItem("additionalName").getNodeValue() : null;
_currentItem.id = itemId; _currentItem.id = itemId;
_currentItem.name = itemName;
_currentItem.type = className; _currentItem.type = className;
_currentItem.set = new StatSet(); _currentItem.set = new StatSet();
_currentItem.set.set("item_id", itemId); _currentItem.set.set("item_id", itemId);

View File

@ -18,12 +18,16 @@ package org.l2jmobius.gameserver.datatables;
import static org.l2jmobius.gameserver.model.itemcontainer.Inventory.ADENA_ID; import static org.l2jmobius.gameserver.model.itemcontainer.Inventory.ADENA_ID;
import java.io.File;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -31,8 +35,8 @@ import java.util.logging.Logger;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.commons.database.DatabaseFactory; 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.data.xml.impl.EnchantItemHPBonusData;
import org.l2jmobius.gameserver.engines.DocumentEngine;
import org.l2jmobius.gameserver.enums.ItemLocation; import org.l2jmobius.gameserver.enums.ItemLocation;
import org.l2jmobius.gameserver.instancemanager.IdManager; import org.l2jmobius.gameserver.instancemanager.IdManager;
import org.l2jmobius.gameserver.model.World; 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.Item;
import org.l2jmobius.gameserver.model.items.Weapon; import org.l2jmobius.gameserver.model.items.Weapon;
import org.l2jmobius.gameserver.model.items.instance.ItemInstance; import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
import org.l2jmobius.gameserver.util.DocumentItem;
import org.l2jmobius.gameserver.util.GMAudit; 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 final Logger LOGGER = Logger.getLogger(ItemTable.class.getName());
private static Logger LOGGER_ITEMS = Logger.getLogger("item"); private static Logger LOGGER_ITEMS = Logger.getLogger("item");
public static final Map<String, Long> SLOTS = new HashMap<>();
private Item[] _allTemplates; private Item[] _allTemplates;
private final Map<Integer, EtcItem> _etcItems = new HashMap<>(); private final Map<Integer, EtcItem> _etcItems = new HashMap<>();
private final Map<Integer, Armor> _armors = new HashMap<>(); private final Map<Integer, Armor> _armors = new HashMap<>();
private final Map<Integer, Weapon> _weapons = new HashMap<>(); private final Map<Integer, Weapon> _weapons = new HashMap<>();
private final List<File> _itemFiles = new ArrayList<>();
public static final Map<String, Long> SLOTS = new HashMap<>();
static static
{ {
SLOTS.put("shirt", (long) Item.SLOT_UNDERWEAR); SLOTS.put("shirt", (long) Item.SLOT_UNDERWEAR);
@ -107,26 +113,77 @@ public class ItemTable
SLOTS.put("waist", (long) Item.SLOT_BELT); SLOTS.put("waist", (long) Item.SLOT_BELT);
} }
/**
* @return a reference to this ItemTable object
*/
public static ItemTable getInstance()
{
return SingletonHolder.INSTANCE;
}
protected ItemTable() protected ItemTable()
{ {
processDirectory("data/stats/items", _itemFiles);
if (Config.CUSTOM_ITEMS_LOAD)
{
processDirectory("data/stats/items/custom", _itemFiles);
}
load(); 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() private void load()
{ {
int highest = 0; int highest = 0;
_armors.clear(); _armors.clear();
_etcItems.clear(); _etcItems.clear();
_weapons.clear(); _weapons.clear();
for (Item item : DocumentEngine.getInstance().loadItems()) for (Item item : loadItems())
{ {
if (highest < item.getId()) if (highest < item.getId())
{ {
@ -464,6 +521,11 @@ public class ItemTable
return _allTemplates.length; return _allTemplates.length;
} }
public static ItemTable getInstance()
{
return SingletonHolder.INSTANCE;
}
private static class SingletonHolder private static class SingletonHolder
{ {
protected static final ItemTable INSTANCE = new ItemTable(); 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,245 +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 java.io.File;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
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;
import org.l2jmobius.gameserver.model.conditions.Condition;
import org.l2jmobius.gameserver.model.holders.ItemSkillHolder;
import org.l2jmobius.gameserver.model.items.Item;
import org.l2jmobius.gameserver.model.stats.Stat;
import org.l2jmobius.gameserver.model.stats.functions.FuncTemplate;
/**
* @author mkizub, JIV
*/
public class DocumentItem extends DocumentBase implements IXmlReader
{
private static final Logger LOGGER = Logger.getLogger(DocumentItem.class.getName());
private ItemDataHolder _currentItem = null;
private final List<Item> _itemsInFile = new ArrayList<>();
/**
* @param file
*/
public DocumentItem(File file)
{
super(file);
}
@Override
protected StatSet getStatSet()
{
return _currentItem.set;
}
@Override
protected String getTableValue(String name)
{
return _tables.get(name)[_currentItem.currentLevel];
}
@Override
protected String getTableValue(String name, int idx)
{
return _tables.get(name)[idx - 1];
}
@Override
protected void parseDocument(Document doc)
{
for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling())
{
if ("list".equalsIgnoreCase(n.getNodeName()))
{
for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
{
if ("item".equalsIgnoreCase(d.getNodeName()))
{
try
{
_currentItem = new ItemDataHolder();
parseItem(d);
_itemsInFile.add(_currentItem.item);
resetTable();
}
catch (Exception e)
{
LOGGER.log(Level.WARNING, "Cannot create item " + _currentItem.id, e);
}
}
}
}
}
}
protected void parseItem(Node node) throws InvocationTargetException
{
Node n = node;
final int itemId = Integer.parseInt(n.getAttributes().getNamedItem("id").getNodeValue());
final String className = n.getAttributes().getNamedItem("type").getNodeValue();
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);
_currentItem.set.set("name", itemName);
_currentItem.set.set("additionalName", additionalName);
final Node first = n.getFirstChild();
for (n = first; n != null; n = n.getNextSibling())
{
if ("table".equalsIgnoreCase(n.getNodeName()))
{
if (_currentItem.item != null)
{
throw new IllegalStateException("Item created but table node found! Item " + itemId);
}
parseTable(n);
}
else if ("set".equalsIgnoreCase(n.getNodeName()))
{
if (_currentItem.item != null)
{
throw new IllegalStateException("Item created but set node found! Item " + itemId);
}
parseBeanSet(n, _currentItem.set, 1);
}
else if ("stats".equalsIgnoreCase(n.getNodeName()))
{
makeItem();
for (Node b = n.getFirstChild(); b != null; b = b.getNextSibling())
{
if ("stat".equalsIgnoreCase(b.getNodeName()))
{
final Stat type = Stat.valueOfXml(b.getAttributes().getNamedItem("type").getNodeValue());
final double value = Double.parseDouble(b.getTextContent());
_currentItem.item.addFunctionTemplate(new FuncTemplate(null, null, "add", 0x00, type, value));
}
}
}
else if ("skills".equalsIgnoreCase(n.getNodeName()))
{
makeItem();
for (Node b = n.getFirstChild(); b != null; b = b.getNextSibling())
{
if ("skill".equalsIgnoreCase(b.getNodeName()))
{
final int id = parseInteger(b.getAttributes(), "id");
final int level = parseInteger(b.getAttributes(), "level");
final ItemSkillType type = parseEnum(b.getAttributes(), ItemSkillType.class, "type", ItemSkillType.NORMAL);
final int chance = parseInteger(b.getAttributes(), "type_chance", 100);
final int value = parseInteger(b.getAttributes(), "type_value", 0);
_currentItem.item.addSkill(new ItemSkillHolder(id, level, type, chance, value));
}
}
}
else if ("capsuled_items".equalsIgnoreCase(n.getNodeName()))
{
makeItem();
for (Node b = n.getFirstChild(); b != null; b = b.getNextSibling())
{
if ("item".equals(b.getNodeName()))
{
final int id = parseInteger(b.getAttributes(), "id");
final int min = parseInteger(b.getAttributes(), "min");
final int max = parseInteger(b.getAttributes(), "max");
final double chance = parseDouble(b.getAttributes(), "chance");
final int minEnchant = parseInteger(b.getAttributes(), "minEnchant", 0);
final int maxEnchant = parseInteger(b.getAttributes(), "maxEnchant", 0);
_currentItem.item.addCapsuledItem(new ExtractableProduct(id, min, max, chance, minEnchant, maxEnchant));
}
}
}
else if ("cond".equalsIgnoreCase(n.getNodeName()))
{
makeItem();
final Condition condition = parseCondition(n.getFirstChild(), _currentItem.item);
final Node msg = n.getAttributes().getNamedItem("msg");
final Node msgId = n.getAttributes().getNamedItem("msgId");
if ((condition != null) && (msg != null))
{
condition.setMessage(msg.getNodeValue());
}
else if ((condition != null) && (msgId != null))
{
condition.setMessageId(Integer.decode(getValue(msgId.getNodeValue(), null)));
final Node addName = n.getAttributes().getNamedItem("addName");
if ((addName != null) && (Integer.decode(getValue(msgId.getNodeValue(), null)) > 0))
{
condition.addName();
}
}
_currentItem.item.attachCondition(condition);
}
}
// bah! in this point item doesn't have to be still created
makeItem();
}
private void makeItem() throws InvocationTargetException
{
// If item exists just reload the data.
if (_currentItem.item != null)
{
_currentItem.item.set(_currentItem.set);
return;
}
try
{
final Constructor<?> itemClass = Class.forName("org.l2jmobius.gameserver.model.items." + _currentItem.type).getConstructor(StatSet.class);
_currentItem.item = (Item) itemClass.newInstance(_currentItem.set);
}
catch (Exception e)
{
throw new InvocationTargetException(e);
}
}
public List<Item> getItemList()
{
return _itemsInFile;
}
@Override
public void load()
{
}
@Override
public void parseDocument(Document doc, File f)
{
}
}

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;
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,249 @@
/*
* 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.util;
import java.io.File;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.l2jmobius.commons.util.IXmlReader;
import org.l2jmobius.gameserver.enums.ItemSkillType;
import org.l2jmobius.gameserver.model.ExtractableProduct;
import org.l2jmobius.gameserver.model.StatSet;
import org.l2jmobius.gameserver.model.conditions.Condition;
import org.l2jmobius.gameserver.model.holders.ItemSkillHolder;
import org.l2jmobius.gameserver.model.items.Item;
import org.l2jmobius.gameserver.model.stats.Stat;
import org.l2jmobius.gameserver.model.stats.functions.FuncTemplate;
/**
* @author mkizub, JIV
*/
public class DocumentItem extends DocumentBase implements IXmlReader
{
private static final Logger LOGGER = Logger.getLogger(DocumentItem.class.getName());
private DocumentItemDataHolder _currentItem = null;
private final List<Item> _itemsInFile = new ArrayList<>();
private class DocumentItemDataHolder
{
int id;
String type;
StatSet set;
int currentLevel;
Item item;
}
public DocumentItem(File file)
{
super(file);
}
@Override
protected StatSet getStatSet()
{
return _currentItem.set;
}
@Override
protected String getTableValue(String name)
{
return _tables.get(name)[_currentItem.currentLevel];
}
@Override
protected String getTableValue(String name, int idx)
{
return _tables.get(name)[idx - 1];
}
@Override
protected void parseDocument(Document doc)
{
for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling())
{
if ("list".equalsIgnoreCase(n.getNodeName()))
{
for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
{
if ("item".equalsIgnoreCase(d.getNodeName()))
{
try
{
_currentItem = new DocumentItemDataHolder();
parseItem(d);
_itemsInFile.add(_currentItem.item);
resetTable();
}
catch (Exception e)
{
LOGGER.log(Level.WARNING, "Cannot create item " + _currentItem.id, e);
}
}
}
}
}
}
private void parseItem(Node node) throws InvocationTargetException
{
Node n = node;
final int itemId = Integer.parseInt(n.getAttributes().getNamedItem("id").getNodeValue());
final String className = n.getAttributes().getNamedItem("type").getNodeValue();
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.type = className;
_currentItem.set = new StatSet();
_currentItem.set.set("item_id", itemId);
_currentItem.set.set("name", itemName);
_currentItem.set.set("additionalName", additionalName);
final Node first = n.getFirstChild();
for (n = first; n != null; n = n.getNextSibling())
{
if ("table".equalsIgnoreCase(n.getNodeName()))
{
if (_currentItem.item != null)
{
throw new IllegalStateException("Item created but table node found! Item " + itemId);
}
parseTable(n);
}
else if ("set".equalsIgnoreCase(n.getNodeName()))
{
if (_currentItem.item != null)
{
throw new IllegalStateException("Item created but set node found! Item " + itemId);
}
parseBeanSet(n, _currentItem.set, 1);
}
else if ("stats".equalsIgnoreCase(n.getNodeName()))
{
makeItem();
for (Node b = n.getFirstChild(); b != null; b = b.getNextSibling())
{
if ("stat".equalsIgnoreCase(b.getNodeName()))
{
final Stat type = Stat.valueOfXml(b.getAttributes().getNamedItem("type").getNodeValue());
final double value = Double.parseDouble(b.getTextContent());
_currentItem.item.addFunctionTemplate(new FuncTemplate(null, null, "add", 0x00, type, value));
}
}
}
else if ("skills".equalsIgnoreCase(n.getNodeName()))
{
makeItem();
for (Node b = n.getFirstChild(); b != null; b = b.getNextSibling())
{
if ("skill".equalsIgnoreCase(b.getNodeName()))
{
final int id = parseInteger(b.getAttributes(), "id");
final int level = parseInteger(b.getAttributes(), "level");
final ItemSkillType type = parseEnum(b.getAttributes(), ItemSkillType.class, "type", ItemSkillType.NORMAL);
final int chance = parseInteger(b.getAttributes(), "type_chance", 100);
final int value = parseInteger(b.getAttributes(), "type_value", 0);
_currentItem.item.addSkill(new ItemSkillHolder(id, level, type, chance, value));
}
}
}
else if ("capsuled_items".equalsIgnoreCase(n.getNodeName()))
{
makeItem();
for (Node b = n.getFirstChild(); b != null; b = b.getNextSibling())
{
if ("item".equals(b.getNodeName()))
{
final int id = parseInteger(b.getAttributes(), "id");
final int min = parseInteger(b.getAttributes(), "min");
final int max = parseInteger(b.getAttributes(), "max");
final double chance = parseDouble(b.getAttributes(), "chance");
final int minEnchant = parseInteger(b.getAttributes(), "minEnchant", 0);
final int maxEnchant = parseInteger(b.getAttributes(), "maxEnchant", 0);
_currentItem.item.addCapsuledItem(new ExtractableProduct(id, min, max, chance, minEnchant, maxEnchant));
}
}
}
else if ("cond".equalsIgnoreCase(n.getNodeName()))
{
makeItem();
final Condition condition = parseCondition(n.getFirstChild(), _currentItem.item);
final Node msg = n.getAttributes().getNamedItem("msg");
final Node msgId = n.getAttributes().getNamedItem("msgId");
if ((condition != null) && (msg != null))
{
condition.setMessage(msg.getNodeValue());
}
else if ((condition != null) && (msgId != null))
{
condition.setMessageId(Integer.decode(getValue(msgId.getNodeValue(), null)));
final Node addName = n.getAttributes().getNamedItem("addName");
if ((addName != null) && (Integer.decode(getValue(msgId.getNodeValue(), null)) > 0))
{
condition.addName();
}
}
_currentItem.item.attachCondition(condition);
}
}
// bah! in this point item doesn't have to be still created
makeItem();
}
private void makeItem() throws InvocationTargetException
{
// If item exists just reload the data.
if (_currentItem.item != null)
{
_currentItem.item.set(_currentItem.set);
return;
}
try
{
final Constructor<?> itemClass = Class.forName("org.l2jmobius.gameserver.model.items." + _currentItem.type).getConstructor(StatSet.class);
_currentItem.item = (Item) itemClass.newInstance(_currentItem.set);
}
catch (Exception e)
{
throw new InvocationTargetException(e);
}
}
public List<Item> getItemList()
{
return _itemsInFile;
}
@Override
public void load()
{
}
@Override
public void parseDocument(Document doc, File f)
{
}
}

View File

@ -18,12 +18,16 @@ package org.l2jmobius.gameserver.datatables;
import static org.l2jmobius.gameserver.model.itemcontainer.Inventory.ADENA_ID; import static org.l2jmobius.gameserver.model.itemcontainer.Inventory.ADENA_ID;
import java.io.File;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -31,8 +35,8 @@ import java.util.logging.Logger;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.commons.database.DatabaseFactory; 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.data.xml.impl.EnchantItemHPBonusData;
import org.l2jmobius.gameserver.engines.DocumentEngine;
import org.l2jmobius.gameserver.enums.ItemLocation; import org.l2jmobius.gameserver.enums.ItemLocation;
import org.l2jmobius.gameserver.instancemanager.IdManager; import org.l2jmobius.gameserver.instancemanager.IdManager;
import org.l2jmobius.gameserver.model.World; 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.Item;
import org.l2jmobius.gameserver.model.items.Weapon; import org.l2jmobius.gameserver.model.items.Weapon;
import org.l2jmobius.gameserver.model.items.instance.ItemInstance; import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
import org.l2jmobius.gameserver.util.DocumentItem;
import org.l2jmobius.gameserver.util.GMAudit; 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 final Logger LOGGER = Logger.getLogger(ItemTable.class.getName());
private static Logger LOGGER_ITEMS = Logger.getLogger("item"); private static Logger LOGGER_ITEMS = Logger.getLogger("item");
public static final Map<String, Long> SLOTS = new HashMap<>();
private Item[] _allTemplates; private Item[] _allTemplates;
private final Map<Integer, EtcItem> _etcItems = new HashMap<>(); private final Map<Integer, EtcItem> _etcItems = new HashMap<>();
private final Map<Integer, Armor> _armors = new HashMap<>(); private final Map<Integer, Armor> _armors = new HashMap<>();
private final Map<Integer, Weapon> _weapons = new HashMap<>(); private final Map<Integer, Weapon> _weapons = new HashMap<>();
private final List<File> _itemFiles = new ArrayList<>();
public static final Map<String, Long> SLOTS = new HashMap<>();
static static
{ {
SLOTS.put("shirt", (long) Item.SLOT_UNDERWEAR); SLOTS.put("shirt", (long) Item.SLOT_UNDERWEAR);
@ -109,26 +115,77 @@ public class ItemTable
SLOTS.put("waist", (long) Item.SLOT_BELT); SLOTS.put("waist", (long) Item.SLOT_BELT);
} }
/**
* @return a reference to this ItemTable object
*/
public static ItemTable getInstance()
{
return SingletonHolder.INSTANCE;
}
protected ItemTable() protected ItemTable()
{ {
processDirectory("data/stats/items", _itemFiles);
if (Config.CUSTOM_ITEMS_LOAD)
{
processDirectory("data/stats/items/custom", _itemFiles);
}
load(); 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() private void load()
{ {
int highest = 0; int highest = 0;
_armors.clear(); _armors.clear();
_etcItems.clear(); _etcItems.clear();
_weapons.clear(); _weapons.clear();
for (Item item : DocumentEngine.getInstance().loadItems()) for (Item item : loadItems())
{ {
if (highest < item.getId()) if (highest < item.getId())
{ {
@ -466,6 +523,11 @@ public class ItemTable
return _allTemplates.length; return _allTemplates.length;
} }
public static ItemTable getInstance()
{
return SingletonHolder.INSTANCE;
}
private static class SingletonHolder private static class SingletonHolder
{ {
protected static final ItemTable INSTANCE = new ItemTable(); 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,245 +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 java.io.File;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
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;
import org.l2jmobius.gameserver.model.conditions.Condition;
import org.l2jmobius.gameserver.model.holders.ItemSkillHolder;
import org.l2jmobius.gameserver.model.items.Item;
import org.l2jmobius.gameserver.model.stats.Stat;
import org.l2jmobius.gameserver.model.stats.functions.FuncTemplate;
/**
* @author mkizub, JIV
*/
public class DocumentItem extends DocumentBase implements IXmlReader
{
private static final Logger LOGGER = Logger.getLogger(DocumentItem.class.getName());
private ItemDataHolder _currentItem = null;
private final List<Item> _itemsInFile = new ArrayList<>();
/**
* @param file
*/
public DocumentItem(File file)
{
super(file);
}
@Override
protected StatSet getStatSet()
{
return _currentItem.set;
}
@Override
protected String getTableValue(String name)
{
return _tables.get(name)[_currentItem.currentLevel];
}
@Override
protected String getTableValue(String name, int idx)
{
return _tables.get(name)[idx - 1];
}
@Override
protected void parseDocument(Document doc)
{
for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling())
{
if ("list".equalsIgnoreCase(n.getNodeName()))
{
for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
{
if ("item".equalsIgnoreCase(d.getNodeName()))
{
try
{
_currentItem = new ItemDataHolder();
parseItem(d);
_itemsInFile.add(_currentItem.item);
resetTable();
}
catch (Exception e)
{
LOGGER.log(Level.WARNING, "Cannot create item " + _currentItem.id, e);
}
}
}
}
}
}
protected void parseItem(Node node) throws InvocationTargetException
{
Node n = node;
final int itemId = Integer.parseInt(n.getAttributes().getNamedItem("id").getNodeValue());
final String className = n.getAttributes().getNamedItem("type").getNodeValue();
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);
_currentItem.set.set("name", itemName);
_currentItem.set.set("additionalName", additionalName);
final Node first = n.getFirstChild();
for (n = first; n != null; n = n.getNextSibling())
{
if ("table".equalsIgnoreCase(n.getNodeName()))
{
if (_currentItem.item != null)
{
throw new IllegalStateException("Item created but table node found! Item " + itemId);
}
parseTable(n);
}
else if ("set".equalsIgnoreCase(n.getNodeName()))
{
if (_currentItem.item != null)
{
throw new IllegalStateException("Item created but set node found! Item " + itemId);
}
parseBeanSet(n, _currentItem.set, 1);
}
else if ("stats".equalsIgnoreCase(n.getNodeName()))
{
makeItem();
for (Node b = n.getFirstChild(); b != null; b = b.getNextSibling())
{
if ("stat".equalsIgnoreCase(b.getNodeName()))
{
final Stat type = Stat.valueOfXml(b.getAttributes().getNamedItem("type").getNodeValue());
final double value = Double.parseDouble(b.getTextContent());
_currentItem.item.addFunctionTemplate(new FuncTemplate(null, null, "add", 0x00, type, value));
}
}
}
else if ("skills".equalsIgnoreCase(n.getNodeName()))
{
makeItem();
for (Node b = n.getFirstChild(); b != null; b = b.getNextSibling())
{
if ("skill".equalsIgnoreCase(b.getNodeName()))
{
final int id = parseInteger(b.getAttributes(), "id");
final int level = parseInteger(b.getAttributes(), "level");
final ItemSkillType type = parseEnum(b.getAttributes(), ItemSkillType.class, "type", ItemSkillType.NORMAL);
final int chance = parseInteger(b.getAttributes(), "type_chance", 100);
final int value = parseInteger(b.getAttributes(), "type_value", 0);
_currentItem.item.addSkill(new ItemSkillHolder(id, level, type, chance, value));
}
}
}
else if ("capsuled_items".equalsIgnoreCase(n.getNodeName()))
{
makeItem();
for (Node b = n.getFirstChild(); b != null; b = b.getNextSibling())
{
if ("item".equals(b.getNodeName()))
{
final int id = parseInteger(b.getAttributes(), "id");
final int min = parseInteger(b.getAttributes(), "min");
final int max = parseInteger(b.getAttributes(), "max");
final double chance = parseDouble(b.getAttributes(), "chance");
final int minEnchant = parseInteger(b.getAttributes(), "minEnchant", 0);
final int maxEnchant = parseInteger(b.getAttributes(), "maxEnchant", 0);
_currentItem.item.addCapsuledItem(new ExtractableProduct(id, min, max, chance, minEnchant, maxEnchant));
}
}
}
else if ("cond".equalsIgnoreCase(n.getNodeName()))
{
makeItem();
final Condition condition = parseCondition(n.getFirstChild(), _currentItem.item);
final Node msg = n.getAttributes().getNamedItem("msg");
final Node msgId = n.getAttributes().getNamedItem("msgId");
if ((condition != null) && (msg != null))
{
condition.setMessage(msg.getNodeValue());
}
else if ((condition != null) && (msgId != null))
{
condition.setMessageId(Integer.decode(getValue(msgId.getNodeValue(), null)));
final Node addName = n.getAttributes().getNamedItem("addName");
if ((addName != null) && (Integer.decode(getValue(msgId.getNodeValue(), null)) > 0))
{
condition.addName();
}
}
_currentItem.item.attachCondition(condition);
}
}
// bah! in this point item doesn't have to be still created
makeItem();
}
private void makeItem() throws InvocationTargetException
{
// If item exists just reload the data.
if (_currentItem.item != null)
{
_currentItem.item.set(_currentItem.set);
return;
}
try
{
final Constructor<?> itemClass = Class.forName("org.l2jmobius.gameserver.model.items." + _currentItem.type).getConstructor(StatSet.class);
_currentItem.item = (Item) itemClass.newInstance(_currentItem.set);
}
catch (Exception e)
{
throw new InvocationTargetException(e);
}
}
public List<Item> getItemList()
{
return _itemsInFile;
}
@Override
public void load()
{
}
@Override
public void parseDocument(Document doc, File f)
{
}
}

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;
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,249 @@
/*
* 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.util;
import java.io.File;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.l2jmobius.commons.util.IXmlReader;
import org.l2jmobius.gameserver.enums.ItemSkillType;
import org.l2jmobius.gameserver.model.ExtractableProduct;
import org.l2jmobius.gameserver.model.StatSet;
import org.l2jmobius.gameserver.model.conditions.Condition;
import org.l2jmobius.gameserver.model.holders.ItemSkillHolder;
import org.l2jmobius.gameserver.model.items.Item;
import org.l2jmobius.gameserver.model.stats.Stat;
import org.l2jmobius.gameserver.model.stats.functions.FuncTemplate;
/**
* @author mkizub, JIV
*/
public class DocumentItem extends DocumentBase implements IXmlReader
{
private static final Logger LOGGER = Logger.getLogger(DocumentItem.class.getName());
private DocumentItemDataHolder _currentItem = null;
private final List<Item> _itemsInFile = new ArrayList<>();
private class DocumentItemDataHolder
{
int id;
String type;
StatSet set;
int currentLevel;
Item item;
}
public DocumentItem(File file)
{
super(file);
}
@Override
protected StatSet getStatSet()
{
return _currentItem.set;
}
@Override
protected String getTableValue(String name)
{
return _tables.get(name)[_currentItem.currentLevel];
}
@Override
protected String getTableValue(String name, int idx)
{
return _tables.get(name)[idx - 1];
}
@Override
protected void parseDocument(Document doc)
{
for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling())
{
if ("list".equalsIgnoreCase(n.getNodeName()))
{
for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
{
if ("item".equalsIgnoreCase(d.getNodeName()))
{
try
{
_currentItem = new DocumentItemDataHolder();
parseItem(d);
_itemsInFile.add(_currentItem.item);
resetTable();
}
catch (Exception e)
{
LOGGER.log(Level.WARNING, "Cannot create item " + _currentItem.id, e);
}
}
}
}
}
}
private void parseItem(Node node) throws InvocationTargetException
{
Node n = node;
final int itemId = Integer.parseInt(n.getAttributes().getNamedItem("id").getNodeValue());
final String className = n.getAttributes().getNamedItem("type").getNodeValue();
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.type = className;
_currentItem.set = new StatSet();
_currentItem.set.set("item_id", itemId);
_currentItem.set.set("name", itemName);
_currentItem.set.set("additionalName", additionalName);
final Node first = n.getFirstChild();
for (n = first; n != null; n = n.getNextSibling())
{
if ("table".equalsIgnoreCase(n.getNodeName()))
{
if (_currentItem.item != null)
{
throw new IllegalStateException("Item created but table node found! Item " + itemId);
}
parseTable(n);
}
else if ("set".equalsIgnoreCase(n.getNodeName()))
{
if (_currentItem.item != null)
{
throw new IllegalStateException("Item created but set node found! Item " + itemId);
}
parseBeanSet(n, _currentItem.set, 1);
}
else if ("stats".equalsIgnoreCase(n.getNodeName()))
{
makeItem();
for (Node b = n.getFirstChild(); b != null; b = b.getNextSibling())
{
if ("stat".equalsIgnoreCase(b.getNodeName()))
{
final Stat type = Stat.valueOfXml(b.getAttributes().getNamedItem("type").getNodeValue());
final double value = Double.parseDouble(b.getTextContent());
_currentItem.item.addFunctionTemplate(new FuncTemplate(null, null, "add", 0x00, type, value));
}
}
}
else if ("skills".equalsIgnoreCase(n.getNodeName()))
{
makeItem();
for (Node b = n.getFirstChild(); b != null; b = b.getNextSibling())
{
if ("skill".equalsIgnoreCase(b.getNodeName()))
{
final int id = parseInteger(b.getAttributes(), "id");
final int level = parseInteger(b.getAttributes(), "level");
final ItemSkillType type = parseEnum(b.getAttributes(), ItemSkillType.class, "type", ItemSkillType.NORMAL);
final int chance = parseInteger(b.getAttributes(), "type_chance", 100);
final int value = parseInteger(b.getAttributes(), "type_value", 0);
_currentItem.item.addSkill(new ItemSkillHolder(id, level, type, chance, value));
}
}
}
else if ("capsuled_items".equalsIgnoreCase(n.getNodeName()))
{
makeItem();
for (Node b = n.getFirstChild(); b != null; b = b.getNextSibling())
{
if ("item".equals(b.getNodeName()))
{
final int id = parseInteger(b.getAttributes(), "id");
final int min = parseInteger(b.getAttributes(), "min");
final int max = parseInteger(b.getAttributes(), "max");
final double chance = parseDouble(b.getAttributes(), "chance");
final int minEnchant = parseInteger(b.getAttributes(), "minEnchant", 0);
final int maxEnchant = parseInteger(b.getAttributes(), "maxEnchant", 0);
_currentItem.item.addCapsuledItem(new ExtractableProduct(id, min, max, chance, minEnchant, maxEnchant));
}
}
}
else if ("cond".equalsIgnoreCase(n.getNodeName()))
{
makeItem();
final Condition condition = parseCondition(n.getFirstChild(), _currentItem.item);
final Node msg = n.getAttributes().getNamedItem("msg");
final Node msgId = n.getAttributes().getNamedItem("msgId");
if ((condition != null) && (msg != null))
{
condition.setMessage(msg.getNodeValue());
}
else if ((condition != null) && (msgId != null))
{
condition.setMessageId(Integer.decode(getValue(msgId.getNodeValue(), null)));
final Node addName = n.getAttributes().getNamedItem("addName");
if ((addName != null) && (Integer.decode(getValue(msgId.getNodeValue(), null)) > 0))
{
condition.addName();
}
}
_currentItem.item.attachCondition(condition);
}
}
// bah! in this point item doesn't have to be still created
makeItem();
}
private void makeItem() throws InvocationTargetException
{
// If item exists just reload the data.
if (_currentItem.item != null)
{
_currentItem.item.set(_currentItem.set);
return;
}
try
{
final Constructor<?> itemClass = Class.forName("org.l2jmobius.gameserver.model.items." + _currentItem.type).getConstructor(StatSet.class);
_currentItem.item = (Item) itemClass.newInstance(_currentItem.set);
}
catch (Exception e)
{
throw new InvocationTargetException(e);
}
}
public List<Item> getItemList()
{
return _itemsInFile;
}
@Override
public void load()
{
}
@Override
public void parseDocument(Document doc, File f)
{
}
}

View File

@ -18,12 +18,16 @@ package org.l2jmobius.gameserver.datatables;
import static org.l2jmobius.gameserver.model.itemcontainer.Inventory.ADENA_ID; import static org.l2jmobius.gameserver.model.itemcontainer.Inventory.ADENA_ID;
import java.io.File;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -31,8 +35,8 @@ import java.util.logging.Logger;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.commons.database.DatabaseFactory; 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.data.xml.impl.EnchantItemHPBonusData;
import org.l2jmobius.gameserver.engines.DocumentEngine;
import org.l2jmobius.gameserver.enums.ItemLocation; import org.l2jmobius.gameserver.enums.ItemLocation;
import org.l2jmobius.gameserver.instancemanager.IdManager; import org.l2jmobius.gameserver.instancemanager.IdManager;
import org.l2jmobius.gameserver.model.World; 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.Item;
import org.l2jmobius.gameserver.model.items.Weapon; import org.l2jmobius.gameserver.model.items.Weapon;
import org.l2jmobius.gameserver.model.items.instance.ItemInstance; import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
import org.l2jmobius.gameserver.util.DocumentItem;
import org.l2jmobius.gameserver.util.GMAudit; 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 final Logger LOGGER = Logger.getLogger(ItemTable.class.getName());
private static Logger LOGGER_ITEMS = Logger.getLogger("item"); private static Logger LOGGER_ITEMS = Logger.getLogger("item");
public static final Map<String, Long> SLOTS = new HashMap<>();
private Item[] _allTemplates; private Item[] _allTemplates;
private final Map<Integer, EtcItem> _etcItems = new HashMap<>(); private final Map<Integer, EtcItem> _etcItems = new HashMap<>();
private final Map<Integer, Armor> _armors = new HashMap<>(); private final Map<Integer, Armor> _armors = new HashMap<>();
private final Map<Integer, Weapon> _weapons = new HashMap<>(); private final Map<Integer, Weapon> _weapons = new HashMap<>();
private final List<File> _itemFiles = new ArrayList<>();
public static final Map<String, Long> SLOTS = new HashMap<>();
static static
{ {
SLOTS.put("shirt", (long) Item.SLOT_UNDERWEAR); SLOTS.put("shirt", (long) Item.SLOT_UNDERWEAR);
@ -109,26 +115,77 @@ public class ItemTable
SLOTS.put("waist", (long) Item.SLOT_BELT); SLOTS.put("waist", (long) Item.SLOT_BELT);
} }
/**
* @return a reference to this ItemTable object
*/
public static ItemTable getInstance()
{
return SingletonHolder.INSTANCE;
}
protected ItemTable() protected ItemTable()
{ {
processDirectory("data/stats/items", _itemFiles);
if (Config.CUSTOM_ITEMS_LOAD)
{
processDirectory("data/stats/items/custom", _itemFiles);
}
load(); 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() private void load()
{ {
int highest = 0; int highest = 0;
_armors.clear(); _armors.clear();
_etcItems.clear(); _etcItems.clear();
_weapons.clear(); _weapons.clear();
for (Item item : DocumentEngine.getInstance().loadItems()) for (Item item : loadItems())
{ {
if (highest < item.getId()) if (highest < item.getId())
{ {
@ -466,6 +523,11 @@ public class ItemTable
return _allTemplates.length; return _allTemplates.length;
} }
public static ItemTable getInstance()
{
return SingletonHolder.INSTANCE;
}
private static class SingletonHolder private static class SingletonHolder
{ {
protected static final ItemTable INSTANCE = new ItemTable(); 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,245 +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 java.io.File;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
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;
import org.l2jmobius.gameserver.model.conditions.Condition;
import org.l2jmobius.gameserver.model.holders.ItemSkillHolder;
import org.l2jmobius.gameserver.model.items.Item;
import org.l2jmobius.gameserver.model.stats.Stat;
import org.l2jmobius.gameserver.model.stats.functions.FuncTemplate;
/**
* @author mkizub, JIV
*/
public class DocumentItem extends DocumentBase implements IXmlReader
{
private static final Logger LOGGER = Logger.getLogger(DocumentItem.class.getName());
private ItemDataHolder _currentItem = null;
private final List<Item> _itemsInFile = new ArrayList<>();
/**
* @param file
*/
public DocumentItem(File file)
{
super(file);
}
@Override
protected StatSet getStatSet()
{
return _currentItem.set;
}
@Override
protected String getTableValue(String name)
{
return _tables.get(name)[_currentItem.currentLevel];
}
@Override
protected String getTableValue(String name, int idx)
{
return _tables.get(name)[idx - 1];
}
@Override
protected void parseDocument(Document doc)
{
for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling())
{
if ("list".equalsIgnoreCase(n.getNodeName()))
{
for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
{
if ("item".equalsIgnoreCase(d.getNodeName()))
{
try
{
_currentItem = new ItemDataHolder();
parseItem(d);
_itemsInFile.add(_currentItem.item);
resetTable();
}
catch (Exception e)
{
LOGGER.log(Level.WARNING, "Cannot create item " + _currentItem.id, e);
}
}
}
}
}
}
protected void parseItem(Node node) throws InvocationTargetException
{
Node n = node;
final int itemId = Integer.parseInt(n.getAttributes().getNamedItem("id").getNodeValue());
final String className = n.getAttributes().getNamedItem("type").getNodeValue();
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);
_currentItem.set.set("name", itemName);
_currentItem.set.set("additionalName", additionalName);
final Node first = n.getFirstChild();
for (n = first; n != null; n = n.getNextSibling())
{
if ("table".equalsIgnoreCase(n.getNodeName()))
{
if (_currentItem.item != null)
{
throw new IllegalStateException("Item created but table node found! Item " + itemId);
}
parseTable(n);
}
else if ("set".equalsIgnoreCase(n.getNodeName()))
{
if (_currentItem.item != null)
{
throw new IllegalStateException("Item created but set node found! Item " + itemId);
}
parseBeanSet(n, _currentItem.set, 1);
}
else if ("stats".equalsIgnoreCase(n.getNodeName()))
{
makeItem();
for (Node b = n.getFirstChild(); b != null; b = b.getNextSibling())
{
if ("stat".equalsIgnoreCase(b.getNodeName()))
{
final Stat type = Stat.valueOfXml(b.getAttributes().getNamedItem("type").getNodeValue());
final double value = Double.parseDouble(b.getTextContent());
_currentItem.item.addFunctionTemplate(new FuncTemplate(null, null, "add", 0x00, type, value));
}
}
}
else if ("skills".equalsIgnoreCase(n.getNodeName()))
{
makeItem();
for (Node b = n.getFirstChild(); b != null; b = b.getNextSibling())
{
if ("skill".equalsIgnoreCase(b.getNodeName()))
{
final int id = parseInteger(b.getAttributes(), "id");
final int level = parseInteger(b.getAttributes(), "level");
final ItemSkillType type = parseEnum(b.getAttributes(), ItemSkillType.class, "type", ItemSkillType.NORMAL);
final int chance = parseInteger(b.getAttributes(), "type_chance", 100);
final int value = parseInteger(b.getAttributes(), "type_value", 0);
_currentItem.item.addSkill(new ItemSkillHolder(id, level, type, chance, value));
}
}
}
else if ("capsuled_items".equalsIgnoreCase(n.getNodeName()))
{
makeItem();
for (Node b = n.getFirstChild(); b != null; b = b.getNextSibling())
{
if ("item".equals(b.getNodeName()))
{
final int id = parseInteger(b.getAttributes(), "id");
final int min = parseInteger(b.getAttributes(), "min");
final int max = parseInteger(b.getAttributes(), "max");
final double chance = parseDouble(b.getAttributes(), "chance");
final int minEnchant = parseInteger(b.getAttributes(), "minEnchant", 0);
final int maxEnchant = parseInteger(b.getAttributes(), "maxEnchant", 0);
_currentItem.item.addCapsuledItem(new ExtractableProduct(id, min, max, chance, minEnchant, maxEnchant));
}
}
}
else if ("cond".equalsIgnoreCase(n.getNodeName()))
{
makeItem();
final Condition condition = parseCondition(n.getFirstChild(), _currentItem.item);
final Node msg = n.getAttributes().getNamedItem("msg");
final Node msgId = n.getAttributes().getNamedItem("msgId");
if ((condition != null) && (msg != null))
{
condition.setMessage(msg.getNodeValue());
}
else if ((condition != null) && (msgId != null))
{
condition.setMessageId(Integer.decode(getValue(msgId.getNodeValue(), null)));
final Node addName = n.getAttributes().getNamedItem("addName");
if ((addName != null) && (Integer.decode(getValue(msgId.getNodeValue(), null)) > 0))
{
condition.addName();
}
}
_currentItem.item.attachCondition(condition);
}
}
// bah! in this point item doesn't have to be still created
makeItem();
}
private void makeItem() throws InvocationTargetException
{
// If item exists just reload the data.
if (_currentItem.item != null)
{
_currentItem.item.set(_currentItem.set);
return;
}
try
{
final Constructor<?> itemClass = Class.forName("org.l2jmobius.gameserver.model.items." + _currentItem.type).getConstructor(StatSet.class);
_currentItem.item = (Item) itemClass.newInstance(_currentItem.set);
}
catch (Exception e)
{
throw new InvocationTargetException(e);
}
}
public List<Item> getItemList()
{
return _itemsInFile;
}
@Override
public void load()
{
}
@Override
public void parseDocument(Document doc, File f)
{
}
}

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;
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,249 @@
/*
* 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.util;
import java.io.File;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.l2jmobius.commons.util.IXmlReader;
import org.l2jmobius.gameserver.enums.ItemSkillType;
import org.l2jmobius.gameserver.model.ExtractableProduct;
import org.l2jmobius.gameserver.model.StatSet;
import org.l2jmobius.gameserver.model.conditions.Condition;
import org.l2jmobius.gameserver.model.holders.ItemSkillHolder;
import org.l2jmobius.gameserver.model.items.Item;
import org.l2jmobius.gameserver.model.stats.Stat;
import org.l2jmobius.gameserver.model.stats.functions.FuncTemplate;
/**
* @author mkizub, JIV
*/
public class DocumentItem extends DocumentBase implements IXmlReader
{
private static final Logger LOGGER = Logger.getLogger(DocumentItem.class.getName());
private DocumentItemDataHolder _currentItem = null;
private final List<Item> _itemsInFile = new ArrayList<>();
private class DocumentItemDataHolder
{
int id;
String type;
StatSet set;
int currentLevel;
Item item;
}
public DocumentItem(File file)
{
super(file);
}
@Override
protected StatSet getStatSet()
{
return _currentItem.set;
}
@Override
protected String getTableValue(String name)
{
return _tables.get(name)[_currentItem.currentLevel];
}
@Override
protected String getTableValue(String name, int idx)
{
return _tables.get(name)[idx - 1];
}
@Override
protected void parseDocument(Document doc)
{
for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling())
{
if ("list".equalsIgnoreCase(n.getNodeName()))
{
for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
{
if ("item".equalsIgnoreCase(d.getNodeName()))
{
try
{
_currentItem = new DocumentItemDataHolder();
parseItem(d);
_itemsInFile.add(_currentItem.item);
resetTable();
}
catch (Exception e)
{
LOGGER.log(Level.WARNING, "Cannot create item " + _currentItem.id, e);
}
}
}
}
}
}
private void parseItem(Node node) throws InvocationTargetException
{
Node n = node;
final int itemId = Integer.parseInt(n.getAttributes().getNamedItem("id").getNodeValue());
final String className = n.getAttributes().getNamedItem("type").getNodeValue();
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.type = className;
_currentItem.set = new StatSet();
_currentItem.set.set("item_id", itemId);
_currentItem.set.set("name", itemName);
_currentItem.set.set("additionalName", additionalName);
final Node first = n.getFirstChild();
for (n = first; n != null; n = n.getNextSibling())
{
if ("table".equalsIgnoreCase(n.getNodeName()))
{
if (_currentItem.item != null)
{
throw new IllegalStateException("Item created but table node found! Item " + itemId);
}
parseTable(n);
}
else if ("set".equalsIgnoreCase(n.getNodeName()))
{
if (_currentItem.item != null)
{
throw new IllegalStateException("Item created but set node found! Item " + itemId);
}
parseBeanSet(n, _currentItem.set, 1);
}
else if ("stats".equalsIgnoreCase(n.getNodeName()))
{
makeItem();
for (Node b = n.getFirstChild(); b != null; b = b.getNextSibling())
{
if ("stat".equalsIgnoreCase(b.getNodeName()))
{
final Stat type = Stat.valueOfXml(b.getAttributes().getNamedItem("type").getNodeValue());
final double value = Double.parseDouble(b.getTextContent());
_currentItem.item.addFunctionTemplate(new FuncTemplate(null, null, "add", 0x00, type, value));
}
}
}
else if ("skills".equalsIgnoreCase(n.getNodeName()))
{
makeItem();
for (Node b = n.getFirstChild(); b != null; b = b.getNextSibling())
{
if ("skill".equalsIgnoreCase(b.getNodeName()))
{
final int id = parseInteger(b.getAttributes(), "id");
final int level = parseInteger(b.getAttributes(), "level");
final ItemSkillType type = parseEnum(b.getAttributes(), ItemSkillType.class, "type", ItemSkillType.NORMAL);
final int chance = parseInteger(b.getAttributes(), "type_chance", 100);
final int value = parseInteger(b.getAttributes(), "type_value", 0);
_currentItem.item.addSkill(new ItemSkillHolder(id, level, type, chance, value));
}
}
}
else if ("capsuled_items".equalsIgnoreCase(n.getNodeName()))
{
makeItem();
for (Node b = n.getFirstChild(); b != null; b = b.getNextSibling())
{
if ("item".equals(b.getNodeName()))
{
final int id = parseInteger(b.getAttributes(), "id");
final int min = parseInteger(b.getAttributes(), "min");
final int max = parseInteger(b.getAttributes(), "max");
final double chance = parseDouble(b.getAttributes(), "chance");
final int minEnchant = parseInteger(b.getAttributes(), "minEnchant", 0);
final int maxEnchant = parseInteger(b.getAttributes(), "maxEnchant", 0);
_currentItem.item.addCapsuledItem(new ExtractableProduct(id, min, max, chance, minEnchant, maxEnchant));
}
}
}
else if ("cond".equalsIgnoreCase(n.getNodeName()))
{
makeItem();
final Condition condition = parseCondition(n.getFirstChild(), _currentItem.item);
final Node msg = n.getAttributes().getNamedItem("msg");
final Node msgId = n.getAttributes().getNamedItem("msgId");
if ((condition != null) && (msg != null))
{
condition.setMessage(msg.getNodeValue());
}
else if ((condition != null) && (msgId != null))
{
condition.setMessageId(Integer.decode(getValue(msgId.getNodeValue(), null)));
final Node addName = n.getAttributes().getNamedItem("addName");
if ((addName != null) && (Integer.decode(getValue(msgId.getNodeValue(), null)) > 0))
{
condition.addName();
}
}
_currentItem.item.attachCondition(condition);
}
}
// bah! in this point item doesn't have to be still created
makeItem();
}
private void makeItem() throws InvocationTargetException
{
// If item exists just reload the data.
if (_currentItem.item != null)
{
_currentItem.item.set(_currentItem.set);
return;
}
try
{
final Constructor<?> itemClass = Class.forName("org.l2jmobius.gameserver.model.items." + _currentItem.type).getConstructor(StatSet.class);
_currentItem.item = (Item) itemClass.newInstance(_currentItem.set);
}
catch (Exception e)
{
throw new InvocationTargetException(e);
}
}
public List<Item> getItemList()
{
return _itemsInFile;
}
@Override
public void load()
{
}
@Override
public void parseDocument(Document doc, File f)
{
}
}

View File

@ -18,12 +18,16 @@ package org.l2jmobius.gameserver.datatables;
import static org.l2jmobius.gameserver.model.itemcontainer.Inventory.ADENA_ID; import static org.l2jmobius.gameserver.model.itemcontainer.Inventory.ADENA_ID;
import java.io.File;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -31,8 +35,8 @@ import java.util.logging.Logger;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.commons.database.DatabaseFactory; 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.data.xml.impl.EnchantItemHPBonusData;
import org.l2jmobius.gameserver.engines.DocumentEngine;
import org.l2jmobius.gameserver.enums.ItemLocation; import org.l2jmobius.gameserver.enums.ItemLocation;
import org.l2jmobius.gameserver.instancemanager.IdManager; import org.l2jmobius.gameserver.instancemanager.IdManager;
import org.l2jmobius.gameserver.model.World; 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.Item;
import org.l2jmobius.gameserver.model.items.Weapon; import org.l2jmobius.gameserver.model.items.Weapon;
import org.l2jmobius.gameserver.model.items.instance.ItemInstance; import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
import org.l2jmobius.gameserver.util.DocumentItem;
import org.l2jmobius.gameserver.util.GMAudit; 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 final Logger LOGGER = Logger.getLogger(ItemTable.class.getName());
private static Logger LOGGER_ITEMS = Logger.getLogger("item"); private static Logger LOGGER_ITEMS = Logger.getLogger("item");
public static final Map<String, Long> SLOTS = new HashMap<>();
private Item[] _allTemplates; private Item[] _allTemplates;
private final Map<Integer, EtcItem> _etcItems = new HashMap<>(); private final Map<Integer, EtcItem> _etcItems = new HashMap<>();
private final Map<Integer, Armor> _armors = new HashMap<>(); private final Map<Integer, Armor> _armors = new HashMap<>();
private final Map<Integer, Weapon> _weapons = new HashMap<>(); private final Map<Integer, Weapon> _weapons = new HashMap<>();
private final List<File> _itemFiles = new ArrayList<>();
public static final Map<String, Long> SLOTS = new HashMap<>();
static static
{ {
SLOTS.put("shirt", (long) Item.SLOT_UNDERWEAR); SLOTS.put("shirt", (long) Item.SLOT_UNDERWEAR);
@ -109,26 +115,77 @@ public class ItemTable
SLOTS.put("waist", (long) Item.SLOT_BELT); SLOTS.put("waist", (long) Item.SLOT_BELT);
} }
/**
* @return a reference to this ItemTable object
*/
public static ItemTable getInstance()
{
return SingletonHolder.INSTANCE;
}
protected ItemTable() protected ItemTable()
{ {
processDirectory("data/stats/items", _itemFiles);
if (Config.CUSTOM_ITEMS_LOAD)
{
processDirectory("data/stats/items/custom", _itemFiles);
}
load(); 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() private void load()
{ {
int highest = 0; int highest = 0;
_armors.clear(); _armors.clear();
_etcItems.clear(); _etcItems.clear();
_weapons.clear(); _weapons.clear();
for (Item item : DocumentEngine.getInstance().loadItems()) for (Item item : loadItems())
{ {
if (highest < item.getId()) if (highest < item.getId())
{ {
@ -466,6 +523,11 @@ public class ItemTable
return _allTemplates.length; return _allTemplates.length;
} }
public static ItemTable getInstance()
{
return SingletonHolder.INSTANCE;
}
private static class SingletonHolder private static class SingletonHolder
{ {
protected static final ItemTable INSTANCE = new ItemTable(); 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,245 +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 java.io.File;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
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;
import org.l2jmobius.gameserver.model.conditions.Condition;
import org.l2jmobius.gameserver.model.holders.ItemSkillHolder;
import org.l2jmobius.gameserver.model.items.Item;
import org.l2jmobius.gameserver.model.stats.Stat;
import org.l2jmobius.gameserver.model.stats.functions.FuncTemplate;
/**
* @author mkizub, JIV
*/
public class DocumentItem extends DocumentBase implements IXmlReader
{
private static final Logger LOGGER = Logger.getLogger(DocumentItem.class.getName());
private ItemDataHolder _currentItem = null;
private final List<Item> _itemsInFile = new ArrayList<>();
/**
* @param file
*/
public DocumentItem(File file)
{
super(file);
}
@Override
protected StatSet getStatSet()
{
return _currentItem.set;
}
@Override
protected String getTableValue(String name)
{
return _tables.get(name)[_currentItem.currentLevel];
}
@Override
protected String getTableValue(String name, int idx)
{
return _tables.get(name)[idx - 1];
}
@Override
protected void parseDocument(Document doc)
{
for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling())
{
if ("list".equalsIgnoreCase(n.getNodeName()))
{
for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
{
if ("item".equalsIgnoreCase(d.getNodeName()))
{
try
{
_currentItem = new ItemDataHolder();
parseItem(d);
_itemsInFile.add(_currentItem.item);
resetTable();
}
catch (Exception e)
{
LOGGER.log(Level.WARNING, "Cannot create item " + _currentItem.id, e);
}
}
}
}
}
}
protected void parseItem(Node node) throws InvocationTargetException
{
Node n = node;
final int itemId = Integer.parseInt(n.getAttributes().getNamedItem("id").getNodeValue());
final String className = n.getAttributes().getNamedItem("type").getNodeValue();
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);
_currentItem.set.set("name", itemName);
_currentItem.set.set("additionalName", additionalName);
final Node first = n.getFirstChild();
for (n = first; n != null; n = n.getNextSibling())
{
if ("table".equalsIgnoreCase(n.getNodeName()))
{
if (_currentItem.item != null)
{
throw new IllegalStateException("Item created but table node found! Item " + itemId);
}
parseTable(n);
}
else if ("set".equalsIgnoreCase(n.getNodeName()))
{
if (_currentItem.item != null)
{
throw new IllegalStateException("Item created but set node found! Item " + itemId);
}
parseBeanSet(n, _currentItem.set, 1);
}
else if ("stats".equalsIgnoreCase(n.getNodeName()))
{
makeItem();
for (Node b = n.getFirstChild(); b != null; b = b.getNextSibling())
{
if ("stat".equalsIgnoreCase(b.getNodeName()))
{
final Stat type = Stat.valueOfXml(b.getAttributes().getNamedItem("type").getNodeValue());
final double value = Double.parseDouble(b.getTextContent());
_currentItem.item.addFunctionTemplate(new FuncTemplate(null, null, "add", 0x00, type, value));
}
}
}
else if ("skills".equalsIgnoreCase(n.getNodeName()))
{
makeItem();
for (Node b = n.getFirstChild(); b != null; b = b.getNextSibling())
{
if ("skill".equalsIgnoreCase(b.getNodeName()))
{
final int id = parseInteger(b.getAttributes(), "id");
final int level = parseInteger(b.getAttributes(), "level");
final ItemSkillType type = parseEnum(b.getAttributes(), ItemSkillType.class, "type", ItemSkillType.NORMAL);
final int chance = parseInteger(b.getAttributes(), "type_chance", 100);
final int value = parseInteger(b.getAttributes(), "type_value", 0);
_currentItem.item.addSkill(new ItemSkillHolder(id, level, type, chance, value));
}
}
}
else if ("capsuled_items".equalsIgnoreCase(n.getNodeName()))
{
makeItem();
for (Node b = n.getFirstChild(); b != null; b = b.getNextSibling())
{
if ("item".equals(b.getNodeName()))
{
final int id = parseInteger(b.getAttributes(), "id");
final int min = parseInteger(b.getAttributes(), "min");
final int max = parseInteger(b.getAttributes(), "max");
final double chance = parseDouble(b.getAttributes(), "chance");
final int minEnchant = parseInteger(b.getAttributes(), "minEnchant", 0);
final int maxEnchant = parseInteger(b.getAttributes(), "maxEnchant", 0);
_currentItem.item.addCapsuledItem(new ExtractableProduct(id, min, max, chance, minEnchant, maxEnchant));
}
}
}
else if ("cond".equalsIgnoreCase(n.getNodeName()))
{
makeItem();
final Condition condition = parseCondition(n.getFirstChild(), _currentItem.item);
final Node msg = n.getAttributes().getNamedItem("msg");
final Node msgId = n.getAttributes().getNamedItem("msgId");
if ((condition != null) && (msg != null))
{
condition.setMessage(msg.getNodeValue());
}
else if ((condition != null) && (msgId != null))
{
condition.setMessageId(Integer.decode(getValue(msgId.getNodeValue(), null)));
final Node addName = n.getAttributes().getNamedItem("addName");
if ((addName != null) && (Integer.decode(getValue(msgId.getNodeValue(), null)) > 0))
{
condition.addName();
}
}
_currentItem.item.attachCondition(condition);
}
}
// bah! in this point item doesn't have to be still created
makeItem();
}
private void makeItem() throws InvocationTargetException
{
// If item exists just reload the data.
if (_currentItem.item != null)
{
_currentItem.item.set(_currentItem.set);
return;
}
try
{
final Constructor<?> itemClass = Class.forName("org.l2jmobius.gameserver.model.items." + _currentItem.type).getConstructor(StatSet.class);
_currentItem.item = (Item) itemClass.newInstance(_currentItem.set);
}
catch (Exception e)
{
throw new InvocationTargetException(e);
}
}
public List<Item> getItemList()
{
return _itemsInFile;
}
@Override
public void load()
{
}
@Override
public void parseDocument(Document doc, File f)
{
}
}

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 * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * 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.io.File;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -0,0 +1,249 @@
/*
* 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.util;
import java.io.File;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.l2jmobius.commons.util.IXmlReader;
import org.l2jmobius.gameserver.enums.ItemSkillType;
import org.l2jmobius.gameserver.model.ExtractableProduct;
import org.l2jmobius.gameserver.model.StatSet;
import org.l2jmobius.gameserver.model.conditions.Condition;
import org.l2jmobius.gameserver.model.holders.ItemSkillHolder;
import org.l2jmobius.gameserver.model.items.Item;
import org.l2jmobius.gameserver.model.stats.Stat;
import org.l2jmobius.gameserver.model.stats.functions.FuncTemplate;
/**
* @author mkizub, JIV
*/
public class DocumentItem extends DocumentBase implements IXmlReader
{
private static final Logger LOGGER = Logger.getLogger(DocumentItem.class.getName());
private DocumentItemDataHolder _currentItem = null;
private final List<Item> _itemsInFile = new ArrayList<>();
private class DocumentItemDataHolder
{
int id;
String type;
StatSet set;
int currentLevel;
Item item;
}
public DocumentItem(File file)
{
super(file);
}
@Override
protected StatSet getStatSet()
{
return _currentItem.set;
}
@Override
protected String getTableValue(String name)
{
return _tables.get(name)[_currentItem.currentLevel];
}
@Override
protected String getTableValue(String name, int idx)
{
return _tables.get(name)[idx - 1];
}
@Override
protected void parseDocument(Document doc)
{
for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling())
{
if ("list".equalsIgnoreCase(n.getNodeName()))
{
for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
{
if ("item".equalsIgnoreCase(d.getNodeName()))
{
try
{
_currentItem = new DocumentItemDataHolder();
parseItem(d);
_itemsInFile.add(_currentItem.item);
resetTable();
}
catch (Exception e)
{
LOGGER.log(Level.WARNING, "Cannot create item " + _currentItem.id, e);
}
}
}
}
}
}
private void parseItem(Node node) throws InvocationTargetException
{
Node n = node;
final int itemId = Integer.parseInt(n.getAttributes().getNamedItem("id").getNodeValue());
final String className = n.getAttributes().getNamedItem("type").getNodeValue();
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.type = className;
_currentItem.set = new StatSet();
_currentItem.set.set("item_id", itemId);
_currentItem.set.set("name", itemName);
_currentItem.set.set("additionalName", additionalName);
final Node first = n.getFirstChild();
for (n = first; n != null; n = n.getNextSibling())
{
if ("table".equalsIgnoreCase(n.getNodeName()))
{
if (_currentItem.item != null)
{
throw new IllegalStateException("Item created but table node found! Item " + itemId);
}
parseTable(n);
}
else if ("set".equalsIgnoreCase(n.getNodeName()))
{
if (_currentItem.item != null)
{
throw new IllegalStateException("Item created but set node found! Item " + itemId);
}
parseBeanSet(n, _currentItem.set, 1);
}
else if ("stats".equalsIgnoreCase(n.getNodeName()))
{
makeItem();
for (Node b = n.getFirstChild(); b != null; b = b.getNextSibling())
{
if ("stat".equalsIgnoreCase(b.getNodeName()))
{
final Stat type = Stat.valueOfXml(b.getAttributes().getNamedItem("type").getNodeValue());
final double value = Double.parseDouble(b.getTextContent());
_currentItem.item.addFunctionTemplate(new FuncTemplate(null, null, "add", 0x00, type, value));
}
}
}
else if ("skills".equalsIgnoreCase(n.getNodeName()))
{
makeItem();
for (Node b = n.getFirstChild(); b != null; b = b.getNextSibling())
{
if ("skill".equalsIgnoreCase(b.getNodeName()))
{
final int id = parseInteger(b.getAttributes(), "id");
final int level = parseInteger(b.getAttributes(), "level");
final ItemSkillType type = parseEnum(b.getAttributes(), ItemSkillType.class, "type", ItemSkillType.NORMAL);
final int chance = parseInteger(b.getAttributes(), "type_chance", 100);
final int value = parseInteger(b.getAttributes(), "type_value", 0);
_currentItem.item.addSkill(new ItemSkillHolder(id, level, type, chance, value));
}
}
}
else if ("capsuled_items".equalsIgnoreCase(n.getNodeName()))
{
makeItem();
for (Node b = n.getFirstChild(); b != null; b = b.getNextSibling())
{
if ("item".equals(b.getNodeName()))
{
final int id = parseInteger(b.getAttributes(), "id");
final int min = parseInteger(b.getAttributes(), "min");
final int max = parseInteger(b.getAttributes(), "max");
final double chance = parseDouble(b.getAttributes(), "chance");
final int minEnchant = parseInteger(b.getAttributes(), "minEnchant", 0);
final int maxEnchant = parseInteger(b.getAttributes(), "maxEnchant", 0);
_currentItem.item.addCapsuledItem(new ExtractableProduct(id, min, max, chance, minEnchant, maxEnchant));
}
}
}
else if ("cond".equalsIgnoreCase(n.getNodeName()))
{
makeItem();
final Condition condition = parseCondition(n.getFirstChild(), _currentItem.item);
final Node msg = n.getAttributes().getNamedItem("msg");
final Node msgId = n.getAttributes().getNamedItem("msgId");
if ((condition != null) && (msg != null))
{
condition.setMessage(msg.getNodeValue());
}
else if ((condition != null) && (msgId != null))
{
condition.setMessageId(Integer.decode(getValue(msgId.getNodeValue(), null)));
final Node addName = n.getAttributes().getNamedItem("addName");
if ((addName != null) && (Integer.decode(getValue(msgId.getNodeValue(), null)) > 0))
{
condition.addName();
}
}
_currentItem.item.attachCondition(condition);
}
}
// bah! in this point item doesn't have to be still created
makeItem();
}
private void makeItem() throws InvocationTargetException
{
// If item exists just reload the data.
if (_currentItem.item != null)
{
_currentItem.item.set(_currentItem.set);
return;
}
try
{
final Constructor<?> itemClass = Class.forName("org.l2jmobius.gameserver.model.items." + _currentItem.type).getConstructor(StatSet.class);
_currentItem.item = (Item) itemClass.newInstance(_currentItem.set);
}
catch (Exception e)
{
throw new InvocationTargetException(e);
}
}
public List<Item> getItemList()
{
return _itemsInFile;
}
@Override
public void load()
{
}
@Override
public void parseDocument(Document doc, File f)
{
}
}

View File

@ -18,12 +18,16 @@ package org.l2jmobius.gameserver.datatables;
import static org.l2jmobius.gameserver.model.itemcontainer.Inventory.ADENA_ID; import static org.l2jmobius.gameserver.model.itemcontainer.Inventory.ADENA_ID;
import java.io.File;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -31,8 +35,8 @@ import java.util.logging.Logger;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.commons.database.DatabaseFactory; 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.data.xml.impl.EnchantItemHPBonusData;
import org.l2jmobius.gameserver.engines.DocumentEngine;
import org.l2jmobius.gameserver.enums.ItemLocation; import org.l2jmobius.gameserver.enums.ItemLocation;
import org.l2jmobius.gameserver.instancemanager.IdManager; import org.l2jmobius.gameserver.instancemanager.IdManager;
import org.l2jmobius.gameserver.model.World; 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.Item;
import org.l2jmobius.gameserver.model.items.Weapon; import org.l2jmobius.gameserver.model.items.Weapon;
import org.l2jmobius.gameserver.model.items.instance.ItemInstance; import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
import org.l2jmobius.gameserver.util.DocumentItem;
import org.l2jmobius.gameserver.util.GMAudit; 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 final Logger LOGGER = Logger.getLogger(ItemTable.class.getName());
private static Logger LOGGER_ITEMS = Logger.getLogger("item"); private static Logger LOGGER_ITEMS = Logger.getLogger("item");
public static final Map<String, Long> SLOTS = new HashMap<>();
private Item[] _allTemplates; private Item[] _allTemplates;
private final Map<Integer, EtcItem> _etcItems = new HashMap<>(); private final Map<Integer, EtcItem> _etcItems = new HashMap<>();
private final Map<Integer, Armor> _armors = new HashMap<>(); private final Map<Integer, Armor> _armors = new HashMap<>();
private final Map<Integer, Weapon> _weapons = new HashMap<>(); private final Map<Integer, Weapon> _weapons = new HashMap<>();
private final List<File> _itemFiles = new ArrayList<>();
public static final Map<String, Long> SLOTS = new HashMap<>();
static static
{ {
SLOTS.put("shirt", (long) Item.SLOT_UNDERWEAR); SLOTS.put("shirt", (long) Item.SLOT_UNDERWEAR);
@ -109,26 +115,77 @@ public class ItemTable
SLOTS.put("waist", (long) Item.SLOT_BELT); SLOTS.put("waist", (long) Item.SLOT_BELT);
} }
/**
* @return a reference to this ItemTable object
*/
public static ItemTable getInstance()
{
return SingletonHolder.INSTANCE;
}
protected ItemTable() protected ItemTable()
{ {
processDirectory("data/stats/items", _itemFiles);
if (Config.CUSTOM_ITEMS_LOAD)
{
processDirectory("data/stats/items/custom", _itemFiles);
}
load(); 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() private void load()
{ {
int highest = 0; int highest = 0;
_armors.clear(); _armors.clear();
_etcItems.clear(); _etcItems.clear();
_weapons.clear(); _weapons.clear();
for (Item item : DocumentEngine.getInstance().loadItems()) for (Item item : loadItems())
{ {
if (highest < item.getId()) if (highest < item.getId())
{ {
@ -466,6 +523,11 @@ public class ItemTable
return _allTemplates.length; return _allTemplates.length;
} }
public static ItemTable getInstance()
{
return SingletonHolder.INSTANCE;
}
private static class SingletonHolder private static class SingletonHolder
{ {
protected static final ItemTable INSTANCE = new ItemTable(); 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,245 +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 java.io.File;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
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;
import org.l2jmobius.gameserver.model.conditions.Condition;
import org.l2jmobius.gameserver.model.holders.ItemSkillHolder;
import org.l2jmobius.gameserver.model.items.Item;
import org.l2jmobius.gameserver.model.stats.Stat;
import org.l2jmobius.gameserver.model.stats.functions.FuncTemplate;
/**
* @author mkizub, JIV
*/
public class DocumentItem extends DocumentBase implements IXmlReader
{
private static final Logger LOGGER = Logger.getLogger(DocumentItem.class.getName());
private ItemDataHolder _currentItem = null;
private final List<Item> _itemsInFile = new ArrayList<>();
/**
* @param file
*/
public DocumentItem(File file)
{
super(file);
}
@Override
protected StatSet getStatSet()
{
return _currentItem.set;
}
@Override
protected String getTableValue(String name)
{
return _tables.get(name)[_currentItem.currentLevel];
}
@Override
protected String getTableValue(String name, int idx)
{
return _tables.get(name)[idx - 1];
}
@Override
protected void parseDocument(Document doc)
{
for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling())
{
if ("list".equalsIgnoreCase(n.getNodeName()))
{
for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
{
if ("item".equalsIgnoreCase(d.getNodeName()))
{
try
{
_currentItem = new ItemDataHolder();
parseItem(d);
_itemsInFile.add(_currentItem.item);
resetTable();
}
catch (Exception e)
{
LOGGER.log(Level.WARNING, "Cannot create item " + _currentItem.id, e);
}
}
}
}
}
}
protected void parseItem(Node node) throws InvocationTargetException
{
Node n = node;
final int itemId = Integer.parseInt(n.getAttributes().getNamedItem("id").getNodeValue());
final String className = n.getAttributes().getNamedItem("type").getNodeValue();
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);
_currentItem.set.set("name", itemName);
_currentItem.set.set("additionalName", additionalName);
final Node first = n.getFirstChild();
for (n = first; n != null; n = n.getNextSibling())
{
if ("table".equalsIgnoreCase(n.getNodeName()))
{
if (_currentItem.item != null)
{
throw new IllegalStateException("Item created but table node found! Item " + itemId);
}
parseTable(n);
}
else if ("set".equalsIgnoreCase(n.getNodeName()))
{
if (_currentItem.item != null)
{
throw new IllegalStateException("Item created but set node found! Item " + itemId);
}
parseBeanSet(n, _currentItem.set, 1);
}
else if ("stats".equalsIgnoreCase(n.getNodeName()))
{
makeItem();
for (Node b = n.getFirstChild(); b != null; b = b.getNextSibling())
{
if ("stat".equalsIgnoreCase(b.getNodeName()))
{
final Stat type = Stat.valueOfXml(b.getAttributes().getNamedItem("type").getNodeValue());
final double value = Double.parseDouble(b.getTextContent());
_currentItem.item.addFunctionTemplate(new FuncTemplate(null, null, "add", 0x00, type, value));
}
}
}
else if ("skills".equalsIgnoreCase(n.getNodeName()))
{
makeItem();
for (Node b = n.getFirstChild(); b != null; b = b.getNextSibling())
{
if ("skill".equalsIgnoreCase(b.getNodeName()))
{
final int id = parseInteger(b.getAttributes(), "id");
final int level = parseInteger(b.getAttributes(), "level");
final ItemSkillType type = parseEnum(b.getAttributes(), ItemSkillType.class, "type", ItemSkillType.NORMAL);
final int chance = parseInteger(b.getAttributes(), "type_chance", 100);
final int value = parseInteger(b.getAttributes(), "type_value", 0);
_currentItem.item.addSkill(new ItemSkillHolder(id, level, type, chance, value));
}
}
}
else if ("capsuled_items".equalsIgnoreCase(n.getNodeName()))
{
makeItem();
for (Node b = n.getFirstChild(); b != null; b = b.getNextSibling())
{
if ("item".equals(b.getNodeName()))
{
final int id = parseInteger(b.getAttributes(), "id");
final int min = parseInteger(b.getAttributes(), "min");
final int max = parseInteger(b.getAttributes(), "max");
final double chance = parseDouble(b.getAttributes(), "chance");
final int minEnchant = parseInteger(b.getAttributes(), "minEnchant", 0);
final int maxEnchant = parseInteger(b.getAttributes(), "maxEnchant", 0);
_currentItem.item.addCapsuledItem(new ExtractableProduct(id, min, max, chance, minEnchant, maxEnchant));
}
}
}
else if ("cond".equalsIgnoreCase(n.getNodeName()))
{
makeItem();
final Condition condition = parseCondition(n.getFirstChild(), _currentItem.item);
final Node msg = n.getAttributes().getNamedItem("msg");
final Node msgId = n.getAttributes().getNamedItem("msgId");
if ((condition != null) && (msg != null))
{
condition.setMessage(msg.getNodeValue());
}
else if ((condition != null) && (msgId != null))
{
condition.setMessageId(Integer.decode(getValue(msgId.getNodeValue(), null)));
final Node addName = n.getAttributes().getNamedItem("addName");
if ((addName != null) && (Integer.decode(getValue(msgId.getNodeValue(), null)) > 0))
{
condition.addName();
}
}
_currentItem.item.attachCondition(condition);
}
}
// bah! in this point item doesn't have to be still created
makeItem();
}
private void makeItem() throws InvocationTargetException
{
// If item exists just reload the data.
if (_currentItem.item != null)
{
_currentItem.item.set(_currentItem.set);
return;
}
try
{
final Constructor<?> itemClass = Class.forName("org.l2jmobius.gameserver.model.items." + _currentItem.type).getConstructor(StatSet.class);
_currentItem.item = (Item) itemClass.newInstance(_currentItem.set);
}
catch (Exception e)
{
throw new InvocationTargetException(e);
}
}
public List<Item> getItemList()
{
return _itemsInFile;
}
@Override
public void load()
{
}
@Override
public void parseDocument(Document doc, File f)
{
}
}

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 * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * 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.io.File;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -0,0 +1,249 @@
/*
* 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.util;
import java.io.File;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.l2jmobius.commons.util.IXmlReader;
import org.l2jmobius.gameserver.enums.ItemSkillType;
import org.l2jmobius.gameserver.model.ExtractableProduct;
import org.l2jmobius.gameserver.model.StatSet;
import org.l2jmobius.gameserver.model.conditions.Condition;
import org.l2jmobius.gameserver.model.holders.ItemSkillHolder;
import org.l2jmobius.gameserver.model.items.Item;
import org.l2jmobius.gameserver.model.stats.Stat;
import org.l2jmobius.gameserver.model.stats.functions.FuncTemplate;
/**
* @author mkizub, JIV
*/
public class DocumentItem extends DocumentBase implements IXmlReader
{
private static final Logger LOGGER = Logger.getLogger(DocumentItem.class.getName());
private DocumentItemDataHolder _currentItem = null;
private final List<Item> _itemsInFile = new ArrayList<>();
private class DocumentItemDataHolder
{
int id;
String type;
StatSet set;
int currentLevel;
Item item;
}
public DocumentItem(File file)
{
super(file);
}
@Override
protected StatSet getStatSet()
{
return _currentItem.set;
}
@Override
protected String getTableValue(String name)
{
return _tables.get(name)[_currentItem.currentLevel];
}
@Override
protected String getTableValue(String name, int idx)
{
return _tables.get(name)[idx - 1];
}
@Override
protected void parseDocument(Document doc)
{
for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling())
{
if ("list".equalsIgnoreCase(n.getNodeName()))
{
for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
{
if ("item".equalsIgnoreCase(d.getNodeName()))
{
try
{
_currentItem = new DocumentItemDataHolder();
parseItem(d);
_itemsInFile.add(_currentItem.item);
resetTable();
}
catch (Exception e)
{
LOGGER.log(Level.WARNING, "Cannot create item " + _currentItem.id, e);
}
}
}
}
}
}
private void parseItem(Node node) throws InvocationTargetException
{
Node n = node;
final int itemId = Integer.parseInt(n.getAttributes().getNamedItem("id").getNodeValue());
final String className = n.getAttributes().getNamedItem("type").getNodeValue();
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.type = className;
_currentItem.set = new StatSet();
_currentItem.set.set("item_id", itemId);
_currentItem.set.set("name", itemName);
_currentItem.set.set("additionalName", additionalName);
final Node first = n.getFirstChild();
for (n = first; n != null; n = n.getNextSibling())
{
if ("table".equalsIgnoreCase(n.getNodeName()))
{
if (_currentItem.item != null)
{
throw new IllegalStateException("Item created but table node found! Item " + itemId);
}
parseTable(n);
}
else if ("set".equalsIgnoreCase(n.getNodeName()))
{
if (_currentItem.item != null)
{
throw new IllegalStateException("Item created but set node found! Item " + itemId);
}
parseBeanSet(n, _currentItem.set, 1);
}
else if ("stats".equalsIgnoreCase(n.getNodeName()))
{
makeItem();
for (Node b = n.getFirstChild(); b != null; b = b.getNextSibling())
{
if ("stat".equalsIgnoreCase(b.getNodeName()))
{
final Stat type = Stat.valueOfXml(b.getAttributes().getNamedItem("type").getNodeValue());
final double value = Double.parseDouble(b.getTextContent());
_currentItem.item.addFunctionTemplate(new FuncTemplate(null, null, "add", 0x00, type, value));
}
}
}
else if ("skills".equalsIgnoreCase(n.getNodeName()))
{
makeItem();
for (Node b = n.getFirstChild(); b != null; b = b.getNextSibling())
{
if ("skill".equalsIgnoreCase(b.getNodeName()))
{
final int id = parseInteger(b.getAttributes(), "id");
final int level = parseInteger(b.getAttributes(), "level");
final ItemSkillType type = parseEnum(b.getAttributes(), ItemSkillType.class, "type", ItemSkillType.NORMAL);
final int chance = parseInteger(b.getAttributes(), "type_chance", 100);
final int value = parseInteger(b.getAttributes(), "type_value", 0);
_currentItem.item.addSkill(new ItemSkillHolder(id, level, type, chance, value));
}
}
}
else if ("capsuled_items".equalsIgnoreCase(n.getNodeName()))
{
makeItem();
for (Node b = n.getFirstChild(); b != null; b = b.getNextSibling())
{
if ("item".equals(b.getNodeName()))
{
final int id = parseInteger(b.getAttributes(), "id");
final int min = parseInteger(b.getAttributes(), "min");
final int max = parseInteger(b.getAttributes(), "max");
final double chance = parseDouble(b.getAttributes(), "chance");
final int minEnchant = parseInteger(b.getAttributes(), "minEnchant", 0);
final int maxEnchant = parseInteger(b.getAttributes(), "maxEnchant", 0);
_currentItem.item.addCapsuledItem(new ExtractableProduct(id, min, max, chance, minEnchant, maxEnchant));
}
}
}
else if ("cond".equalsIgnoreCase(n.getNodeName()))
{
makeItem();
final Condition condition = parseCondition(n.getFirstChild(), _currentItem.item);
final Node msg = n.getAttributes().getNamedItem("msg");
final Node msgId = n.getAttributes().getNamedItem("msgId");
if ((condition != null) && (msg != null))
{
condition.setMessage(msg.getNodeValue());
}
else if ((condition != null) && (msgId != null))
{
condition.setMessageId(Integer.decode(getValue(msgId.getNodeValue(), null)));
final Node addName = n.getAttributes().getNamedItem("addName");
if ((addName != null) && (Integer.decode(getValue(msgId.getNodeValue(), null)) > 0))
{
condition.addName();
}
}
_currentItem.item.attachCondition(condition);
}
}
// bah! in this point item doesn't have to be still created
makeItem();
}
private void makeItem() throws InvocationTargetException
{
// If item exists just reload the data.
if (_currentItem.item != null)
{
_currentItem.item.set(_currentItem.set);
return;
}
try
{
final Constructor<?> itemClass = Class.forName("org.l2jmobius.gameserver.model.items." + _currentItem.type).getConstructor(StatSet.class);
_currentItem.item = (Item) itemClass.newInstance(_currentItem.set);
}
catch (Exception e)
{
throw new InvocationTargetException(e);
}
}
public List<Item> getItemList()
{
return _itemsInFile;
}
@Override
public void load()
{
}
@Override
public void parseDocument(Document doc, File f)
{
}
}

View File

@ -16,9 +16,12 @@
*/ */
package org.l2jmobius.gameserver.datatables; package org.l2jmobius.gameserver.datatables;
import java.io.File;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
@ -30,8 +33,6 @@ import org.l2jmobius.Config;
import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.commons.database.DatabaseFactory; import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.gameserver.datatables.sql.PetDataTable; 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.instancemanager.IdManager;
import org.l2jmobius.gameserver.model.World; import org.l2jmobius.gameserver.model.World;
import org.l2jmobius.gameserver.model.WorldObject; 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.Weapon;
import org.l2jmobius.gameserver.model.items.instance.ItemInstance; import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
import org.l2jmobius.gameserver.model.items.instance.ItemInstance.ItemLocation; 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 $ * @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, EtcItem> _etcItems;
private final Map<Integer, Armor> _armors; private final Map<Integer, Armor> _armors;
private final Map<Integer, Weapon> _weapons; private final Map<Integer, Weapon> _weapons;
private final List<File> _itemFiles = new ArrayList<>();
private static final Map<String, Integer> _crystalTypes = new HashMap<>(); private static final Map<String, Integer> _crystalTypes = new HashMap<>();
static static
@ -70,33 +73,57 @@ public class ItemTable
_crystalTypes.put("none", Item.CRYSTAL_NONE); _crystalTypes.put("none", Item.CRYSTAL_NONE);
} }
/**
* Returns a new object Item
* @return
*/
public ItemDataHolder newItem()
{
return new ItemDataHolder();
}
/**
* Constructor.
*/
private ItemTable() private ItemTable()
{ {
hashFiles("data/stats/items", _itemFiles);
_etcItems = new HashMap<>(); _etcItems = new HashMap<>();
_armors = new HashMap<>(); _armors = new HashMap<>();
_weapons = new HashMap<>(); _weapons = new HashMap<>();
load(); 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() private void load()
{ {
int highest = 0; int highest = 0;
_armors.clear(); _armors.clear();
_etcItems.clear(); _etcItems.clear();
_weapons.clear(); _weapons.clear();
for (Item item : DocumentEngine.getInstance().loadItems()) for (Item item : loadItems())
{ {
if (highest < item.getItemId()) if (highest < item.getItemId())
{ {

View File

@ -16,27 +16,91 @@
*/ */
package org.l2jmobius.gameserver.datatables; package org.l2jmobius.gameserver.datatables;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; 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.Skill;
import org.l2jmobius.gameserver.model.items.type.WeaponType; import org.l2jmobius.gameserver.model.items.type.WeaponType;
import org.l2jmobius.gameserver.util.DocumentSkill;
public class SkillTable 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 Map<Integer, Skill> _skills = new HashMap<>();
private final boolean _initialized = true; private final boolean _initialized = true;
private SkillTable() private SkillTable()
{ {
hashFiles("data/stats/skills", _skillFiles);
reload(); 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() public void reload()
{ {
_skills.clear(); _skills.clear();
DocumentEngine.getInstance().loadAllSkills(_skills); loadAllSkills(_skills);
} }
public boolean isInitialized() public boolean isInitialized()

View File

@ -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();
}
}

View File

@ -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;
}

View File

@ -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<>();
}

View File

@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * 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.io.File;
import java.util.ArrayList; import java.util.ArrayList;
@ -93,7 +93,7 @@ public abstract class DocumentBase
_tables = new HashMap<>(); _tables = new HashMap<>();
} }
Document parse() public Document parse()
{ {
Document doc; Document doc;
try try

View File

@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * 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.io.File;
import java.util.ArrayList; import java.util.ArrayList;
@ -38,11 +38,20 @@ import org.l2jmobius.gameserver.model.items.type.WeaponType;
/** /**
* @author mkizub, JIV * @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 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<>(); private static final Map<String, Integer> _slots = new HashMap<>();
static static
{ {
@ -134,7 +143,7 @@ final class DocumentItem extends DocumentBase
{ {
try try
{ {
_currentItem = new ItemDataHolder(); _currentItem = new DocumentItemDataHolder();
parseItem(d); parseItem(d);
_itemsInFile.add(_currentItem.item); _itemsInFile.add(_currentItem.item);
resetTable(); resetTable();
@ -149,7 +158,7 @@ final class DocumentItem extends DocumentBase
} }
} }
protected void parseItem(Node node) private void parseItem(Node node)
{ {
Node n = node; Node n = node;
final int itemId = Integer.parseInt(n.getAttributes().getNamedItem("id").getNodeValue()); 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(); final String itemName = n.getAttributes().getNamedItem("name").getNodeValue();
_currentItem.id = itemId; _currentItem.id = itemId;
_currentItem.name = itemName;
_currentItem.set = new StatSet(); _currentItem.set = new StatSet();
_currentItem.set.set("item_id", itemId); _currentItem.set.set("item_id", itemId);
_currentItem.set.set("name", itemName); _currentItem.set.set("name", itemName);

View File

@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * 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.io.File;
import java.util.ArrayList; import java.util.ArrayList;
@ -32,17 +32,29 @@ import org.l2jmobius.gameserver.model.skills.conditions.Condition;
/** /**
* @author mkizub * @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<>(); 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); super(file);
} }
private void setCurrentSkill(SkillDataHolder skill) private void setCurrentSkill(DocumentSkillDataHolder skill)
{ {
_currentSkill = skill; _currentSkill = skill;
} }
@ -53,11 +65,6 @@ final class DocumentSkill extends DocumentBase
return _currentSkill.sets[_currentSkill.currentLevel]; return _currentSkill.sets[_currentSkill.currentLevel];
} }
protected List<Skill> getSkills()
{
return _skillsInFile;
}
@Override @Override
protected String getTableValue(String name) protected String getTableValue(String name)
{ {
@ -97,7 +104,7 @@ final class DocumentSkill extends DocumentBase
{ {
if ("skill".equalsIgnoreCase(d.getNodeName())) if ("skill".equalsIgnoreCase(d.getNodeName()))
{ {
setCurrentSkill(new SkillDataHolder()); setCurrentSkill(new DocumentSkillDataHolder());
parseSkill(d); parseSkill(d);
_skillsInFile.addAll(_currentSkill.skills); _skillsInFile.addAll(_currentSkill.skills);
resetTable(); resetTable();
@ -106,14 +113,14 @@ final class DocumentSkill extends DocumentBase
} }
else if ("skill".equalsIgnoreCase(n.getNodeName())) else if ("skill".equalsIgnoreCase(n.getNodeName()))
{ {
setCurrentSkill(new SkillDataHolder()); setCurrentSkill(new DocumentSkillDataHolder());
parseSkill(n); parseSkill(n);
_skillsInFile.addAll(_currentSkill.skills); _skillsInFile.addAll(_currentSkill.skills);
} }
} }
} }
protected void parseSkill(Node node) private void parseSkill(Node node)
{ {
Node n = node; Node n = node;
final NamedNodeMap attrs = n.getAttributes(); final NamedNodeMap attrs = n.getAttributes();
@ -402,4 +409,9 @@ final class DocumentSkill extends DocumentBase
} }
} }
} }
public List<Skill> getSkills()
{
return _skillsInFile;
}
} }

View File

@ -16,9 +16,12 @@
*/ */
package org.l2jmobius.gameserver.datatables; package org.l2jmobius.gameserver.datatables;
import java.io.File;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
@ -30,8 +33,6 @@ import org.l2jmobius.Config;
import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.commons.database.DatabaseFactory; import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.gameserver.datatables.sql.PetDataTable; 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.instancemanager.IdManager;
import org.l2jmobius.gameserver.model.World; import org.l2jmobius.gameserver.model.World;
import org.l2jmobius.gameserver.model.WorldObject; 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.Weapon;
import org.l2jmobius.gameserver.model.items.instance.ItemInstance; import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
import org.l2jmobius.gameserver.model.items.instance.ItemInstance.ItemLocation; 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 $ * @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, EtcItem> _etcItems;
private final Map<Integer, Armor> _armors; private final Map<Integer, Armor> _armors;
private final Map<Integer, Weapon> _weapons; private final Map<Integer, Weapon> _weapons;
private final List<File> _itemFiles = new ArrayList<>();
private static final Map<String, Integer> _crystalTypes = new HashMap<>(); private static final Map<String, Integer> _crystalTypes = new HashMap<>();
static static
@ -70,33 +73,57 @@ public class ItemTable
_crystalTypes.put("none", Item.CRYSTAL_NONE); _crystalTypes.put("none", Item.CRYSTAL_NONE);
} }
/**
* Returns a new object Item
* @return
*/
public ItemDataHolder newItem()
{
return new ItemDataHolder();
}
/**
* Constructor.
*/
private ItemTable() private ItemTable()
{ {
hashFiles("data/stats/items", _itemFiles);
_etcItems = new HashMap<>(); _etcItems = new HashMap<>();
_armors = new HashMap<>(); _armors = new HashMap<>();
_weapons = new HashMap<>(); _weapons = new HashMap<>();
load(); 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() private void load()
{ {
int highest = 0; int highest = 0;
_armors.clear(); _armors.clear();
_etcItems.clear(); _etcItems.clear();
_weapons.clear(); _weapons.clear();
for (Item item : DocumentEngine.getInstance().loadItems()) for (Item item : loadItems())
{ {
if (highest < item.getItemId()) if (highest < item.getItemId())
{ {

View File

@ -16,27 +16,91 @@
*/ */
package org.l2jmobius.gameserver.datatables; package org.l2jmobius.gameserver.datatables;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; 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.Skill;
import org.l2jmobius.gameserver.model.items.type.WeaponType; import org.l2jmobius.gameserver.model.items.type.WeaponType;
import org.l2jmobius.gameserver.util.DocumentSkill;
public class SkillTable 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 Map<Integer, Skill> _skills = new HashMap<>();
private final boolean _initialized = true; private final boolean _initialized = true;
private SkillTable() private SkillTable()
{ {
hashFiles("data/stats/skills", _skillFiles);
reload(); 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() public void reload()
{ {
_skills.clear(); _skills.clear();
DocumentEngine.getInstance().loadAllSkills(_skills); loadAllSkills(_skills);
} }
public boolean isInitialized() public boolean isInitialized()

View File

@ -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();
}
}

View File

@ -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;
}

View File

@ -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<>();
}

View File

@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * 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.io.File;
import java.util.ArrayList; import java.util.ArrayList;
@ -93,7 +93,7 @@ public abstract class DocumentBase
_tables = new HashMap<>(); _tables = new HashMap<>();
} }
Document parse() public Document parse()
{ {
Document doc; Document doc;
try try

View File

@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * 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.io.File;
import java.util.ArrayList; import java.util.ArrayList;
@ -38,11 +38,20 @@ import org.l2jmobius.gameserver.model.items.type.WeaponType;
/** /**
* @author mkizub, JIV * @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 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<>(); private static final Map<String, Integer> _slots = new HashMap<>();
static static
{ {
@ -134,7 +143,7 @@ final class DocumentItem extends DocumentBase
{ {
try try
{ {
_currentItem = new ItemDataHolder(); _currentItem = new DocumentItemDataHolder();
parseItem(d); parseItem(d);
_itemsInFile.add(_currentItem.item); _itemsInFile.add(_currentItem.item);
resetTable(); resetTable();
@ -149,7 +158,7 @@ final class DocumentItem extends DocumentBase
} }
} }
protected void parseItem(Node node) private void parseItem(Node node)
{ {
Node n = node; Node n = node;
final int itemId = Integer.parseInt(n.getAttributes().getNamedItem("id").getNodeValue()); 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(); final String itemName = n.getAttributes().getNamedItem("name").getNodeValue();
_currentItem.id = itemId; _currentItem.id = itemId;
_currentItem.name = itemName;
_currentItem.set = new StatSet(); _currentItem.set = new StatSet();
_currentItem.set.set("item_id", itemId); _currentItem.set.set("item_id", itemId);
_currentItem.set.set("name", itemName); _currentItem.set.set("name", itemName);

View File

@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * 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.io.File;
import java.util.ArrayList; import java.util.ArrayList;
@ -32,17 +32,29 @@ import org.l2jmobius.gameserver.model.skills.conditions.Condition;
/** /**
* @author mkizub * @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<>(); 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); super(file);
} }
private void setCurrentSkill(SkillDataHolder skill) private void setCurrentSkill(DocumentSkillDataHolder skill)
{ {
_currentSkill = skill; _currentSkill = skill;
} }
@ -53,11 +65,6 @@ final class DocumentSkill extends DocumentBase
return _currentSkill.sets[_currentSkill.currentLevel]; return _currentSkill.sets[_currentSkill.currentLevel];
} }
protected List<Skill> getSkills()
{
return _skillsInFile;
}
@Override @Override
protected String getTableValue(String name) protected String getTableValue(String name)
{ {
@ -97,7 +104,7 @@ final class DocumentSkill extends DocumentBase
{ {
if ("skill".equalsIgnoreCase(d.getNodeName())) if ("skill".equalsIgnoreCase(d.getNodeName()))
{ {
setCurrentSkill(new SkillDataHolder()); setCurrentSkill(new DocumentSkillDataHolder());
parseSkill(d); parseSkill(d);
_skillsInFile.addAll(_currentSkill.skills); _skillsInFile.addAll(_currentSkill.skills);
resetTable(); resetTable();
@ -106,14 +113,14 @@ final class DocumentSkill extends DocumentBase
} }
else if ("skill".equalsIgnoreCase(n.getNodeName())) else if ("skill".equalsIgnoreCase(n.getNodeName()))
{ {
setCurrentSkill(new SkillDataHolder()); setCurrentSkill(new DocumentSkillDataHolder());
parseSkill(n); parseSkill(n);
_skillsInFile.addAll(_currentSkill.skills); _skillsInFile.addAll(_currentSkill.skills);
} }
} }
} }
protected void parseSkill(Node node) private void parseSkill(Node node)
{ {
Node n = node; Node n = node;
final NamedNodeMap attrs = n.getAttributes(); final NamedNodeMap attrs = n.getAttributes();
@ -402,4 +409,9 @@ final class DocumentSkill extends DocumentBase
} }
} }
} }
public List<Skill> getSkills()
{
return _skillsInFile;
}
} }

View File

@ -16,13 +16,21 @@
*/ */
package org.l2jmobius.gameserver.data.xml.impl; package org.l2jmobius.gameserver.data.xml.impl;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.l2jmobius.gameserver.engines.DocumentEngine; import org.l2jmobius.Config;
import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.commons.util.file.filter.XMLFilter;
import org.l2jmobius.gameserver.model.skills.Skill; import org.l2jmobius.gameserver.model.skills.Skill;
import org.l2jmobius.gameserver.util.DocumentSkill;
/** /**
* Skill data. * Skill data.
@ -34,23 +42,103 @@ public class SkillData
private final Map<Integer, Skill> _skills = new ConcurrentHashMap<>(); private final Map<Integer, Skill> _skills = new ConcurrentHashMap<>();
private final Map<Integer, Integer> _skillMaxLevel = new ConcurrentHashMap<>(); private final Map<Integer, Integer> _skillMaxLevel = new ConcurrentHashMap<>();
private final Set<Integer> _enchantable = ConcurrentHashMap.newKeySet(); private final Set<Integer> _enchantable = ConcurrentHashMap.newKeySet();
private final List<File> _skillFiles = new ArrayList<>();
private static int count = 0;
protected SkillData() protected SkillData()
{ {
processDirectory("data/stats/skills", _skillFiles);
if (Config.CUSTOM_SKILLS_LOAD)
{
processDirectory("data/stats/skills/custom", _skillFiles);
}
load(); load();
} }
public void reload() private void processDirectory(String dirName, List<File> list)
{ {
load(); final File dir = new File(Config.DATAPACK_ROOT, dirName);
// Reload Skill Tree as well. if (!dir.exists())
SkillTreeData.getInstance().load(); {
LOGGER.warning("Dir " + dir.getAbsolutePath() + " does not exist.");
return;
}
final File[] files = dir.listFiles(new XMLFilter());
for (File file : files)
{
list.add(file);
}
}
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)
{
if (Config.THREADS_FOR_LOADING)
{
final Collection<ScheduledFuture<?>> jobs = ConcurrentHashMap.newKeySet();
for (File file : _skillFiles)
{
jobs.add(ThreadPool.schedule(() ->
{
final List<Skill> skills = loadSkills(file);
if (skills == null)
{
return;
}
for (Skill skill : skills)
{
allSkills.put(SkillData.getSkillHashCode(skill), skill);
count++;
}
}, 0));
}
while (!jobs.isEmpty())
{
for (ScheduledFuture<?> job : jobs)
{
if ((job == null) || job.isDone() || job.isCancelled())
{
jobs.remove(job);
}
}
}
}
else
{
for (File file : _skillFiles)
{
final List<Skill> skills = loadSkills(file);
if (skills == null)
{
return;
}
for (Skill skill : skills)
{
allSkills.put(SkillData.getSkillHashCode(skill), skill);
count++;
}
}
}
LOGGER.info(getClass().getSimpleName() + ": Loaded " + count + " Skill templates from XML files.");
} }
private void load() private void load()
{ {
final Map<Integer, Skill> temp = new ConcurrentHashMap<>(); final Map<Integer, Skill> temp = new ConcurrentHashMap<>();
DocumentEngine.getInstance().loadAllSkills(temp); loadAllSkills(temp);
_skills.clear(); _skills.clear();
_skills.putAll(temp); _skills.putAll(temp);
@ -79,6 +167,13 @@ public class SkillData
} }
} }
public void reload()
{
load();
// Reload Skill Tree as well.
SkillTreeData.getInstance().load();
}
/** /**
* Provides the skill hash * Provides the skill hash
* @param skill The Skill to be hashed * @param skill The Skill to be hashed

View File

@ -18,11 +18,16 @@ package org.l2jmobius.gameserver.datatables;
import static org.l2jmobius.gameserver.model.itemcontainer.Inventory.ADENA_ID; import static org.l2jmobius.gameserver.model.itemcontainer.Inventory.ADENA_ID;
import java.io.File;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -30,8 +35,8 @@ import java.util.logging.Logger;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.commons.database.DatabaseFactory; 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.data.xml.impl.EnchantItemHPBonusData;
import org.l2jmobius.gameserver.engines.DocumentEngine;
import org.l2jmobius.gameserver.enums.ItemLocation; import org.l2jmobius.gameserver.enums.ItemLocation;
import org.l2jmobius.gameserver.instancemanager.IdManager; import org.l2jmobius.gameserver.instancemanager.IdManager;
import org.l2jmobius.gameserver.model.World; import org.l2jmobius.gameserver.model.World;
@ -47,6 +52,7 @@ import org.l2jmobius.gameserver.model.items.EtcItem;
import org.l2jmobius.gameserver.model.items.Item; import org.l2jmobius.gameserver.model.items.Item;
import org.l2jmobius.gameserver.model.items.Weapon; import org.l2jmobius.gameserver.model.items.Weapon;
import org.l2jmobius.gameserver.model.items.instance.ItemInstance; import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
import org.l2jmobius.gameserver.util.DocumentItem;
import org.l2jmobius.gameserver.util.GMAudit; import org.l2jmobius.gameserver.util.GMAudit;
/** /**
@ -100,27 +106,83 @@ public class ItemTable
private final Map<Integer, EtcItem> _etcItems = new HashMap<>(); private final Map<Integer, EtcItem> _etcItems = new HashMap<>();
private final Map<Integer, Armor> _armors = new HashMap<>(); private final Map<Integer, Armor> _armors = new HashMap<>();
private final Map<Integer, Weapon> _weapons = new HashMap<>(); private final Map<Integer, Weapon> _weapons = new HashMap<>();
private final List<File> _itemFiles = new ArrayList<>();
/**
* @return a reference to this ItemTable object
*/
public static ItemTable getInstance()
{
return SingletonHolder.INSTANCE;
}
protected ItemTable() protected ItemTable()
{ {
processDirectory("data/stats/items", _itemFiles);
if (Config.CUSTOM_ITEMS_LOAD)
{
processDirectory("data/stats/items/custom", _itemFiles);
}
load(); 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);
}
}
/**
* 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 void load() private void load()
{ {
int highest = 0; int highest = 0;
_armors.clear(); _armors.clear();
_etcItems.clear(); _etcItems.clear();
_weapons.clear(); _weapons.clear();
for (Item item : DocumentEngine.getInstance().loadItems()) for (Item item : loadItems())
{ {
if (highest < item.getId()) if (highest < item.getId())
{ {
@ -435,6 +497,11 @@ public class ItemTable
return _allTemplates.length; return _allTemplates.length;
} }
public static ItemTable getInstance()
{
return SingletonHolder.INSTANCE;
}
private static class SingletonHolder private static class SingletonHolder
{ {
protected static final ItemTable INSTANCE = new ItemTable(); protected static final ItemTable INSTANCE = new ItemTable();

View File

@ -1,192 +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.Map;
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.data.xml.impl.SkillData;
import org.l2jmobius.gameserver.engines.items.DocumentItem;
import org.l2jmobius.gameserver.engines.skills.DocumentSkill;
import org.l2jmobius.gameserver.model.items.Item;
import org.l2jmobius.gameserver.model.skills.Skill;
/**
* @author mkizub
*/
public class DocumentEngine
{
private static final Logger LOGGER = Logger.getLogger(DocumentEngine.class.getName());
private final List<File> _itemFiles = new ArrayList<>();
private final List<File> _skillFiles = new ArrayList<>();
private static int count = 0;
protected DocumentEngine()
{
processDirectory("data/stats/items", _itemFiles);
if (Config.CUSTOM_ITEMS_LOAD)
{
processDirectory("data/stats/items/custom", _itemFiles);
}
processDirectory("data/stats/skills", _skillFiles);
if (Config.CUSTOM_SKILLS_LOAD)
{
processDirectory("data/stats/skills/custom", _skillFiles);
}
}
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);
}
}
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)
{
if (Config.THREADS_FOR_LOADING)
{
final Collection<ScheduledFuture<?>> jobs = ConcurrentHashMap.newKeySet();
for (File file : _skillFiles)
{
jobs.add(ThreadPool.schedule(() ->
{
final List<Skill> skills = loadSkills(file);
if (skills == null)
{
return;
}
for (Skill skill : skills)
{
allSkills.put(SkillData.getSkillHashCode(skill), skill);
count++;
}
}, 0));
}
while (!jobs.isEmpty())
{
for (ScheduledFuture<?> job : jobs)
{
if ((job == null) || job.isDone() || job.isCancelled())
{
jobs.remove(job);
}
}
}
}
else
{
for (File file : _skillFiles)
{
final List<Skill> skills = loadSkills(file);
if (skills == null)
{
return;
}
for (Skill skill : skills)
{
allSkills.put(SkillData.getSkillHashCode(skill), skill);
count++;
}
}
}
LOGGER.info(getClass().getSimpleName() + ": Loaded " + count + " Skill templates from XML files.");
}
/**
* 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

@ -1,44 +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.skills;
import java.util.ArrayList;
import java.util.List;
import org.l2jmobius.gameserver.model.StatSet;
import org.l2jmobius.gameserver.model.skills.Skill;
/**
* @author Mobius
*/
public class SkillDataHolder
{
public int id;
public String name;
public StatSet[] sets;
public StatSet[] enchsets1;
public StatSet[] enchsets2;
public StatSet[] enchsets3;
public StatSet[] enchsets4;
public StatSet[] enchsets5;
public StatSet[] enchsets6;
public StatSet[] enchsets7;
public StatSet[] enchsets8;
public int currentLevel;
public List<Skill> skills = new ArrayList<>();
public List<Skill> currentSkills = new ArrayList<>();
}

View File

@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * 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.io.File;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * 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.io.File;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
@ -26,7 +26,6 @@ import java.util.logging.Level;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.l2jmobius.gameserver.engines.DocumentBase;
import org.l2jmobius.gameserver.model.StatSet; import org.l2jmobius.gameserver.model.StatSet;
import org.l2jmobius.gameserver.model.conditions.Condition; import org.l2jmobius.gameserver.model.conditions.Condition;
import org.l2jmobius.gameserver.model.items.Item; import org.l2jmobius.gameserver.model.items.Item;
@ -36,9 +35,18 @@ import org.l2jmobius.gameserver.model.items.Item;
*/ */
public 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 final List<Item> _itemsInFile = new ArrayList<>();
private class DocumentItemDataHolder
{
int id;
String type;
StatSet set;
int currentLevel;
Item item;
}
/** /**
* @param file * @param file
*/ */
@ -78,7 +86,7 @@ public class DocumentItem extends DocumentBase
{ {
try try
{ {
_currentItem = new ItemDataHolder(); _currentItem = new DocumentItemDataHolder();
parseItem(d); parseItem(d);
_itemsInFile.add(_currentItem.item); _itemsInFile.add(_currentItem.item);
resetTable(); resetTable();
@ -93,7 +101,7 @@ public class DocumentItem extends DocumentBase
} }
} }
protected void parseItem(Node node) throws InvocationTargetException private void parseItem(Node node) throws InvocationTargetException
{ {
Node n = node; Node n = node;
final int itemId = Integer.parseInt(n.getAttributes().getNamedItem("id").getNodeValue()); final int itemId = Integer.parseInt(n.getAttributes().getNamedItem("id").getNodeValue());
@ -101,7 +109,6 @@ public class DocumentItem extends DocumentBase
final String itemName = n.getAttributes().getNamedItem("name").getNodeValue(); final String itemName = n.getAttributes().getNamedItem("name").getNodeValue();
_currentItem.id = itemId; _currentItem.id = itemId;
_currentItem.name = itemName;
_currentItem.type = className; _currentItem.type = className;
_currentItem.set = new StatSet(); _currentItem.set = new StatSet();
_currentItem.set.set("item_id", itemId); _currentItem.set.set("item_id", itemId);

View File

@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.l2jmobius.gameserver.engines.skills; package org.l2jmobius.gameserver.util;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
@ -26,7 +26,6 @@ import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.l2jmobius.gameserver.data.xml.impl.EnchantSkillGroupsData; import org.l2jmobius.gameserver.data.xml.impl.EnchantSkillGroupsData;
import org.l2jmobius.gameserver.engines.DocumentBase;
import org.l2jmobius.gameserver.model.StatSet; import org.l2jmobius.gameserver.model.StatSet;
import org.l2jmobius.gameserver.model.conditions.Condition; import org.l2jmobius.gameserver.model.conditions.Condition;
import org.l2jmobius.gameserver.model.skills.EffectScope; import org.l2jmobius.gameserver.model.skills.EffectScope;
@ -37,15 +36,33 @@ import org.l2jmobius.gameserver.model.skills.Skill;
*/ */
public class DocumentSkill extends DocumentBase public class DocumentSkill extends DocumentBase
{ {
private SkillDataHolder _currentSkill; private DocumentSkillDataHolder _currentSkill;
private final List<Skill> _skillsInFile = new ArrayList<>(); private final List<Skill> _skillsInFile = new ArrayList<>();
private class DocumentSkillDataHolder
{
public int id;
public String name;
public StatSet[] sets;
public StatSet[] enchsets1;
public StatSet[] enchsets2;
public StatSet[] enchsets3;
public StatSet[] enchsets4;
public StatSet[] enchsets5;
public StatSet[] enchsets6;
public StatSet[] enchsets7;
public StatSet[] enchsets8;
public int currentLevel;
public List<Skill> skills = new ArrayList<>();
public List<Skill> currentSkills = new ArrayList<>();
}
public DocumentSkill(File file) public DocumentSkill(File file)
{ {
super(file); super(file);
} }
private void setCurrentSkill(SkillDataHolder skill) private void setCurrentSkill(DocumentSkillDataHolder skill)
{ {
_currentSkill = skill; _currentSkill = skill;
} }
@ -56,11 +73,6 @@ public class DocumentSkill extends DocumentBase
return _currentSkill.sets[_currentSkill.currentLevel]; return _currentSkill.sets[_currentSkill.currentLevel];
} }
public List<Skill> getSkills()
{
return _skillsInFile;
}
@Override @Override
protected String getTableValue(String name) protected String getTableValue(String name)
{ {
@ -100,7 +112,7 @@ public class DocumentSkill extends DocumentBase
{ {
if ("skill".equalsIgnoreCase(d.getNodeName())) if ("skill".equalsIgnoreCase(d.getNodeName()))
{ {
setCurrentSkill(new SkillDataHolder()); setCurrentSkill(new DocumentSkillDataHolder());
parseSkill(d); parseSkill(d);
_skillsInFile.addAll(_currentSkill.skills); _skillsInFile.addAll(_currentSkill.skills);
resetTable(); resetTable();
@ -109,14 +121,14 @@ public class DocumentSkill extends DocumentBase
} }
else if ("skill".equalsIgnoreCase(n.getNodeName())) else if ("skill".equalsIgnoreCase(n.getNodeName()))
{ {
setCurrentSkill(new SkillDataHolder()); setCurrentSkill(new DocumentSkillDataHolder());
parseSkill(n); parseSkill(n);
_skillsInFile.addAll(_currentSkill.skills); _skillsInFile.addAll(_currentSkill.skills);
} }
} }
} }
protected void parseSkill(Node node) private void parseSkill(Node node)
{ {
Node n = node; Node n = node;
final NamedNodeMap attrs = n.getAttributes(); final NamedNodeMap attrs = n.getAttributes();
@ -1655,4 +1667,9 @@ public class DocumentSkill extends DocumentBase
} }
} }
} }
public List<Skill> getSkills()
{
return _skillsInFile;
}
} }

View File

@ -16,13 +16,21 @@
*/ */
package org.l2jmobius.gameserver.data.xml.impl; package org.l2jmobius.gameserver.data.xml.impl;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.l2jmobius.gameserver.engines.DocumentEngine; import org.l2jmobius.Config;
import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.commons.util.file.filter.XMLFilter;
import org.l2jmobius.gameserver.model.skills.Skill; import org.l2jmobius.gameserver.model.skills.Skill;
import org.l2jmobius.gameserver.util.DocumentSkill;
/** /**
* Skill data. * Skill data.
@ -34,23 +42,103 @@ public class SkillData
private final Map<Integer, Skill> _skills = new ConcurrentHashMap<>(); private final Map<Integer, Skill> _skills = new ConcurrentHashMap<>();
private final Map<Integer, Integer> _skillMaxLevel = new ConcurrentHashMap<>(); private final Map<Integer, Integer> _skillMaxLevel = new ConcurrentHashMap<>();
private final Set<Integer> _enchantable = ConcurrentHashMap.newKeySet(); private final Set<Integer> _enchantable = ConcurrentHashMap.newKeySet();
private final List<File> _skillFiles = new ArrayList<>();
private static int count = 0;
protected SkillData() protected SkillData()
{ {
processDirectory("data/stats/skills", _skillFiles);
if (Config.CUSTOM_SKILLS_LOAD)
{
processDirectory("data/stats/skills/custom", _skillFiles);
}
load(); load();
} }
public void reload() private void processDirectory(String dirName, List<File> list)
{ {
load(); final File dir = new File(Config.DATAPACK_ROOT, dirName);
// Reload Skill Tree as well. if (!dir.exists())
SkillTreeData.getInstance().load(); {
LOGGER.warning("Dir " + dir.getAbsolutePath() + " does not exist.");
return;
}
final File[] files = dir.listFiles(new XMLFilter());
for (File file : files)
{
list.add(file);
}
}
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)
{
if (Config.THREADS_FOR_LOADING)
{
final Collection<ScheduledFuture<?>> jobs = ConcurrentHashMap.newKeySet();
for (File file : _skillFiles)
{
jobs.add(ThreadPool.schedule(() ->
{
final List<Skill> skills = loadSkills(file);
if (skills == null)
{
return;
}
for (Skill skill : skills)
{
allSkills.put(SkillData.getSkillHashCode(skill), skill);
count++;
}
}, 0));
}
while (!jobs.isEmpty())
{
for (ScheduledFuture<?> job : jobs)
{
if ((job == null) || job.isDone() || job.isCancelled())
{
jobs.remove(job);
}
}
}
}
else
{
for (File file : _skillFiles)
{
final List<Skill> skills = loadSkills(file);
if (skills == null)
{
return;
}
for (Skill skill : skills)
{
allSkills.put(SkillData.getSkillHashCode(skill), skill);
count++;
}
}
}
LOGGER.info(getClass().getSimpleName() + ": Loaded " + count + " Skill templates from XML files.");
} }
private void load() private void load()
{ {
final Map<Integer, Skill> temp = new ConcurrentHashMap<>(); final Map<Integer, Skill> temp = new ConcurrentHashMap<>();
DocumentEngine.getInstance().loadAllSkills(temp); loadAllSkills(temp);
_skills.clear(); _skills.clear();
_skills.putAll(temp); _skills.putAll(temp);
@ -79,6 +167,13 @@ public class SkillData
} }
} }
public void reload()
{
load();
// Reload Skill Tree as well.
SkillTreeData.getInstance().load();
}
/** /**
* Provides the skill hash * Provides the skill hash
* @param skill The Skill to be hashed * @param skill The Skill to be hashed

View File

@ -18,11 +18,16 @@ package org.l2jmobius.gameserver.datatables;
import static org.l2jmobius.gameserver.model.itemcontainer.Inventory.ADENA_ID; import static org.l2jmobius.gameserver.model.itemcontainer.Inventory.ADENA_ID;
import java.io.File;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -30,8 +35,8 @@ import java.util.logging.Logger;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.commons.database.DatabaseFactory; 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.data.xml.impl.EnchantItemHPBonusData;
import org.l2jmobius.gameserver.engines.DocumentEngine;
import org.l2jmobius.gameserver.enums.ItemLocation; import org.l2jmobius.gameserver.enums.ItemLocation;
import org.l2jmobius.gameserver.instancemanager.IdManager; import org.l2jmobius.gameserver.instancemanager.IdManager;
import org.l2jmobius.gameserver.model.World; import org.l2jmobius.gameserver.model.World;
@ -47,6 +52,7 @@ import org.l2jmobius.gameserver.model.items.EtcItem;
import org.l2jmobius.gameserver.model.items.Item; import org.l2jmobius.gameserver.model.items.Item;
import org.l2jmobius.gameserver.model.items.Weapon; import org.l2jmobius.gameserver.model.items.Weapon;
import org.l2jmobius.gameserver.model.items.instance.ItemInstance; import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
import org.l2jmobius.gameserver.util.DocumentItem;
import org.l2jmobius.gameserver.util.GMAudit; import org.l2jmobius.gameserver.util.GMAudit;
/** /**
@ -100,27 +106,83 @@ public class ItemTable
private final Map<Integer, EtcItem> _etcItems = new HashMap<>(); private final Map<Integer, EtcItem> _etcItems = new HashMap<>();
private final Map<Integer, Armor> _armors = new HashMap<>(); private final Map<Integer, Armor> _armors = new HashMap<>();
private final Map<Integer, Weapon> _weapons = new HashMap<>(); private final Map<Integer, Weapon> _weapons = new HashMap<>();
private final List<File> _itemFiles = new ArrayList<>();
/**
* @return a reference to this ItemTable object
*/
public static ItemTable getInstance()
{
return SingletonHolder.INSTANCE;
}
protected ItemTable() protected ItemTable()
{ {
processDirectory("data/stats/items", _itemFiles);
if (Config.CUSTOM_ITEMS_LOAD)
{
processDirectory("data/stats/items/custom", _itemFiles);
}
load(); 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);
}
}
/**
* 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 void load() private void load()
{ {
int highest = 0; int highest = 0;
_armors.clear(); _armors.clear();
_etcItems.clear(); _etcItems.clear();
_weapons.clear(); _weapons.clear();
for (Item item : DocumentEngine.getInstance().loadItems()) for (Item item : loadItems())
{ {
if (highest < item.getId()) if (highest < item.getId())
{ {
@ -435,6 +497,11 @@ public class ItemTable
return _allTemplates.length; return _allTemplates.length;
} }
public static ItemTable getInstance()
{
return SingletonHolder.INSTANCE;
}
private static class SingletonHolder private static class SingletonHolder
{ {
protected static final ItemTable INSTANCE = new ItemTable(); protected static final ItemTable INSTANCE = new ItemTable();

View File

@ -1,192 +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.Map;
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.data.xml.impl.SkillData;
import org.l2jmobius.gameserver.engines.items.DocumentItem;
import org.l2jmobius.gameserver.engines.skills.DocumentSkill;
import org.l2jmobius.gameserver.model.items.Item;
import org.l2jmobius.gameserver.model.skills.Skill;
/**
* @author mkizub
*/
public class DocumentEngine
{
private static final Logger LOGGER = Logger.getLogger(DocumentEngine.class.getName());
private final List<File> _itemFiles = new ArrayList<>();
private final List<File> _skillFiles = new ArrayList<>();
private static int count = 0;
protected DocumentEngine()
{
processDirectory("data/stats/items", _itemFiles);
if (Config.CUSTOM_ITEMS_LOAD)
{
processDirectory("data/stats/items/custom", _itemFiles);
}
processDirectory("data/stats/skills", _skillFiles);
if (Config.CUSTOM_SKILLS_LOAD)
{
processDirectory("data/stats/skills/custom", _skillFiles);
}
}
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);
}
}
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)
{
if (Config.THREADS_FOR_LOADING)
{
final Collection<ScheduledFuture<?>> jobs = ConcurrentHashMap.newKeySet();
for (File file : _skillFiles)
{
jobs.add(ThreadPool.schedule(() ->
{
final List<Skill> skills = loadSkills(file);
if (skills == null)
{
return;
}
for (Skill skill : skills)
{
allSkills.put(SkillData.getSkillHashCode(skill), skill);
count++;
}
}, 0));
}
while (!jobs.isEmpty())
{
for (ScheduledFuture<?> job : jobs)
{
if ((job == null) || job.isDone() || job.isCancelled())
{
jobs.remove(job);
}
}
}
}
else
{
for (File file : _skillFiles)
{
final List<Skill> skills = loadSkills(file);
if (skills == null)
{
return;
}
for (Skill skill : skills)
{
allSkills.put(SkillData.getSkillHashCode(skill), skill);
count++;
}
}
}
LOGGER.info(getClass().getSimpleName() + ": Loaded " + count + " Skill templates from XML files.");
}
/**
* 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

@ -1,44 +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.skills;
import java.util.ArrayList;
import java.util.List;
import org.l2jmobius.gameserver.model.StatSet;
import org.l2jmobius.gameserver.model.skills.Skill;
/**
* @author Mobius
*/
public class SkillDataHolder
{
public int id;
public String name;
public StatSet[] sets;
public StatSet[] enchsets1;
public StatSet[] enchsets2;
public StatSet[] enchsets3;
public StatSet[] enchsets4;
public StatSet[] enchsets5;
public StatSet[] enchsets6;
public StatSet[] enchsets7;
public StatSet[] enchsets8;
public int currentLevel;
public List<Skill> skills = new ArrayList<>();
public List<Skill> currentSkills = new ArrayList<>();
}

View File

@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * 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.io.File;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * 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.io.File;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
@ -26,7 +26,6 @@ import java.util.logging.Level;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.l2jmobius.gameserver.engines.DocumentBase;
import org.l2jmobius.gameserver.model.StatSet; import org.l2jmobius.gameserver.model.StatSet;
import org.l2jmobius.gameserver.model.conditions.Condition; import org.l2jmobius.gameserver.model.conditions.Condition;
import org.l2jmobius.gameserver.model.items.Item; import org.l2jmobius.gameserver.model.items.Item;
@ -36,9 +35,18 @@ import org.l2jmobius.gameserver.model.items.Item;
*/ */
public 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 final List<Item> _itemsInFile = new ArrayList<>();
private class DocumentItemDataHolder
{
int id;
String type;
StatSet set;
int currentLevel;
Item item;
}
/** /**
* @param file * @param file
*/ */
@ -78,7 +86,7 @@ public class DocumentItem extends DocumentBase
{ {
try try
{ {
_currentItem = new ItemDataHolder(); _currentItem = new DocumentItemDataHolder();
parseItem(d); parseItem(d);
_itemsInFile.add(_currentItem.item); _itemsInFile.add(_currentItem.item);
resetTable(); resetTable();
@ -93,7 +101,7 @@ public class DocumentItem extends DocumentBase
} }
} }
protected void parseItem(Node node) throws InvocationTargetException private void parseItem(Node node) throws InvocationTargetException
{ {
Node n = node; Node n = node;
final int itemId = Integer.parseInt(n.getAttributes().getNamedItem("id").getNodeValue()); final int itemId = Integer.parseInt(n.getAttributes().getNamedItem("id").getNodeValue());
@ -101,7 +109,6 @@ public class DocumentItem extends DocumentBase
final String itemName = n.getAttributes().getNamedItem("name").getNodeValue(); final String itemName = n.getAttributes().getNamedItem("name").getNodeValue();
_currentItem.id = itemId; _currentItem.id = itemId;
_currentItem.name = itemName;
_currentItem.type = className; _currentItem.type = className;
_currentItem.set = new StatSet(); _currentItem.set = new StatSet();
_currentItem.set.set("item_id", itemId); _currentItem.set.set("item_id", itemId);

View File

@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.l2jmobius.gameserver.engines.skills; package org.l2jmobius.gameserver.util;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
@ -26,7 +26,6 @@ import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.l2jmobius.gameserver.data.xml.impl.EnchantSkillGroupsData; import org.l2jmobius.gameserver.data.xml.impl.EnchantSkillGroupsData;
import org.l2jmobius.gameserver.engines.DocumentBase;
import org.l2jmobius.gameserver.model.StatSet; import org.l2jmobius.gameserver.model.StatSet;
import org.l2jmobius.gameserver.model.conditions.Condition; import org.l2jmobius.gameserver.model.conditions.Condition;
import org.l2jmobius.gameserver.model.skills.EffectScope; import org.l2jmobius.gameserver.model.skills.EffectScope;
@ -37,15 +36,33 @@ import org.l2jmobius.gameserver.model.skills.Skill;
*/ */
public class DocumentSkill extends DocumentBase public class DocumentSkill extends DocumentBase
{ {
private SkillDataHolder _currentSkill; private DocumentSkillDataHolder _currentSkill;
private final List<Skill> _skillsInFile = new ArrayList<>(); private final List<Skill> _skillsInFile = new ArrayList<>();
private class DocumentSkillDataHolder
{
public int id;
public String name;
public StatSet[] sets;
public StatSet[] enchsets1;
public StatSet[] enchsets2;
public StatSet[] enchsets3;
public StatSet[] enchsets4;
public StatSet[] enchsets5;
public StatSet[] enchsets6;
public StatSet[] enchsets7;
public StatSet[] enchsets8;
public int currentLevel;
public List<Skill> skills = new ArrayList<>();
public List<Skill> currentSkills = new ArrayList<>();
}
public DocumentSkill(File file) public DocumentSkill(File file)
{ {
super(file); super(file);
} }
private void setCurrentSkill(SkillDataHolder skill) private void setCurrentSkill(DocumentSkillDataHolder skill)
{ {
_currentSkill = skill; _currentSkill = skill;
} }
@ -56,11 +73,6 @@ public class DocumentSkill extends DocumentBase
return _currentSkill.sets[_currentSkill.currentLevel]; return _currentSkill.sets[_currentSkill.currentLevel];
} }
public List<Skill> getSkills()
{
return _skillsInFile;
}
@Override @Override
protected String getTableValue(String name) protected String getTableValue(String name)
{ {
@ -100,7 +112,7 @@ public class DocumentSkill extends DocumentBase
{ {
if ("skill".equalsIgnoreCase(d.getNodeName())) if ("skill".equalsIgnoreCase(d.getNodeName()))
{ {
setCurrentSkill(new SkillDataHolder()); setCurrentSkill(new DocumentSkillDataHolder());
parseSkill(d); parseSkill(d);
_skillsInFile.addAll(_currentSkill.skills); _skillsInFile.addAll(_currentSkill.skills);
resetTable(); resetTable();
@ -109,14 +121,14 @@ public class DocumentSkill extends DocumentBase
} }
else if ("skill".equalsIgnoreCase(n.getNodeName())) else if ("skill".equalsIgnoreCase(n.getNodeName()))
{ {
setCurrentSkill(new SkillDataHolder()); setCurrentSkill(new DocumentSkillDataHolder());
parseSkill(n); parseSkill(n);
_skillsInFile.addAll(_currentSkill.skills); _skillsInFile.addAll(_currentSkill.skills);
} }
} }
} }
protected void parseSkill(Node node) private void parseSkill(Node node)
{ {
Node n = node; Node n = node;
final NamedNodeMap attrs = n.getAttributes(); final NamedNodeMap attrs = n.getAttributes();
@ -1655,4 +1667,9 @@ public class DocumentSkill extends DocumentBase
} }
} }
} }
public List<Skill> getSkills()
{
return _skillsInFile;
}
} }

View File

@ -18,12 +18,16 @@ package org.l2jmobius.gameserver.datatables;
import static org.l2jmobius.gameserver.model.itemcontainer.Inventory.ADENA_ID; import static org.l2jmobius.gameserver.model.itemcontainer.Inventory.ADENA_ID;
import java.io.File;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -31,8 +35,8 @@ import java.util.logging.Logger;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.commons.database.DatabaseFactory; 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.data.xml.impl.EnchantItemHPBonusData;
import org.l2jmobius.gameserver.engines.DocumentEngine;
import org.l2jmobius.gameserver.enums.ItemLocation; import org.l2jmobius.gameserver.enums.ItemLocation;
import org.l2jmobius.gameserver.instancemanager.IdManager; import org.l2jmobius.gameserver.instancemanager.IdManager;
import org.l2jmobius.gameserver.model.World; 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.Item;
import org.l2jmobius.gameserver.model.items.Weapon; import org.l2jmobius.gameserver.model.items.Weapon;
import org.l2jmobius.gameserver.model.items.instance.ItemInstance; import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
import org.l2jmobius.gameserver.util.DocumentItem;
import org.l2jmobius.gameserver.util.GMAudit; 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 final Logger LOGGER = Logger.getLogger(ItemTable.class.getName());
private static Logger LOGGER_ITEMS = Logger.getLogger("item"); private static Logger LOGGER_ITEMS = Logger.getLogger("item");
public static final Map<String, Integer> SLOTS = new HashMap<>();
private Item[] _allTemplates; private Item[] _allTemplates;
private final Map<Integer, EtcItem> _etcItems = new HashMap<>(); private final Map<Integer, EtcItem> _etcItems = new HashMap<>();
private final Map<Integer, Armor> _armors = new HashMap<>(); private final Map<Integer, Armor> _armors = new HashMap<>();
private final Map<Integer, Weapon> _weapons = 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 static
{ {
SLOTS.put("shirt", Item.SLOT_UNDERWEAR); SLOTS.put("shirt", Item.SLOT_UNDERWEAR);
@ -106,26 +112,77 @@ public class ItemTable
SLOTS.put("waist", Item.SLOT_BELT); SLOTS.put("waist", Item.SLOT_BELT);
} }
/**
* @return a reference to this ItemTable object
*/
public static ItemTable getInstance()
{
return SingletonHolder.INSTANCE;
}
protected ItemTable() protected ItemTable()
{ {
processDirectory("data/stats/items", _itemFiles);
if (Config.CUSTOM_ITEMS_LOAD)
{
processDirectory("data/stats/items/custom", _itemFiles);
}
load(); 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() private void load()
{ {
int highest = 0; int highest = 0;
_armors.clear(); _armors.clear();
_etcItems.clear(); _etcItems.clear();
_weapons.clear(); _weapons.clear();
for (Item item : DocumentEngine.getInstance().loadItems()) for (Item item : loadItems())
{ {
if (highest < item.getId()) if (highest < item.getId())
{ {
@ -463,6 +520,11 @@ public class ItemTable
return _allTemplates.length; return _allTemplates.length;
} }
public static ItemTable getInstance()
{
return SingletonHolder.INSTANCE;
}
private static class SingletonHolder private static class SingletonHolder
{ {
protected static final ItemTable INSTANCE = new ItemTable(); 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,245 +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 java.io.File;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
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;
import org.l2jmobius.gameserver.model.conditions.Condition;
import org.l2jmobius.gameserver.model.holders.ItemSkillHolder;
import org.l2jmobius.gameserver.model.items.Item;
import org.l2jmobius.gameserver.model.stats.Stat;
import org.l2jmobius.gameserver.model.stats.functions.FuncTemplate;
/**
* @author mkizub, JIV
*/
public class DocumentItem extends DocumentBase implements IXmlReader
{
private static final Logger LOGGER = Logger.getLogger(DocumentItem.class.getName());
private ItemDataHolder _currentItem = null;
private final List<Item> _itemsInFile = new ArrayList<>();
/**
* @param file
*/
public DocumentItem(File file)
{
super(file);
}
@Override
protected StatSet getStatSet()
{
return _currentItem.set;
}
@Override
protected String getTableValue(String name)
{
return _tables.get(name)[_currentItem.currentLevel];
}
@Override
protected String getTableValue(String name, int idx)
{
return _tables.get(name)[idx - 1];
}
@Override
protected void parseDocument(Document doc)
{
for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling())
{
if ("list".equalsIgnoreCase(n.getNodeName()))
{
for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
{
if ("item".equalsIgnoreCase(d.getNodeName()))
{
try
{
_currentItem = new ItemDataHolder();
parseItem(d);
_itemsInFile.add(_currentItem.item);
resetTable();
}
catch (Exception e)
{
LOGGER.log(Level.WARNING, "Cannot create item " + _currentItem.id, e);
}
}
}
}
}
}
protected void parseItem(Node node) throws InvocationTargetException
{
Node n = node;
final int itemId = Integer.parseInt(n.getAttributes().getNamedItem("id").getNodeValue());
final String className = n.getAttributes().getNamedItem("type").getNodeValue();
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);
_currentItem.set.set("name", itemName);
_currentItem.set.set("additionalName", additionalName);
final Node first = n.getFirstChild();
for (n = first; n != null; n = n.getNextSibling())
{
if ("table".equalsIgnoreCase(n.getNodeName()))
{
if (_currentItem.item != null)
{
throw new IllegalStateException("Item created but table node found! Item " + itemId);
}
parseTable(n);
}
else if ("set".equalsIgnoreCase(n.getNodeName()))
{
if (_currentItem.item != null)
{
throw new IllegalStateException("Item created but set node found! Item " + itemId);
}
parseBeanSet(n, _currentItem.set, 1);
}
else if ("stats".equalsIgnoreCase(n.getNodeName()))
{
makeItem();
for (Node b = n.getFirstChild(); b != null; b = b.getNextSibling())
{
if ("stat".equalsIgnoreCase(b.getNodeName()))
{
final Stat type = Stat.valueOfXml(b.getAttributes().getNamedItem("type").getNodeValue());
final double value = Double.parseDouble(b.getTextContent());
_currentItem.item.addFunctionTemplate(new FuncTemplate(null, null, "add", 0x00, type, value));
}
}
}
else if ("skills".equalsIgnoreCase(n.getNodeName()))
{
makeItem();
for (Node b = n.getFirstChild(); b != null; b = b.getNextSibling())
{
if ("skill".equalsIgnoreCase(b.getNodeName()))
{
final int id = parseInteger(b.getAttributes(), "id");
final int level = parseInteger(b.getAttributes(), "level");
final ItemSkillType type = parseEnum(b.getAttributes(), ItemSkillType.class, "type", ItemSkillType.NORMAL);
final int chance = parseInteger(b.getAttributes(), "type_chance", 100);
final int value = parseInteger(b.getAttributes(), "type_value", 0);
_currentItem.item.addSkill(new ItemSkillHolder(id, level, type, chance, value));
}
}
}
else if ("capsuled_items".equalsIgnoreCase(n.getNodeName()))
{
makeItem();
for (Node b = n.getFirstChild(); b != null; b = b.getNextSibling())
{
if ("item".equals(b.getNodeName()))
{
final int id = parseInteger(b.getAttributes(), "id");
final int min = parseInteger(b.getAttributes(), "min");
final int max = parseInteger(b.getAttributes(), "max");
final double chance = parseDouble(b.getAttributes(), "chance");
final int minEnchant = parseInteger(b.getAttributes(), "minEnchant", 0);
final int maxEnchant = parseInteger(b.getAttributes(), "maxEnchant", 0);
_currentItem.item.addCapsuledItem(new ExtractableProduct(id, min, max, chance, minEnchant, maxEnchant));
}
}
}
else if ("cond".equalsIgnoreCase(n.getNodeName()))
{
makeItem();
final Condition condition = parseCondition(n.getFirstChild(), _currentItem.item);
final Node msg = n.getAttributes().getNamedItem("msg");
final Node msgId = n.getAttributes().getNamedItem("msgId");
if ((condition != null) && (msg != null))
{
condition.setMessage(msg.getNodeValue());
}
else if ((condition != null) && (msgId != null))
{
condition.setMessageId(Integer.decode(getValue(msgId.getNodeValue(), null)));
final Node addName = n.getAttributes().getNamedItem("addName");
if ((addName != null) && (Integer.decode(getValue(msgId.getNodeValue(), null)) > 0))
{
condition.addName();
}
}
_currentItem.item.attachCondition(condition);
}
}
// bah! in this point item doesn't have to be still created
makeItem();
}
private void makeItem() throws InvocationTargetException
{
// If item exists just reload the data.
if (_currentItem.item != null)
{
_currentItem.item.set(_currentItem.set);
return;
}
try
{
final Constructor<?> itemClass = Class.forName("org.l2jmobius.gameserver.model.items." + _currentItem.type).getConstructor(StatSet.class);
_currentItem.item = (Item) itemClass.newInstance(_currentItem.set);
}
catch (Exception e)
{
throw new InvocationTargetException(e);
}
}
public List<Item> getItemList()
{
return _itemsInFile;
}
@Override
public void load()
{
}
@Override
public void parseDocument(Document doc, File f)
{
}
}

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;
}

Some files were not shown because too many files have changed in this diff Show More