Advertisement
xSweeTs

ItemIcon

Dec 3rd, 2018
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package l2.ae.pvp.gameserver.datatables;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.File;
  5. import java.io.FileReader;
  6. import java.util.HashMap;
  7. import java.util.Map;
  8. import java.util.logging.Logger;
  9.  
  10. import l2.ae.pvp.gameserver.GameServer;
  11.  
  12. public class IconsTable
  13. {
  14.     private static final Map<Integer, String> itemIcons = new HashMap<>();
  15.     private static final Map<Integer, String> skillIcons = new HashMap<>();
  16.     private static final Logger _log = Logger.getLogger(GameServer.class.getName());
  17.    
  18.     protected IconsTable()
  19.     {
  20.         parseData();
  21.     }
  22.    
  23.     public void reload()
  24.     {
  25.         itemIcons.clear();
  26.         // skillIcons.clear();
  27.         parseData();
  28.     }
  29.    
  30.     public static void parseData()
  31.     {
  32.         final long t0 = System.currentTimeMillis();
  33.         try
  34.         {
  35.             loadItemIcons();
  36.             // not needed loadSkillIcons();
  37.             final long t = System.currentTimeMillis() - t0;
  38.             _log.config("IconsTable: Succesfully loaded " + (itemIcons.size() + skillIcons.size()) + " icons, in " + t + " Milliseconds.");
  39.         }
  40.         catch (final Exception e)
  41.         {
  42.             _log.config("IconsTable: Failed loading IconsTable. Possible error: " + e.getMessage());
  43.             e.printStackTrace();
  44.         }
  45.     }
  46.    
  47.     private static void loadItemIcons() throws Exception
  48.     {
  49.         final File f = new File("./data/icons.xml");
  50.         try (final BufferedReader br = new BufferedReader(new FileReader(f)))
  51.         {
  52.             String line = null;
  53.             while ((line=br.readLine()) != null)
  54.             {
  55.                 String[] explode = line.split("\t");
  56.                 if (explode.length > 1)
  57.                 {
  58.                     final int id = Integer.parseInt(explode[0]);
  59.                     itemIcons.put(id, explode[1]);
  60.                 }
  61.             }
  62.         }
  63.     }
  64.    
  65.     /**
  66.      * @param id the requested itemId
  67.      * @return the String value of the Icon of the given itemId.
  68.      */
  69.     public static String getItemIcon(final int id)
  70.     {
  71.         final String ico = itemIcons.get(id);
  72.         if (ico == null)
  73.         {
  74.             _log.config("IconsTable: Invalid Item-Icon request: " + id + ", or it doesn't exist, Ignoring ...");
  75.             return "l2aerogamingicons.pvp_weapons";
  76.         }
  77.         return ico;
  78.     }
  79.    
  80.     /**
  81.      * @param id the requested skillId
  82.      * @return the String value of the Icon of the given itemId.
  83.      */
  84.     public static String getSkillIcon(final int id)
  85.     {
  86.         final String ico = skillIcons.get(id);
  87.         if (ico == null)
  88.         {
  89.             _log.config("IconsTable: Invalid Skill-Icon request: " + id + ", or it doesn't exist, Ignoring ...");
  90.             return "icon.skill1050";
  91.         }
  92.         return ico;
  93.     }
  94.    
  95.     public static final IconsTable getInstance()
  96.     {
  97.         return SingletonHolder._instance;
  98.     }
  99.    
  100.     private static class SingletonHolder
  101.     {
  102.         protected static final IconsTable _instance = new IconsTable();
  103.     }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement