TeleportLocationTable.java 4.0 KB

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