AdminDebug.java 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 com.l2jserver.gameserver.handler.IAdminCommandHandler;
  17. import com.l2jserver.gameserver.model.L2Object;
  18. import com.l2jserver.gameserver.model.L2World;
  19. import com.l2jserver.gameserver.model.actor.L2Character;
  20. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  21. public class AdminDebug implements IAdminCommandHandler
  22. {
  23. private static final String[] ADMIN_COMMANDS =
  24. {
  25. "admin_debug"
  26. };
  27. @Override
  28. public final boolean useAdminCommand(String command, L2PcInstance activeChar)
  29. {
  30. String[] commandSplit = command.split(" ");
  31. if (ADMIN_COMMANDS[0].equalsIgnoreCase(commandSplit[0]))
  32. {
  33. L2Object target;
  34. if (commandSplit.length > 1)
  35. {
  36. target = L2World.getInstance().getPlayer(commandSplit[1].trim());
  37. if (target == null)
  38. {
  39. activeChar.sendMessage("Player not found.");
  40. return true;
  41. }
  42. }
  43. else
  44. target = activeChar.getTarget();
  45. if (target instanceof L2Character)
  46. setDebug(activeChar, (L2Character)target);
  47. else
  48. setDebug(activeChar, activeChar);
  49. }
  50. return true;
  51. }
  52. @Override
  53. public final String[] getAdminCommandList()
  54. {
  55. return ADMIN_COMMANDS;
  56. }
  57. private final void setDebug(L2PcInstance activeChar, L2Character target)
  58. {
  59. if (target.isDebug())
  60. {
  61. target.setDebug(null);
  62. activeChar.sendMessage("Stop debugging "+target.getName());
  63. }
  64. else
  65. {
  66. target.setDebug(activeChar);
  67. activeChar.sendMessage("Start debugging "+target.getName());
  68. }
  69. }
  70. }