remove old list auction method(s) from AuctionAPI, in favour of AuctionCreator

Took 13 minutes
This commit is contained in:
Kiran Hart 2022-11-18 17:40:47 -05:00
parent d82ae6ae34
commit a1763f8a7f
No known key found for this signature in database
GPG Key ID: 5F36C7BC79D3EBC3
5 changed files with 160 additions and 292 deletions

View File

@ -33,5 +33,6 @@ public enum ListingResult {
CANNOT_SELL_BUNDLE_ITEM,
UNKNOWN,
EVENT_CANCELED
}

View File

@ -19,21 +19,15 @@
package ca.tweetzy.auctionhouse.api;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.api.events.AuctionStartEvent;
import ca.tweetzy.auctionhouse.api.hook.MMOItemsHook;
import ca.tweetzy.auctionhouse.api.hook.McMMOHook;
import ca.tweetzy.auctionhouse.auction.AuctionPlayer;
import ca.tweetzy.auctionhouse.auction.AuctionedItem;
import ca.tweetzy.auctionhouse.auction.MinItemPrice;
import ca.tweetzy.auctionhouse.auction.enums.AuctionSaleType;
import ca.tweetzy.auctionhouse.helpers.ConfigurationItemHelper;
import ca.tweetzy.auctionhouse.helpers.MaterialCategorizer;
import ca.tweetzy.auctionhouse.managers.SoundManager;
import ca.tweetzy.auctionhouse.settings.Settings;
import ca.tweetzy.core.compatibility.ServerVersion;
import ca.tweetzy.core.compatibility.XMaterial;
import ca.tweetzy.core.hooks.EconomyManager;
import ca.tweetzy.core.utils.PlayerUtils;
import ca.tweetzy.core.utils.TextUtils;
import ca.tweetzy.core.utils.items.ItemUtils;
import ca.tweetzy.core.utils.nms.NBTEditor;
@ -679,158 +673,6 @@ public class AuctionAPI {
return Settings.TAX_LISTING_FEE_PERCENTAGE.getBoolean() ? (Settings.TAX_LISTING_FEE.getDouble() / 100D) * basePrice : Settings.TAX_LISTING_FEE.getDouble();
}
public void listAuction(Player seller, ItemStack original, ItemStack item, int seconds, double basePrice, double bidStartPrice, double bidIncPrice, double currentPrice, boolean isBiddingItem, boolean isUsingBundle, boolean requiresHandRemove) {
listAuction(seller, original, item, seconds, basePrice, bidStartPrice, bidIncPrice, currentPrice, isBiddingItem, isUsingBundle, requiresHandRemove, false, false);
}
/**
* Used to insert an auction into the database
*
* @param seller Is the player who is listing the item
* @param item Is the item stack being listed to the auction house
* @param original Is the original item stack (only applies if using a bundle)
* @param seconds Is the total amount of seconds the item will be active for
* @param basePrice Is the buy now price
* @param bidStartPrice Is the price the bidding will start at if the item is an auction
* @param bidIncPrice Is the default price increment for an auction
* @param currentPrice Is the current/start price of an item
* @param isBiddingItem States whether the item is an auction or bin item
* @param isUsingBundle States whether the item is a bundled item
*/
public void listAuction(Player seller, ItemStack original, ItemStack item, int seconds, double basePrice, double bidStartPrice, double bidIncPrice, double currentPrice, boolean isBiddingItem, boolean isUsingBundle, boolean requiresHandRemove, boolean isInfinite, boolean allowPartialBuy) {
if (McMMOHook.isUsingAbility(seller)) {
AuctionHouse.getInstance().getLocale().getMessage("general.mcmmo_ability_active").sendPrefixedMessage(seller);
return;
}
if (!Settings.ALLOW_SALE_OF_DAMAGED_ITEMS.getBoolean() && isDamaged(item)) {
AuctionHouse.getInstance().getLocale().getMessage("general.cannot list damaged item").sendPrefixedMessage(seller);
return;
}
if (Settings.PREVENT_SALE_OF_REPAIRED_ITEMS.getBoolean() && isRepaired(item)) {
AuctionHouse.getInstance().getLocale().getMessage("general.cannot list repaired item").sendPrefixedMessage(seller);
return;
}
if (!meetsMinItemPrice(isUsingBundle, isBiddingItem, original, basePrice, bidStartPrice)) {
AuctionHouse.getInstance().getLocale().getMessage("pricing.minitemprice").processPlaceholder("price", AuctionAPI.getInstance().formatNumber(AuctionHouse.getInstance().getMinItemPriceManager().getMinPrice(original).getPrice())).sendPrefixedMessage(seller);
return;
}
AuctionedItem auctionedItem = new AuctionedItem();
auctionedItem.setId(UUID.randomUUID());
auctionedItem.setOwner(seller.getUniqueId());
auctionedItem.setHighestBidder(seller.getUniqueId());
auctionedItem.setOwnerName(seller.getName());
auctionedItem.setHighestBidderName(seller.getName());
auctionedItem.setItem(item);
auctionedItem.setCategory(MaterialCategorizer.getMaterialCategory(item));
auctionedItem.setExpiresAt(System.currentTimeMillis() + 1000L * seconds);
auctionedItem.setBidItem(isBiddingItem);
auctionedItem.setExpired(false);
auctionedItem.setBasePrice(Settings.ROUND_ALL_PRICES.getBoolean() ? Math.round(basePrice) : basePrice);
auctionedItem.setBidStartingPrice(Settings.ROUND_ALL_PRICES.getBoolean() ? Math.round(bidStartPrice) : bidStartPrice);
auctionedItem.setBidIncrementPrice(Settings.ROUND_ALL_PRICES.getBoolean() ? Math.round(bidIncPrice) : bidIncPrice);
auctionedItem.setCurrentPrice(Settings.ROUND_ALL_PRICES.getBoolean() ? Math.round(currentPrice) : currentPrice);
auctionedItem.setListedWorld(seller.getWorld().getName());
auctionedItem.setInfinite(isInfinite);
auctionedItem.setAllowPartialBuy(allowPartialBuy);
if (Settings.TAX_ENABLED.getBoolean() && Settings.TAX_CHARGE_LISTING_FEE.getBoolean()) {
if (!EconomyManager.hasBalance(seller, calculateListingFee(basePrice))) {
AuctionHouse.getInstance().getLocale().getMessage("auction.tax.cannotpaylistingfee").processPlaceholder("price", AuctionAPI.getInstance().formatNumber(calculateListingFee(basePrice))).sendPrefixedMessage(seller);
return;
}
EconomyManager.withdrawBalance(seller, calculateListingFee(basePrice));
AuctionHouse.getInstance().getLocale().getMessage("auction.tax.paidlistingfee").processPlaceholder("price", AuctionAPI.getInstance().formatNumber(calculateListingFee(basePrice))).sendPrefixedMessage(seller);
AuctionHouse.getInstance().getLocale().getMessage("pricing.moneyremove").processPlaceholder("player_balance", AuctionAPI.getInstance().formatNumber(EconomyManager.getBalance(seller))).processPlaceholder("price", AuctionAPI.getInstance().formatNumber(calculateListingFee(basePrice))).sendPrefixedMessage(seller);
}
AuctionStartEvent startEvent = new AuctionStartEvent(seller, auctionedItem, Settings.TAX_ENABLED.getBoolean() && Settings.TAX_CHARGE_LISTING_FEE.getBoolean() ? calculateListingFee(basePrice) : 0D);
Bukkit.getServer().getPluginManager().callEvent(startEvent);
if (startEvent.isCancelled()) return;
ItemStack finalItemToSell = item.clone();
int totalOriginal = isUsingBundle ? AuctionAPI.getInstance().getItemCountInPlayerInventory(seller, original) : finalItemToSell.getAmount();
if (requiresHandRemove) {
removeSpecificItemQuantityFromPlayer(seller, finalItemToSell, totalOriginal);
}
// PlayerUtils.takeActiveItem(seller, CompatibleHand.MAIN_HAND, totalOriginal);
SoundManager.getInstance().playSound(seller, Settings.SOUNDS_LISTED_ITEM_ON_AUCTION_HOUSE.getString(), 1.0F, 1.0F);
String NAX = AuctionHouse.getInstance().getLocale().getMessage("auction.biditemwithdisabledbuynow").getMessage();
String msg = AuctionHouse.getInstance().getLocale().getMessage(auctionedItem.isBidItem() ? "auction.listed.withbid" : "auction.listed.nobid")
.processPlaceholder("amount", finalItemToSell.getAmount())
.processPlaceholder("item", AuctionAPI.getInstance().getItemName(finalItemToSell))
.processPlaceholder("base_price", auctionedItem.getBasePrice() <= -1 ? NAX : AuctionAPI.getInstance().formatNumber(auctionedItem.getBasePrice()))
.processPlaceholder("start_price", AuctionAPI.getInstance().formatNumber(auctionedItem.getBidStartingPrice()))
.processPlaceholder("increment_price", AuctionAPI.getInstance().formatNumber(auctionedItem.getBidIncrementPrice())).getMessage();
if (AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(seller.getUniqueId()) == null) {
AuctionHouse.getInstance().getLocale().newMessage(TextUtils.formatText("&cCould not find auction player instance for&f: &e" + seller.getName() + "&c creating one now.")).sendPrefixedMessage(Bukkit.getConsoleSender());
AuctionHouse.getInstance().getAuctionPlayerManager().addPlayer(new AuctionPlayer(seller));
}
if (AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(seller.getUniqueId()).isShowListingInfo()) {
AuctionHouse.getInstance().getLocale().newMessage(msg).sendPrefixedMessage(seller);
}
// Actually attempt the insertion now
AuctionHouse.getInstance().getDataManager().insertAuctionAsync(auctionedItem, (error, inserted) -> {
AuctionPlayer auctionPlayer = AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(seller.getUniqueId());
if (auctionPlayer != null)
auctionPlayer.setItemBeingListed(null);
if (error != null) {
AuctionHouse.getInstance().getLocale().getMessage("general.something_went_wrong_while_listing").sendPrefixedMessage(seller);
ItemStack originalCopy = original.clone();
if (isUsingBundle) {
originalCopy.setAmount(1);
for (int i = 0; i < totalOriginal; i++) PlayerUtils.giveItem(seller, originalCopy);
} else {
originalCopy.setAmount(totalOriginal);
PlayerUtils.giveItem(seller, originalCopy);
}
// If the item could not be added for whatever reason and the tax listing fee is enabled, refund them
if (Settings.TAX_ENABLED.getBoolean() && Settings.TAX_CHARGE_LISTING_FEE.getBoolean()) {
EconomyManager.deposit(seller, calculateListingFee(basePrice));
AuctionHouse.getInstance().getLocale().getMessage("pricing.moneyadd").processPlaceholder("player_balance", AuctionAPI.getInstance().formatNumber(EconomyManager.getBalance(seller))).processPlaceholder("price", AuctionAPI.getInstance().formatNumber(calculateListingFee(basePrice))).sendPrefixedMessage(seller);
}
return;
}
AuctionHouse.getInstance().getAuctionItemManager().addAuctionItem(auctionedItem);
if (Settings.BROADCAST_AUCTION_LIST.getBoolean()) {
final String prefix = AuctionHouse.getInstance().getLocale().getMessage("general.prefix").getMessage();
String msgToAll = AuctionHouse.getInstance().getLocale().getMessage(auctionedItem.isBidItem() ? "auction.broadcast.withbid" : "auction.broadcast.nobid")
.processPlaceholder("amount", finalItemToSell.getAmount())
.processPlaceholder("player", seller.getName())
.processPlaceholder("player_displayname", AuctionAPI.getInstance().getDisplayName(seller))
.processPlaceholder("item", AuctionAPI.getInstance().getItemName(finalItemToSell))
.processPlaceholder("base_price", auctionedItem.getBasePrice() <= -1 ? NAX : AuctionAPI.getInstance().formatNumber(auctionedItem.getBasePrice()))
.processPlaceholder("start_price", AuctionAPI.getInstance().formatNumber(auctionedItem.getBidStartingPrice()))
.processPlaceholder("increment_price", AuctionAPI.getInstance().formatNumber(auctionedItem.getBidIncrementPrice())).getMessage();
Bukkit.getOnlinePlayers().forEach(p -> {
if (!p.getUniqueId().equals(seller.getUniqueId()))
p.sendMessage(TextUtils.formatText((prefix.length() == 0 ? "" : prefix + " ") + msgToAll));
});
}
});
}
public boolean meetsMinItemPrice(boolean isUsingBundle, boolean isBiddingItem, ItemStack original, double basePrice, double bidStartPrice) {
boolean valid = true;

View File

@ -19,6 +19,7 @@
package ca.tweetzy.auctionhouse.commands;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.ahv3.api.ListingResult;
import ca.tweetzy.auctionhouse.api.AuctionAPI;
import ca.tweetzy.auctionhouse.auction.AuctionPlayer;
import ca.tweetzy.auctionhouse.auction.AuctionedItem;
@ -28,14 +29,17 @@ import ca.tweetzy.auctionhouse.guis.GUIBundleCreation;
import ca.tweetzy.auctionhouse.guis.confirmation.GUIListingConfirm;
import ca.tweetzy.auctionhouse.guis.sell.GUISellListingType;
import ca.tweetzy.auctionhouse.guis.sell.GUISellPlaceItem;
import ca.tweetzy.auctionhouse.helpers.AuctionCreator;
import ca.tweetzy.auctionhouse.helpers.MaterialCategorizer;
import ca.tweetzy.auctionhouse.helpers.PlayerHelper;
import ca.tweetzy.auctionhouse.settings.Settings;
import ca.tweetzy.core.commands.AbstractCommand;
import ca.tweetzy.core.compatibility.XMaterial;
import ca.tweetzy.core.utils.NumberUtils;
import ca.tweetzy.core.utils.PlayerUtils;
import ca.tweetzy.core.utils.TextUtils;
import ca.tweetzy.core.utils.nms.NBTEditor;
import ca.tweetzy.flight.comp.enums.CompMaterial;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
@ -316,83 +320,60 @@ public final class CommandSell extends AbstractCommand {
return ReturnType.SUCCESS;
}
AuctionedItem auctionedItem = new AuctionedItem();
auctionedItem.setId(UUID.randomUUID());
auctionedItem.setOwner(player.getUniqueId());
auctionedItem.setHighestBidder(player.getUniqueId());
auctionedItem.setOwnerName(player.getName());
auctionedItem.setHighestBidderName(player.getName());
auctionedItem.setItem(itemToSell);
auctionedItem.setCategory(MaterialCategorizer.getMaterialCategory(itemToSell));
auctionedItem.setExpiresAt(System.currentTimeMillis() + 1000L * allowedTime);
auctionedItem.setBidItem(isBiddingItem);
auctionedItem.setExpired(false);
auctionedItem.setBasePrice(Settings.ROUND_ALL_PRICES.getBoolean() ? Math.round(buyNowAllow ? buyNowPrice : -1) : buyNowAllow ? buyNowPrice : -1);
auctionedItem.setBidStartingPrice(Settings.ROUND_ALL_PRICES.getBoolean() ? Math.round(isBiddingItem ? startingBid : 0) : isBiddingItem ? startingBid : 0);
auctionedItem.setBidIncrementPrice(Settings.ROUND_ALL_PRICES.getBoolean() ? Math.round(isBiddingItem ? bidIncrement != null ? bidIncrement : Settings.MIN_AUCTION_INCREMENT_PRICE.getDouble() : 0) : isBiddingItem ? bidIncrement != null ? bidIncrement : Settings.MIN_AUCTION_INCREMENT_PRICE.getDouble() : 0);
auctionedItem.setCurrentPrice(Settings.ROUND_ALL_PRICES.getBoolean() ? Math.round(isBiddingItem ? startingBid : buyNowPrice <= -1 ? startingBid : buyNowPrice) : isBiddingItem ? startingBid : buyNowPrice <= -1 ? startingBid : buyNowPrice);
auctionedItem.setListedWorld(player.getWorld().getName());
auctionedItem.setInfinite(isInfinite);
auctionedItem.setAllowPartialBuy(partialBuy);
player.getInventory().setItemInHand(CompMaterial.AIR.parseItem());
if (Settings.ASK_FOR_LISTING_CONFIRMATION.getBoolean()) {
// TODO clean up is monstrosity
AuctionedItem auctionedItem = new AuctionedItem();
auctionedItem.setId(UUID.randomUUID());
auctionedItem.setOwner(player.getUniqueId());
auctionedItem.setHighestBidder(player.getUniqueId());
auctionedItem.setOwnerName(player.getName());
auctionedItem.setHighestBidderName(player.getName());
auctionedItem.setItem(itemToSell);
auctionedItem.setCategory(MaterialCategorizer.getMaterialCategory(itemToSell));
auctionedItem.setExpiresAt(System.currentTimeMillis() + 1000L * allowedTime);
auctionedItem.setBidItem(isBiddingItem);
auctionedItem.setExpired(false);
auctionedItem.setBasePrice(Settings.ROUND_ALL_PRICES.getBoolean() ? Math.round(buyNowAllow ? buyNowPrice : -1) : buyNowAllow ? buyNowPrice : -1);
auctionedItem.setBidStartingPrice(Settings.ROUND_ALL_PRICES.getBoolean() ? Math.round(isBiddingItem ? startingBid : 0) : isBiddingItem ? startingBid : 0);
auctionedItem.setBidIncrementPrice(Settings.ROUND_ALL_PRICES.getBoolean() ? Math.round(isBiddingItem ? bidIncrement != null ? bidIncrement : Settings.MIN_AUCTION_INCREMENT_PRICE.getDouble() : 0) : isBiddingItem ? bidIncrement != null ? bidIncrement : Settings.MIN_AUCTION_INCREMENT_PRICE.getDouble() : 0);
auctionedItem.setCurrentPrice(Settings.ROUND_ALL_PRICES.getBoolean() ? Math.round(isBiddingItem ? startingBid : buyNowPrice <= -1 ? startingBid : buyNowPrice) : isBiddingItem ? startingBid : buyNowPrice <= -1 ? startingBid : buyNowPrice);
auctionedItem.setListedWorld(player.getWorld().getName());
auctionedItem.setInfinite(isInfinite);
auctionedItem.setAllowPartialBuy(partialBuy);
ItemStack finalItemToSell = itemToSell;
int finalAllowedTime = allowedTime;
Double finalBuyNowPrice = buyNowPrice;
Double finalStartingBid = startingBid;
Double finalBidIncrement = bidIncrement;
Double finalStartingBid1 = startingBid;
boolean finalIsInfinite = isInfinite;
boolean finalPartialBuy = partialBuy;
boolean finalIsBundle = isBundle;
instance.getGuiManager().showGUI(player, new GUIListingConfirm(player, auctionedItem, result -> {
if (!result) {
player.closeInventory();
PlayerUtils.giveItem(player, auctionedItem.getItem());
auctionPlayer.setItemBeingListed(null);
return;
}
AuctionAPI.getInstance().listAuction(
player,
originalItem,
finalItemToSell,
finalAllowedTime,
/* buy now price */ buyNowAllow ? finalBuyNowPrice : -1,
/* start bid price */ isBiddingItem ? finalStartingBid : !buyNowAllow ? finalBuyNowPrice : 0,
/* bid inc price */ isBiddingItem ? finalBidIncrement != null ? finalBidIncrement : Settings.MIN_AUCTION_INCREMENT_PRICE.getDouble() : 0,
/* current price */ isBiddingItem ? finalStartingBid : finalBuyNowPrice <= -1 ? finalStartingBid1 : finalBuyNowPrice,
isBiddingItem || !buyNowAllow,
finalIsBundle,
true,
finalIsInfinite,
finalPartialBuy
);
AuctionCreator.create(auctionPlayer, auctionedItem, (auction, listingResult) -> {
if (listingResult != ListingResult.SUCCESS) {
PlayerUtils.giveItem(player, auction.getItem());
auctionPlayer.setItemBeingListed(null);
return;
}
player.closeInventory();
if (Settings.OPEN_MAIN_AUCTION_HOUSE_AFTER_MENU_LIST.getBoolean()) {
instance.getGuiManager().showGUI(player, new GUIAuctionHouse(instance.getAuctionPlayerManager().getPlayer(player.getUniqueId())));
}
if (Settings.OPEN_MAIN_AUCTION_HOUSE_AFTER_MENU_LIST.getBoolean())
instance.getGuiManager().showGUI(player, new GUIAuctionHouse(auctionPlayer));
});
}));
} else {
AuctionAPI.getInstance().listAuction(
player,
originalItem,
itemToSell,
allowedTime,
/* buy now price */ buyNowAllow ? buyNowPrice : -1,
/* start bid price */ isBiddingItem ? startingBid : !buyNowAllow ? buyNowPrice : 0,
/* bid inc price */ isBiddingItem ? bidIncrement != null ? bidIncrement : Settings.MIN_AUCTION_INCREMENT_PRICE.getDouble() : 0,
/* current price */ isBiddingItem ? startingBid : buyNowPrice <= -1 ? startingBid : buyNowPrice,
isBiddingItem || !buyNowAllow,
isBundle,
true,
isInfinite,
partialBuy
);
AuctionCreator.create(auctionPlayer, auctionedItem, (auction, listingResult) -> {
if (listingResult != ListingResult.SUCCESS) {
PlayerUtils.giveItem(player, auction.getItem());
auctionPlayer.setItemBeingListed(null);
return;
}
if (Settings.OPEN_MAIN_AUCTION_HOUSE_AFTER_MENU_LIST.getBoolean())
instance.getGuiManager().showGUI(player, new GUIAuctionHouse(auctionPlayer));
});
}
return ReturnType.SUCCESS;

View File

@ -19,10 +19,12 @@
package ca.tweetzy.auctionhouse.guis;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.ahv3.api.ListingResult;
import ca.tweetzy.auctionhouse.api.AuctionAPI;
import ca.tweetzy.auctionhouse.auction.AuctionPlayer;
import ca.tweetzy.auctionhouse.auction.AuctionedItem;
import ca.tweetzy.auctionhouse.guis.confirmation.GUIListingConfirm;
import ca.tweetzy.auctionhouse.helpers.AuctionCreator;
import ca.tweetzy.auctionhouse.helpers.ConfigurationItemHelper;
import ca.tweetzy.auctionhouse.helpers.MaterialCategorizer;
import ca.tweetzy.auctionhouse.settings.Settings;
@ -46,8 +48,10 @@ import java.util.stream.Collectors;
*/
public final class GUIBundleCreation extends AbstractPlaceholderGui {
public GUIBundleCreation(AuctionPlayer player, int allowedTime, boolean buyNowAllow, boolean isBiddingItem, Double buyNowPrice, Double startingBid, Double bidIncrement) {
super(player);
final AuctionHouse instance = AuctionHouse.getInstance();
public GUIBundleCreation(AuctionPlayer auctionPlayer, int allowedTime, boolean buyNowAllow, boolean isBiddingItem, Double buyNowPrice, Double startingBid, Double bidIncrement) {
super(auctionPlayer);
setTitle(Settings.GUI_CREATE_BUNDLE_TITLE.getString());
setRows(6);
setAllowDrops(false);
@ -59,7 +63,7 @@ public final class GUIBundleCreation extends AbstractPlaceholderGui {
for (int i = 0; i < 44; i++) {
final ItemStack item = getItem(i);
if (item == null || item.getType() == XMaterial.AIR.parseMaterial()) continue;
PlayerUtils.giveItem(player.getPlayer(), item);
PlayerUtils.giveItem(auctionPlayer.getPlayer(), item);
}
});
@ -123,7 +127,7 @@ public final class GUIBundleCreation extends AbstractPlaceholderGui {
}
// are they even allowed to sell more items
if (player.isAtSellLimit()) {
if (auctionPlayer.isAtSellLimit()) {
AuctionHouse.getInstance().getLocale().getMessage("general.sellinglimit").sendPrefixedMessage(e.player);
return;
}
@ -136,77 +140,58 @@ public final class GUIBundleCreation extends AbstractPlaceholderGui {
if (validItems.size() == 0) return;
final ItemStack bundle = AuctionAPI.getInstance().createBundledItem(firstItem, validItems.toArray(new ItemStack[0]));
AuctionedItem auctionedItem = new AuctionedItem();
auctionedItem.setId(UUID.randomUUID());
auctionedItem.setOwner(e.player.getUniqueId());
auctionedItem.setHighestBidder(e.player.getUniqueId());
auctionedItem.setOwnerName(e.player.getName());
auctionedItem.setHighestBidderName(e.player.getName());
auctionedItem.setItem(validItems.size() > 1 ? bundle : validItems.get(0));
auctionedItem.setCategory(MaterialCategorizer.getMaterialCategory(validItems.size() > 1 ? bundle : validItems.get(0)));
auctionedItem.setExpiresAt(System.currentTimeMillis() + 1000L * allowedTime);
auctionedItem.setBidItem(isBiddingItem);
auctionedItem.setExpired(false);
auctionedItem.setBasePrice(Settings.ROUND_ALL_PRICES.getBoolean() ? Math.round(buyNowAllow ? buyNowPrice : -1) : buyNowAllow ? buyNowPrice : -1);
auctionedItem.setBidStartingPrice(Settings.ROUND_ALL_PRICES.getBoolean() ? Math.round(isBiddingItem ? startingBid : !buyNowAllow ? buyNowPrice : 0) : isBiddingItem ? startingBid : !buyNowAllow ? buyNowPrice : 0);
auctionedItem.setBidIncrementPrice(Settings.ROUND_ALL_PRICES.getBoolean() ? Math.round(isBiddingItem ? bidIncrement != null ? bidIncrement : Settings.MIN_AUCTION_INCREMENT_PRICE.getDouble() : 0) : isBiddingItem ? bidIncrement != null ? bidIncrement : Settings.MIN_AUCTION_INCREMENT_PRICE.getDouble() : 0);
auctionedItem.setCurrentPrice(Settings.ROUND_ALL_PRICES.getBoolean() ? Math.round(isBiddingItem ? startingBid : buyNowPrice <= -1 ? startingBid : buyNowPrice) : isBiddingItem ? startingBid : buyNowPrice <= -1 ? startingBid : buyNowPrice);
auctionedItem.setListedWorld(e.player.getWorld().getName());
auctionedItem.setInfinite(false);
auctionedItem.setAllowPartialBuy(false);
if (Settings.ASK_FOR_LISTING_CONFIRMATION.getBoolean()) {
// TODO clean up is monstrosity
AuctionedItem auctionedItem = new AuctionedItem();
auctionedItem.setId(UUID.randomUUID());
auctionedItem.setOwner(e.player.getUniqueId());
auctionedItem.setHighestBidder(e.player.getUniqueId());
auctionedItem.setOwnerName(e.player.getName());
auctionedItem.setHighestBidderName(e.player.getName());
auctionedItem.setItem(validItems.size() > 1 ? bundle : validItems.get(0));
auctionedItem.setCategory(MaterialCategorizer.getMaterialCategory(validItems.size() > 1 ? bundle : validItems.get(0)));
auctionedItem.setExpiresAt(System.currentTimeMillis() + 1000L * allowedTime);
auctionedItem.setBidItem(isBiddingItem);
auctionedItem.setExpired(false);
auctionedItem.setBasePrice(Settings.ROUND_ALL_PRICES.getBoolean() ? Math.round(buyNowAllow ? buyNowPrice : -1) : buyNowAllow ? buyNowPrice : -1);
auctionedItem.setBidStartingPrice(Settings.ROUND_ALL_PRICES.getBoolean() ? Math.round(isBiddingItem ? startingBid : !buyNowAllow ? buyNowPrice : 0) : isBiddingItem ? startingBid : !buyNowAllow ? buyNowPrice : 0);
auctionedItem.setBidIncrementPrice(Settings.ROUND_ALL_PRICES.getBoolean() ? Math.round(isBiddingItem ? bidIncrement != null ? bidIncrement : Settings.MIN_AUCTION_INCREMENT_PRICE.getDouble() : 0) : isBiddingItem ? bidIncrement != null ? bidIncrement : Settings.MIN_AUCTION_INCREMENT_PRICE.getDouble() : 0);
auctionedItem.setCurrentPrice(Settings.ROUND_ALL_PRICES.getBoolean() ? Math.round(isBiddingItem ? startingBid : buyNowPrice <= -1 ? startingBid : buyNowPrice) : isBiddingItem ? startingBid : buyNowPrice <= -1 ? startingBid : buyNowPrice);
auctionedItem.setListedWorld(e.player.getWorld().getName());
auctionedItem.setInfinite(false);
auctionedItem.setAllowPartialBuy(false);
ItemStack finalFirstItem = firstItem;
AuctionHouse.getInstance().getGuiManager().showGUI(e.player, new GUIListingConfirm(e.player, auctionedItem, result -> {
instance.getGuiManager().showGUI(auctionPlayer.getPlayer(), new GUIListingConfirm(auctionPlayer.getPlayer(), auctionedItem, result -> {
if (!result) {
e.player.closeInventory();
validItems.forEach(item -> PlayerUtils.giveItem(e.player, item));
auctionPlayer.getPlayer().closeInventory();
PlayerUtils.giveItem(auctionPlayer.getPlayer(), auctionedItem.getItem());
auctionPlayer.setItemBeingListed(null);
return;
}
AuctionAPI.getInstance().listAuction(
player.getPlayer(),
validItems.size() > 1 ? finalFirstItem : validItems.get(0),
validItems.size() > 1 ? bundle : validItems.get(0),
allowedTime,
/* buy now price */ buyNowAllow ? buyNowPrice : -1,
/* start bid price */ isBiddingItem ? startingBid : !buyNowAllow ? buyNowPrice : 0,
/* bid inc price */ isBiddingItem ? bidIncrement != null ? bidIncrement : Settings.MIN_AUCTION_INCREMENT_PRICE.getDouble() : 0,
/* current price */ isBiddingItem ? startingBid : buyNowPrice <= -1 ? startingBid : buyNowPrice,
isBiddingItem || !buyNowAllow,
validItems.size() > 1,
false
);
AuctionCreator.create(auctionPlayer, auctionedItem, (auction, listingResult) -> {
if (listingResult != ListingResult.SUCCESS) {
PlayerUtils.giveItem(auctionPlayer.getPlayer(), auction.getItem());
auctionPlayer.setItemBeingListed(null);
return;
}
e.gui.exit();
if (Settings.OPEN_MAIN_AUCTION_HOUSE_AFTER_MENU_LIST.getBoolean()) {
e.manager.showGUI(e.player, new GUIAuctionHouse(player));
}
if (Settings.OPEN_MAIN_AUCTION_HOUSE_AFTER_MENU_LIST.getBoolean())
instance.getGuiManager().showGUI(auctionPlayer.getPlayer(), new GUIAuctionHouse(auctionPlayer));
});
}));
} else {
AuctionAPI.getInstance().listAuction(
player.getPlayer(),
validItems.size() > 1 ? firstItem : validItems.get(0),
validItems.size() > 1 ? bundle : validItems.get(0),
allowedTime,
/* buy now price */ buyNowAllow ? buyNowPrice : -1,
/* start bid price */ isBiddingItem ? startingBid : !buyNowAllow ? buyNowPrice : 0,
/* bid inc price */ isBiddingItem ? bidIncrement != null ? bidIncrement : Settings.MIN_AUCTION_INCREMENT_PRICE.getDouble() : 0,
/* current price */ isBiddingItem ? startingBid : buyNowPrice <= -1 ? startingBid : buyNowPrice,
isBiddingItem || !buyNowAllow,
validItems.size() > 1,
false
);
AuctionCreator.create(auctionPlayer, auctionedItem, (auction, listingResult) -> {
if (listingResult != ListingResult.SUCCESS) {
PlayerUtils.giveItem(auctionPlayer.getPlayer(), auction.getItem());
auctionPlayer.setItemBeingListed(null);
return;
}
e.gui.exit();
if (Settings.OPEN_MAIN_AUCTION_HOUSE_AFTER_MENU_LIST.getBoolean()) {
e.manager.showGUI(e.player, new GUIAuctionHouse(player));
}
if (Settings.OPEN_MAIN_AUCTION_HOUSE_AFTER_MENU_LIST.getBoolean())
instance.getGuiManager().showGUI(auctionPlayer.getPlayer(), new GUIAuctionHouse(auctionPlayer));
});
}
});
}

View File

@ -21,15 +21,19 @@ package ca.tweetzy.auctionhouse.helpers;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.ahv3.api.ListingResult;
import ca.tweetzy.auctionhouse.api.AuctionAPI;
import ca.tweetzy.auctionhouse.api.events.AuctionStartEvent;
import ca.tweetzy.auctionhouse.api.hook.McMMOHook;
import ca.tweetzy.auctionhouse.auction.AuctionPlayer;
import ca.tweetzy.auctionhouse.auction.AuctionedItem;
import ca.tweetzy.auctionhouse.managers.SoundManager;
import ca.tweetzy.auctionhouse.settings.Settings;
import ca.tweetzy.core.hooks.EconomyManager;
import ca.tweetzy.core.utils.PlayerUtils;
import ca.tweetzy.core.utils.TextUtils;
import ca.tweetzy.flight.comp.NBTEditor;
import lombok.NonNull;
import lombok.experimental.UtilityClass;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@ -77,6 +81,7 @@ public final class AuctionCreator {
return;
}
final ItemStack finalItemToSell = auctionItem.getItem().clone();
final double originalBasePrice = auctionItem.getBasePrice();
final double originalStartPrice = auctionItem.getBidStartingPrice();
final double originalIncrementPrice = auctionItem.getBidIncrementPrice();
@ -108,6 +113,38 @@ public final class AuctionCreator {
if (auctionItem.getListedWorld() == null)
auctionItem.setListedWorld(seller.getWorld().getName());
AuctionStartEvent startEvent = new AuctionStartEvent(seller, auctionItem, listingFee);
Bukkit.getServer().getPluginManager().callEvent(startEvent);
if (startEvent.isCancelled()) {
result.accept(auctionItem, EVENT_CANCELED);
return;
}
//====================================================================================
// A VERY UGLY LISTING MESSAGING THING, IDEK, I GOTTA DEAL WITH THIS EVENTUALLY 💀
SoundManager.getInstance().playSound(seller, Settings.SOUNDS_LISTED_ITEM_ON_AUCTION_HOUSE.getString(), 1.0F, 1.0F);
String NAX = AuctionHouse.getInstance().getLocale().getMessage("auction.biditemwithdisabledbuynow").getMessage();
String msg = AuctionHouse.getInstance().getLocale().getMessage(auctionItem.isBidItem() ? "auction.listed.withbid" : "auction.listed.nobid")
.processPlaceholder("amount", finalItemToSell.getAmount())
.processPlaceholder("item", AuctionAPI.getInstance().getItemName(finalItemToSell))
.processPlaceholder("base_price", auctionItem.getBasePrice() <= -1 ? NAX : AuctionAPI.getInstance().formatNumber(auctionItem.getBasePrice()))
.processPlaceholder("start_price", AuctionAPI.getInstance().formatNumber(auctionItem.getBidStartingPrice()))
.processPlaceholder("increment_price", AuctionAPI.getInstance().formatNumber(auctionItem.getBidIncrementPrice())).getMessage();
if (AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(seller.getUniqueId()) == null) {
AuctionHouse.getInstance().getLocale().newMessage(TextUtils.formatText("&cCould not find auction player instance for&f: &e" + seller.getName() + "&c creating one now.")).sendPrefixedMessage(Bukkit.getConsoleSender());
AuctionHouse.getInstance().getAuctionPlayerManager().addPlayer(new AuctionPlayer(seller));
}
if (AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(seller.getUniqueId()).isShowListingInfo()) {
AuctionHouse.getInstance().getLocale().newMessage(msg).sendPrefixedMessage(seller);
}
//====================================================================================
// Actually attempt the insertion now
AuctionHouse.getInstance().getDataManager().insertAuctionAsync(auctionItem, (error, inserted) -> {
auctionPlayer.setItemBeingListed(null);
@ -136,8 +173,30 @@ public final class AuctionCreator {
}
AuctionHouse.getInstance().getAuctionItemManager().addAuctionItem(auctionItem);
result.accept(auctionItem, SUCCESS);
//====================================================================================
// 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")
.processPlaceholder("amount", finalItemToSell.getAmount())
.processPlaceholder("player", seller.getName())
.processPlaceholder("player_displayname", AuctionAPI.getInstance().getDisplayName(seller))
.processPlaceholder("item", AuctionAPI.getInstance().getItemName(finalItemToSell))
.processPlaceholder("base_price", auctionItem.getBasePrice() <= -1 ? NAX : AuctionAPI.getInstance().formatNumber(auctionItem.getBasePrice()))
.processPlaceholder("start_price", AuctionAPI.getInstance().formatNumber(auctionItem.getBidStartingPrice()))
.processPlaceholder("increment_price", AuctionAPI.getInstance().formatNumber(auctionItem.getBidIncrementPrice())).getMessage();
Bukkit.getOnlinePlayers().forEach(p -> {
if (!p.getUniqueId().equals(seller.getUniqueId()))
p.sendMessage(TextUtils.formatText((prefix.length() == 0 ? "" : prefix + " ") + msgToAll));
});
}
//====================================================================================
result.accept(auctionItem, SUCCESS);
});
}
}