ItemAuctionLink.java 3.8 KB

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