ItemAuctionLink.java 3.8 KB

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