AdminPetition.java 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 net.sf.l2j.gameserver.handler.admincommandhandlers;
  16. import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
  17. import net.sf.l2j.gameserver.instancemanager.PetitionManager;
  18. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  19. import net.sf.l2j.gameserver.network.SystemMessageId;
  20. import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
  21. /**
  22. * This class handles commands for GMs to respond to petitions.
  23. *
  24. * @author Tempy
  25. *
  26. */
  27. public class AdminPetition implements IAdminCommandHandler
  28. {
  29. private static final String[] ADMIN_COMMANDS =
  30. {
  31. "admin_view_petitions",
  32. "admin_view_petition",
  33. "admin_accept_petition",
  34. "admin_reject_petition",
  35. "admin_reset_petitions"
  36. };
  37. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  38. {
  39. int petitionId = -1;
  40. try
  41. {
  42. petitionId = Integer.parseInt(command.split(" ")[1]);
  43. }
  44. catch (Exception e)
  45. {
  46. }
  47. if (command.equals("admin_view_petitions"))
  48. PetitionManager.getInstance().sendPendingPetitionList(activeChar);
  49. else if (command.startsWith("admin_view_petition"))
  50. PetitionManager.getInstance().viewPetition(activeChar, petitionId);
  51. else if (command.startsWith("admin_accept_petition"))
  52. {
  53. if (PetitionManager.getInstance().isPlayerInConsultation(activeChar))
  54. {
  55. activeChar.sendPacket(new SystemMessage(SystemMessageId.ONLY_ONE_ACTIVE_PETITION_AT_TIME));
  56. return true;
  57. }
  58. if (PetitionManager.getInstance().isPetitionInProcess(petitionId))
  59. {
  60. activeChar.sendPacket(new SystemMessage(SystemMessageId.PETITION_UNDER_PROCESS));
  61. return true;
  62. }
  63. if (!PetitionManager.getInstance().acceptPetition(activeChar, petitionId))
  64. activeChar.sendPacket(new SystemMessage(SystemMessageId.NOT_UNDER_PETITION_CONSULTATION));
  65. }
  66. else if (command.startsWith("admin_reject_petition"))
  67. {
  68. if (!PetitionManager.getInstance().rejectPetition(activeChar, petitionId))
  69. activeChar.sendPacket(new SystemMessage(SystemMessageId.FAILED_CANCEL_PETITION_TRY_LATER));
  70. }
  71. else if (command.equals("admin_reset_petitions"))
  72. {
  73. if (PetitionManager.getInstance().isPetitionInProcess())
  74. {
  75. activeChar.sendPacket(new SystemMessage(SystemMessageId.PETITION_UNDER_PROCESS));
  76. return false;
  77. }
  78. PetitionManager.getInstance().clearPendingPetitions();
  79. }
  80. return true;
  81. }
  82. public String[] getAdminCommandList()
  83. {
  84. return ADMIN_COMMANDS;
  85. }
  86. }