ItemAuctionLink.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 com.l2jserver.Config;
  20. import com.l2jserver.gameserver.handler.IBypassHandler;
  21. import com.l2jserver.gameserver.instancemanager.ItemAuctionManager;
  22. import com.l2jserver.gameserver.model.actor.L2Character;
  23. import com.l2jserver.gameserver.model.actor.L2Npc;
  24. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  25. import com.l2jserver.gameserver.model.itemauction.ItemAuction;
  26. import com.l2jserver.gameserver.model.itemauction.ItemAuctionInstance;
  27. import com.l2jserver.gameserver.network.SystemMessageId;
  28. import com.l2jserver.gameserver.network.serverpackets.ExItemAuctionInfoPacket;
  29. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  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. public boolean useBypass(String command, L2PcInstance activeChar, L2Character target)
  38. {
  39. if (!(target instanceof L2Npc))
  40. return false;
  41. if (!Config.ALT_ITEM_AUCTION_ENABLED)
  42. {
  43. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.NO_AUCTION_PERIOD));
  44. return true;
  45. }
  46. final ItemAuctionInstance au = ItemAuctionManager.getInstance().getManagerInstance(((L2Npc)target).getNpcId());
  47. if (au == null)
  48. return false;
  49. try
  50. {
  51. StringTokenizer st = new StringTokenizer(command);
  52. st.nextToken(); // bypass "ItemAuction"
  53. if (!st.hasMoreTokens())
  54. return false;
  55. String cmd = st.nextToken();
  56. if ("show".equalsIgnoreCase(cmd))
  57. {
  58. if (!activeChar.getFloodProtectors().getItemAuction().tryPerformAction("RequestInfoItemAuction"))
  59. return false;
  60. if (activeChar.isItemAuctionPolling())
  61. return false;
  62. final ItemAuction currentAuction = au.getCurrentAuction();
  63. final ItemAuction nextAuction = au.getNextAuction();
  64. if (currentAuction == null)
  65. {
  66. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.NO_AUCTION_PERIOD));
  67. if (nextAuction != null) // used only once when database is empty
  68. activeChar.sendMessage("The next auction will begin on the " + fmt.format(new Date(nextAuction.getStartingTime())) + ".");
  69. return true;
  70. }
  71. activeChar.sendPacket(new ExItemAuctionInfoPacket(false, currentAuction, nextAuction));
  72. }
  73. else if ("cancel".equalsIgnoreCase(cmd))
  74. {
  75. final ItemAuction[] auctions = au.getAuctionsByBidder(activeChar.getObjectId());
  76. boolean returned = false;
  77. for (final ItemAuction auction : auctions)
  78. {
  79. if (auction.cancelBid(activeChar))
  80. returned = true;
  81. }
  82. if (!returned)
  83. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.NO_OFFERINGS_OWN_OR_MADE_BID_FOR));
  84. }
  85. else
  86. return false;
  87. }
  88. catch (Exception e)
  89. {
  90. _log.severe("Exception in: " + getClass().getSimpleName() + ":" + e.getMessage());
  91. }
  92. return true;
  93. }
  94. public String[] getBypassList()
  95. {
  96. return COMMANDS;
  97. }
  98. }