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