AdminQuest.java 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * $Header: AdminTest.java, 25/07/2005 17:15:21 luisantonioa Exp $
  3. *
  4. * $Author: luisantonioa $
  5. * $Date: 25/07/2005 17:15:21 $
  6. * $Revision: 1 $
  7. * $Log: AdminTest.java,v $
  8. * Revision 1 25/07/2005 17:15:21 luisantonioa
  9. * Added copyright notice
  10. *
  11. *
  12. * This program is free software: you can redistribute it and/or modify it under
  13. * the terms of the GNU General Public License as published by the Free Software
  14. * Foundation, either version 3 of the License, or (at your option) any later
  15. * version.
  16. *
  17. * This program is distributed in the hope that it will be useful, but WITHOUT
  18. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  19. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  20. * details.
  21. *
  22. * You should have received a copy of the GNU General Public License along with
  23. * this program. If not, see <http://www.gnu.org/licenses/>.
  24. */
  25. package net.sf.l2j.gameserver.handler.admincommandhandlers;
  26. import java.io.File;
  27. import javax.script.ScriptException;
  28. import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
  29. import net.sf.l2j.gameserver.instancemanager.QuestManager;
  30. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  31. import net.sf.l2j.gameserver.scripting.L2ScriptEngineManager;
  32. public class AdminQuest implements IAdminCommandHandler
  33. {
  34. private static final String[] ADMIN_COMMANDS =
  35. {
  36. "admin_quest_reload",
  37. "admin_script_load"
  38. };
  39. /**
  40. *
  41. * @see net.sf.l2j.gameserver.handler.IAdminCommandHandler#useAdminCommand(java.lang.String, net.sf.l2j.gameserver.model.actor.instance.L2PcInstance)
  42. */
  43. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  44. {
  45. if (activeChar == null)
  46. return false;
  47. // syntax will either be:
  48. // //quest_reload <id>
  49. // //quest_reload <questName>
  50. // The questName MUST start with a non-numeric character for this to work,
  51. // regardless which of the two formats is used.
  52. // Example: //quest_reload orc_occupation_change_1
  53. // Example: //quest_reload chests
  54. // Example: //quest_reload SagasSuperclass
  55. // Example: //quest_reload 12
  56. if (command.startsWith("admin_quest_reload"))
  57. {
  58. String[] parts = command.split(" ");
  59. if (parts.length < 2)
  60. {
  61. activeChar.sendMessage("Syntax: //quest_reload <questFolder>.<questSubFolders...>.questName> or //quest_reload <id>");
  62. }
  63. else
  64. {
  65. // try the first param as id
  66. try
  67. {
  68. int questId = Integer.parseInt(parts[1]);
  69. if (QuestManager.getInstance().reload(questId))
  70. {
  71. activeChar.sendMessage("Quest Reloaded Successfully.");
  72. }
  73. else
  74. {
  75. activeChar.sendMessage("Quest Reloaded Failed");
  76. }
  77. }
  78. catch (NumberFormatException e)
  79. {
  80. if (QuestManager.getInstance().reload(parts[1]))
  81. {
  82. activeChar.sendMessage("Quest Reloaded Successfully.");
  83. }
  84. else
  85. {
  86. activeChar.sendMessage("Quest Reloaded Failed");
  87. }
  88. }
  89. }
  90. }
  91. // script load should NOT be used in place of reload. If a script is already loaded
  92. // successfully, quest_reload ought to be used. The script_load command should only
  93. // be used for scripts that failed to load altogether (eg. due to errors) or that
  94. // did not at all exist during server boot. Using script_load to re-load a previously
  95. // loaded script may cause unpredictable script flow, minor loss of data, and more.
  96. // This provides a way to load new scripts without having to reboot the server.
  97. else if (command.startsWith("admin_script_load"))
  98. {
  99. String[] parts = command.split(" ");
  100. if (parts.length < 2)
  101. {
  102. //activeChar.sendMessage("Example: //script_load <questFolder>/<questSubFolders...>/<filename>.<ext> ");
  103. activeChar.sendMessage("Example: //script_load quests/SagasSuperclass/__init__.py");
  104. }
  105. else
  106. {
  107. File file = new File(L2ScriptEngineManager.SCRIPT_FOLDER, parts[1]);
  108. if (file.isFile())
  109. {
  110. try
  111. {
  112. L2ScriptEngineManager.getInstance().executeScript(file);
  113. }
  114. catch (ScriptException e)
  115. {
  116. activeChar.sendMessage("Failed loading: " + parts[1]);
  117. L2ScriptEngineManager.getInstance().reportScriptFileError(file, e);
  118. }
  119. catch (Exception e)
  120. {
  121. activeChar.sendMessage("Failed loading: " + parts[1]);
  122. }
  123. }
  124. else
  125. {
  126. activeChar.sendMessage("File Not Found: " + parts[1]);
  127. }
  128. }
  129. }
  130. return true;
  131. }
  132. /**
  133. *
  134. * @see net.sf.l2j.gameserver.handler.IAdminCommandHandler#getAdminCommandList()
  135. */
  136. public String[] getAdminCommandList()
  137. {
  138. return ADMIN_COMMANDS;
  139. }
  140. }