AdminCache.java 3.3 KB

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