ItemAuctionInstance.java 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. /*
  2. * Copyright (C) 2004-2014 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server 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 Server 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 com.l2jserver.gameserver.model.itemauction;
  20. import java.sql.Connection;
  21. import java.sql.PreparedStatement;
  22. import java.sql.ResultSet;
  23. import java.sql.SQLException;
  24. import java.text.SimpleDateFormat;
  25. import java.util.ArrayList;
  26. import java.util.Arrays;
  27. import java.util.Comparator;
  28. import java.util.Date;
  29. import java.util.concurrent.ScheduledFuture;
  30. import java.util.concurrent.TimeUnit;
  31. import java.util.concurrent.atomic.AtomicInteger;
  32. import java.util.logging.Level;
  33. import java.util.logging.Logger;
  34. import org.w3c.dom.NamedNodeMap;
  35. import org.w3c.dom.Node;
  36. import com.l2jserver.Config;
  37. import com.l2jserver.L2DatabaseFactory;
  38. import com.l2jserver.gameserver.ThreadPoolManager;
  39. import com.l2jserver.gameserver.datatables.CharNameTable;
  40. import com.l2jserver.gameserver.enums.ItemLocation;
  41. import com.l2jserver.gameserver.instancemanager.ItemAuctionManager;
  42. import com.l2jserver.gameserver.model.L2World;
  43. import com.l2jserver.gameserver.model.StatsSet;
  44. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  45. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  46. import com.l2jserver.gameserver.network.SystemMessageId;
  47. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  48. import com.l2jserver.util.Rnd;
  49. import gnu.trove.map.hash.TIntObjectHashMap;
  50. public final class ItemAuctionInstance
  51. {
  52. protected static final Logger _log = Logger.getLogger(ItemAuctionInstance.class.getName());
  53. private final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("HH:mm:ss dd.MM.yy");
  54. private static final long START_TIME_SPACE = TimeUnit.MILLISECONDS.convert(1, TimeUnit.MINUTES);
  55. private static final long FINISH_TIME_SPACE = TimeUnit.MILLISECONDS.convert(10, TimeUnit.MINUTES);
  56. // SQL queries
  57. private static final String SELECT_AUCTION_ID_BY_INSTANCE_ID = "SELECT auctionId FROM item_auction WHERE instanceId = ?";
  58. private static final String SELECT_AUCTION_INFO = "SELECT auctionItemId, startingTime, endingTime, auctionStateId FROM item_auction WHERE auctionId = ? ";
  59. private static final String DELETE_AUCTION_INFO_BY_AUCTION_ID = "DELETE FROM item_auction WHERE auctionId = ?";
  60. private static final String DELETE_AUCTION_BID_INFO_BY_AUCTION_ID = "DELETE FROM item_auction_bid WHERE auctionId = ?";
  61. private static final String SELECT_PLAYERS_ID_BY_AUCTION_ID = "SELECT playerObjId, playerBid FROM item_auction_bid WHERE auctionId = ?";
  62. /**
  63. * Cached comparator to avoid initialization on each loop run.
  64. */
  65. private static final Comparator<ItemAuction> itemAuctionComparator = new Comparator<ItemAuction>()
  66. {
  67. @Override
  68. public final int compare(final ItemAuction o1, final ItemAuction o2)
  69. {
  70. return Long.valueOf(o2.getStartingTime()).compareTo(Long.valueOf(o1.getStartingTime()));
  71. }
  72. };
  73. private final int _instanceId;
  74. private final AtomicInteger _auctionIds;
  75. private final TIntObjectHashMap<ItemAuction> _auctions;
  76. private final ArrayList<AuctionItem> _items;
  77. private final AuctionDateGenerator _dateGenerator;
  78. private ItemAuction _currentAuction;
  79. private ItemAuction _nextAuction;
  80. private ScheduledFuture<?> _stateTask;
  81. public ItemAuctionInstance(final int instanceId, final AtomicInteger auctionIds, final Node node) throws Exception
  82. {
  83. _instanceId = instanceId;
  84. _auctionIds = auctionIds;
  85. _auctions = new TIntObjectHashMap<>();
  86. _items = new ArrayList<>();
  87. final NamedNodeMap nanode = node.getAttributes();
  88. final StatsSet generatorConfig = new StatsSet();
  89. for (int i = nanode.getLength(); i-- > 0;)
  90. {
  91. final Node n = nanode.item(i);
  92. if (n != null)
  93. {
  94. generatorConfig.set(n.getNodeName(), n.getNodeValue());
  95. }
  96. }
  97. _dateGenerator = new AuctionDateGenerator(generatorConfig);
  98. for (Node na = node.getFirstChild(); na != null; na = na.getNextSibling())
  99. {
  100. try
  101. {
  102. if ("item".equalsIgnoreCase(na.getNodeName()))
  103. {
  104. final NamedNodeMap naa = na.getAttributes();
  105. final int auctionItemId = Integer.parseInt(naa.getNamedItem("auctionItemId").getNodeValue());
  106. final int auctionLenght = Integer.parseInt(naa.getNamedItem("auctionLenght").getNodeValue());
  107. final long auctionInitBid = Integer.parseInt(naa.getNamedItem("auctionInitBid").getNodeValue());
  108. final int itemId = Integer.parseInt(naa.getNamedItem("itemId").getNodeValue());
  109. final int itemCount = Integer.parseInt(naa.getNamedItem("itemCount").getNodeValue());
  110. if (auctionLenght < 1)
  111. {
  112. throw new IllegalArgumentException("auctionLenght < 1 for instanceId: " + _instanceId + ", itemId " + itemId);
  113. }
  114. final StatsSet itemExtra = new StatsSet();
  115. final AuctionItem item = new AuctionItem(auctionItemId, auctionLenght, auctionInitBid, itemId, itemCount, itemExtra);
  116. if (!item.checkItemExists())
  117. {
  118. throw new IllegalArgumentException("Item with id " + itemId + " not found");
  119. }
  120. for (final AuctionItem tmp : _items)
  121. {
  122. if (tmp.getAuctionItemId() == auctionItemId)
  123. {
  124. throw new IllegalArgumentException("Dublicated auction item id " + auctionItemId);
  125. }
  126. }
  127. _items.add(item);
  128. for (Node nb = na.getFirstChild(); nb != null; nb = nb.getNextSibling())
  129. {
  130. if ("extra".equalsIgnoreCase(nb.getNodeName()))
  131. {
  132. final NamedNodeMap nab = nb.getAttributes();
  133. for (int i = nab.getLength(); i-- > 0;)
  134. {
  135. final Node n = nab.item(i);
  136. if (n != null)
  137. {
  138. itemExtra.set(n.getNodeName(), n.getNodeValue());
  139. }
  140. }
  141. }
  142. }
  143. }
  144. }
  145. catch (final IllegalArgumentException e)
  146. {
  147. _log.log(Level.WARNING, getClass().getSimpleName() + ": Failed loading auction item", e);
  148. }
  149. }
  150. if (_items.isEmpty())
  151. {
  152. throw new IllegalArgumentException("No items defined");
  153. }
  154. try (Connection con = L2DatabaseFactory.getInstance().getConnection();
  155. PreparedStatement ps = con.prepareStatement(SELECT_AUCTION_ID_BY_INSTANCE_ID))
  156. {
  157. ps.setInt(1, _instanceId);
  158. try (ResultSet rset = ps.executeQuery())
  159. {
  160. while (rset.next())
  161. {
  162. final int auctionId = rset.getInt(1);
  163. try
  164. {
  165. final ItemAuction auction = loadAuction(auctionId);
  166. if (auction != null)
  167. {
  168. _auctions.put(auctionId, auction);
  169. }
  170. else
  171. {
  172. ItemAuctionManager.deleteAuction(auctionId);
  173. }
  174. }
  175. catch (final SQLException e)
  176. {
  177. _log.log(Level.WARNING, getClass().getSimpleName() + ": Failed loading auction: " + auctionId, e);
  178. }
  179. }
  180. }
  181. }
  182. catch (final SQLException e)
  183. {
  184. _log.log(Level.SEVERE, getClass().getSimpleName() + ": Failed loading auctions.", e);
  185. return;
  186. }
  187. _log.log(Level.INFO, getClass().getSimpleName() + ": Loaded " + _items.size() + " item(s) and registered " + _auctions.size() + " auction(s) for instance " + _instanceId + ".");
  188. checkAndSetCurrentAndNextAuction();
  189. }
  190. public final ItemAuction getCurrentAuction()
  191. {
  192. return _currentAuction;
  193. }
  194. public final ItemAuction getNextAuction()
  195. {
  196. return _nextAuction;
  197. }
  198. public final void shutdown()
  199. {
  200. final ScheduledFuture<?> stateTask = _stateTask;
  201. if (stateTask != null)
  202. {
  203. stateTask.cancel(false);
  204. }
  205. }
  206. private final AuctionItem getAuctionItem(final int auctionItemId)
  207. {
  208. for (int i = _items.size(); i-- > 0;)
  209. {
  210. final AuctionItem item = _items.get(i);
  211. if (item.getAuctionItemId() == auctionItemId)
  212. {
  213. return item;
  214. }
  215. }
  216. return null;
  217. }
  218. final void checkAndSetCurrentAndNextAuction()
  219. {
  220. final ItemAuction[] auctions = _auctions.values(new ItemAuction[0]);
  221. ItemAuction currentAuction = null;
  222. ItemAuction nextAuction = null;
  223. switch (auctions.length)
  224. {
  225. case 0:
  226. {
  227. nextAuction = createAuction(System.currentTimeMillis() + START_TIME_SPACE);
  228. break;
  229. }
  230. case 1:
  231. {
  232. switch (auctions[0].getAuctionState())
  233. {
  234. case CREATED:
  235. {
  236. if (auctions[0].getStartingTime() < (System.currentTimeMillis() + START_TIME_SPACE))
  237. {
  238. currentAuction = auctions[0];
  239. nextAuction = createAuction(System.currentTimeMillis() + START_TIME_SPACE);
  240. }
  241. else
  242. {
  243. nextAuction = auctions[0];
  244. }
  245. break;
  246. }
  247. case STARTED:
  248. {
  249. currentAuction = auctions[0];
  250. nextAuction = createAuction(Math.max(currentAuction.getEndingTime() + FINISH_TIME_SPACE, System.currentTimeMillis() + START_TIME_SPACE));
  251. break;
  252. }
  253. case FINISHED:
  254. {
  255. currentAuction = auctions[0];
  256. nextAuction = createAuction(System.currentTimeMillis() + START_TIME_SPACE);
  257. break;
  258. }
  259. default:
  260. throw new IllegalArgumentException();
  261. }
  262. break;
  263. }
  264. default:
  265. {
  266. Arrays.sort(auctions, itemAuctionComparator);
  267. // just to make sure we won`t skip any auction because of little different times
  268. final long currentTime = System.currentTimeMillis();
  269. for (final ItemAuction auction : auctions)
  270. {
  271. if (auction.getAuctionState() == ItemAuctionState.STARTED)
  272. {
  273. currentAuction = auction;
  274. break;
  275. }
  276. else if (auction.getStartingTime() <= currentTime)
  277. {
  278. currentAuction = auction;
  279. break; // only first
  280. }
  281. }
  282. for (final ItemAuction auction : auctions)
  283. {
  284. if ((auction.getStartingTime() > currentTime) && (currentAuction != auction))
  285. {
  286. nextAuction = auction;
  287. break;
  288. }
  289. }
  290. if (nextAuction == null)
  291. {
  292. nextAuction = createAuction(System.currentTimeMillis() + START_TIME_SPACE);
  293. }
  294. break;
  295. }
  296. }
  297. _auctions.put(nextAuction.getAuctionId(), nextAuction);
  298. _currentAuction = currentAuction;
  299. _nextAuction = nextAuction;
  300. if ((currentAuction != null) && (currentAuction.getAuctionState() != ItemAuctionState.FINISHED))
  301. {
  302. if (currentAuction.getAuctionState() == ItemAuctionState.STARTED)
  303. {
  304. setStateTask(ThreadPoolManager.getInstance().scheduleGeneral(new ScheduleAuctionTask(currentAuction), Math.max(currentAuction.getEndingTime() - System.currentTimeMillis(), 0L)));
  305. }
  306. else
  307. {
  308. setStateTask(ThreadPoolManager.getInstance().scheduleGeneral(new ScheduleAuctionTask(currentAuction), Math.max(currentAuction.getStartingTime() - System.currentTimeMillis(), 0L)));
  309. }
  310. _log.log(Level.INFO, getClass().getSimpleName() + ": Schedule current auction " + currentAuction.getAuctionId() + " for instance " + _instanceId);
  311. }
  312. else
  313. {
  314. setStateTask(ThreadPoolManager.getInstance().scheduleGeneral(new ScheduleAuctionTask(nextAuction), Math.max(nextAuction.getStartingTime() - System.currentTimeMillis(), 0L)));
  315. _log.log(Level.INFO, getClass().getSimpleName() + ": Schedule next auction " + nextAuction.getAuctionId() + " on " + DATE_FORMAT.format(new Date(nextAuction.getStartingTime())) + " for instance " + _instanceId);
  316. }
  317. }
  318. public final ItemAuction getAuction(final int auctionId)
  319. {
  320. return _auctions.get(auctionId);
  321. }
  322. public final ItemAuction[] getAuctionsByBidder(final int bidderObjId)
  323. {
  324. final ItemAuction[] auctions = getAuctions();
  325. final ArrayList<ItemAuction> stack = new ArrayList<>(auctions.length);
  326. for (final ItemAuction auction : getAuctions())
  327. {
  328. if (auction.getAuctionState() != ItemAuctionState.CREATED)
  329. {
  330. final ItemAuctionBid bid = auction.getBidFor(bidderObjId);
  331. if (bid != null)
  332. {
  333. stack.add(auction);
  334. }
  335. }
  336. }
  337. return stack.toArray(new ItemAuction[stack.size()]);
  338. }
  339. public final ItemAuction[] getAuctions()
  340. {
  341. final ItemAuction[] auctions;
  342. synchronized (_auctions)
  343. {
  344. auctions = _auctions.values(new ItemAuction[0]);
  345. }
  346. return auctions;
  347. }
  348. private final class ScheduleAuctionTask implements Runnable
  349. {
  350. private final ItemAuction _auction;
  351. public ScheduleAuctionTask(final ItemAuction auction)
  352. {
  353. _auction = auction;
  354. }
  355. @Override
  356. public final void run()
  357. {
  358. try
  359. {
  360. runImpl();
  361. }
  362. catch (final Exception e)
  363. {
  364. _log.log(Level.SEVERE, getClass().getSimpleName() + ": Failed scheduling auction " + _auction.getAuctionId(), e);
  365. }
  366. }
  367. private final void runImpl() throws Exception
  368. {
  369. final ItemAuctionState state = _auction.getAuctionState();
  370. switch (state)
  371. {
  372. case CREATED:
  373. {
  374. if (!_auction.setAuctionState(state, ItemAuctionState.STARTED))
  375. {
  376. throw new IllegalStateException("Could not set auction state: " + ItemAuctionState.STARTED.toString() + ", expected: " + state.toString());
  377. }
  378. _log.log(Level.INFO, getClass().getSimpleName() + ": Auction " + _auction.getAuctionId() + " has started for instance " + _auction.getInstanceId());
  379. checkAndSetCurrentAndNextAuction();
  380. break;
  381. }
  382. case STARTED:
  383. {
  384. switch (_auction.getAuctionEndingExtendState())
  385. {
  386. case EXTEND_BY_5_MIN:
  387. {
  388. if (_auction.getScheduledAuctionEndingExtendState() == ItemAuctionExtendState.INITIAL)
  389. {
  390. _auction.setScheduledAuctionEndingExtendState(ItemAuctionExtendState.EXTEND_BY_5_MIN);
  391. setStateTask(ThreadPoolManager.getInstance().scheduleGeneral(this, Math.max(_auction.getEndingTime() - System.currentTimeMillis(), 0L)));
  392. return;
  393. }
  394. break;
  395. }
  396. case EXTEND_BY_3_MIN:
  397. {
  398. if (_auction.getScheduledAuctionEndingExtendState() != ItemAuctionExtendState.EXTEND_BY_3_MIN)
  399. {
  400. _auction.setScheduledAuctionEndingExtendState(ItemAuctionExtendState.EXTEND_BY_3_MIN);
  401. setStateTask(ThreadPoolManager.getInstance().scheduleGeneral(this, Math.max(_auction.getEndingTime() - System.currentTimeMillis(), 0L)));
  402. return;
  403. }
  404. break;
  405. }
  406. case EXTEND_BY_CONFIG_PHASE_A:
  407. {
  408. if (_auction.getScheduledAuctionEndingExtendState() != ItemAuctionExtendState.EXTEND_BY_CONFIG_PHASE_B)
  409. {
  410. _auction.setScheduledAuctionEndingExtendState(ItemAuctionExtendState.EXTEND_BY_CONFIG_PHASE_B);
  411. setStateTask(ThreadPoolManager.getInstance().scheduleGeneral(this, Math.max(_auction.getEndingTime() - System.currentTimeMillis(), 0L)));
  412. return;
  413. }
  414. break;
  415. }
  416. case EXTEND_BY_CONFIG_PHASE_B:
  417. {
  418. if (_auction.getScheduledAuctionEndingExtendState() != ItemAuctionExtendState.EXTEND_BY_CONFIG_PHASE_A)
  419. {
  420. _auction.setScheduledAuctionEndingExtendState(ItemAuctionExtendState.EXTEND_BY_CONFIG_PHASE_A);
  421. setStateTask(ThreadPoolManager.getInstance().scheduleGeneral(this, Math.max(_auction.getEndingTime() - System.currentTimeMillis(), 0L)));
  422. return;
  423. }
  424. }
  425. }
  426. if (!_auction.setAuctionState(state, ItemAuctionState.FINISHED))
  427. {
  428. throw new IllegalStateException("Could not set auction state: " + ItemAuctionState.FINISHED.toString() + ", expected: " + state.toString());
  429. }
  430. onAuctionFinished(_auction);
  431. checkAndSetCurrentAndNextAuction();
  432. break;
  433. }
  434. default:
  435. throw new IllegalStateException("Invalid state: " + state);
  436. }
  437. }
  438. }
  439. final void onAuctionFinished(final ItemAuction auction)
  440. {
  441. auction.broadcastToAllBiddersInternal(SystemMessage.getSystemMessage(SystemMessageId.S1_AUCTION_ENDED).addInt(auction.getAuctionId()));
  442. final ItemAuctionBid bid = auction.getHighestBid();
  443. if (bid != null)
  444. {
  445. final L2ItemInstance item = auction.createNewItemInstance();
  446. final L2PcInstance player = bid.getPlayer();
  447. if (player != null)
  448. {
  449. player.getWarehouse().addItem("ItemAuction", item, null, null);
  450. player.sendPacket(SystemMessageId.WON_BID_ITEM_CAN_BE_FOUND_IN_WAREHOUSE);
  451. _log.log(Level.INFO, getClass().getSimpleName() + ": Auction " + auction.getAuctionId() + " has finished. Highest bid by " + player.getName() + " for instance " + _instanceId);
  452. }
  453. else
  454. {
  455. item.setOwnerId(bid.getPlayerObjId());
  456. item.setItemLocation(ItemLocation.WAREHOUSE);
  457. item.updateDatabase();
  458. L2World.getInstance().removeObject(item);
  459. _log.log(Level.INFO, getClass().getSimpleName() + ": Auction " + auction.getAuctionId() + " has finished. Highest bid by " + CharNameTable.getInstance().getNameById(bid.getPlayerObjId()) + " for instance " + _instanceId);
  460. }
  461. // Clean all canceled bids
  462. auction.clearCanceledBids();
  463. }
  464. else
  465. {
  466. _log.log(Level.INFO, getClass().getSimpleName() + ": Auction " + auction.getAuctionId() + " has finished. There have not been any bid for instance " + _instanceId);
  467. }
  468. }
  469. final void setStateTask(final ScheduledFuture<?> future)
  470. {
  471. final ScheduledFuture<?> stateTask = _stateTask;
  472. if (stateTask != null)
  473. {
  474. stateTask.cancel(false);
  475. }
  476. _stateTask = future;
  477. }
  478. private final ItemAuction createAuction(final long after)
  479. {
  480. final AuctionItem auctionItem = _items.get(Rnd.get(_items.size()));
  481. final long startingTime = _dateGenerator.nextDate(after);
  482. final long endingTime = startingTime + TimeUnit.MILLISECONDS.convert(auctionItem.getAuctionLength(), TimeUnit.MINUTES);
  483. final ItemAuction auction = new ItemAuction(_auctionIds.getAndIncrement(), _instanceId, startingTime, endingTime, auctionItem);
  484. auction.storeMe();
  485. return auction;
  486. }
  487. private final ItemAuction loadAuction(final int auctionId) throws SQLException
  488. {
  489. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  490. {
  491. int auctionItemId = 0;
  492. long startingTime = 0;
  493. long endingTime = 0;
  494. byte auctionStateId = 0;
  495. try (PreparedStatement ps = con.prepareStatement(SELECT_AUCTION_INFO))
  496. {
  497. ps.setInt(1, auctionId);
  498. try (ResultSet rset = ps.executeQuery())
  499. {
  500. if (!rset.next())
  501. {
  502. _log.log(Level.WARNING, getClass().getSimpleName() + ": Auction data not found for auction: " + auctionId);
  503. return null;
  504. }
  505. auctionItemId = rset.getInt(1);
  506. startingTime = rset.getLong(2);
  507. endingTime = rset.getLong(3);
  508. auctionStateId = rset.getByte(4);
  509. }
  510. }
  511. if (startingTime >= endingTime)
  512. {
  513. _log.log(Level.WARNING, getClass().getSimpleName() + ": Invalid starting/ending paramaters for auction: " + auctionId);
  514. return null;
  515. }
  516. final AuctionItem auctionItem = getAuctionItem(auctionItemId);
  517. if (auctionItem == null)
  518. {
  519. _log.log(Level.WARNING, getClass().getSimpleName() + ": AuctionItem: " + auctionItemId + ", not found for auction: " + auctionId);
  520. return null;
  521. }
  522. final ItemAuctionState auctionState = ItemAuctionState.stateForStateId(auctionStateId);
  523. if (auctionState == null)
  524. {
  525. _log.log(Level.WARNING, getClass().getSimpleName() + ": Invalid auctionStateId: " + auctionStateId + ", for auction: " + auctionId);
  526. return null;
  527. }
  528. if ((auctionState == ItemAuctionState.FINISHED) && (startingTime < (System.currentTimeMillis() - TimeUnit.MILLISECONDS.convert(Config.ALT_ITEM_AUCTION_EXPIRED_AFTER, TimeUnit.DAYS))))
  529. {
  530. _log.log(Level.INFO, getClass().getSimpleName() + ": Clearing expired auction: " + auctionId);
  531. try (PreparedStatement ps = con.prepareStatement(DELETE_AUCTION_INFO_BY_AUCTION_ID))
  532. {
  533. ps.setInt(1, auctionId);
  534. ps.execute();
  535. }
  536. try (PreparedStatement ps = con.prepareStatement(DELETE_AUCTION_BID_INFO_BY_AUCTION_ID))
  537. {
  538. ps.setInt(1, auctionId);
  539. ps.execute();
  540. }
  541. return null;
  542. }
  543. final ArrayList<ItemAuctionBid> auctionBids = new ArrayList<>();
  544. try (PreparedStatement ps = con.prepareStatement(SELECT_PLAYERS_ID_BY_AUCTION_ID))
  545. {
  546. ps.setInt(1, auctionId);
  547. try (ResultSet rs = ps.executeQuery())
  548. {
  549. while (rs.next())
  550. {
  551. final int playerObjId = rs.getInt(1);
  552. final long playerBid = rs.getLong(2);
  553. final ItemAuctionBid bid = new ItemAuctionBid(playerObjId, playerBid);
  554. auctionBids.add(bid);
  555. }
  556. }
  557. }
  558. return new ItemAuction(auctionId, _instanceId, startingTime, endingTime, auctionItem, auctionBids, auctionState);
  559. }
  560. }
  561. }