🆕 implement new auction listing structure

Took 16 seconds
This commit is contained in:
Kiran Hart 2023-10-27 10:45:36 -04:00
parent c411c95fe7
commit cc47c7fb26
No known key found for this signature in database
GPG Key ID: 5F36C7BC79D3EBC3
4 changed files with 472 additions and 0 deletions

View File

@ -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 <https://www.gnu.org/licenses/>.
*/
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<Bid> storedItem) {
// TODO implement auction bid store
}
}

View File

@ -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 <https://www.gnu.org/licenses/>.
*/
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<AuctionItem>, Unstoreable<ListingDeleteResult> {
protected final ItemStack item;
protected final ListingType listingType;
@Override
public void unStore(@Nullable Consumer<ListingDeleteResult> 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);
//
// });
}
}

View File

@ -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 <https://www.gnu.org/licenses/>.
*/
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<Bid> 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<Bid> 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<Bid> bids
) {
super(ListingType.AUCTION, player, item, binPrice);
this.startingBid = startingBid;
this.bids = bids;
}
@Override
public double getStartingPrice() {
return this.startingBid;
}
@Override
public List<Bid> 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;
}
}

View File

@ -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 <https://www.gnu.org/licenses/>.
*/
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<Boolean> wasSuccess) {
}
@Override
public void store(Consumer<AuctionItem> stored) {
// AuctionHouse.getDataManager().createListing(this, (error, created) -> {
// if (error != null) return;
//
// if (stored != null)
// stored.accept(created);
// });
}
@Override
public List<String> getDisplayLore(@NonNull ListingDisplayMode displayMode) {
final List<String> 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<String> wrapInBox(String[] strings) {
ArrayList<String> 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;
}
}