PrivateWarehouse.java 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 com.l2jserver.Config;
  17. import com.l2jserver.gameserver.handler.IBypassHandler;
  18. import com.l2jserver.gameserver.model.actor.L2Character;
  19. import com.l2jserver.gameserver.model.actor.L2Npc;
  20. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  21. import com.l2jserver.gameserver.network.SystemMessageId;
  22. import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
  23. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  24. import com.l2jserver.gameserver.network.serverpackets.SortedWareHouseWithdrawalList;
  25. import com.l2jserver.gameserver.network.serverpackets.SortedWareHouseWithdrawalList.WarehouseListType;
  26. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  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. public boolean useBypass(String command, L2PcInstance activeChar, L2Character target)
  38. {
  39. if (!(target instanceof L2Npc))
  40. return false;
  41. if (activeChar.isEnchanting())
  42. return false;
  43. try
  44. {
  45. if (command.toLowerCase().startsWith(COMMANDS[0])) // WithdrawP
  46. {
  47. if (Config.L2JMOD_ENABLE_WAREHOUSESORTING_PRIVATE)
  48. {
  49. NpcHtmlMessage msg = new NpcHtmlMessage(((L2Npc)target).getObjectId());
  50. msg.setFile(activeChar.getHtmlPrefix(), "data/html/mods/WhSortedP.htm");
  51. msg.replace("%objectId%", String.valueOf(((L2Npc)target).getObjectId()));
  52. activeChar.sendPacket(msg);
  53. }
  54. else
  55. showWithdrawWindow(activeChar, null, (byte) 0);
  56. return true;
  57. }
  58. else if (command.toLowerCase().startsWith(COMMANDS[1])) // WithdrawSortedP
  59. {
  60. final String param[] = command.split(" ");
  61. if (param.length > 2)
  62. showWithdrawWindow(activeChar, WarehouseListType.valueOf(param[1]), SortedWareHouseWithdrawalList.getOrder(param[2]));
  63. else if (param.length > 1)
  64. showWithdrawWindow(activeChar, WarehouseListType.valueOf(param[1]), SortedWareHouseWithdrawalList.A2Z);
  65. else
  66. showWithdrawWindow(activeChar, WarehouseListType.ALL, SortedWareHouseWithdrawalList.A2Z);
  67. return true;
  68. }
  69. else if (command.toLowerCase().startsWith(COMMANDS[2])) // DepositP
  70. {
  71. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  72. activeChar.setActiveWarehouse(activeChar.getWarehouse());
  73. activeChar.tempInventoryDisable();
  74. if (Config.DEBUG)
  75. _log.fine("Source: L2WarehouseInstance.java; Player: "+activeChar.getName()+"; Command: showDepositWindow; Message: Showing items to deposit.");
  76. activeChar.sendPacket(new WareHouseDepositList(activeChar, WareHouseDepositList.PRIVATE));
  77. return true;
  78. }
  79. return false;
  80. }
  81. catch (Exception e)
  82. {
  83. _log.info("Exception in " + getClass().getSimpleName());
  84. }
  85. return false;
  86. }
  87. private static final void showWithdrawWindow(L2PcInstance player, WarehouseListType itemtype, byte sortorder)
  88. {
  89. player.sendPacket(ActionFailed.STATIC_PACKET);
  90. player.setActiveWarehouse(player.getWarehouse());
  91. if (player.getActiveWarehouse().getSize() == 0)
  92. {
  93. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.NO_ITEM_DEPOSITED_IN_WH));
  94. return;
  95. }
  96. if (itemtype != null)
  97. player.sendPacket(new SortedWareHouseWithdrawalList(player, WareHouseWithdrawalList.PRIVATE, itemtype, sortorder));
  98. else
  99. player.sendPacket(new WareHouseWithdrawalList(player, WareHouseWithdrawalList.PRIVATE));
  100. if (Config.DEBUG)
  101. _log.fine("Source: L2WarehouseInstance.java; Player: "+player.getName()+"; Command: showRetrieveWindow; Message: Showing stored items.");
  102. }
  103. public String[] getBypassList()
  104. {
  105. return COMMANDS;
  106. }
  107. }