ClanWarehouse.java 5.8 KB

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