ResidentialSkillTable.java 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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.Level;
  7. import java.util.logging.Logger;
  8. import javolution.util.FastList;
  9. import com.l2jserver.L2DatabaseFactory;
  10. import com.l2jserver.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(ResidentialSkillTable.class.getName());
  19. private static ResidentialSkillTable _instance = null;
  20. private static TIntObjectHashMap<FastList<L2Skill>> _list;
  21. ResidentialSkillTable()
  22. {
  23. load();
  24. }
  25. private void load()
  26. {
  27. _list = new TIntObjectHashMap<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. rs.close();
  55. statement.close();
  56. }
  57. catch (Exception e)
  58. {
  59. _log.log(Level.WARNING, "ResidentialSkillTable: a problem occured while loading skills! " + e.getMessage(), e);
  60. }
  61. finally
  62. {
  63. L2DatabaseFactory.close(con);
  64. _log.info("ResidentialSkillTable: Loaded " + _list.size() + " entities with associated skills.");
  65. }
  66. }
  67. public FastList<L2Skill> getSkills(int entityId)
  68. {
  69. if (_list.containsKey(entityId))
  70. return _list.get(entityId);
  71. return null;
  72. }
  73. public static ResidentialSkillTable getInstance()
  74. {
  75. if (_instance == null)
  76. _instance = new ResidentialSkillTable();
  77. return _instance;
  78. }
  79. }