PrivateWarehouse.java 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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.actor.L2Character;
  20. import com.l2jserver.gameserver.model.actor.L2Npc;
  21. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  22. import com.l2jserver.gameserver.network.SystemMessageId;
  23. import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
  24. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  25. import com.l2jserver.gameserver.network.serverpackets.SortedWareHouseWithdrawalList;
  26. import com.l2jserver.gameserver.network.serverpackets.SortedWareHouseWithdrawalList.WarehouseListType;
  27. import com.l2jserver.gameserver.network.serverpackets.WareHouseDepositList;
  28. import com.l2jserver.gameserver.network.serverpackets.WareHouseWithdrawalList;
  29. public class PrivateWarehouse implements IBypassHandler
  30. {
  31. private static final String[] COMMANDS =
  32. {
  33. "withdrawp",
  34. "withdrawsortedp",
  35. "depositp"
  36. };
  37. @Override
  38. public boolean useBypass(String command, L2PcInstance activeChar, L2Character target)
  39. {
  40. if (!(target instanceof L2Npc))
  41. {
  42. return false;
  43. }
  44. if (activeChar.isEnchanting())
  45. {
  46. return false;
  47. }
  48. try
  49. {
  50. if (command.toLowerCase().startsWith(COMMANDS[0])) // WithdrawP
  51. {
  52. if (Config.L2JMOD_ENABLE_WAREHOUSESORTING_PRIVATE)
  53. {
  54. NpcHtmlMessage msg = new NpcHtmlMessage(((L2Npc) target).getObjectId());
  55. msg.setFile(activeChar.getHtmlPrefix(), "data/html/mods/WhSortedP.htm");
  56. msg.replace("%objectId%", String.valueOf(((L2Npc) target).getObjectId()));
  57. activeChar.sendPacket(msg);
  58. }
  59. else
  60. {
  61. showWithdrawWindow(activeChar, null, (byte) 0);
  62. }
  63. return true;
  64. }
  65. else if (command.toLowerCase().startsWith(COMMANDS[1])) // WithdrawSortedP
  66. {
  67. final String param[] = command.split(" ");
  68. if (param.length > 2)
  69. {
  70. showWithdrawWindow(activeChar, WarehouseListType.valueOf(param[1]), SortedWareHouseWithdrawalList.getOrder(param[2]));
  71. }
  72. else if (param.length > 1)
  73. {
  74. showWithdrawWindow(activeChar, WarehouseListType.valueOf(param[1]), SortedWareHouseWithdrawalList.A2Z);
  75. }
  76. else
  77. {
  78. showWithdrawWindow(activeChar, WarehouseListType.ALL, SortedWareHouseWithdrawalList.A2Z);
  79. }
  80. return true;
  81. }
  82. else if (command.toLowerCase().startsWith(COMMANDS[2])) // DepositP
  83. {
  84. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  85. activeChar.setActiveWarehouse(activeChar.getWarehouse());
  86. activeChar.tempInventoryDisable();
  87. if (Config.DEBUG)
  88. {
  89. _log.fine("Source: L2WarehouseInstance.java; Player: " + activeChar.getName() + "; Command: showDepositWindow; Message: Showing items to deposit.");
  90. }
  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. }