ReloadHandler.java 5.0 KB

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