ArmorSetsTable.java 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. /**
  16. * @author godson
  17. */
  18. package com.l2jserver.gameserver.datatables;
  19. import gnu.trove.TIntObjectHashMap;
  20. import java.sql.Connection;
  21. import java.sql.PreparedStatement;
  22. import java.sql.ResultSet;
  23. import java.util.logging.Logger;
  24. import com.l2jserver.Config;
  25. import com.l2jserver.L2DatabaseFactory;
  26. import com.l2jserver.gameserver.model.L2ArmorSet;
  27. /**
  28. *
  29. *
  30. * @author Luno
  31. */
  32. public class ArmorSetsTable
  33. {
  34. private static Logger _log = Logger.getLogger(ArmorSetsTable.class.getName());
  35. private TIntObjectHashMap<L2ArmorSet> _armorSets;
  36. public static ArmorSetsTable getInstance()
  37. {
  38. return SingletonHolder._instance;
  39. }
  40. private ArmorSetsTable()
  41. {
  42. _armorSets = new TIntObjectHashMap<L2ArmorSet>();
  43. loadData();
  44. }
  45. private void loadData()
  46. {
  47. Connection con = null;
  48. PreparedStatement statement = null;
  49. try
  50. {
  51. con = L2DatabaseFactory.getInstance().getConnection();
  52. statement = con.prepareStatement("SELECT chest, legs, head, gloves, feet, skill, shield, shield_skill_id, enchant6skill, mw_legs, mw_head, mw_gloves, mw_feet, mw_shield FROM armorsets");
  53. ResultSet rset = statement.executeQuery();
  54. while (rset.next())
  55. {
  56. int chest = rset.getInt("chest");
  57. int legs = rset.getInt("legs");
  58. int head = rset.getInt("head");
  59. int gloves = rset.getInt("gloves");
  60. int feet = rset.getInt("feet");
  61. String[] skills = rset.getString("skill").split(";");
  62. int shield = rset.getInt("shield");
  63. int shield_skill_id = rset.getInt("shield_skill_id");
  64. int enchant6skill = rset.getInt("enchant6skill");
  65. int mw_legs = rset.getInt("mw_legs");
  66. int mw_head = rset.getInt("mw_head");
  67. int mw_gloves = rset.getInt("mw_gloves");
  68. int mw_feet = rset.getInt("mw_feet");
  69. int mw_shield = rset.getInt("mw_shield");
  70. _armorSets.put(chest, new L2ArmorSet(chest, legs, head, gloves, feet, skills, shield, shield_skill_id, enchant6skill, mw_legs, mw_head, mw_gloves, mw_feet, mw_shield));
  71. }
  72. _log.config("ArmorSetsTable: Loaded " + _armorSets.size() + " armor sets.");
  73. }
  74. catch (Exception e)
  75. {
  76. _log.severe("ArmorSetsTable: Error reading ArmorSets table: " + e);
  77. }
  78. finally
  79. {
  80. try
  81. {
  82. statement.close();
  83. }
  84. catch (Exception e)
  85. {
  86. }
  87. try
  88. {
  89. con.close();
  90. }
  91. catch (Exception e)
  92. {
  93. }
  94. }
  95. if (Config.CUSTOM_ARMORSETS_TABLE)
  96. {
  97. try
  98. {
  99. int cSets = _armorSets.size();
  100. con = L2DatabaseFactory.getInstance().getConnection();
  101. statement = con.prepareStatement("SELECT chest, legs, head, gloves, feet, skill, shield, shield_skill_id, enchant6skill, mw_legs, mw_head, mw_gloves, mw_feet, mw_shield FROM custom_armorsets");
  102. ResultSet rset = statement.executeQuery();
  103. while (rset.next())
  104. {
  105. int chest = rset.getInt("chest");
  106. int legs = rset.getInt("legs");
  107. int head = rset.getInt("head");
  108. int gloves = rset.getInt("gloves");
  109. int feet = rset.getInt("feet");
  110. String[] skills = rset.getString("skill").split(";");
  111. int shield = rset.getInt("shield");
  112. int shield_skill_id = rset.getInt("shield_skill_id");
  113. int enchant6skill = rset.getInt("enchant6skill");
  114. int mw_legs = rset.getInt("mw_legs");
  115. int mw_head = rset.getInt("mw_head");
  116. int mw_gloves = rset.getInt("mw_gloves");
  117. int mw_feet = rset.getInt("mw_feet");
  118. int mw_shield = rset.getInt("mw_shield");
  119. _armorSets.put(chest, new L2ArmorSet(chest, legs, head, gloves, feet, skills, shield, shield_skill_id, enchant6skill, mw_legs, mw_head, mw_gloves, mw_feet, mw_shield));
  120. }
  121. _log.config("ArmorSetsTable: Loaded " + (_armorSets.size() - cSets) + " Custom armor sets.");
  122. }
  123. catch (Exception e)
  124. {
  125. _log.severe("ArmorSetsTable: Error reading Custom ArmorSets table: " + e);
  126. }
  127. finally
  128. {
  129. try
  130. {
  131. statement.close();
  132. }
  133. catch (Exception e)
  134. {
  135. }
  136. try
  137. {
  138. con.close();
  139. }
  140. catch (Exception e)
  141. {
  142. }
  143. }
  144. }
  145. }
  146. public boolean setExists(int chestId)
  147. {
  148. return _armorSets.containsKey(chestId);
  149. }
  150. public L2ArmorSet getSet(int chestId)
  151. {
  152. return _armorSets.get(chestId);
  153. }
  154. @SuppressWarnings("synthetic-access")
  155. private static class SingletonHolder
  156. {
  157. protected static final ArmorSetsTable _instance = new ArmorSetsTable();
  158. }
  159. }