TeleportLocationTable.java 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 java.sql.Connection;
  17. import java.sql.ResultSet;
  18. import java.sql.Statement;
  19. import java.util.HashMap;
  20. import java.util.Map;
  21. import java.util.logging.Level;
  22. import java.util.logging.Logger;
  23. import com.l2jserver.Config;
  24. import com.l2jserver.L2DatabaseFactory;
  25. import com.l2jserver.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 = new HashMap<>();
  35. protected TeleportLocationTable()
  36. {
  37. reloadAll();
  38. }
  39. public void reloadAll()
  40. {
  41. _teleports.clear();
  42. try (Connection con = L2DatabaseFactory.getInstance().getConnection();
  43. Statement s = con.createStatement();
  44. ResultSet rs = s.executeQuery("SELECT id, loc_x, loc_y, loc_z, price, fornoble, itemId FROM teleport"))
  45. {
  46. L2TeleportLocation teleport;
  47. while (rs.next())
  48. {
  49. teleport = new L2TeleportLocation();
  50. teleport.setTeleId(rs.getInt("id"));
  51. teleport.setLocX(rs.getInt("loc_x"));
  52. teleport.setLocY(rs.getInt("loc_y"));
  53. teleport.setLocZ(rs.getInt("loc_z"));
  54. teleport.setPrice(rs.getInt("price"));
  55. teleport.setIsForNoble(rs.getInt("fornoble") == 1);
  56. teleport.setItemId(rs.getInt("itemId"));
  57. _teleports.put(teleport.getTeleId(), teleport);
  58. }
  59. _log.info(getClass().getSimpleName() + ": Loaded " + _teleports.size() + " Teleport Location Templates.");
  60. }
  61. catch (Exception e)
  62. {
  63. _log.log(Level.SEVERE, getClass().getSimpleName() + ": Error loading Teleport Table.", e);
  64. }
  65. if (Config.CUSTOM_TELEPORT_TABLE)
  66. {
  67. int _cTeleCount = _teleports.size();
  68. try (Connection con = L2DatabaseFactory.getInstance().getConnection();
  69. Statement s = con.createStatement();
  70. ResultSet rs = s.executeQuery("SELECT id, loc_x, loc_y, loc_z, price, fornoble, itemId FROM custom_teleport"))
  71. {
  72. L2TeleportLocation teleport;
  73. while (rs.next())
  74. {
  75. teleport = new L2TeleportLocation();
  76. teleport.setTeleId(rs.getInt("id"));
  77. teleport.setLocX(rs.getInt("loc_x"));
  78. teleport.setLocY(rs.getInt("loc_y"));
  79. teleport.setLocZ(rs.getInt("loc_z"));
  80. teleport.setPrice(rs.getInt("price"));
  81. teleport.setIsForNoble(rs.getInt("fornoble") == 1);
  82. teleport.setItemId(rs.getInt("itemId"));
  83. _teleports.put(teleport.getTeleId(), teleport);
  84. }
  85. _cTeleCount = _teleports.size() - _cTeleCount;
  86. if (_cTeleCount > 0)
  87. {
  88. _log.info(getClass().getSimpleName() + ": Loaded " + _cTeleCount + " Custom Teleport Location Templates.");
  89. }
  90. }
  91. catch (Exception e)
  92. {
  93. _log.log(Level.WARNING, getClass().getSimpleName() + ": Error while creating custom teleport table " + e.getMessage(), e);
  94. }
  95. }
  96. }
  97. /**
  98. * @param id
  99. * @return
  100. */
  101. public L2TeleportLocation getTemplate(int id)
  102. {
  103. return _teleports.get(id);
  104. }
  105. public static TeleportLocationTable getInstance()
  106. {
  107. return SingletonHolder._instance;
  108. }
  109. private static class SingletonHolder
  110. {
  111. protected static final TeleportLocationTable _instance = new TeleportLocationTable();
  112. }
  113. }