ReloadHandler.java 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. * Copyright (C) 2004-2014 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J DataPack is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package handlers.telnethandlers;
  20. import java.io.File;
  21. import java.io.PrintWriter;
  22. import java.net.Socket;
  23. import java.util.StringTokenizer;
  24. import javax.script.ScriptException;
  25. import com.l2jserver.gameserver.cache.HtmCache;
  26. import com.l2jserver.gameserver.datatables.ItemTable;
  27. import com.l2jserver.gameserver.datatables.MultisellData;
  28. import com.l2jserver.gameserver.datatables.NpcData;
  29. import com.l2jserver.gameserver.datatables.SkillData;
  30. import com.l2jserver.gameserver.datatables.SpawnTable;
  31. import com.l2jserver.gameserver.datatables.TeleportLocationTable;
  32. import com.l2jserver.gameserver.handler.ITelnetHandler;
  33. import com.l2jserver.gameserver.instancemanager.DayNightSpawnManager;
  34. import com.l2jserver.gameserver.instancemanager.QuestManager;
  35. import com.l2jserver.gameserver.instancemanager.RaidBossSpawnManager;
  36. import com.l2jserver.gameserver.instancemanager.ZoneManager;
  37. import com.l2jserver.gameserver.model.L2World;
  38. import com.l2jserver.gameserver.scripting.L2ScriptEngineManager;
  39. /**
  40. * @author UnAfraid
  41. */
  42. public class ReloadHandler implements ITelnetHandler
  43. {
  44. private final String[] _commands =
  45. {
  46. "reload"
  47. };
  48. @Override
  49. public boolean useCommand(String command, PrintWriter _print, Socket _cSocket, int _uptime)
  50. {
  51. if (command.startsWith("reload"))
  52. {
  53. StringTokenizer st = new StringTokenizer(command.substring(7));
  54. try
  55. {
  56. String type = st.nextToken();
  57. if (type.equals("multisell"))
  58. {
  59. _print.print("Reloading multisell... ");
  60. MultisellData.getInstance().load();
  61. _print.println("done");
  62. }
  63. else if (type.equals("skill"))
  64. {
  65. _print.print("Reloading skills... ");
  66. SkillData.getInstance().reload();
  67. _print.println("done");
  68. }
  69. else if (type.equals("npc"))
  70. {
  71. _print.print("Reloading npc templates... ");
  72. NpcData.getInstance().load();
  73. QuestManager.getInstance().reloadAllScripts();
  74. _print.println("done");
  75. }
  76. else if (type.equals("html"))
  77. {
  78. _print.print("Reloading html cache... ");
  79. HtmCache.getInstance().reload();
  80. _print.println("done");
  81. }
  82. else if (type.equals("item"))
  83. {
  84. _print.print("Reloading item templates... ");
  85. ItemTable.getInstance().reload();
  86. _print.println("done");
  87. }
  88. else if (type.equals("zone"))
  89. {
  90. _print.print("Reloading zone tables... ");
  91. ZoneManager.getInstance().reload();
  92. _print.println("done");
  93. }
  94. else if (type.equals("teleports"))
  95. {
  96. _print.print("Reloading telport location table... ");
  97. TeleportLocationTable.getInstance().reloadAll();
  98. _print.println("done");
  99. }
  100. else if (type.equals("spawns"))
  101. {
  102. _print.print("Reloading spawns... ");
  103. RaidBossSpawnManager.getInstance().cleanUp();
  104. DayNightSpawnManager.getInstance().cleanUp();
  105. L2World.getInstance().deleteVisibleNpcSpawns();
  106. NpcData.getInstance().load();
  107. SpawnTable.getInstance().load();
  108. RaidBossSpawnManager.getInstance().load();
  109. _print.println("done\n");
  110. }
  111. else if (type.equalsIgnoreCase("script"))
  112. {
  113. try
  114. {
  115. String questPath = st.hasMoreTokens() ? st.nextToken() : "";
  116. File file = new File(L2ScriptEngineManager.SCRIPT_FOLDER, questPath);
  117. if (file.isFile())
  118. {
  119. try
  120. {
  121. L2ScriptEngineManager.getInstance().executeScript(file);
  122. _print.println(file.getName() + " was successfully loaded!\n");
  123. }
  124. catch (ScriptException e)
  125. {
  126. _print.println("Failed loading: " + questPath);
  127. L2ScriptEngineManager.getInstance().reportScriptFileError(file, e);
  128. }
  129. catch (Exception e)
  130. {
  131. _print.println("Failed loading: " + questPath);
  132. }
  133. }
  134. else
  135. {
  136. _print.println(file.getName() + " is not a file in: " + questPath);
  137. }
  138. }
  139. catch (StringIndexOutOfBoundsException e)
  140. {
  141. _print.println("Please Enter Some Text!");
  142. }
  143. }
  144. }
  145. catch (Exception e)
  146. {
  147. }
  148. }
  149. return false;
  150. }
  151. @Override
  152. public String[] getCommandList()
  153. {
  154. return _commands;
  155. }
  156. }