ClanWarehouse.java 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. * Copyright (C) 2004-2013 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.bypasshandlers;
  20. import java.util.logging.Level;
  21. import com.l2jserver.Config;
  22. import com.l2jserver.gameserver.handler.IBypassHandler;
  23. import com.l2jserver.gameserver.model.L2Clan;
  24. import com.l2jserver.gameserver.model.actor.L2Character;
  25. import com.l2jserver.gameserver.model.actor.L2Npc;
  26. import com.l2jserver.gameserver.model.actor.instance.L2ClanHallManagerInstance;
  27. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  28. import com.l2jserver.gameserver.model.actor.instance.L2WarehouseInstance;
  29. import com.l2jserver.gameserver.network.SystemMessageId;
  30. import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
  31. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  32. import com.l2jserver.gameserver.network.serverpackets.SortedWareHouseWithdrawalList;
  33. import com.l2jserver.gameserver.network.serverpackets.SortedWareHouseWithdrawalList.WarehouseListType;
  34. import com.l2jserver.gameserver.network.serverpackets.WareHouseDepositList;
  35. import com.l2jserver.gameserver.network.serverpackets.WareHouseWithdrawalList;
  36. public class ClanWarehouse implements IBypassHandler
  37. {
  38. private static final String[] COMMANDS =
  39. {
  40. "withdrawc",
  41. "withdrawsortedc",
  42. "depositc"
  43. };
  44. @Override
  45. public boolean useBypass(String command, L2PcInstance activeChar, L2Character target)
  46. {
  47. if (!(target instanceof L2WarehouseInstance) && !(target instanceof L2ClanHallManagerInstance))
  48. {
  49. return false;
  50. }
  51. if (activeChar.isEnchanting())
  52. {
  53. return false;
  54. }
  55. if (activeChar.getClan() == null)
  56. {
  57. activeChar.sendPacket(SystemMessageId.YOU_DO_NOT_HAVE_THE_RIGHT_TO_USE_CLAN_WAREHOUSE);
  58. return false;
  59. }
  60. if (activeChar.getClan().getLevel() == 0)
  61. {
  62. activeChar.sendPacket(SystemMessageId.ONLY_LEVEL_1_CLAN_OR_HIGHER_CAN_USE_WAREHOUSE);
  63. return false;
  64. }
  65. try
  66. {
  67. if (command.toLowerCase().startsWith(COMMANDS[0])) // WithdrawC
  68. {
  69. if (Config.L2JMOD_ENABLE_WAREHOUSESORTING_CLAN)
  70. {
  71. final NpcHtmlMessage msg = new NpcHtmlMessage(((L2Npc) target).getObjectId());
  72. msg.setFile(activeChar.getHtmlPrefix(), "data/html/mods/WhSortedC.htm");
  73. msg.replace("%objectId%", String.valueOf(((L2Npc) target).getObjectId()));
  74. activeChar.sendPacket(msg);
  75. }
  76. else
  77. {
  78. showWithdrawWindow(activeChar, null, (byte) 0);
  79. }
  80. return true;
  81. }
  82. else if (command.toLowerCase().startsWith(COMMANDS[1])) // WithdrawSortedC
  83. {
  84. final String param[] = command.split(" ");
  85. if (param.length > 2)
  86. {
  87. showWithdrawWindow(activeChar, WarehouseListType.valueOf(param[1]), SortedWareHouseWithdrawalList.getOrder(param[2]));
  88. }
  89. else if (param.length > 1)
  90. {
  91. showWithdrawWindow(activeChar, WarehouseListType.valueOf(param[1]), SortedWareHouseWithdrawalList.A2Z);
  92. }
  93. else
  94. {
  95. showWithdrawWindow(activeChar, WarehouseListType.ALL, SortedWareHouseWithdrawalList.A2Z);
  96. }
  97. return true;
  98. }
  99. else if (command.toLowerCase().startsWith(COMMANDS[2])) // DepositC
  100. {
  101. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  102. activeChar.setActiveWarehouse(activeChar.getClan().getWarehouse());
  103. activeChar.setInventoryBlockingStatus(true);
  104. if (Config.DEBUG)
  105. {
  106. _log.fine("Source: L2WarehouseInstance.java; Player: " + activeChar.getName() + "; Command: showDepositWindowClan; Message: Showing items to deposit.");
  107. }
  108. activeChar.sendPacket(new WareHouseDepositList(activeChar, WareHouseDepositList.CLAN));
  109. return true;
  110. }
  111. return false;
  112. }
  113. catch (Exception e)
  114. {
  115. _log.log(Level.WARNING, "Exception in " + getClass().getSimpleName(), e);
  116. }
  117. return false;
  118. }
  119. private static final void showWithdrawWindow(L2PcInstance player, WarehouseListType itemtype, byte sortorder)
  120. {
  121. player.sendPacket(ActionFailed.STATIC_PACKET);
  122. if (!player.hasClanPrivilege(L2Clan.CP_CL_VIEW_WAREHOUSE))
  123. {
  124. player.sendPacket(SystemMessageId.YOU_DO_NOT_HAVE_THE_RIGHT_TO_USE_CLAN_WAREHOUSE);
  125. return;
  126. }
  127. player.setActiveWarehouse(player.getClan().getWarehouse());
  128. if (player.getActiveWarehouse().getSize() == 0)
  129. {
  130. player.sendPacket(SystemMessageId.NO_ITEM_DEPOSITED_IN_WH);
  131. return;
  132. }
  133. if (itemtype != null)
  134. {
  135. player.sendPacket(new SortedWareHouseWithdrawalList(player, WareHouseWithdrawalList.CLAN, itemtype, sortorder));
  136. }
  137. else
  138. {
  139. player.sendPacket(new WareHouseWithdrawalList(player, WareHouseWithdrawalList.CLAN));
  140. }
  141. if (Config.DEBUG)
  142. {
  143. _log.fine("Source: L2WarehouseInstance.java; Player: " + player.getName() + "; Command: showRetrieveWindowClan; Message: Showing stored items.");
  144. }
  145. }
  146. @Override
  147. public String[] getBypassList()
  148. {
  149. return COMMANDS;
  150. }
  151. }