AdminCache.java 3.4 KB

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