AdminPetition.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * Copyright (C) 2004-2015 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J DataPack is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package handlers.admincommandhandlers;
  20. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  21. import com.l2jserver.gameserver.instancemanager.PetitionManager;
  22. import com.l2jserver.gameserver.model.L2Object;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  24. import com.l2jserver.gameserver.network.SystemMessageId;
  25. /**
  26. * This class handles commands for GMs to respond to petitions.
  27. * @author Tempy
  28. */
  29. public class AdminPetition implements IAdminCommandHandler
  30. {
  31. private static final String[] ADMIN_COMMANDS =
  32. {
  33. "admin_view_petitions",
  34. "admin_view_petition",
  35. "admin_accept_petition",
  36. "admin_reject_petition",
  37. "admin_reset_petitions",
  38. "admin_force_peti"
  39. };
  40. @Override
  41. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  42. {
  43. int petitionId = -1;
  44. try
  45. {
  46. petitionId = Integer.parseInt(command.split(" ")[1]);
  47. }
  48. catch (Exception e)
  49. {
  50. }
  51. if (command.equals("admin_view_petitions"))
  52. {
  53. PetitionManager.getInstance().sendPendingPetitionList(activeChar);
  54. }
  55. else if (command.startsWith("admin_view_petition"))
  56. {
  57. PetitionManager.getInstance().viewPetition(activeChar, petitionId);
  58. }
  59. else if (command.startsWith("admin_accept_petition"))
  60. {
  61. if (PetitionManager.getInstance().isPlayerInConsultation(activeChar))
  62. {
  63. activeChar.sendPacket(SystemMessageId.ONLY_ONE_ACTIVE_PETITION_AT_TIME);
  64. return true;
  65. }
  66. if (PetitionManager.getInstance().isPetitionInProcess(petitionId))
  67. {
  68. activeChar.sendPacket(SystemMessageId.PETITION_UNDER_PROCESS);
  69. return true;
  70. }
  71. if (!PetitionManager.getInstance().acceptPetition(activeChar, petitionId))
  72. {
  73. activeChar.sendPacket(SystemMessageId.NOT_UNDER_PETITION_CONSULTATION);
  74. }
  75. }
  76. else if (command.startsWith("admin_reject_petition"))
  77. {
  78. if (!PetitionManager.getInstance().rejectPetition(activeChar, petitionId))
  79. {
  80. activeChar.sendPacket(SystemMessageId.FAILED_CANCEL_PETITION_TRY_LATER);
  81. }
  82. PetitionManager.getInstance().sendPendingPetitionList(activeChar);
  83. }
  84. else if (command.equals("admin_reset_petitions"))
  85. {
  86. if (PetitionManager.getInstance().isPetitionInProcess())
  87. {
  88. activeChar.sendPacket(SystemMessageId.PETITION_UNDER_PROCESS);
  89. return false;
  90. }
  91. PetitionManager.getInstance().clearPendingPetitions();
  92. PetitionManager.getInstance().sendPendingPetitionList(activeChar);
  93. }
  94. else if (command.startsWith("admin_force_peti"))
  95. {
  96. try
  97. {
  98. L2Object targetChar = activeChar.getTarget();
  99. if ((targetChar == null) || !(targetChar instanceof L2PcInstance))
  100. {
  101. activeChar.sendPacket(SystemMessageId.TARGET_IS_INCORRECT);
  102. return false;
  103. }
  104. L2PcInstance targetPlayer = (L2PcInstance) targetChar;
  105. String val = command.substring(15);
  106. petitionId = PetitionManager.getInstance().submitPetition(targetPlayer, val, 9);
  107. PetitionManager.getInstance().acceptPetition(activeChar, petitionId);
  108. }
  109. catch (StringIndexOutOfBoundsException e)
  110. {
  111. activeChar.sendMessage("Usage: //force_peti text");
  112. return false;
  113. }
  114. }
  115. return true;
  116. }
  117. @Override
  118. public String[] getAdminCommandList()
  119. {
  120. return ADMIN_COMMANDS;
  121. }
  122. }