💪 server auctions implemented

Took 4 seconds
This commit is contained in:
Kiran Hart 2023-09-11 20:00:01 -04:00
parent 7b5e4c93f0
commit 35ab8d2339
No known key found for this signature in database
GPG Key ID: 5F36C7BC79D3EBC3
7 changed files with 41 additions and 6 deletions

View File

@ -119,6 +119,8 @@ public class AuctionedItem {
if (meta != null && meta.getLore() != null)
lore.addAll(meta.getLore());
if (this.serverItem)
this.ownerName = AuctionHouse.getInstance().getLocale().getMessage("general.server listing").getMessage();
lore.addAll(TextUtils.formatText(Settings.AUCTION_STACK_DETAILS_HEADER.getStringList()));
lore.addAll(TextUtils.formatText(Settings.AUCTION_STACK_DETAILS_SELLER.getStringList().stream().map(s -> s.replace("%seller%", this.ownerName)).collect(Collectors.toList())));
@ -156,6 +158,8 @@ public class AuctionedItem {
if (meta != null && meta.getLore() != null)
lore.addAll(meta.getLore());
if (this.serverItem)
this.ownerName = AuctionHouse.getInstance().getLocale().getMessage("general.server listing").getMessage();
lore.addAll(TextUtils.formatText(Settings.AUCTION_STACK_DETAILS_HEADER.getStringList()));
lore.addAll(TextUtils.formatText(Settings.AUCTION_STACK_DETAILS_SELLER.getStringList().stream().map(s -> s.replace("%seller%", this.ownerName)).collect(Collectors.toList())));

View File

@ -145,6 +145,7 @@ public final class CommandSell extends AbstractCommand {
boolean isInfinite = false;
boolean isStackPrice = false;
boolean partialBuy = false;
boolean serverAuction = false;
List<String> timeSets = Arrays.asList(
"second",
@ -187,6 +188,10 @@ public final class CommandSell extends AbstractCommand {
if ((args[i].equalsIgnoreCase("-i") || args[i].equalsIgnoreCase("-infinite")) && (player.hasPermission("auctionhouse.admin") || player.isOp()))
isInfinite = true;
// check if the listing should be a server auction
if (args[i].equalsIgnoreCase("-server"))
serverAuction = true;
if (args[i].toLowerCase().startsWith("-t") && Settings.ALLOW_PLAYERS_TO_DEFINE_AUCTION_TIME.getBoolean()) {
if (i + 2 < args.length) {
int customTime = (int) AuctionAPI.toTicks(args[i + 1] + " " + args[i + 2]);
@ -317,6 +322,7 @@ public final class CommandSell extends AbstractCommand {
auctionedItem.setCategory(MaterialCategorizer.getMaterialCategory(itemToSell));
auctionedItem.setExpiresAt(System.currentTimeMillis() + 1000L * allowedTime);
auctionedItem.setBidItem(isBiddingItem);
auctionedItem.setServerItem(serverAuction);
auctionedItem.setExpired(false);
double theStartingPrice = buyNowAllow ? buyNowPrice : -1;

View File

@ -323,7 +323,7 @@ public class DataManager extends DataManagerAbstract {
public void insertAuction(AuctionedItem item, Callback<AuctionedItem> callback) {
this.databaseConnector.connect(connection -> {
try (PreparedStatement statement = connection.prepareStatement("INSERT INTO " + this.getTablePrefix() + "auctions(id, owner, highest_bidder, owner_name, highest_bidder_name, category, base_price, bid_start_price, bid_increment_price, current_price, expired, expires_at, item_material, item_name, item_lore, item_enchants, item, listed_world, infinite, allow_partial_buys) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")) {
try (PreparedStatement statement = connection.prepareStatement("INSERT INTO " + this.getTablePrefix() + "auctions(id, owner, highest_bidder, owner_name, highest_bidder_name, category, base_price, bid_start_price, bid_increment_price, current_price, expired, expires_at, item_material, item_name, item_lore, item_enchants, item, listed_world, infinite, allow_partial_buys, server_auction) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")) {
final AuctionAPI api = AuctionAPI.getInstance();
PreparedStatement fetch = connection.prepareStatement("SELECT * FROM " + this.getTablePrefix() + "auctions WHERE id = ?");
@ -348,6 +348,8 @@ public class DataManager extends DataManagerAbstract {
statement.setString(18, item.getListedWorld());
statement.setBoolean(19, item.isInfinite());
statement.setBoolean(20, item.isAllowPartialBuy());
statement.setBoolean(21, item.isServerItem());
statement.executeUpdate();
if (callback != null) {
@ -729,6 +731,8 @@ public class DataManager extends DataManagerAbstract {
auctionItem.setListedWorld(resultSet.getString("listed_world"));
auctionItem.setInfinite(hasColumn(resultSet, "infinite") && resultSet.getBoolean("infinite"));
auctionItem.setAllowPartialBuy(hasColumn(resultSet, "allow_partial_buys") && resultSet.getBoolean("allow_partial_buys"));
auctionItem.setServerItem(resultSet.getBoolean("server_auction"));
return auctionItem;
}

View File

@ -74,8 +74,10 @@ public class GUIAdminItem extends AbstractPlaceholderGui {
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) return;
this.auctionItem.setExpiresAt(System.currentTimeMillis());
this.auctionItem.setExpired(true);
if (!this.auctionItem.isServerItem()) {
this.auctionItem.setExpiresAt(System.currentTimeMillis());
this.auctionItem.setExpired(true);
}
if (Settings.BIDDING_TAKES_MONEY.getBoolean() && !this.auctionItem.getHighestBidder().equals(this.auctionItem.getOwner())) {
final OfflinePlayer oldBidder = Bukkit.getOfflinePlayer(this.auctionItem.getHighestBidder());
@ -96,6 +98,7 @@ public class GUIAdminItem extends AbstractPlaceholderGui {
}
AuctionHouse.getInstance().getAuctionItemManager().sendToGarbage(this.auctionItem);
e.gui.close();
});

View File

@ -38,6 +38,7 @@ import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.BiConsumer;
@ -127,6 +128,14 @@ public final class AuctionCreator {
return;
}
// overwrite to be random uuid since it's a server auction
final String SERVER_LISTING_NAME = AuctionHouse.getInstance().getLocale().getMessage("general.server listing").getMessage();
if (auctionItem.isServerItem()) {
auctionItem.setOwner(UUID.randomUUID());
auctionItem.setOwnerName(SERVER_LISTING_NAME);
}
//====================================================================================
// A VERY UGLY LISTING MESSAGING THING, IDEK, I GOTTA DEAL WITH THIS EVENTUALLY 💀
@ -195,9 +204,10 @@ public final class AuctionCreator {
//====================================================================================
// ANOTHER VERY SHIT BROADCAST THAT IS IN FACT BROKEN
if (Settings.BROADCAST_AUCTION_LIST.getBoolean()) {
final String prefix = AuctionHouse.getInstance().getLocale().getMessage("general.prefix").getMessage();
String msgToAll = AuctionHouse.getInstance().getLocale().getMessage(auctionItem.isBidItem() ? "auction.broadcast.withbid" : "auction.broadcast.nobid")
String msgToAll = AuctionHouse.getInstance().getLocale().getMessage(auctionItem.isServerItem() ? "auction.broadcast.serverlisting" : auctionItem.isBidItem() ? "auction.broadcast.withbid" : "auction.broadcast.nobid")
.processPlaceholder("amount", finalItemToSell.getAmount())
.processPlaceholder("player", seller.getName())
.processPlaceholder("player_displayname", AuctionAPI.getInstance().getDisplayName(seller))

View File

@ -39,6 +39,7 @@ public class LocaleSettings {
static {
languageNodes.put("general.prefix", "&8[&eAuctionHouse&8]");
languageNodes.put("general.server listing", "&eAuctionHouse");
languageNodes.put("general.notanumber", "&cThe entry &4%value% &cis not a valid number!");
languageNodes.put("general.locked", "&cThe Auction House is currently locked!");
languageNodes.put("general.playernotfound", "&cCould not find the player &4%player%");
@ -179,6 +180,7 @@ public class LocaleSettings {
languageNodes.put("auction.broadcast.withbid", "&e%player% listed &fx%amount% &6%item% &e&lBuy Now&f: &a%base_price% &e&lStarting&f: &a%start_price% &e&lIncrement&f: &a%increment_price%");
languageNodes.put("auction.broadcast.nobid", "&e%player% listed &fx%amount% &6%item% &efor &a%base_price%");
languageNodes.put("auction.broadcast.sold", "&e&fx%amount% &6%item% &esold to %player% for &a%price%");
languageNodes.put("auction.broadcast.serverlisting", "&e&fx%amount% &6%item% &ehas appeared on the auction house.");
languageNodes.put("auction.broadcast.bid", "&e%player% increased the bid to &a$%amount% &eon &6%item%");
languageNodes.put("auction.broadcast.ending", "&eAuction for &6%item% &eis ending in &6%seconds%&es");

View File

@ -119,7 +119,10 @@ public class TickAuctionsTask extends BukkitRunnable {
// the owner is the highest bidder, so just expire
if (auctionItem.getHighestBidder().equals(auctionItem.getOwner())) {
auctionItem.setExpired(true);
if (auctionItem.isServerItem())
instance.getAuctionItemManager().sendToGarbage(auctionItem);
else
auctionItem.setExpired(true);
continue;
}
@ -130,7 +133,10 @@ public class TickAuctionsTask extends BukkitRunnable {
if (!Settings.BIDDING_TAKES_MONEY.getBoolean())
if (!EconomyManager.hasBalance(auctionWinner, Settings.TAX_CHARGE_SALES_TAX_TO_BUYER.getBoolean() ? finalPrice + tax : finalPrice)) {
auctionItem.setExpired(true);
if (auctionItem.isServerItem())
instance.getAuctionItemManager().sendToGarbage(auctionItem);
else
auctionItem.setExpired(true);
continue;
}