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