ReloadHandler.java 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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.telnethandlers;
  16. import java.io.File;
  17. import java.io.PrintWriter;
  18. import java.net.Socket;
  19. import java.util.StringTokenizer;
  20. import javax.script.ScriptException;
  21. import com.l2jserver.gameserver.cache.HtmCache;
  22. import com.l2jserver.gameserver.datatables.ItemTable;
  23. import com.l2jserver.gameserver.datatables.MultiSell;
  24. import com.l2jserver.gameserver.datatables.NpcTable;
  25. import com.l2jserver.gameserver.datatables.SkillTable;
  26. import com.l2jserver.gameserver.datatables.SpawnTable;
  27. import com.l2jserver.gameserver.datatables.TeleportLocationTable;
  28. import com.l2jserver.gameserver.handler.ITelnetHandler;
  29. import com.l2jserver.gameserver.instancemanager.DayNightSpawnManager;
  30. import com.l2jserver.gameserver.instancemanager.QuestManager;
  31. import com.l2jserver.gameserver.instancemanager.RaidBossSpawnManager;
  32. import com.l2jserver.gameserver.instancemanager.ZoneManager;
  33. import com.l2jserver.gameserver.model.L2World;
  34. import com.l2jserver.gameserver.scripting.L2ScriptEngineManager;
  35. /**
  36. * @author UnAfraid
  37. */
  38. public class ReloadHandler implements ITelnetHandler
  39. {
  40. private final String[] _commands =
  41. {
  42. "reload"
  43. };
  44. @Override
  45. public boolean useCommand(String command, PrintWriter _print, Socket _cSocket, int _uptime)
  46. {
  47. if (command.startsWith("reload"))
  48. {
  49. StringTokenizer st = new StringTokenizer(command.substring(7));
  50. try
  51. {
  52. String type = st.nextToken();
  53. if (type.equals("multisell"))
  54. {
  55. _print.print("Reloading multisell... ");
  56. MultiSell.getInstance().reload();
  57. _print.println("done");
  58. }
  59. else if (type.equals("skill"))
  60. {
  61. _print.print("Reloading skills... ");
  62. SkillTable.getInstance().reload();
  63. _print.println("done");
  64. }
  65. else if (type.equals("npc"))
  66. {
  67. _print.print("Reloading npc templates... ");
  68. NpcTable.getInstance().reloadAllNpc();
  69. QuestManager.getInstance().reloadAllQuests();
  70. _print.println("done");
  71. }
  72. else if (type.equals("html"))
  73. {
  74. _print.print("Reloading html cache... ");
  75. HtmCache.getInstance().reload();
  76. _print.println("done");
  77. }
  78. else if (type.equals("item"))
  79. {
  80. _print.print("Reloading item templates... ");
  81. ItemTable.getInstance().reload();
  82. _print.println("done");
  83. }
  84. else if (type.equals("zone"))
  85. {
  86. _print.print("Reloading zone tables... ");
  87. ZoneManager.getInstance().reload();
  88. _print.println("done");
  89. }
  90. else if (type.equals("teleports"))
  91. {
  92. _print.print("Reloading telport location table... ");
  93. TeleportLocationTable.getInstance().reloadAll();
  94. _print.println("done");
  95. }
  96. else if (type.equals("spawns"))
  97. {
  98. _print.print("Reloading spawns... ");
  99. RaidBossSpawnManager.getInstance().cleanUp();
  100. DayNightSpawnManager.getInstance().cleanUp();
  101. L2World.getInstance().deleteVisibleNpcSpawns();
  102. NpcTable.getInstance().reloadAllNpc();
  103. SpawnTable.getInstance().reloadAll();
  104. RaidBossSpawnManager.getInstance().load();
  105. _print.println("done\n");
  106. }
  107. else if (type.equalsIgnoreCase("script"))
  108. {
  109. try
  110. {
  111. String questPath = st.hasMoreTokens() ? st.nextToken() : "";
  112. File file = new File(L2ScriptEngineManager.SCRIPT_FOLDER, questPath);
  113. if (file.isFile())
  114. {
  115. try
  116. {
  117. L2ScriptEngineManager.getInstance().executeScript(file);
  118. _print.println(file.getName() + " was successfully loaded!\n");
  119. }
  120. catch (ScriptException e)
  121. {
  122. _print.println("Failed loading: " + questPath);
  123. L2ScriptEngineManager.getInstance().reportScriptFileError(file, e);
  124. }
  125. catch (Exception e)
  126. {
  127. _print.println("Failed loading: " + questPath);
  128. }
  129. }
  130. else
  131. {
  132. _print.println(file.getName() + " is not a file in: " + questPath);
  133. }
  134. }
  135. catch (StringIndexOutOfBoundsException e)
  136. {
  137. _print.println("Please Enter Some Text!");
  138. }
  139. }
  140. }
  141. catch (Exception e)
  142. {
  143. }
  144. }
  145. return false;
  146. }
  147. @Override
  148. public String[] getCommandList()
  149. {
  150. return _commands;
  151. }
  152. }