ClanWarehouse.java 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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.L2Clan;
  19. import com.l2jserver.gameserver.model.actor.L2Character;
  20. import com.l2jserver.gameserver.model.actor.L2Npc;
  21. import com.l2jserver.gameserver.model.actor.instance.L2ClanHallManagerInstance;
  22. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  23. import com.l2jserver.gameserver.model.actor.instance.L2WarehouseInstance;
  24. import com.l2jserver.gameserver.network.SystemMessageId;
  25. import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
  26. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  27. import com.l2jserver.gameserver.network.serverpackets.SortedWareHouseWithdrawalList;
  28. import com.l2jserver.gameserver.network.serverpackets.SortedWareHouseWithdrawalList.WarehouseListType;
  29. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  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. public boolean useBypass(String command, L2PcInstance activeChar, L2Character target)
  41. {
  42. if (!(target instanceof L2WarehouseInstance) && !(target instanceof L2ClanHallManagerInstance))
  43. return false;
  44. if (activeChar.isEnchanting())
  45. return false;
  46. if (activeChar.getClan() == null)
  47. {
  48. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_DO_NOT_HAVE_THE_RIGHT_TO_USE_CLAN_WAREHOUSE));
  49. return false;
  50. }
  51. if (activeChar.getClan().getLevel() == 0)
  52. {
  53. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.ONLY_LEVEL_1_CLAN_OR_HIGHER_CAN_USE_WAREHOUSE));
  54. return false;
  55. }
  56. try
  57. {
  58. if (command.toLowerCase().startsWith(COMMANDS[0])) // WithdrawC
  59. {
  60. if (Config.L2JMOD_ENABLE_WAREHOUSESORTING_CLAN)
  61. {
  62. NpcHtmlMessage msg = new NpcHtmlMessage(((L2Npc)target).getObjectId());
  63. msg.setFile(activeChar.getHtmlPrefix(), "data/html/mods/WhSortedC.htm");
  64. msg.replace("%objectId%", String.valueOf(((L2Npc)target).getObjectId()));
  65. activeChar.sendPacket(msg);
  66. }
  67. else
  68. showWithdrawWindow(activeChar, null, (byte) 0);
  69. return true;
  70. }
  71. else if (command.toLowerCase().startsWith(COMMANDS[1])) // WithdrawSortedC
  72. {
  73. final String param[] = command.split(" ");
  74. if (param.length > 2)
  75. showWithdrawWindow(activeChar, WarehouseListType.valueOf(param[1]), SortedWareHouseWithdrawalList.getOrder(param[2]));
  76. else if (param.length > 1)
  77. showWithdrawWindow(activeChar, WarehouseListType.valueOf(param[1]), SortedWareHouseWithdrawalList.A2Z);
  78. else
  79. showWithdrawWindow(activeChar, WarehouseListType.ALL, SortedWareHouseWithdrawalList.A2Z);
  80. return true;
  81. }
  82. else if (command.toLowerCase().startsWith(COMMANDS[2])) // DepositC
  83. {
  84. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  85. activeChar.setActiveWarehouse(activeChar.getClan().getWarehouse());
  86. activeChar.tempInventoryDisable();
  87. if (Config.DEBUG)
  88. _log.fine("Source: L2WarehouseInstance.java; Player: "+activeChar.getName()+"; Command: showDepositWindowClan; Message: Showing items to deposit.");
  89. activeChar.sendPacket(new WareHouseDepositList(activeChar, WareHouseDepositList.CLAN));
  90. return true;
  91. }
  92. return false;
  93. }
  94. catch (Exception e)
  95. {
  96. _log.info("Exception in " + getClass().getSimpleName());
  97. }
  98. return false;
  99. }
  100. private static final void showWithdrawWindow(L2PcInstance player, WarehouseListType itemtype, byte sortorder)
  101. {
  102. player.sendPacket(ActionFailed.STATIC_PACKET);
  103. if ((player.getClanPrivileges() & L2Clan.CP_CL_VIEW_WAREHOUSE) != L2Clan.CP_CL_VIEW_WAREHOUSE)
  104. {
  105. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_DO_NOT_HAVE_THE_RIGHT_TO_USE_CLAN_WAREHOUSE));
  106. return;
  107. }
  108. player.setActiveWarehouse(player.getClan().getWarehouse());
  109. if (player.getActiveWarehouse().getSize() == 0)
  110. {
  111. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.NO_ITEM_DEPOSITED_IN_WH));
  112. return;
  113. }
  114. if (itemtype != null)
  115. player.sendPacket(new SortedWareHouseWithdrawalList(player, WareHouseWithdrawalList.CLAN, itemtype, sortorder));
  116. else
  117. player.sendPacket(new WareHouseWithdrawalList(player, WareHouseWithdrawalList.CLAN));
  118. if (Config.DEBUG)
  119. _log.fine("Source: L2WarehouseInstance.java; Player: "+player.getName()+"; Command: showRetrieveWindowClan; Message: Showing stored items.");
  120. }
  121. public String[] getBypassList()
  122. {
  123. return COMMANDS;
  124. }
  125. }