AdminPetition.java 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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.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 = {"admin_view_petitions", "admin_view_petition",
  30. "admin_accept_petition", "admin_reject_petition", "admin_reset_petitions"};
  31. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  32. {
  33. int petitionId = -1;
  34. try
  35. {
  36. petitionId = Integer.parseInt(command.split(" ")[1]);
  37. }
  38. catch (Exception e) {}
  39. if (command.equals("admin_view_petitions"))
  40. PetitionManager.getInstance().sendPendingPetitionList(activeChar);
  41. else if (command.startsWith("admin_view_petition"))
  42. PetitionManager.getInstance().viewPetition(activeChar, petitionId);
  43. else if (command.startsWith("admin_accept_petition"))
  44. {
  45. if (PetitionManager.getInstance().isPlayerInConsultation(activeChar))
  46. {
  47. activeChar.sendPacket( new SystemMessage(SystemMessageId.ONLY_ONE_ACTIVE_PETITION_AT_TIME));
  48. return true;
  49. }
  50. if (PetitionManager.getInstance().isPetitionInProcess(petitionId))
  51. {
  52. activeChar.sendPacket( new SystemMessage(SystemMessageId.PETITION_UNDER_PROCESS));
  53. return true;
  54. }
  55. if (!PetitionManager.getInstance().acceptPetition(activeChar, petitionId))
  56. activeChar.sendPacket( new SystemMessage(SystemMessageId.NOT_UNDER_PETITION_CONSULTATION));
  57. }
  58. else if (command.startsWith("admin_reject_petition"))
  59. {
  60. if (!PetitionManager.getInstance().rejectPetition(activeChar, petitionId))
  61. activeChar.sendPacket( new SystemMessage(SystemMessageId.FAILED_CANCEL_PETITION_TRY_LATER));
  62. }
  63. else if (command.equals("admin_reset_petitions"))
  64. {
  65. if (PetitionManager.getInstance().isPetitionInProcess())
  66. {
  67. activeChar.sendPacket( new SystemMessage(SystemMessageId.PETITION_UNDER_PROCESS));
  68. return false;
  69. }
  70. PetitionManager.getInstance().clearPendingPetitions();
  71. }
  72. return true;
  73. }
  74. public String[] getAdminCommandList() {
  75. return ADMIN_COMMANDS;
  76. }
  77. }