Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.util.HashMap;
- import java.util.Map;
- import java.util.logging.Logger;
- import net.sf.l2j.gameserver.GameServer;
- import net.sf.l2j.gameserver.xmlfactory.XMLDocumentFactory;
- import org.w3c.dom.Document;
- import org.w3c.dom.NamedNodeMap;
- import org.w3c.dom.Node;
- public class IconsTable
- {
- private static final Logger _log = Logger.getLogger(GameServer.class.getName());
- private static final Map<Integer, String> _icons = new HashMap<>();
- public void reload()
- {
- _icons.clear();
- parseData();
- }
- public static void parseData()
- {
- try
- {
- File f = new File("./data/xml/icons.xml");
- Document doc = XMLDocumentFactory.getInstance().loadDocument(f);
- 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 (d.getNodeName().equalsIgnoreCase("icon"))
- {
- count++;
- NamedNodeMap attrs = d.getAttributes();
- Node att = attrs.getNamedItem("Id");
- Node att2 = attrs.getNamedItem("value");
- _icons.put(Integer.valueOf(att.getNodeValue()), String.valueOf(att2.getNodeValue()));
- }
- }
- }
- }
- }
- catch (Exception e)
- {
- _log.config("IconsTable: Failed loading IconsTable. Possible error: " + e.getMessage());
- }
- }
- public static String getIcon(int id)
- {
- if (_icons.get(id) == null)
- {
- _log.config("IconsTable: Invalid Icon request: " + id + ", or it doesn't exist, Ignoring ...");
- return "null";
- }
- return _icons.get(id);
- }
- public static final IconsTable getInstance()
- {
- return SingletonHolder._instance;
- }
- private static class SingletonHolder
- {
- protected static final IconsTable _instance = new IconsTable();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement