AdminQuest.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 handlers.admincommandhandlers;
  16. import java.io.File;
  17. import javax.script.ScriptException;
  18. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  19. import com.l2jserver.gameserver.instancemanager.QuestManager;
  20. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  21. import com.l2jserver.gameserver.scripting.L2ScriptEngineManager;
  22. public class AdminQuest implements IAdminCommandHandler
  23. {
  24. private static final String[] ADMIN_COMMANDS =
  25. {
  26. "admin_quest_reload",
  27. "admin_script_load"
  28. };
  29. /**
  30. *
  31. * @see com.l2jserver.gameserver.handler.IAdminCommandHandler#useAdminCommand(java.lang.String, com.l2jserver.gameserver.model.actor.instance.L2PcInstance)
  32. */
  33. @Override
  34. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  35. {
  36. if (activeChar == null)
  37. return false;
  38. // syntax will either be:
  39. // //quest_reload <id>
  40. // //quest_reload <questName>
  41. // The questName MUST start with a non-numeric character for this to work,
  42. // regardless which of the two formats is used.
  43. // Example: //quest_reload orc_occupation_change_1
  44. // Example: //quest_reload chests
  45. // Example: //quest_reload SagasSuperclass
  46. // Example: //quest_reload 12
  47. if (command.startsWith("admin_quest_reload"))
  48. {
  49. String[] parts = command.split(" ");
  50. if (parts.length < 2)
  51. {
  52. activeChar.sendMessage("Syntax: //quest_reload <questFolder>.<questSubFolders...>.questName> or //quest_reload <id>");
  53. }
  54. else
  55. {
  56. // try the first param as id
  57. try
  58. {
  59. int questId = Integer.parseInt(parts[1]);
  60. if (QuestManager.getInstance().reload(questId))
  61. {
  62. activeChar.sendMessage("Quest Reloaded Successfully.");
  63. }
  64. else
  65. {
  66. activeChar.sendMessage("Quest Reloaded Failed");
  67. }
  68. }
  69. catch (NumberFormatException e)
  70. {
  71. if (QuestManager.getInstance().reload(parts[1]))
  72. {
  73. activeChar.sendMessage("Quest Reloaded Successfully.");
  74. }
  75. else
  76. {
  77. activeChar.sendMessage("Quest Reloaded Failed");
  78. }
  79. }
  80. }
  81. }
  82. // script load should NOT be used in place of reload. If a script is already loaded
  83. // successfully, quest_reload ought to be used. The script_load command should only
  84. // be used for scripts that failed to load altogether (eg. due to errors) or that
  85. // did not at all exist during server boot. Using script_load to re-load a previously
  86. // loaded script may cause unpredictable script flow, minor loss of data, and more.
  87. // This provides a way to load new scripts without having to reboot the server.
  88. else if (command.startsWith("admin_script_load"))
  89. {
  90. String[] parts = command.split(" ");
  91. if (parts.length < 2)
  92. {
  93. //activeChar.sendMessage("Example: //script_load <questFolder>/<questSubFolders...>/<filename>.<ext> ");
  94. activeChar.sendMessage("Example: //script_load quests/SagasSuperclass/__init__.py");
  95. }
  96. else
  97. {
  98. File file = new File(L2ScriptEngineManager.SCRIPT_FOLDER, parts[1]);
  99. if (file.isFile())
  100. {
  101. try
  102. {
  103. L2ScriptEngineManager.getInstance().executeScript(file);
  104. }
  105. catch (ScriptException e)
  106. {
  107. activeChar.sendMessage("Failed loading: " + parts[1]);
  108. L2ScriptEngineManager.getInstance().reportScriptFileError(file, e);
  109. }
  110. catch (Exception e)
  111. {
  112. activeChar.sendMessage("Failed loading: " + parts[1]);
  113. }
  114. }
  115. else
  116. {
  117. activeChar.sendMessage("File Not Found: " + parts[1]);
  118. }
  119. }
  120. }
  121. return true;
  122. }
  123. /**
  124. *
  125. * @see com.l2jserver.gameserver.handler.IAdminCommandHandler#getAdminCommandList()
  126. */
  127. @Override
  128. public String[] getAdminCommandList()
  129. {
  130. return ADMIN_COMMANDS;
  131. }
  132. }