Advertisement
Guest User

IconTable

a guest
May 21st, 2019
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 1.83 KB | None | 0 0
  1. import java.io.File;
  2. import java.util.HashMap;
  3. import java.util.Map;
  4. import java.util.logging.Logger;
  5.  
  6. import net.sf.l2j.gameserver.GameServer;
  7. import net.sf.l2j.gameserver.xmlfactory.XMLDocumentFactory;
  8.  
  9. import org.w3c.dom.Document;
  10. import org.w3c.dom.NamedNodeMap;
  11. import org.w3c.dom.Node;
  12.  
  13. public class IconsTable
  14. {
  15.     private static final Logger _log = Logger.getLogger(GameServer.class.getName());
  16.  
  17.     private static final Map<Integer, String> _icons = new HashMap<>();
  18.  
  19.     public void reload()
  20.     {
  21.         _icons.clear();
  22.         parseData();
  23.     }
  24.    
  25.     public static void parseData()
  26.     {
  27.         try
  28.         {
  29.             File f = new File("./data/xml/icons.xml");
  30.             Document doc = XMLDocumentFactory.getInstance().loadDocument(f);
  31.            
  32.             for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling())
  33.             {
  34.                 if ("list".equalsIgnoreCase(n.getNodeName()))
  35.                 {
  36.                     for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
  37.                     {
  38.                         if (d.getNodeName().equalsIgnoreCase("icon"))
  39.                         {
  40.                             count++;
  41.                             NamedNodeMap attrs = d.getAttributes();
  42.                             Node att = attrs.getNamedItem("Id");
  43.                             Node att2 = attrs.getNamedItem("value");
  44.                             _icons.put(Integer.valueOf(att.getNodeValue()), String.valueOf(att2.getNodeValue()));
  45.                         }
  46.                     }
  47.                 }
  48.             }
  49.         }
  50.         catch (Exception e)
  51.         {
  52.             _log.config("IconsTable: Failed loading IconsTable. Possible error: " + e.getMessage());
  53.         }
  54.     }
  55.    
  56.     public static String getIcon(int id)
  57.     {
  58.         if (_icons.get(id) == null)
  59.         {
  60.             _log.config("IconsTable: Invalid Icon request: " + id + ", or it doesn't exist, Ignoring ...");
  61.             return "null";
  62.         }
  63.         return _icons.get(id);
  64.     }
  65.    
  66.     public static final IconsTable getInstance()
  67.     {
  68.         return SingletonHolder._instance;
  69.     }
  70.    
  71.     private static class SingletonHolder
  72.     {
  73.         protected static final IconsTable _instance = new IconsTable();
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement