TeleportLocationTable.java 4.2 KB

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