TaskDailyQuestClean.java 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 Gnacik
  25. */
  26. public class TaskDailyQuestClean extends Task
  27. {
  28. private static final String NAME = "daily_quest_clean";
  29. private static final String[] _daily_names =
  30. {
  31. "463_IMustBeaGenius",
  32. "464_Oath",
  33. "458_PerfectForm",
  34. "461_RumbleInTheBase",
  35. "551_OlympiadStarter",
  36. "552_OlympiadVeteran",
  37. "553_OlympiadUndefeated"
  38. };
  39. @Override
  40. public String getName()
  41. {
  42. return NAME;
  43. }
  44. @Override
  45. public void onTimeElapsed(ExecutedTask task)
  46. {
  47. Connection con = null;
  48. try
  49. {
  50. con = L2DatabaseFactory.getInstance().getConnection();
  51. for (String name : _daily_names)
  52. {
  53. try (PreparedStatement ps = con.prepareStatement("DELETE FROM character_quests WHERE name=? AND var='<state>' AND value='Completed';"))
  54. {
  55. ps.setString(1, name);
  56. ps.execute();
  57. }
  58. }
  59. }
  60. catch (Exception e)
  61. {
  62. _log.severe(getClass().getSimpleName() + ": Could not reset daily quests: " + e);
  63. }
  64. finally
  65. {
  66. L2DatabaseFactory.close(con);
  67. }
  68. _log.info("Daily quests cleared");
  69. }
  70. @Override
  71. public void initializate()
  72. {
  73. super.initializate();
  74. TaskManager.addUniqueTask(NAME, TaskTypes.TYPE_GLOBAL_TASK, "1", "06:30:00", "");
  75. }
  76. }