From cc47c7fb268542e47984b5c294f0a42b80b9ede1 Mon Sep 17 00:00:00 2001 From: Kiran Hart Date: Fri, 27 Oct 2023 10:45:36 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=86=95=20implement=20new=20auction=20list?= =?UTF-8?q?ing=20structure?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Took 16 seconds --- .../auctionhouse/impl/listing/AuctionBid.java | 84 +++++++ .../impl/listing/AuctionItem.java | 52 ++++ .../impl/listing/AuctionListing.java | 99 ++++++++ .../auctionhouse/impl/listing/BinListing.java | 237 ++++++++++++++++++ 4 files changed, 472 insertions(+) create mode 100644 src/main/java/ca/tweetzy/auctionhouse/impl/listing/AuctionBid.java create mode 100644 src/main/java/ca/tweetzy/auctionhouse/impl/listing/AuctionItem.java create mode 100644 src/main/java/ca/tweetzy/auctionhouse/impl/listing/AuctionListing.java create mode 100644 src/main/java/ca/tweetzy/auctionhouse/impl/listing/BinListing.java diff --git a/src/main/java/ca/tweetzy/auctionhouse/impl/listing/AuctionBid.java b/src/main/java/ca/tweetzy/auctionhouse/impl/listing/AuctionBid.java new file mode 100644 index 0000000..467e796 --- /dev/null +++ b/src/main/java/ca/tweetzy/auctionhouse/impl/listing/AuctionBid.java @@ -0,0 +1,84 @@ +/* + * Auction House + * Copyright 2023 Kiran Hart + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package ca.tweetzy.auctionhouse.impl.listing; + +import ca.tweetzy.auctionhouse.api.auction.Bid; +import lombok.AllArgsConstructor; +import lombok.NonNull; + +import java.util.UUID; +import java.util.function.Consumer; + +@AllArgsConstructor +public final class AuctionBid implements Bid { + + private final UUID id; + private final UUID auctionId; + private final UUID bidderUUID; + private final String bidderName; + private final double amount; + private final String world; + private final String server; + private final long time; + + @Override + public @NonNull UUID getId() { + return this.id; + } + + @Override + public UUID getAuctionId() { + return this.auctionId; + } + + @Override + public UUID getBidderUUID() { + return this.bidderUUID; + } + + @Override + public String getBidderName() { + return this.bidderName; + } + + @Override + public double getAmount() { + return this.amount; + } + + @Override + public String getBidWorld() { + return this.world; + } + + @Override + public String getServer() { + return this.server; + } + + @Override + public long getBidTime() { + return this.time; + } + + @Override + public void store(Consumer storedItem) { + // TODO implement auction bid store + } +} \ No newline at end of file diff --git a/src/main/java/ca/tweetzy/auctionhouse/impl/listing/AuctionItem.java b/src/main/java/ca/tweetzy/auctionhouse/impl/listing/AuctionItem.java new file mode 100644 index 0000000..01d4841 --- /dev/null +++ b/src/main/java/ca/tweetzy/auctionhouse/impl/listing/AuctionItem.java @@ -0,0 +1,52 @@ +/* + * Auction House + * Copyright 2023 Kiran Hart + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package ca.tweetzy.auctionhouse.impl.listing; + +import ca.tweetzy.auctionhouse.api.auction.Auction; +import ca.tweetzy.auctionhouse.api.auction.ListingType; +import ca.tweetzy.auctionhouse.api.sync.ListingDeleteResult; +import ca.tweetzy.auctionhouse.api.sync.Storeable; +import ca.tweetzy.auctionhouse.api.sync.Unstoreable; +import lombok.AllArgsConstructor; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.Nullable; + +import java.util.function.Consumer; + +@AllArgsConstructor +public abstract class AuctionItem implements Auction, Storeable, Unstoreable { + + protected final ItemStack item; + protected final ListingType listingType; + + @Override + public void unStore(@Nullable Consumer result) { +// AuctionHouse.getDataManager().deleteListing(this, (error, status) -> { +// if (error != null && result != null) { +// error.printStackTrace(); +// result.accept(ListingDeleteResult.NOT_DELETED); +// return; +// } +// +// if (result != null) +// result.accept(status); +// +// }); + } +} \ No newline at end of file diff --git a/src/main/java/ca/tweetzy/auctionhouse/impl/listing/AuctionListing.java b/src/main/java/ca/tweetzy/auctionhouse/impl/listing/AuctionListing.java new file mode 100644 index 0000000..90799b5 --- /dev/null +++ b/src/main/java/ca/tweetzy/auctionhouse/impl/listing/AuctionListing.java @@ -0,0 +1,99 @@ +/* + * Auction House + * Copyright 2023 Kiran Hart + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package ca.tweetzy.auctionhouse.impl.listing; + +import ca.tweetzy.auctionhouse.api.auction.Bid; +import ca.tweetzy.auctionhouse.api.auction.Biddable; +import ca.tweetzy.auctionhouse.api.auction.ListingType; +import lombok.NonNull; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import java.util.List; +import java.util.UUID; + +public final class AuctionListing extends BinListing implements Biddable { + + private final double startingBid; + + private UUID highestBidderUUID; + private String highestBidderName; + + private final List bids; + + public AuctionListing( + @NonNull UUID uuid, + @NonNull UUID ownerUUID, + @NonNull String ownerName, + @NonNull ItemStack item, + double startingBid, + double binPrice, + @NonNull String listedWorld, + @NonNull String listedServer, + @NonNull UUID highestBidderUUID, + @NonNull String highestBidderName, + @NonNull List bids, + long listedAt, + long expiresAt + ) { + super(ListingType.AUCTION, uuid, ownerUUID, ownerName, item, binPrice, listedWorld, listedServer, listedAt, expiresAt); + this.startingBid = startingBid; + this.highestBidderName = highestBidderName; + this.highestBidderUUID = highestBidderUUID; + this.bids = bids; + } + + public AuctionListing( + @NonNull Player player, + @NonNull ItemStack item, + double startingBid, + final double binPrice, + @NonNull List bids + ) { + super(ListingType.AUCTION, player, item, binPrice); + this.startingBid = startingBid; + this.bids = bids; + } + + @Override + public double getStartingPrice() { + return this.startingBid; + } + + @Override + public List getBids() { + return this.bids; + } + + public UUID getHighestBidderUUID() { + return highestBidderUUID; + } + + public void setHighestBidderUUID(@NonNull final UUID highestBidderUUID) { + this.highestBidderUUID = highestBidderUUID; + } + + public String getHighestBidderName() { + return highestBidderName; + } + + public void setHighestBidderName(@NonNull String highestBidderName) { + this.highestBidderName = highestBidderName; + } +} \ No newline at end of file diff --git a/src/main/java/ca/tweetzy/auctionhouse/impl/listing/BinListing.java b/src/main/java/ca/tweetzy/auctionhouse/impl/listing/BinListing.java new file mode 100644 index 0000000..8a5ca7b --- /dev/null +++ b/src/main/java/ca/tweetzy/auctionhouse/impl/listing/BinListing.java @@ -0,0 +1,237 @@ +/* + * Auction House + * Copyright 2023 Kiran Hart + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package ca.tweetzy.auctionhouse.impl.listing; + +import ca.tweetzy.auctionhouse.api.auction.ListingDisplayMode; +import ca.tweetzy.auctionhouse.api.auction.ListingType; +import ca.tweetzy.flight.utils.ItemUtil; +import lombok.NonNull; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import java.util.function.Consumer; + +public class BinListing extends AuctionItem { + + private final UUID uuid; + private final UUID ownerUUID; + private final String ownerName; + + private double binPrice; + + private final String listedWorld; + private final String listedServer; + + private final long listedAt; + private long expiresAt; + + private boolean isBeingBought = false; + + public BinListing( + @NonNull final ListingType listingType, + @NonNull final UUID uuid, + @NonNull final UUID ownerUUID, + @NonNull final String ownerName, + @NonNull final ItemStack item, + final double price, + @NonNull final String listedWorld, + @NonNull final String listedServer, + final long listedAt, + final long expiresAt + ) { + super(item, listingType); + this.uuid = uuid; + this.ownerUUID = ownerUUID; + this.ownerName = ownerName; + this.binPrice = price; + this.listedWorld = listedWorld; + this.listedServer = listedServer; + this.listedAt = listedAt; + this.expiresAt = expiresAt; + } + + public BinListing( + @NonNull final ListingType listingType, + @NonNull final Player player, + @NonNull final ItemStack item, + final double price + ) { + this(listingType, UUID.randomUUID(), player.getUniqueId(), player.getName(), item, price, player.getWorld().getName(), player.getServer().getName(), System.currentTimeMillis(), System.currentTimeMillis() + 1000 * 60 * 60); + } + + public BinListing( + @NonNull final Player player, + @NonNull final ItemStack item, + final double price + ) { + this(ListingType.BIN, UUID.randomUUID(), player.getUniqueId(), player.getName(), item, price, player.getWorld().getName(), player.getServer().getName(), System.currentTimeMillis(), System.currentTimeMillis() + 1000 * 60 * 60); + } + + @NonNull + @Override + public UUID getId() { + return this.uuid; + } + + @Override + public UUID getOwner() { + return this.ownerUUID; + } + + @Override + public String getOwnerName() { + return this.ownerName; + } + + @Override + public ItemStack getItem() { + return this.item; + } + + @Override + public ListingType getType() { + return this.listingType; + } + + @Override + public double getBinPrice() { + return this.binPrice; + } + + @Override + public String getListedWorld() { + return this.listedWorld; + } + + @Override + public String getListedServer() { + return this.listedServer; + } + + @Override + public long getListedAt() { + return this.listedAt; + } + + @Override + public long getExpirationTime() { + return this.expiresAt; + } + + @Override + public void setExpirationTime(long expirationTime) { + this.expiresAt = expirationTime; + } + + @Override + public void setBinPrice(double binPrice) { + this.binPrice = binPrice; + } + + @Override + public boolean isBeingBought() { + return this.isBeingBought; + } + + @Override + public void setIsBeingBought(boolean isBeingBought) { + this.isBeingBought = isBeingBought; + } + + @Override + public long getTimeCreated() { + return this.listedAt; + } + + @Override + public long getLastUpdated() { + return 0; + } + + @Override + public void sync(Consumer wasSuccess) { + + } + + @Override + public void store(Consumer stored) { +// AuctionHouse.getDataManager().createListing(this, (error, created) -> { +// if (error != null) return; +// +// if (stored != null) +// stored.accept(created); +// }); + } + + @Override + public List getDisplayLore(@NonNull ListingDisplayMode displayMode) { + final List displayLore = new ArrayList<>(ItemUtil.getItemLore(this.item)); + + // header + displayLore.add("&7&m-------------------------"); + displayLore.add("#FE8295Seller&f: &e%listing_seller%"); + displayLore.add("#FE8295Price&f: &a$%listing_price%"); + displayLore.add(" "); + + // remaining time + displayLore.add("#FE8295Time&F: &f%days_left%&bd &f%hours_left%&bh &f%minutes_left%&bm &f%seconds_left%&bs"); + + + // footer + displayLore.add("&7&m-------------------------"); + displayLore.add("&e&lLeft Click &8ยป &7To Purchase"); + displayLore.add("&7&m-------------------------"); + displayLore.add("&c&lPress 1 &cTo Moderate Item"); + displayLore.add("&7&m-------------------------"); + return displayLore; + } + + + public ArrayList wrapInBox(String[] strings) { + ArrayList result = new ArrayList<>(); + int maxLength = 0; + + for (String s : strings) { + if (s.length() > maxLength) { + maxLength = s.length(); + } + } + + String topAndBottom = "&7&m"; + for (int i = 0; i < maxLength + 2; i++) { + topAndBottom += "-"; + } + + result.add(topAndBottom); + + for (String s : strings) { + String paddedString = "&7| " + s; + while (paddedString.length() < maxLength + 2) { + paddedString += " "; + } + paddedString += " &7|"; + result.add(paddedString); + } + result.add(topAndBottom); + return result; + } +} \ No newline at end of file