ResidentialSkillTable.java 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package net.sf.l2j.gameserver.datatables;
  2. import java.sql.Connection;
  3. import java.sql.PreparedStatement;
  4. import java.sql.ResultSet;
  5. import java.util.logging.Logger;
  6. import javolution.util.FastList;
  7. import javolution.util.FastMap;
  8. import net.sf.l2j.L2DatabaseFactory;
  9. import net.sf.l2j.gameserver.datatables.SkillTable;
  10. import net.sf.l2j.gameserver.model.L2Skill;
  11. /**
  12. * Warning: must be loaded after loading SkillTable
  13. *
  14. * @author DrHouse
  15. */
  16. public class ResidentialSkillTable
  17. {
  18. private static Logger _log = Logger.getLogger(ArmorSetsTable.class.getName());
  19. private static ResidentialSkillTable _instance = null;
  20. private static FastMap<Integer, FastList<L2Skill>> _list;
  21. ResidentialSkillTable()
  22. {
  23. load();
  24. }
  25. private void load()
  26. {
  27. _list = new FastMap<Integer, FastList<L2Skill>>();
  28. Connection con = null;
  29. try
  30. {
  31. con = L2DatabaseFactory.getInstance().getConnection();
  32. PreparedStatement statement = con.prepareStatement("SELECT * FROM skill_residential ORDER BY entityId");
  33. ResultSet rs = statement.executeQuery();
  34. while (rs.next())
  35. {
  36. int entityId = rs.getInt("entityId");
  37. int skillId = rs.getInt("skillId");
  38. int skillLvl = rs.getInt("skillLevel");
  39. L2Skill sk = SkillTable.getInstance().getInfo(skillId, skillLvl);
  40. if (sk == null)
  41. {
  42. _log.warning("ResidentialSkillTable: SkillTable has returned null for ID/level: " +skillId+"/"+skillLvl);
  43. continue;
  44. }
  45. if (!_list.containsKey(entityId))
  46. {
  47. FastList<L2Skill> aux = new FastList<L2Skill>();
  48. aux.add(sk);
  49. _list.put(entityId, aux);
  50. }
  51. else
  52. _list.get(entityId).add(sk);
  53. }
  54. statement.close();
  55. rs.close();
  56. }
  57. catch (Exception e)
  58. {
  59. _log.warning("ResidentialSkillTable: a problem occured while loading skills!");
  60. e.printStackTrace();
  61. }
  62. finally
  63. {
  64. try
  65. {
  66. con.close();
  67. }
  68. catch(Exception e)
  69. {
  70. }
  71. _log.info("ResidentialSkillTable: Loaded " + _list.size() + " entities with associated skills.");
  72. }
  73. }
  74. public FastList<L2Skill> getSkills(int entityId)
  75. {
  76. if (_list.containsKey(entityId))
  77. return _list.get(entityId);
  78. else return null;
  79. }
  80. public static ResidentialSkillTable getInstance()
  81. {
  82. if (_instance == null)
  83. _instance = new ResidentialSkillTable();
  84. return _instance;
  85. }
  86. }