AdminCache.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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.admincommandhandlers;
  16. import java.io.File;
  17. import com.l2jserver.Config;
  18. import com.l2jserver.gameserver.cache.CrestCache;
  19. import com.l2jserver.gameserver.cache.HtmCache;
  20. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  21. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  22. /**
  23. * @author Layanere
  24. *
  25. */
  26. public class AdminCache implements IAdminCommandHandler
  27. {
  28. private static final String[] ADMIN_COMMANDS =
  29. {
  30. "admin_cache_htm_rebuild",
  31. "admin_cache_htm_reload",
  32. "admin_cache_reload_path",
  33. "admin_cache_reload_file",
  34. "admin_cache_crest_rebuild",
  35. "admin_cache_crest_reload",
  36. "admin_cache_crest_fix"
  37. };
  38. @Override
  39. public String[] getAdminCommandList()
  40. {
  41. return ADMIN_COMMANDS;
  42. }
  43. @Override
  44. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  45. {
  46. if (command.startsWith("admin_cache_htm_rebuild") || command.equals("admin_cache_htm_reload"))
  47. {
  48. HtmCache.getInstance().reload(Config.DATAPACK_ROOT);
  49. activeChar.sendMessage("Cache[HTML]: " + HtmCache.getInstance().getMemoryUsage() + " MB on " + HtmCache.getInstance().getLoadedFiles() + " file(s) loaded.");
  50. }
  51. else if (command.startsWith("admin_cache_reload_path "))
  52. {
  53. try
  54. {
  55. String path = command.split(" ")[1];
  56. HtmCache.getInstance().reloadPath(new File(Config.DATAPACK_ROOT, path));
  57. activeChar.sendMessage("Cache[HTML]: " + HtmCache.getInstance().getMemoryUsage() + " MB in " + HtmCache.getInstance().getLoadedFiles() + " file(s) loaded.");
  58. }
  59. catch (Exception e)
  60. {
  61. activeChar.sendMessage("Usage: //cache_reload_path <path>");
  62. }
  63. }
  64. else if (command.startsWith("admin_cache_reload_file "))
  65. {
  66. try
  67. {
  68. String path = command.split(" ")[1];
  69. if (HtmCache.getInstance().loadFile(new File(Config.DATAPACK_ROOT, path)) != null)
  70. {
  71. activeChar.sendMessage("Cache[HTML]: file was loaded");
  72. }
  73. else
  74. {
  75. activeChar.sendMessage("Cache[HTML]: file can't be loaded");
  76. }
  77. }
  78. catch (Exception e)
  79. {
  80. activeChar.sendMessage("Usage: //cache_reload_file <relative_path/file>");
  81. }
  82. }
  83. else if (command.startsWith("admin_cache_crest_rebuild") || command.startsWith("admin_cache_crest_reload"))
  84. {
  85. CrestCache.getInstance().reload();
  86. activeChar.sendMessage("Cache[Crest]: " + String.format("%.3f", CrestCache.getInstance().getMemoryUsage()) + " megabytes on " + CrestCache.getInstance().getLoadedFiles() + " files loaded");
  87. }
  88. else if (command.startsWith("admin_cache_crest_fix"))
  89. {
  90. CrestCache.getInstance().convertOldPedgeFiles();
  91. activeChar.sendMessage("Cache[Crest]: crests fixed");
  92. }
  93. return true;
  94. }
  95. }