ClanWarehouse.java 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package handlers.bypasshandlers;
  16. import java.util.logging.Level;
  17. import com.l2jserver.Config;
  18. import com.l2jserver.gameserver.handler.IBypassHandler;
  19. import com.l2jserver.gameserver.model.L2Clan;
  20. import com.l2jserver.gameserver.model.actor.L2Character;
  21. import com.l2jserver.gameserver.model.actor.L2Npc;
  22. import com.l2jserver.gameserver.model.actor.instance.L2ClanHallManagerInstance;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  24. import com.l2jserver.gameserver.model.actor.instance.L2WarehouseInstance;
  25. import com.l2jserver.gameserver.network.SystemMessageId;
  26. import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
  27. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  28. import com.l2jserver.gameserver.network.serverpackets.SortedWareHouseWithdrawalList;
  29. import com.l2jserver.gameserver.network.serverpackets.SortedWareHouseWithdrawalList.WarehouseListType;
  30. import com.l2jserver.gameserver.network.serverpackets.WareHouseDepositList;
  31. import com.l2jserver.gameserver.network.serverpackets.WareHouseWithdrawalList;
  32. public class ClanWarehouse implements IBypassHandler
  33. {
  34. private static final String[] COMMANDS =
  35. {
  36. "withdrawc",
  37. "withdrawsortedc",
  38. "depositc"
  39. };
  40. @Override
  41. public boolean useBypass(String command, L2PcInstance activeChar, L2Character target)
  42. {
  43. if (!(target instanceof L2WarehouseInstance) && !(target instanceof L2ClanHallManagerInstance))
  44. {
  45. return false;
  46. }
  47. if (activeChar.isEnchanting())
  48. {
  49. return false;
  50. }
  51. if (activeChar.getClan() == null)
  52. {
  53. activeChar.sendPacket(SystemMessageId.YOU_DO_NOT_HAVE_THE_RIGHT_TO_USE_CLAN_WAREHOUSE);
  54. return false;
  55. }
  56. if (activeChar.getClan().getLevel() == 0)
  57. {
  58. activeChar.sendPacket(SystemMessageId.ONLY_LEVEL_1_CLAN_OR_HIGHER_CAN_USE_WAREHOUSE);
  59. return false;
  60. }
  61. try
  62. {
  63. if (command.toLowerCase().startsWith(COMMANDS[0])) // WithdrawC
  64. {
  65. if (Config.L2JMOD_ENABLE_WAREHOUSESORTING_CLAN)
  66. {
  67. NpcHtmlMessage msg = new NpcHtmlMessage(((L2Npc) target).getObjectId());
  68. msg.setFile(activeChar.getHtmlPrefix(), "data/html/mods/WhSortedC.htm");
  69. msg.replace("%objectId%", String.valueOf(((L2Npc) target).getObjectId()));
  70. activeChar.sendPacket(msg);
  71. }
  72. else
  73. {
  74. showWithdrawWindow(activeChar, null, (byte) 0);
  75. }
  76. return true;
  77. }
  78. else if (command.toLowerCase().startsWith(COMMANDS[1])) // WithdrawSortedC
  79. {
  80. final String param[] = command.split(" ");
  81. if (param.length > 2)
  82. {
  83. showWithdrawWindow(activeChar, WarehouseListType.valueOf(param[1]), SortedWareHouseWithdrawalList.getOrder(param[2]));
  84. }
  85. else if (param.length > 1)
  86. {
  87. showWithdrawWindow(activeChar, WarehouseListType.valueOf(param[1]), SortedWareHouseWithdrawalList.A2Z);
  88. }
  89. else
  90. {
  91. showWithdrawWindow(activeChar, WarehouseListType.ALL, SortedWareHouseWithdrawalList.A2Z);
  92. }
  93. return true;
  94. }
  95. else if (command.toLowerCase().startsWith(COMMANDS[2])) // DepositC
  96. {
  97. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  98. activeChar.setActiveWarehouse(activeChar.getClan().getWarehouse());
  99. activeChar.tempInventoryDisable();
  100. if (Config.DEBUG)
  101. {
  102. _log.fine("Source: L2WarehouseInstance.java; Player: " + activeChar.getName() + "; Command: showDepositWindowClan; Message: Showing items to deposit.");
  103. }
  104. activeChar.sendPacket(new WareHouseDepositList(activeChar, WareHouseDepositList.CLAN));
  105. return true;
  106. }
  107. return false;
  108. }
  109. catch (Exception e)
  110. {
  111. _log.log(Level.WARNING, "Exception in " + getClass().getSimpleName(), e);
  112. }
  113. return false;
  114. }
  115. private static final void showWithdrawWindow(L2PcInstance player, WarehouseListType itemtype, byte sortorder)
  116. {
  117. player.sendPacket(ActionFailed.STATIC_PACKET);
  118. if ((player.getClanPrivileges() & L2Clan.CP_CL_VIEW_WAREHOUSE) != L2Clan.CP_CL_VIEW_WAREHOUSE)
  119. {
  120. player.sendPacket(SystemMessageId.YOU_DO_NOT_HAVE_THE_RIGHT_TO_USE_CLAN_WAREHOUSE);
  121. return;
  122. }
  123. player.setActiveWarehouse(player.getClan().getWarehouse());
  124. if (player.getActiveWarehouse().getSize() == 0)
  125. {
  126. player.sendPacket(SystemMessageId.NO_ITEM_DEPOSITED_IN_WH);
  127. return;
  128. }
  129. if (itemtype != null)
  130. {
  131. player.sendPacket(new SortedWareHouseWithdrawalList(player, WareHouseWithdrawalList.CLAN, itemtype, sortorder));
  132. }
  133. else
  134. {
  135. player.sendPacket(new WareHouseWithdrawalList(player, WareHouseWithdrawalList.CLAN));
  136. }
  137. if (Config.DEBUG)
  138. {
  139. _log.fine("Source: L2WarehouseInstance.java; Player: " + player.getName() + "; Command: showRetrieveWindowClan; Message: Showing stored items.");
  140. }
  141. }
  142. @Override
  143. public String[] getBypassList()
  144. {
  145. return COMMANDS;
  146. }
  147. }