ItemAuctionInstance.java 21 KB

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