ItemAuctionLink.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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.text.SimpleDateFormat;
  21. import java.util.Date;
  22. import java.util.StringTokenizer;
  23. import java.util.logging.Level;
  24. import com.l2jserver.Config;
  25. import com.l2jserver.gameserver.handler.IBypassHandler;
  26. import com.l2jserver.gameserver.instancemanager.ItemAuctionManager;
  27. import com.l2jserver.gameserver.model.actor.L2Character;
  28. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  29. import com.l2jserver.gameserver.model.itemauction.ItemAuction;
  30. import com.l2jserver.gameserver.model.itemauction.ItemAuctionInstance;
  31. import com.l2jserver.gameserver.network.SystemMessageId;
  32. import com.l2jserver.gameserver.network.serverpackets.ExItemAuctionInfoPacket;
  33. public class ItemAuctionLink implements IBypassHandler
  34. {
  35. private static final SimpleDateFormat fmt = new SimpleDateFormat("HH:mm:ss dd.MM.yyyy");
  36. private static final String[] COMMANDS =
  37. {
  38. "ItemAuction"
  39. };
  40. @Override
  41. public boolean useBypass(String command, L2PcInstance activeChar, L2Character target)
  42. {
  43. if (!target.isNpc())
  44. {
  45. return false;
  46. }
  47. if (!Config.ALT_ITEM_AUCTION_ENABLED)
  48. {
  49. activeChar.sendPacket(SystemMessageId.NO_AUCTION_PERIOD);
  50. return true;
  51. }
  52. final ItemAuctionInstance au = ItemAuctionManager.getInstance().getManagerInstance(target.getId());
  53. if (au == null)
  54. {
  55. return false;
  56. }
  57. try
  58. {
  59. StringTokenizer st = new StringTokenizer(command);
  60. st.nextToken(); // bypass "ItemAuction"
  61. if (!st.hasMoreTokens())
  62. {
  63. return false;
  64. }
  65. String cmd = st.nextToken();
  66. if ("show".equalsIgnoreCase(cmd))
  67. {
  68. if (!activeChar.getFloodProtectors().getItemAuction().tryPerformAction("RequestInfoItemAuction"))
  69. {
  70. return false;
  71. }
  72. if (activeChar.isItemAuctionPolling())
  73. {
  74. return false;
  75. }
  76. final ItemAuction currentAuction = au.getCurrentAuction();
  77. final ItemAuction nextAuction = au.getNextAuction();
  78. if (currentAuction == null)
  79. {
  80. activeChar.sendPacket(SystemMessageId.NO_AUCTION_PERIOD);
  81. if (nextAuction != null)
  82. {
  83. activeChar.sendMessage("The next auction will begin on the " + fmt.format(new Date(nextAuction.getStartingTime())) + ".");
  84. }
  85. return true;
  86. }
  87. activeChar.sendPacket(new ExItemAuctionInfoPacket(false, currentAuction, nextAuction));
  88. }
  89. else if ("cancel".equalsIgnoreCase(cmd))
  90. {
  91. final ItemAuction[] auctions = au.getAuctionsByBidder(activeChar.getObjectId());
  92. boolean returned = false;
  93. for (final ItemAuction auction : auctions)
  94. {
  95. if (auction.cancelBid(activeChar))
  96. {
  97. returned = true;
  98. }
  99. }
  100. if (!returned)
  101. {
  102. activeChar.sendPacket(SystemMessageId.NO_OFFERINGS_OWN_OR_MADE_BID_FOR);
  103. }
  104. }
  105. else
  106. {
  107. return false;
  108. }
  109. }
  110. catch (Exception e)
  111. {
  112. _log.log(Level.WARNING, "Exception in " + getClass().getSimpleName(), e);
  113. }
  114. return true;
  115. }
  116. @Override
  117. public String[] getBypassList()
  118. {
  119. return COMMANDS;
  120. }
  121. }