AdminTest.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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.util.NoSuchElementException;
  17. import java.util.StringTokenizer;
  18. import com.l2jserver.Config;
  19. import com.l2jserver.gameserver.ThreadPoolManager;
  20. import com.l2jserver.gameserver.datatables.SkillTable;
  21. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  22. import com.l2jserver.gameserver.model.L2Object;
  23. import com.l2jserver.gameserver.model.actor.L2Character;
  24. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  25. import com.l2jserver.gameserver.model.skills.L2Skill;
  26. import com.l2jserver.gameserver.network.serverpackets.MagicSkillUse;
  27. /**
  28. * This class ...
  29. *
  30. * @version $Revision: 1.2 $ $Date: 2004/06/27 08:12:59 $
  31. */
  32. public class AdminTest implements IAdminCommandHandler
  33. {
  34. private static final String[] ADMIN_COMMANDS =
  35. {
  36. "admin_stats",
  37. "admin_skill_test",
  38. "admin_known"
  39. };
  40. @Override
  41. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  42. {
  43. if (command.equals("admin_stats"))
  44. {
  45. for (String line : ThreadPoolManager.getInstance().getStats())
  46. {
  47. activeChar.sendMessage(line);
  48. }
  49. }
  50. else if (command.startsWith("admin_skill_test") || command.startsWith("admin_st"))
  51. {
  52. try
  53. {
  54. StringTokenizer st = new StringTokenizer(command);
  55. st.nextToken();
  56. int id = Integer.parseInt(st.nextToken());
  57. if(command.startsWith("admin_skill_test"))
  58. adminTestSkill(activeChar, id, true);
  59. else
  60. adminTestSkill(activeChar, id, false);
  61. }
  62. catch (NumberFormatException e)
  63. {
  64. activeChar.sendMessage("Command format is //skill_test <ID>");
  65. }
  66. catch (NoSuchElementException nsee)
  67. {
  68. activeChar.sendMessage("Command format is //skill_test <ID>");
  69. }
  70. }
  71. else if (command.equals("admin_known on"))
  72. {
  73. Config.CHECK_KNOWN = true;
  74. }
  75. else if (command.equals("admin_known off"))
  76. {
  77. Config.CHECK_KNOWN = false;
  78. }
  79. return true;
  80. }
  81. /**
  82. * @param activeChar
  83. * @param id
  84. * @param msu
  85. */
  86. private void adminTestSkill(L2PcInstance activeChar, int id, boolean msu)
  87. {
  88. L2Character caster;
  89. L2Object target = activeChar.getTarget();
  90. if (!(target instanceof L2Character))
  91. caster = activeChar;
  92. else
  93. caster = (L2Character) target;
  94. L2Skill _skill = SkillTable.getInstance().getInfo(id, 1);
  95. if(_skill != null)
  96. {
  97. caster.setTarget(activeChar);
  98. if(msu)
  99. caster.broadcastPacket(new MagicSkillUse(caster, activeChar, id, 1, _skill.getHitTime(), _skill.getReuseDelay()));
  100. else
  101. caster.doCast(_skill);
  102. }
  103. }
  104. /* (non-Javadoc)
  105. * @see com.l2jserver.gameserver.handler.IAdminCommandHandler#getAdminCommandList()
  106. */
  107. @Override
  108. public String[] getAdminCommandList()
  109. {
  110. return ADMIN_COMMANDS;
  111. }
  112. }