ResidentialSkillTable.java 2.3 KB

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