2
0

TaskRecom.java 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright (C) 2004-2015 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J Server is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.l2jserver.gameserver.taskmanager.tasks;
  20. import java.sql.Connection;
  21. import java.sql.PreparedStatement;
  22. import com.l2jserver.commons.database.pool.impl.ConnectionFactory;
  23. import com.l2jserver.gameserver.taskmanager.Task;
  24. import com.l2jserver.gameserver.taskmanager.TaskManager;
  25. import com.l2jserver.gameserver.taskmanager.TaskManager.ExecutedTask;
  26. import com.l2jserver.gameserver.taskmanager.TaskTypes;
  27. /**
  28. * @author Layane
  29. */
  30. public class TaskRecom extends Task
  31. {
  32. private static final String NAME = "recommendations";
  33. @Override
  34. public String getName()
  35. {
  36. return NAME;
  37. }
  38. @Override
  39. public void onTimeElapsed(ExecutedTask task)
  40. {
  41. try (Connection con = ConnectionFactory.getInstance().getConnection())
  42. {
  43. try (PreparedStatement ps = con.prepareStatement("UPDATE character_reco_bonus SET rec_left=?, time_left=?, rec_have=0 WHERE rec_have <= 20"))
  44. {
  45. ps.setInt(1, 0); // Rec left = 0
  46. ps.setInt(2, 3600000); // Timer = 1 hour
  47. ps.execute();
  48. }
  49. 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"))
  50. {
  51. ps.setInt(1, 0); // Rec left = 0
  52. ps.setInt(2, 3600000); // Timer = 1 hour
  53. ps.execute();
  54. }
  55. }
  56. catch (Exception e)
  57. {
  58. _log.severe(getClass().getSimpleName() + ": Could not reset Recommendations System: " + e);
  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. }