TaskRecom.java 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 com.l2jserver.L2DatabaseFactory;
  19. import com.l2jserver.gameserver.taskmanager.Task;
  20. import com.l2jserver.gameserver.taskmanager.TaskManager;
  21. import com.l2jserver.gameserver.taskmanager.TaskManager.ExecutedTask;
  22. import com.l2jserver.gameserver.taskmanager.TaskTypes;
  23. /**
  24. * @author Layane
  25. */
  26. public class TaskRecom extends Task
  27. {
  28. private static final String NAME = "recommendations";
  29. @Override
  30. public String getName()
  31. {
  32. return NAME;
  33. }
  34. @Override
  35. public void onTimeElapsed(ExecutedTask task)
  36. {
  37. Connection con = null;
  38. try
  39. {
  40. con = L2DatabaseFactory.getInstance().getConnection();
  41. PreparedStatement statement = con.prepareStatement("UPDATE character_reco_bonus SET rec_left=?, time_left=?, rec_have=0 WHERE rec_have <= 20");
  42. statement.setInt(1, 0); // Rec left = 0
  43. statement.setInt(2, 3600000); // Timer = 1 hour
  44. statement.execute();
  45. statement.close();
  46. statement = con.prepareStatement("UPDATE character_reco_bonus SET rec_left=?, time_left=?, rec_have=GREATEST(rec_have-20,0) WHERE rec_have > 20");
  47. statement.setInt(1, 0); // Rec left = 0
  48. statement.setInt(2, 3600000); // Timer = 1 hour
  49. statement.execute();
  50. statement.close();
  51. }
  52. catch (Exception e)
  53. {
  54. _log.severe(getClass().getSimpleName() + ": Could not reset Recommendations System: " + e);
  55. }
  56. finally
  57. {
  58. L2DatabaseFactory.close(con);
  59. }
  60. _log.info("Recommendations System reseted");
  61. }
  62. @Override
  63. public void initializate()
  64. {
  65. super.initializate();
  66. TaskManager.addUniqueTask(NAME, TaskTypes.TYPE_GLOBAL_TASK, "1", "06:30:00", "");
  67. }
  68. }