/*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that
* it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If
* not, see <http://www.gnu.org/licenses/>.
*/
package silentium.scripts.handlers.admin;
import silentium.gameserver.handler.IAdminCommandHandler;
import silentium.gameserver.instancemanager.PetitionManager;
import silentium.gameserver.model.actor.instance.L2PcInstance;
import silentium.gameserver.network.SystemMessageId;
import silentium.gameserver.network.serverpackets.SystemMessage;
/**
* This class handles commands for GMs to respond to petitions.
*
* @author Tempy
*/
public class AdminPetition implements IAdminCommandHandler {
private static final String[] ADMIN_COMMANDS = { "admin_view_petitions", "admin_view_petition", "admin_accept_petition", "admin_reject_petition", "admin_reset_petitions" };
@Override
public boolean useAdminCommand(final String command, final L2PcInstance activeChar) {
int petitionId = -1;
try {
petitionId = Integer.parseInt(command.split(" ")[1]);
} catch (Exception e) {
}
if ("admin_view_petitions".equals(command))
PetitionManager.getInstance().sendPendingPetitionList(activeChar);
else if (command.startsWith("admin_view_petition"))
PetitionManager.getInstance().viewPetition(activeChar, petitionId);
else if (command.startsWith("admin_accept_petition")) {
if (PetitionManager.getInstance().isPlayerInConsultation(activeChar)) {
activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.ONLY_ONE_ACTIVE_PETITION_AT_TIME));
return true;
}
if (PetitionManager.getInstance().isPetitionInProcess(petitionId)) {
activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.PETITION_UNDER_PROCESS));
return true;
}
if (!PetitionManager.getInstance().acceptPetition(activeChar, petitionId))
activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.NOT_UNDER_PETITION_CONSULTATION));
} else if (command.startsWith("admin_reject_petition")) {
if (!PetitionManager.getInstance().rejectPetition(activeChar, petitionId))
activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.FAILED_CANCEL_PETITION_TRY_LATER));
} else if ("admin_reset_petitions".equals(command)) {
if (PetitionManager.getInstance().isPetitionInProcess()) {
activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.PETITION_UNDER_PROCESS));
return false;
}
PetitionManager.getInstance().clearPendingPetitions();
}
return true;
}
@Override
public String[] getAdminCommandList() {
return ADMIN_COMMANDS;
}
}