ChannelLeave.java 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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.usercommandhandlers;
  20. import com.l2jserver.gameserver.handler.IUserCommandHandler;
  21. import com.l2jserver.gameserver.model.L2CommandChannel;
  22. import com.l2jserver.gameserver.model.L2Party;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  24. import com.l2jserver.gameserver.network.SystemMessageId;
  25. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  26. /**
  27. * Channel Leave user command.
  28. * @author Chris, Zoey76
  29. */
  30. public class ChannelLeave implements IUserCommandHandler
  31. {
  32. private static final int[] COMMAND_IDS =
  33. {
  34. 96
  35. };
  36. @Override
  37. public boolean useUserCommand(int id, L2PcInstance activeChar)
  38. {
  39. if (id != COMMAND_IDS[0])
  40. {
  41. return false;
  42. }
  43. if (!activeChar.isInParty() || !activeChar.getParty().isLeader(activeChar))
  44. {
  45. activeChar.sendPacket(SystemMessageId.ONLY_PARTY_LEADER_CAN_LEAVE_CHANNEL);
  46. return false;
  47. }
  48. if (activeChar.getParty().isInCommandChannel())
  49. {
  50. final L2CommandChannel channel = activeChar.getParty().getCommandChannel();
  51. final L2Party party = activeChar.getParty();
  52. channel.removeParty(party);
  53. party.getLeader().sendPacket(SystemMessageId.LEFT_COMMAND_CHANNEL);
  54. final SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_PARTY_LEFT_COMMAND_CHANNEL);
  55. sm.addPcName(party.getLeader());
  56. channel.broadcastPacket(sm);
  57. return true;
  58. }
  59. return false;
  60. }
  61. @Override
  62. public int[] getUserCommandList()
  63. {
  64. return COMMAND_IDS;
  65. }
  66. }