NpcWalkerRoutesTable.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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.PreparedStatement;
  18. import java.sql.ResultSet;
  19. import java.util.logging.Logger;
  20. import com.l2jserver.L2DatabaseFactory;
  21. import com.l2jserver.gameserver.model.L2NpcWalkerNode;
  22. import javolution.util.FastList;
  23. /**
  24. * Main Table to Load Npc Walkers Routes and Chat SQL Table.<br>
  25. *
  26. * @author Rayan RPG for L2Emu Project
  27. *
  28. * @since 927
  29. *
  30. */
  31. public class NpcWalkerRoutesTable
  32. {
  33. private final static Logger _log = Logger.getLogger(SpawnTable.class.getName());
  34. private FastList<L2NpcWalkerNode> _routes = new FastList<L2NpcWalkerNode>();
  35. public static NpcWalkerRoutesTable getInstance()
  36. {
  37. return SingletonHolder._instance;
  38. }
  39. private NpcWalkerRoutesTable()
  40. {
  41. _log.info("Initializing Walkers Routes Table.");
  42. }
  43. public void load()
  44. {
  45. _routes.clear();
  46. Connection con = null;
  47. try
  48. {
  49. con = L2DatabaseFactory.getInstance().getConnection();
  50. PreparedStatement statement = con.prepareStatement("SELECT route_id, npc_id, move_point, chatText, move_x, move_y, move_z, delay, running FROM walker_routes ORDER By move_point ASC");
  51. ResultSet rset = statement.executeQuery();
  52. L2NpcWalkerNode route;
  53. while (rset.next())
  54. {
  55. route = new L2NpcWalkerNode();
  56. route.setRouteId(rset.getInt("route_id"));
  57. route.setNpcId(rset.getInt("npc_id"));
  58. route.setMovePoint(rset.getString("move_point"));
  59. route.setChatText(rset.getString("chatText"));
  60. route.setMoveX(rset.getInt("move_x"));
  61. route.setMoveY(rset.getInt("move_y"));
  62. route.setMoveZ(rset.getInt("move_z"));
  63. route.setDelay(rset.getInt("delay"));
  64. route.setRunning(rset.getBoolean("running"));
  65. _routes.add(route);
  66. }
  67. rset.close();
  68. statement.close();
  69. _log.info("WalkerRoutesTable: Loaded " + _routes.size() + " Npc Walker Routes.");
  70. }
  71. catch (Exception e)
  72. {
  73. _log.severe("WalkerRoutesTable: Error while loading Npc Walkers Routes: " + e.getMessage());
  74. }
  75. finally
  76. {
  77. try
  78. {
  79. con.close();
  80. }
  81. catch (Exception e)
  82. {
  83. }
  84. }
  85. }
  86. public FastList<L2NpcWalkerNode> getRouteForNpc(int id)
  87. {
  88. FastList<L2NpcWalkerNode> _return = new FastList<L2NpcWalkerNode>();
  89. for (FastList.Node<L2NpcWalkerNode> n = _routes.head(), end = _routes.tail(); (n = n.getNext()) != end;)
  90. {
  91. if (n.getValue().getNpcId() == id)
  92. {
  93. _return.add(n.getValue());
  94. }
  95. }
  96. return _return;
  97. }
  98. @SuppressWarnings("synthetic-access")
  99. private static class SingletonHolder
  100. {
  101. protected static final NpcWalkerRoutesTable _instance = new NpcWalkerRoutesTable();
  102. }
  103. }