2
0

TeleportLocationTable.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. L2DatabaseFactory.close(con);
  74. }
  75. if (Config.CUSTOM_TELEPORT_TABLE)
  76. {
  77. try
  78. {
  79. con = L2DatabaseFactory.getInstance().getConnection();
  80. PreparedStatement statement = con.prepareStatement("SELECT id, loc_x, loc_y, loc_z, price, fornoble FROM custom_teleport");
  81. ResultSet rset = statement.executeQuery();
  82. L2TeleportLocation teleport;
  83. int _cTeleCount = _teleports.size();
  84. while (rset.next())
  85. {
  86. teleport = new L2TeleportLocation();
  87. teleport.setTeleId(rset.getInt("id"));
  88. teleport.setLocX(rset.getInt("loc_x"));
  89. teleport.setLocY(rset.getInt("loc_y"));
  90. teleport.setLocZ(rset.getInt("loc_z"));
  91. teleport.setPrice(rset.getInt("price"));
  92. teleport.setIsForNoble(rset.getInt("fornoble") == 1);
  93. _teleports.put(teleport.getTeleId(), teleport);
  94. }
  95. rset.close();
  96. statement.close();
  97. _cTeleCount = _teleports.size() - _cTeleCount;
  98. if (_cTeleCount > 0)
  99. _log.info("TeleportLocationTable: Loaded " + _cTeleCount + " Custom Teleport Location Templates.");
  100. }
  101. catch (Exception e)
  102. {
  103. _log.log(Level.WARNING, "Error while creating custom teleport table " + e.getMessage(), e);
  104. }
  105. finally
  106. {
  107. L2DatabaseFactory.close(con);
  108. }
  109. }
  110. }
  111. /**
  112. * @param template id
  113. * @return
  114. */
  115. public L2TeleportLocation getTemplate(int id)
  116. {
  117. return _teleports.get(id);
  118. }
  119. @SuppressWarnings("synthetic-access")
  120. private static class SingletonHolder
  121. {
  122. protected static final TeleportLocationTable _instance = new TeleportLocationTable();
  123. }
  124. }