TeleportLocationTable.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. package net.sf.l2j.gameserver.datatables;
  16. import java.sql.PreparedStatement;
  17. import java.sql.ResultSet;
  18. import java.util.Map;
  19. import java.util.logging.Level;
  20. import java.util.logging.Logger;
  21. import javolution.util.FastMap;
  22. import net.sf.l2j.Config;
  23. import net.sf.l2j.L2DatabaseFactory;
  24. import net.sf.l2j.gameserver.model.L2TeleportLocation;
  25. /**
  26. * This class ...
  27. *
  28. * @version $Revision: 1.3.2.2.2.3 $ $Date: 2005/03/27 15:29:18 $
  29. */
  30. public class TeleportLocationTable
  31. {
  32. private static Logger _log = Logger.getLogger(TeleportLocationTable.class.getName());
  33. private static TeleportLocationTable _instance;
  34. private Map<Integer, L2TeleportLocation> _teleports;
  35. public static TeleportLocationTable getInstance()
  36. {
  37. if (_instance == null)
  38. {
  39. _instance = new TeleportLocationTable();
  40. }
  41. return _instance;
  42. }
  43. private TeleportLocationTable()
  44. {
  45. reloadAll();
  46. }
  47. public void reloadAll()
  48. {
  49. _teleports = new FastMap<Integer, L2TeleportLocation>();
  50. java.sql.Connection con = null;
  51. try
  52. {
  53. con = L2DatabaseFactory.getInstance().getConnection();
  54. PreparedStatement statement = con.prepareStatement("SELECT Description, id, loc_x, loc_y, loc_z, price, fornoble FROM teleport");
  55. ResultSet rset = statement.executeQuery();
  56. L2TeleportLocation teleport;
  57. while (rset.next())
  58. {
  59. teleport = new L2TeleportLocation();
  60. teleport.setTeleId(rset.getInt("id"));
  61. teleport.setLocX(rset.getInt("loc_x"));
  62. teleport.setLocY(rset.getInt("loc_y"));
  63. teleport.setLocZ(rset.getInt("loc_z"));
  64. teleport.setPrice(rset.getInt("price"));
  65. teleport.setIsForNoble(rset.getInt("fornoble") == 1);
  66. _teleports.put(teleport.getTeleId(), teleport);
  67. }
  68. rset.close();
  69. statement.close();
  70. _log.config("TeleportLocationTable: Loaded " + _teleports.size() + " Teleport Location Templates.");
  71. }
  72. catch (Exception e)
  73. {
  74. _log.log(Level.SEVERE, "Error loading Teleport Table.", e);
  75. }
  76. finally
  77. {
  78. try
  79. {
  80. con.close();
  81. }
  82. catch (Exception e)
  83. {
  84. }
  85. }
  86. if (Config.CUSTOM_TELEPORT_TABLE)
  87. {
  88. try
  89. {
  90. con = L2DatabaseFactory.getInstance().getConnection();
  91. PreparedStatement statement = con.prepareStatement("SELECT Description, id, loc_x, loc_y, loc_z, price, fornoble FROM custom_teleport");
  92. ResultSet rset = statement.executeQuery();
  93. L2TeleportLocation teleport;
  94. int _cTeleCount = _teleports.size();
  95. while (rset.next())
  96. {
  97. teleport = new L2TeleportLocation();
  98. teleport.setTeleId(rset.getInt("id"));
  99. teleport.setLocX(rset.getInt("loc_x"));
  100. teleport.setLocY(rset.getInt("loc_y"));
  101. teleport.setLocZ(rset.getInt("loc_z"));
  102. teleport.setPrice(rset.getInt("price"));
  103. teleport.setIsForNoble(rset.getInt("fornoble") == 1);
  104. _teleports.put(teleport.getTeleId(), teleport);
  105. }
  106. rset.close();
  107. statement.close();
  108. _cTeleCount = _teleports.size() - _cTeleCount;
  109. if (_cTeleCount > 0)
  110. _log.config("TeleportLocationTable: Loaded " + _cTeleCount + " Custom Teleport Location Templates.");
  111. }
  112. catch (Exception e)
  113. {
  114. _log.warning("error while creating custom teleport table " + e);
  115. }
  116. finally
  117. {
  118. try
  119. {
  120. con.close();
  121. }
  122. catch (Exception e)
  123. {
  124. }
  125. }
  126. }
  127. }
  128. /**
  129. * @param template id
  130. * @return
  131. */
  132. public L2TeleportLocation getTemplate(int id)
  133. {
  134. return _teleports.get(id);
  135. }
  136. }