TaskScript.java 1.8 KB

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