PrivateWarehouse.java 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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.actor.L2Character;
  24. import com.l2jserver.gameserver.model.actor.L2Npc;
  25. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  26. import com.l2jserver.gameserver.network.SystemMessageId;
  27. import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
  28. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  29. import com.l2jserver.gameserver.network.serverpackets.SortedWareHouseWithdrawalList;
  30. import com.l2jserver.gameserver.network.serverpackets.SortedWareHouseWithdrawalList.WarehouseListType;
  31. import com.l2jserver.gameserver.network.serverpackets.WareHouseDepositList;
  32. import com.l2jserver.gameserver.network.serverpackets.WareHouseWithdrawalList;
  33. public class PrivateWarehouse implements IBypassHandler
  34. {
  35. private static final String[] COMMANDS =
  36. {
  37. "withdrawp",
  38. "withdrawsortedp",
  39. "depositp"
  40. };
  41. @Override
  42. public boolean useBypass(String command, L2PcInstance activeChar, L2Character target)
  43. {
  44. if (!target.isNpc())
  45. {
  46. return false;
  47. }
  48. if (activeChar.isEnchanting())
  49. {
  50. return false;
  51. }
  52. try
  53. {
  54. if (command.toLowerCase().startsWith(COMMANDS[0])) // WithdrawP
  55. {
  56. if (Config.L2JMOD_ENABLE_WAREHOUSESORTING_PRIVATE)
  57. {
  58. final NpcHtmlMessage msg = new NpcHtmlMessage(((L2Npc) target).getObjectId());
  59. msg.setFile(activeChar.getHtmlPrefix(), "data/html/mods/WhSortedP.htm");
  60. msg.replace("%objectId%", String.valueOf(((L2Npc) target).getObjectId()));
  61. activeChar.sendPacket(msg);
  62. }
  63. else
  64. {
  65. showWithdrawWindow(activeChar, null, (byte) 0);
  66. }
  67. return true;
  68. }
  69. else if (command.toLowerCase().startsWith(COMMANDS[1])) // WithdrawSortedP
  70. {
  71. final String param[] = command.split(" ");
  72. if (param.length > 2)
  73. {
  74. showWithdrawWindow(activeChar, WarehouseListType.valueOf(param[1]), SortedWareHouseWithdrawalList.getOrder(param[2]));
  75. }
  76. else if (param.length > 1)
  77. {
  78. showWithdrawWindow(activeChar, WarehouseListType.valueOf(param[1]), SortedWareHouseWithdrawalList.A2Z);
  79. }
  80. else
  81. {
  82. showWithdrawWindow(activeChar, WarehouseListType.ALL, SortedWareHouseWithdrawalList.A2Z);
  83. }
  84. return true;
  85. }
  86. else if (command.toLowerCase().startsWith(COMMANDS[2])) // DepositP
  87. {
  88. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  89. activeChar.setActiveWarehouse(activeChar.getWarehouse());
  90. activeChar.setInventoryBlockingStatus(true);
  91. activeChar.sendPacket(new WareHouseDepositList(activeChar, WareHouseDepositList.PRIVATE));
  92. return true;
  93. }
  94. return false;
  95. }
  96. catch (Exception e)
  97. {
  98. _log.log(Level.WARNING, "Exception in " + getClass().getSimpleName(), e);
  99. }
  100. return false;
  101. }
  102. private static final void showWithdrawWindow(L2PcInstance player, WarehouseListType itemtype, byte sortorder)
  103. {
  104. player.sendPacket(ActionFailed.STATIC_PACKET);
  105. player.setActiveWarehouse(player.getWarehouse());
  106. if (player.getActiveWarehouse().getSize() == 0)
  107. {
  108. player.sendPacket(SystemMessageId.NO_ITEM_DEPOSITED_IN_WH);
  109. return;
  110. }
  111. if (itemtype != null)
  112. {
  113. player.sendPacket(new SortedWareHouseWithdrawalList(player, WareHouseWithdrawalList.PRIVATE, itemtype, sortorder));
  114. }
  115. else
  116. {
  117. player.sendPacket(new WareHouseWithdrawalList(player, WareHouseWithdrawalList.PRIVATE));
  118. }
  119. if (Config.DEBUG)
  120. {
  121. _log.fine("Source: L2WarehouseInstance.java; Player: " + player.getName() + "; Command: showRetrieveWindow; Message: Showing stored items.");
  122. }
  123. }
  124. @Override
  125. public String[] getBypassList()
  126. {
  127. return COMMANDS;
  128. }
  129. }