From 309af4bd02027c9fd43692cf8b5ffe49d37b4ab9 Mon Sep 17 00:00:00 2001 From: Kiran Hart Date: Wed, 7 Aug 2024 14:14:09 -0400 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20create=20classes=20for=20new=20even?= =?UTF-8?q?ts,=20add=20ListingBuilder=20for=20new=20bin/auction=20system?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Took 17 minutes --- .../ca/tweetzy/auctionhouse/AuctionHouse.java | 5 +- .../category/CategoryConditionType.java | 4 +- .../api/event/AuctionAdminEvent.java | 4 + .../api/event/AuctionBidEvent.java | 4 + .../api/event/AuctionListingEndEvent.java | 4 + .../api/event/AuctionListingStartEvent.java | 4 + .../api/event/AuctionPlayerBanEvent.java | 4 + .../event/AuctionPreListingStartEvent.java | 4 + .../api/event/AuctionProfileUpdateEvent.java | 4 + .../migrations/_25_BidHistoryMigration.java | 31 ++++ .../_26_MultiSerAndCurrencyMigration.java | 23 +++ .../impl/listing/AuctionListing.java | 4 +- .../auctionhouse/model/ListingBuilder.java | 163 ++++++++++++++++++ .../auctionhouse/settings/Settings.java | 2 +- 14 files changed, 254 insertions(+), 6 deletions(-) create mode 100644 src/main/java/ca/tweetzy/auctionhouse/api/event/AuctionAdminEvent.java create mode 100644 src/main/java/ca/tweetzy/auctionhouse/api/event/AuctionBidEvent.java create mode 100644 src/main/java/ca/tweetzy/auctionhouse/api/event/AuctionListingEndEvent.java create mode 100644 src/main/java/ca/tweetzy/auctionhouse/api/event/AuctionListingStartEvent.java create mode 100644 src/main/java/ca/tweetzy/auctionhouse/api/event/AuctionPlayerBanEvent.java create mode 100644 src/main/java/ca/tweetzy/auctionhouse/api/event/AuctionPreListingStartEvent.java create mode 100644 src/main/java/ca/tweetzy/auctionhouse/api/event/AuctionProfileUpdateEvent.java create mode 100644 src/main/java/ca/tweetzy/auctionhouse/database/migrations/_25_BidHistoryMigration.java create mode 100644 src/main/java/ca/tweetzy/auctionhouse/database/migrations/_26_MultiSerAndCurrencyMigration.java create mode 100644 src/main/java/ca/tweetzy/auctionhouse/model/ListingBuilder.java diff --git a/src/main/java/ca/tweetzy/auctionhouse/AuctionHouse.java b/src/main/java/ca/tweetzy/auctionhouse/AuctionHouse.java index 3cdc65e..98ce949 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/AuctionHouse.java +++ b/src/main/java/ca/tweetzy/auctionhouse/AuctionHouse.java @@ -181,8 +181,11 @@ public class AuctionHouse extends TweetyPlugin { new _20_AuctionRequestsMigration(), new _21_RequestsDynAmtMigration(), new _22_BansV2Migration(), + // ================ BEGIN MAJOR CHANGES ================ // new _23_ItemToNBTSerializationMigration(), - new _24_RemainingItemToNBTSerializationMigration() + new _24_RemainingItemToNBTSerializationMigration(), + new _25_BidHistoryMigration(), + new _26_MultiSerAndCurrencyMigration() ); dataMigrationManager.runMigrations(); diff --git a/src/main/java/ca/tweetzy/auctionhouse/api/auction/category/CategoryConditionType.java b/src/main/java/ca/tweetzy/auctionhouse/api/auction/category/CategoryConditionType.java index 1fdd1cd..f97350d 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/api/auction/category/CategoryConditionType.java +++ b/src/main/java/ca/tweetzy/auctionhouse/api/auction/category/CategoryConditionType.java @@ -5,6 +5,6 @@ public enum CategoryConditionType { MATERIAL, NAME, LORE, - ENCHANTMENT; - + ENCHANTMENT, + MODEL_DATA; } diff --git a/src/main/java/ca/tweetzy/auctionhouse/api/event/AuctionAdminEvent.java b/src/main/java/ca/tweetzy/auctionhouse/api/event/AuctionAdminEvent.java new file mode 100644 index 0000000..1e30fc0 --- /dev/null +++ b/src/main/java/ca/tweetzy/auctionhouse/api/event/AuctionAdminEvent.java @@ -0,0 +1,4 @@ +package ca.tweetzy.auctionhouse.api.event; + +public final class AuctionAdminEvent { +} diff --git a/src/main/java/ca/tweetzy/auctionhouse/api/event/AuctionBidEvent.java b/src/main/java/ca/tweetzy/auctionhouse/api/event/AuctionBidEvent.java new file mode 100644 index 0000000..7fcd651 --- /dev/null +++ b/src/main/java/ca/tweetzy/auctionhouse/api/event/AuctionBidEvent.java @@ -0,0 +1,4 @@ +package ca.tweetzy.auctionhouse.api.event; + +public final class AuctionBidEvent { +} diff --git a/src/main/java/ca/tweetzy/auctionhouse/api/event/AuctionListingEndEvent.java b/src/main/java/ca/tweetzy/auctionhouse/api/event/AuctionListingEndEvent.java new file mode 100644 index 0000000..5304547 --- /dev/null +++ b/src/main/java/ca/tweetzy/auctionhouse/api/event/AuctionListingEndEvent.java @@ -0,0 +1,4 @@ +package ca.tweetzy.auctionhouse.api.event; + +public final class AuctionListingEndEvent { +} diff --git a/src/main/java/ca/tweetzy/auctionhouse/api/event/AuctionListingStartEvent.java b/src/main/java/ca/tweetzy/auctionhouse/api/event/AuctionListingStartEvent.java new file mode 100644 index 0000000..73d1f8c --- /dev/null +++ b/src/main/java/ca/tweetzy/auctionhouse/api/event/AuctionListingStartEvent.java @@ -0,0 +1,4 @@ +package ca.tweetzy.auctionhouse.api.event; + +public final class AuctionListingStartEvent { +} diff --git a/src/main/java/ca/tweetzy/auctionhouse/api/event/AuctionPlayerBanEvent.java b/src/main/java/ca/tweetzy/auctionhouse/api/event/AuctionPlayerBanEvent.java new file mode 100644 index 0000000..04bd227 --- /dev/null +++ b/src/main/java/ca/tweetzy/auctionhouse/api/event/AuctionPlayerBanEvent.java @@ -0,0 +1,4 @@ +package ca.tweetzy.auctionhouse.api.event; + +public final class AuctionPlayerBanEvent { +} diff --git a/src/main/java/ca/tweetzy/auctionhouse/api/event/AuctionPreListingStartEvent.java b/src/main/java/ca/tweetzy/auctionhouse/api/event/AuctionPreListingStartEvent.java new file mode 100644 index 0000000..32ac00c --- /dev/null +++ b/src/main/java/ca/tweetzy/auctionhouse/api/event/AuctionPreListingStartEvent.java @@ -0,0 +1,4 @@ +package ca.tweetzy.auctionhouse.api.event; + +public final class AuctionPreListingStartEvent { +} diff --git a/src/main/java/ca/tweetzy/auctionhouse/api/event/AuctionProfileUpdateEvent.java b/src/main/java/ca/tweetzy/auctionhouse/api/event/AuctionProfileUpdateEvent.java new file mode 100644 index 0000000..c785b35 --- /dev/null +++ b/src/main/java/ca/tweetzy/auctionhouse/api/event/AuctionProfileUpdateEvent.java @@ -0,0 +1,4 @@ +package ca.tweetzy.auctionhouse.api.event; + +public final class AuctionProfileUpdateEvent { +} diff --git a/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_25_BidHistoryMigration.java b/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_25_BidHistoryMigration.java new file mode 100644 index 0000000..c95201c --- /dev/null +++ b/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_25_BidHistoryMigration.java @@ -0,0 +1,31 @@ +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 _25_BidHistoryMigration extends DataMigration { + + public _25_BidHistoryMigration() { + super(25); + } + + @Override + public void migrate(Connection connection, String tablePrefix) throws SQLException { + try (Statement statement = connection.createStatement()) { + statement.execute("CREATE TABLE " + tablePrefix + "bids (" + + "id VARCHAR(36) NOT NULL PRIMARY KEY, " + + "listing_id VARCHAR(36) NOT NULL, " + + "bidder_uuid VARCHAR(36) NOT NULL, " + + "bidder_name VARCHAR(16) NOT NULL, " + + "currency TEXT NOT NULL DEFAULT 'Vault/Vault'," + + "currency_item TEXT NULL," + + "amount TEXT NOT NULL, " + + "world TEXT NOT NULL, " + + "server BOOLEAN NOT NULL, " + + "created_at BigInt NOT NULL )"); + } + } +} diff --git a/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_26_MultiSerAndCurrencyMigration.java b/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_26_MultiSerAndCurrencyMigration.java new file mode 100644 index 0000000..af41da0 --- /dev/null +++ b/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_26_MultiSerAndCurrencyMigration.java @@ -0,0 +1,23 @@ +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 _26_MultiSerAndCurrencyMigration extends DataMigration { + + public _26_MultiSerAndCurrencyMigration() { + super(26); + } + + @Override + public void migrate(Connection connection, String tablePrefix) throws SQLException { + try (Statement statement = connection.createStatement()) { + statement.execute("ALTER TABLE " + tablePrefix + "auctions ADD currency TEXT NOT NULL DEFAULT 'Vault/Vault' "); + statement.execute("ALTER TABLE " + tablePrefix + "auctions ADD currency_item TEXT NULL"); + statement.execute("ALTER TABLE " + tablePrefix + "auctions ADD listed_server TEXT NULL"); + } + } +} diff --git a/src/main/java/ca/tweetzy/auctionhouse/impl/listing/AuctionListing.java b/src/main/java/ca/tweetzy/auctionhouse/impl/listing/AuctionListing.java index 0e99fee..e4da5d3 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/impl/listing/AuctionListing.java +++ b/src/main/java/ca/tweetzy/auctionhouse/impl/listing/AuctionListing.java @@ -84,7 +84,7 @@ public final class AuctionListing extends BinListing implements Biddable { } public UUID getHighestBidderUUID() { - return highestBidderUUID; + return this.highestBidderUUID; } public void setHighestBidderUUID(@NonNull final UUID highestBidderUUID) { @@ -92,7 +92,7 @@ public final class AuctionListing extends BinListing implements Biddable { } public String getHighestBidderName() { - return highestBidderName; + return this.highestBidderName; } public void setHighestBidderName(@NonNull String highestBidderName) { diff --git a/src/main/java/ca/tweetzy/auctionhouse/model/ListingBuilder.java b/src/main/java/ca/tweetzy/auctionhouse/model/ListingBuilder.java new file mode 100644 index 0000000..7a35bb5 --- /dev/null +++ b/src/main/java/ca/tweetzy/auctionhouse/model/ListingBuilder.java @@ -0,0 +1,163 @@ +package ca.tweetzy.auctionhouse.model; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +import ca.tweetzy.auctionhouse.api.auction.Bid; +import ca.tweetzy.auctionhouse.api.auction.ListingType; +import ca.tweetzy.auctionhouse.impl.listing.AuctionListing; +import ca.tweetzy.auctionhouse.impl.listing.BinListing; +import ca.tweetzy.flight.comp.enums.CompMaterial; +import lombok.NonNull; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +public class ListingBuilder { + + // Common fields + private UUID uuid; + private UUID ownerUUID; + private String ownerName; + private ItemStack item; + private String currency; + private ItemStack currencyItem; + private double binPrice; + private String listedWorld; + private String listedServer; + private long listedAt; + private long expiresAt; + + // Auction-specific fields + private double startingBid; + private UUID highestBidderUUID; + private String highestBidderName; + private List bids; + private boolean isAuction; + + public static ListingBuilder auction(@NonNull final Player player, @NonNull final ItemStack item) { + return of(player, item, ListingType.AUCTION); + } + + public static ListingBuilder bin(@NonNull final Player player, @NonNull final ItemStack item) { + return of(player, item, ListingType.BIN); + } + + public static ListingBuilder of(Player player, ItemStack item, ListingType listingType) { + ListingBuilder builder = new ListingBuilder(); + builder.setOwner(player); + builder.setItem(item); + builder.setListedWorld(player.getWorld().getName()); + builder.setListedServer(player.getServer().getName()); + + if (listingType == ListingType.AUCTION) { + builder.isAuction = true; + } + return builder; + } + + public ListingBuilder() { + // Initialize default values + this.uuid = UUID.randomUUID(); + this.currency = "Vault/Vault"; + this.currencyItem = CompMaterial.AIR.parseItem(); + this.listedAt = System.currentTimeMillis(); + this.expiresAt = this.listedAt + 1000 * 60 * 60; // Default to 1 hour + this.bids = new ArrayList<>(); + } + + public ListingBuilder setUuid(UUID uuid) { + this.uuid = uuid; + return this; + } + + public ListingBuilder setOwner(UUID ownerUUID, String ownerName) { + this.ownerUUID = ownerUUID; + this.ownerName = ownerName; + return this; + } + + public ListingBuilder setOwner(Player player) { + this.ownerUUID = player.getUniqueId(); + this.ownerName = player.getName(); + this.listedWorld = player.getWorld().getName(); + this.listedServer = player.getServer().getName(); + return this; + } + + public ListingBuilder setItem(ItemStack item) { + this.item = item; + return this; + } + + public ListingBuilder setCurrency(String currency) { + this.currency = currency; + return this; + } + + public ListingBuilder setCurrencyItem(ItemStack currencyItem) { + this.currencyItem = currencyItem; + return this; + } + + public ListingBuilder setBinPrice(double binPrice) { + this.binPrice = binPrice; + return this; + } + + public ListingBuilder setListedWorld(String listedWorld) { + this.listedWorld = listedWorld; + return this; + } + + public ListingBuilder setListedServer(String listedServer) { + this.listedServer = listedServer; + return this; + } + + public ListingBuilder setListedAt(long listedAt) { + this.listedAt = listedAt; + return this; + } + + public ListingBuilder setExpiresAt(long expiresAt) { + this.expiresAt = expiresAt; + return this; + } + + public ListingBuilder setAuction() { + this.isAuction = true; + return this; + } + + public ListingBuilder setStartingBid(double startingBid) { + this.startingBid = startingBid; + this.isAuction = true; + return this; + } + + public ListingBuilder setHighestBidder(UUID highestBidderUUID, String highestBidderName) { + this.highestBidderUUID = highestBidderUUID; + this.highestBidderName = highestBidderName; + return this; + } + + public ListingBuilder setBids(List bids) { + this.bids = bids; + return this; + } + + public AuctionListing buildAuctionListing() { + if (!isAuction) { + throw new IllegalStateException("This builder is not configured for an auction listing."); + } + return new AuctionListing(uuid, ownerUUID, ownerName, item, currency, currencyItem, startingBid, binPrice, listedWorld, listedServer, highestBidderUUID, highestBidderName, bids, listedAt, expiresAt); + } + + public BinListing buildBinListing() { + if (isAuction) { + throw new IllegalStateException("This builder is configured for an auction listing."); + } + return new BinListing(ListingType.BIN, uuid, ownerUUID, ownerName, item, currency, currencyItem, binPrice, listedWorld, listedServer, listedAt, expiresAt); + } +} \ No newline at end of file diff --git a/src/main/java/ca/tweetzy/auctionhouse/settings/Settings.java b/src/main/java/ca/tweetzy/auctionhouse/settings/Settings.java index 4b267c1..7b877f6 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/settings/Settings.java +++ b/src/main/java/ca/tweetzy/auctionhouse/settings/Settings.java @@ -232,7 +232,7 @@ public class Settings { public static final ConfigSetting SEARCH_FILTER_ENABLED = new ConfigSetting(config, "auction setting.enabled filters.search", true, "Should this filter be enabled?"); public static final ConfigSetting SELF_FILTER_ENABLED = new ConfigSetting(config, "auction setting.enabled filters.self", true, "Should this filter be enabled?"); public static final ConfigSetting USE_AUCTION_CHEST_MODE = new ConfigSetting(config, "auction setting.use auction chest mode", false, "Enabling this will make it so players can only access the auction through the auction chest"); - public static final ConfigSetting AUTO_BSTATS = new ConfigSetting(config, "auction setting.auto bstats", true, "Auto enable bStats"); + public static final ConfigSetting AUTO_BSTATS = new ConfigSetting(config, "auction setting.use bstats", true, "Auto enable bStats"); public static final ConfigSetting FORCE_MATERIAL_NAMES_FOR_DISCORD = new ConfigSetting(config, "auction setting.force material names for discord", false, "If true, auction house will use the actual material name rather than custom name"); public static final ConfigSetting ALLOW_ITEM_BUNDLES = new ConfigSetting(config, "auction setting.bundles.enabled", true, "If true, players can use -b in the sell command to bundle all similar items into a single item.");