AdminPetition.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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.instancemanager.PetitionManager;
  18. import com.l2jserver.gameserver.model.L2Object;
  19. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  20. import com.l2jserver.gameserver.network.SystemMessageId;
  21. /**
  22. * This class handles commands for GMs to respond to petitions.
  23. *
  24. * @author Tempy
  25. */
  26. public class AdminPetition implements IAdminCommandHandler
  27. {
  28. private static final String[] ADMIN_COMMANDS =
  29. {
  30. "admin_view_petitions",
  31. "admin_view_petition",
  32. "admin_accept_petition",
  33. "admin_reject_petition",
  34. "admin_reset_petitions",
  35. "admin_force_peti"
  36. };
  37. @Override
  38. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  39. {
  40. int petitionId = -1;
  41. try
  42. {
  43. petitionId = Integer.parseInt(command.split(" ")[1]);
  44. }
  45. catch (Exception e)
  46. {
  47. }
  48. if (command.equals("admin_view_petitions"))
  49. PetitionManager.getInstance().sendPendingPetitionList(activeChar);
  50. else if (command.startsWith("admin_view_petition"))
  51. PetitionManager.getInstance().viewPetition(activeChar, petitionId);
  52. else if (command.startsWith("admin_accept_petition"))
  53. {
  54. if (PetitionManager.getInstance().isPlayerInConsultation(activeChar))
  55. {
  56. activeChar.sendPacket(SystemMessageId.ONLY_ONE_ACTIVE_PETITION_AT_TIME);
  57. return true;
  58. }
  59. if (PetitionManager.getInstance().isPetitionInProcess(petitionId))
  60. {
  61. activeChar.sendPacket(SystemMessageId.PETITION_UNDER_PROCESS);
  62. return true;
  63. }
  64. if (!PetitionManager.getInstance().acceptPetition(activeChar, petitionId))
  65. activeChar.sendPacket(SystemMessageId.NOT_UNDER_PETITION_CONSULTATION);
  66. }
  67. else if (command.startsWith("admin_reject_petition"))
  68. {
  69. if (!PetitionManager.getInstance().rejectPetition(activeChar, petitionId))
  70. activeChar.sendPacket(SystemMessageId.FAILED_CANCEL_PETITION_TRY_LATER);
  71. PetitionManager.getInstance().sendPendingPetitionList(activeChar);
  72. }
  73. else if (command.equals("admin_reset_petitions"))
  74. {
  75. if (PetitionManager.getInstance().isPetitionInProcess())
  76. {
  77. activeChar.sendPacket(SystemMessageId.PETITION_UNDER_PROCESS);
  78. return false;
  79. }
  80. PetitionManager.getInstance().clearPendingPetitions();
  81. PetitionManager.getInstance().sendPendingPetitionList(activeChar);
  82. }
  83. else if (command.startsWith("admin_force_peti"))
  84. {
  85. try
  86. {
  87. L2Object targetChar = activeChar.getTarget();
  88. if (targetChar == null || !(targetChar instanceof L2PcInstance))
  89. {
  90. activeChar.sendPacket(SystemMessageId.TARGET_IS_INCORRECT);
  91. return false;
  92. }
  93. L2PcInstance targetPlayer = (L2PcInstance) targetChar;
  94. String val = command.substring(15);
  95. petitionId = PetitionManager.getInstance().submitPetition(targetPlayer, val, 9);
  96. PetitionManager.getInstance().acceptPetition(activeChar, petitionId);
  97. }
  98. catch (StringIndexOutOfBoundsException e)
  99. {
  100. activeChar.sendMessage("Usage: //force_peti text");
  101. return false;
  102. }
  103. }
  104. return true;
  105. }
  106. @Override
  107. public String[] getAdminCommandList()
  108. {
  109. return ADMIN_COMMANDS;
  110. }
  111. }