AdminQuest.java 5.4 KB

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