TaskRecom.java 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  38. {
  39. try (PreparedStatement ps = con.prepareStatement("UPDATE character_reco_bonus SET rec_left=?, time_left=?, rec_have=0 WHERE rec_have <= 20"))
  40. {
  41. ps.setInt(1, 0); // Rec left = 0
  42. ps.setInt(2, 3600000); // Timer = 1 hour
  43. ps.execute();
  44. }
  45. try (PreparedStatement ps = con.prepareStatement("UPDATE character_reco_bonus SET rec_left=?, time_left=?, rec_have=GREATEST(rec_have-20,0) WHERE rec_have > 20"))
  46. {
  47. ps.setInt(1, 0); // Rec left = 0
  48. ps.setInt(2, 3600000); // Timer = 1 hour
  49. ps.execute();
  50. }
  51. }
  52. catch (Exception e)
  53. {
  54. _log.severe(getClass().getSimpleName() + ": Could not reset Recommendations System: " + e);
  55. }
  56. _log.info("Recommendations System reseted");
  57. }
  58. @Override
  59. public void initializate()
  60. {
  61. super.initializate();
  62. TaskManager.addUniqueTask(NAME, TaskTypes.TYPE_GLOBAL_TASK, "1", "06:30:00", "");
  63. }
  64. }