TaskScript.java 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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.io.File;
  17. import java.util.logging.Logger;
  18. import javax.script.ScriptException;
  19. import com.l2jserver.gameserver.scripting.L2ScriptEngineManager;
  20. import com.l2jserver.gameserver.taskmanager.Task;
  21. import com.l2jserver.gameserver.taskmanager.TaskManager.ExecutedTask;
  22. /**
  23. * @author janiii
  24. *
  25. */
  26. public class TaskScript extends Task
  27. {
  28. private static final Logger _log = Logger.getLogger(TaskScript.class.getName());
  29. public static final String NAME = "script";
  30. /**
  31. *
  32. * @see com.l2jserver.gameserver.taskmanager.Task#getName()
  33. */
  34. @Override
  35. public String getName()
  36. {
  37. return NAME;
  38. }
  39. /**
  40. *
  41. * @see com.l2jserver.gameserver.taskmanager.Task#onTimeElapsed(com.l2jserver.gameserver.taskmanager.TaskManager.ExecutedTask)
  42. */
  43. @Override
  44. public void onTimeElapsed(ExecutedTask task)
  45. {
  46. File file = new File(L2ScriptEngineManager.SCRIPT_FOLDER, "cron/" + task.getParams()[2]);
  47. if (file.isFile())
  48. {
  49. try
  50. {
  51. L2ScriptEngineManager.getInstance().executeScript(file);
  52. }
  53. catch (ScriptException e)
  54. {
  55. _log.warning("Failed loading: " + task.getParams()[2]);
  56. L2ScriptEngineManager.getInstance().reportScriptFileError(file, e);
  57. }
  58. catch (Exception e)
  59. {
  60. _log.warning("Failed loading: " + task.getParams()[2]);
  61. }
  62. }
  63. else
  64. {
  65. _log.warning("File Not Found: " + task.getParams()[2]);
  66. }
  67. }
  68. }