TaskScript.java 1.8 KB

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