TaskRecom.java 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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.taskmanager.tasks;
  16. import java.sql.Connection;
  17. import java.sql.PreparedStatement;
  18. import java.util.logging.Level;
  19. import java.util.logging.Logger;
  20. import com.l2jserver.L2DatabaseFactory;
  21. import com.l2jserver.gameserver.taskmanager.Task;
  22. import com.l2jserver.gameserver.taskmanager.TaskManager;
  23. import com.l2jserver.gameserver.taskmanager.TaskManager.ExecutedTask;
  24. import com.l2jserver.gameserver.taskmanager.TaskTypes;
  25. /**
  26. * @author Layane
  27. *
  28. */
  29. public class TaskRecom extends Task
  30. {
  31. private static final Logger _log = Logger.getLogger(TaskRecom.class.getName());
  32. private static final String NAME = "recommendations";
  33. /**
  34. *
  35. * @see com.l2jserver.gameserver.taskmanager.Task#getName()
  36. */
  37. @Override
  38. public String getName()
  39. {
  40. return NAME;
  41. }
  42. /**
  43. *
  44. * @see com.l2jserver.gameserver.taskmanager.Task#onTimeElapsed(com.l2jserver.gameserver.taskmanager.TaskManager.ExecutedTask)
  45. */
  46. @Override
  47. public void onTimeElapsed(ExecutedTask task)
  48. {
  49. Connection con = null;
  50. try
  51. {
  52. con = L2DatabaseFactory.getInstance().getConnection();
  53. PreparedStatement statement = con.prepareStatement("UPDATE character_reco_bonus SET rec_left=?, time_left=?, rec_have=0 WHERE rec_have <= 20");
  54. statement.setInt(1, 0); // Rec left = 0
  55. statement.setInt(2, 3600000); // Timer = 1 hour
  56. statement.execute();
  57. statement = con.prepareStatement("UPDATE character_reco_bonus SET rec_left=?, time_left=?, rec_have=GREATEST(rec_have-20,0) WHERE rec_have > 20");
  58. statement.setInt(1, 0); // Rec left = 0
  59. statement.setInt(2, 3600000); // Timer = 1 hour
  60. statement.execute();
  61. statement.close();
  62. }
  63. catch (Exception e)
  64. {
  65. _log.log(Level.SEVERE, "Could not reset Recommendations System: " + e);
  66. }
  67. finally
  68. {
  69. L2DatabaseFactory.close(con);
  70. }
  71. _log.config("Recommendations System reseted");
  72. }
  73. /**
  74. *
  75. * @see com.l2jserver.gameserver.taskmanager.Task#initializate()
  76. */
  77. @Override
  78. public void initializate()
  79. {
  80. super.initializate();
  81. TaskManager.addUniqueTask(NAME, TaskTypes.TYPE_GLOBAL_TASK, "1", "06:30:00", "");
  82. }
  83. }