From 22dc21ebbb093f71155512c84f73e108115cff9a Mon Sep 17 00:00:00 2001 From: Kiran Hart Date: Mon, 19 Aug 2024 12:15:23 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=80=20priority=20listing=20data=20colu?= =?UTF-8?q?mns?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Took 13 seconds --- .../auctionhouse/auction/AuctionedItem.java | 9 +++++++- .../auctionhouse/database/DataManager.java | 4 ++++ .../_28_PriorityListingMigration.java | 22 +++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/main/java/ca/tweetzy/auctionhouse/database/migrations/_28_PriorityListingMigration.java diff --git a/src/main/java/ca/tweetzy/auctionhouse/auction/AuctionedItem.java b/src/main/java/ca/tweetzy/auctionhouse/auction/AuctionedItem.java index 96d500c..f58a6fb 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/auction/AuctionedItem.java +++ b/src/main/java/ca/tweetzy/auctionhouse/auction/AuctionedItem.java @@ -76,6 +76,10 @@ public class AuctionedItem { private boolean isRequest = false; private int requestAmount = 0; + // priority listing + private boolean hasListingPriority = false; + private long priorityExpiresAt = 0; + public AuctionedItem() { } @@ -137,7 +141,6 @@ public class AuctionedItem { return requested; } - public ItemStack getBidStack(Player player) { QuickItem itemStack = QuickItem.of(this.item.clone()); itemStack.amount(Math.max(this.item.getAmount(), 1)); @@ -304,4 +307,8 @@ public class AuctionedItem { public boolean containsValidBid() { return isBidItem() && !this.highestBidder.equals(this.owner); } + + public boolean isListingPriorityActive() { + return this.hasListingPriority && this.priorityExpiresAt > System.currentTimeMillis(); + } } diff --git a/src/main/java/ca/tweetzy/auctionhouse/database/DataManager.java b/src/main/java/ca/tweetzy/auctionhouse/database/DataManager.java index a8f267e..08548e4 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/database/DataManager.java +++ b/src/main/java/ca/tweetzy/auctionhouse/database/DataManager.java @@ -424,6 +424,10 @@ public class DataManager extends DataManagerAbstract { auctionItem.setRequest(resultSet.getBoolean("is_request")); auctionItem.setRequestAmount(resultSet.getInt("request_count")); + auctionItem.setHasListingPriority(resultSet.getBoolean("listing_priority")); + auctionItem.setPriorityExpiresAt(resultSet.getLong("priority_expires_at")); + + return auctionItem; } diff --git a/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_28_PriorityListingMigration.java b/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_28_PriorityListingMigration.java new file mode 100644 index 0000000..fed618f --- /dev/null +++ b/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_28_PriorityListingMigration.java @@ -0,0 +1,22 @@ +package ca.tweetzy.auctionhouse.database.migrations; + +import ca.tweetzy.flight.database.DataMigration; + +import java.sql.Connection; +import java.sql.SQLException; +import java.sql.Statement; + +public final class _28_PriorityListingMigration extends DataMigration { + + public _28_PriorityListingMigration() { + super(28); + } + + @Override + public void migrate(Connection connection, String tablePrefix) throws SQLException { + try (Statement statement = connection.createStatement()) { + statement.execute("ALTER TABLE " + tablePrefix + "auctions ADD listing_priority BOOLEAN default 0"); + statement.execute("ALTER TABLE " + tablePrefix + "auctions ADD priority_expires_at BigInt default 0"); + } + } +}