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