diff --git a/src/main/java/ca/tweetzy/auctionhouse/guis/transaction/GUITransactionList.java b/src/main/java/ca/tweetzy/auctionhouse/guis/transaction/GUITransactionList.java index fc9330e..38d080e 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/guis/transaction/GUITransactionList.java +++ b/src/main/java/ca/tweetzy/auctionhouse/guis/transaction/GUITransactionList.java @@ -33,6 +33,7 @@ import ca.tweetzy.auctionhouse.transaction.Transaction; import ca.tweetzy.core.compatibility.XSound; import ca.tweetzy.core.utils.TextUtils; import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; import org.bukkit.inventory.ItemStack; @@ -111,12 +112,16 @@ public class GUITransactionList extends AbstractPlaceholderGui { setOnPage(e -> draw()); int slot = 0; + final String SERVER_LISTING_NAME = AuctionHouse.getInstance().getLocale().getMessage("general.server listing").getMessage(); + for (Transaction transaction : data) { final ItemStack item = transaction.getItem().clone(); + final OfflinePlayer seller = Bukkit.getOfflinePlayer(transaction.getSeller()); + setButton(slot++, ConfigurationItemHelper.createConfigurationItem(this.player, item, Settings.GUI_TRANSACTIONS_ITEM_TRANSACTION_NAME.getString(), Settings.GUI_TRANSACTIONS_ITEM_TRANSACTION_LORE.getStringList(), new HashMap() {{ put("%transaction_id%", transaction.getId().toString()); - put("%seller%", Bukkit.getOfflinePlayer(transaction.getSeller()).getName()); + put("%seller%",seller.hasPlayedBefore() ? seller.getName() : SERVER_LISTING_NAME); put("%buyer%", Bukkit.getOfflinePlayer(transaction.getBuyer()).getName()); put("%date%", AuctionAPI.getInstance().convertMillisToDate(transaction.getTransactionTime())); put("%item_name%", AuctionAPI.getInstance().getItemName(item)); diff --git a/src/main/java/ca/tweetzy/auctionhouse/guis/transaction/GUITransactionView.java b/src/main/java/ca/tweetzy/auctionhouse/guis/transaction/GUITransactionView.java index 2ce5a85..224346e 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/guis/transaction/GUITransactionView.java +++ b/src/main/java/ca/tweetzy/auctionhouse/guis/transaction/GUITransactionView.java @@ -28,6 +28,7 @@ import ca.tweetzy.auctionhouse.settings.Settings; import ca.tweetzy.auctionhouse.transaction.Transaction; import ca.tweetzy.core.utils.TextUtils; import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; import java.util.HashMap; @@ -50,26 +51,30 @@ public class GUITransactionView extends AbstractPlaceholderGui { setButton(5, 0, getBackButtonItem(), e -> e.manager.showGUI(e.player, new GUITransactionList(auctionPlayer.getPlayer(), showAll))); setItem(1, 4, transaction.getItem()); + final String SERVER_LISTING_NAME = AuctionHouse.getInstance().getLocale().getMessage("general.server listing").getMessage(); + final OfflinePlayer seller = Bukkit.getOfflinePlayer(transaction.getSeller()); + final OfflinePlayer buyer = Bukkit.getOfflinePlayer(transaction.getBuyer()); + setItem(3, 2, ConfigurationItemHelper.createConfigurationItem( this.player, - AuctionAPI.getInstance().getPlayerHead(Bukkit.getOfflinePlayer(transaction.getSeller()).getName()), + AuctionAPI.getInstance().getPlayerHead(seller.getName()), Settings.GUI_TRANSACTION_VIEW_ITEM_SELLER_NAME.getString(), Settings.GUI_TRANSACTION_VIEW_ITEM_SELLER_LORE.getStringList(), new HashMap() {{ put("%transaction_id%", transaction.getId().toString()); - put("%seller%", Bukkit.getOfflinePlayer(transaction.getSeller()).getName()); - put("%buyer%", Bukkit.getOfflinePlayer(transaction.getBuyer()).getName()); + put("%seller%", seller.hasPlayedBefore() ? seller.getName() : SERVER_LISTING_NAME); + put("%buyer%",buyer.getName()); put("%date%", AuctionAPI.getInstance().convertMillisToDate(transaction.getTransactionTime())); }})); setItem(3, 6, ConfigurationItemHelper.createConfigurationItem( this.player, - AuctionAPI.getInstance().getPlayerHead(Bukkit.getOfflinePlayer(transaction.getSeller()).getName()), + AuctionAPI.getInstance().getPlayerHead(Bukkit.getOfflinePlayer(transaction.getBuyer()).getName()), Settings.GUI_TRANSACTION_VIEW_ITEM_BUYER_NAME.getString(), Settings.GUI_TRANSACTION_VIEW_ITEM_BUYER_LORE.getStringList(), new HashMap() {{ put("%transaction_id%", transaction.getId().toString()); - put("%seller%", Bukkit.getOfflinePlayer(transaction.getSeller()).getName()); - put("%buyer%", Bukkit.getOfflinePlayer(transaction.getBuyer()).getName()); + put("%seller%",seller.hasPlayedBefore() ? seller.getName() : SERVER_LISTING_NAME); + put("%buyer%", buyer.getName()); put("%date%", AuctionAPI.getInstance().convertMillisToDate(transaction.getTransactionTime())); }})); diff --git a/src/main/java/ca/tweetzy/auctionhouse/helpers/AuctionCreator.java b/src/main/java/ca/tweetzy/auctionhouse/helpers/AuctionCreator.java index 832b8ac..062d5b8 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/helpers/AuctionCreator.java +++ b/src/main/java/ca/tweetzy/auctionhouse/helpers/AuctionCreator.java @@ -48,6 +48,10 @@ import static ca.tweetzy.auctionhouse.api.ListingResult.*; @UtilityClass public final class AuctionCreator { + public static final UUID SERVER_AUCTION_UUID = UUID.fromString("00000000-0000-0000-0000-000000000000"); + public static final String SERVER_LISTING_NAME = AuctionHouse.getInstance().getLocale().getMessage("general.server listing").getMessage(); + + public void create(final AuctionPlayer auctionPlayer, @NonNull final AuctionedItem auctionItem, @NonNull final BiConsumer result) { final AtomicReference status = new AtomicReference<>(SUCCESS); if (!auctionItem.isServerItem() && auctionPlayer == null) { @@ -120,9 +124,10 @@ public final class AuctionCreator { } // final item adjustments - if (auctionItem.getListedWorld() == null) + if (auctionItem.getListedWorld() == null && seller != null) auctionItem.setListedWorld(seller.getWorld().getName()); + AuctionStartEvent startEvent = new AuctionStartEvent(seller, auctionItem, listingFee); if (Bukkit.isPrimaryThread()) @@ -136,18 +141,23 @@ public final class AuctionCreator { } // 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.setOwner(SERVER_AUCTION_UUID); auctionItem.setOwnerName(SERVER_LISTING_NAME); + + auctionItem.setHighestBidder(SERVER_AUCTION_UUID); + auctionItem.setHighestBidderName(SERVER_LISTING_NAME); } //==================================================================================== // 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()); + if (seller != null) + SoundManager.getInstance().playSound(seller, Settings.SOUNDS_LISTED_ITEM_ON_AUCTION_HOUSE.getString()); + + 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()) @@ -156,13 +166,15 @@ public final class AuctionCreator { .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 (seller != null && !auctionItem.isServerItem()) { + 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); + if (AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(seller.getUniqueId()).isShowListingInfo()) { + AuctionHouse.getInstance().getLocale().newMessage(msg).sendPrefixedMessage(seller); + } } //==================================================================================== @@ -176,20 +188,23 @@ public final class AuctionCreator { if (Settings.SHOW_LISTING_ERROR_IN_CONSOLE.getBoolean()) error.printStackTrace(); - instance.getLocale().getMessage("general.something_went_wrong_while_listing").sendPrefixedMessage(seller); - ItemStack originalCopy = auctionItem.getItem().clone(); - int totalOriginal = BundleUtil.isBundledItem(originalCopy) ? AuctionAPI.getInstance().getItemCountInPlayerInventory(seller, originalCopy) : originalCopy.getAmount(); + if (seller != null) { + instance.getLocale().getMessage("general.something_went_wrong_while_listing").sendPrefixedMessage(seller); - if (BundleUtil.isBundledItem(originalCopy)) { - originalCopy.setAmount(1); - for (int i = 0; i < totalOriginal; i++) PlayerUtils.giveItem(seller, originalCopy); - } else { - originalCopy.setAmount(totalOriginal); - PlayerUtils.giveItem(seller, originalCopy); + ItemStack originalCopy = auctionItem.getItem().clone(); + int totalOriginal = BundleUtil.isBundledItem(originalCopy) ? AuctionAPI.getInstance().getItemCountInPlayerInventory(seller, originalCopy) : originalCopy.getAmount(); + + if (BundleUtil.isBundledItem(originalCopy)) { + 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() && !auctionItem.isServerItem()) { + if (Settings.TAX_ENABLED.getBoolean() && Settings.TAX_CHARGE_LISTING_FEE.getBoolean() && !auctionItem.isServerItem() && seller != null) { if (Settings.STORE_PAYMENTS_FOR_MANUAL_COLLECTION.getBoolean()) AuctionHouse.getInstance().getDataManager().insertAuctionPayment(new AuctionPayment( seller.getUniqueId(), @@ -217,16 +232,16 @@ public final class AuctionCreator { 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)) + .processPlaceholder("player", auctionItem.isServerItem() ? SERVER_LISTING_NAME : seller.getName()) + .processPlaceholder("player_displayname", auctionItem.isServerItem() ? SERVER_LISTING_NAME : 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)); + if (seller != null && p.getUniqueId().equals(seller.getUniqueId())) return; + p.sendMessage(TextUtils.formatText((prefix.length() == 0 ? "" : prefix + " ") + msgToAll)); }); } //==================================================================================== diff --git a/src/main/java/ca/tweetzy/auctionhouse/helpers/DiscordMessageCreator.java b/src/main/java/ca/tweetzy/auctionhouse/helpers/DiscordMessageCreator.java index ad8e60d..41032be 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/helpers/DiscordMessageCreator.java +++ b/src/main/java/ca/tweetzy/auctionhouse/helpers/DiscordMessageCreator.java @@ -59,7 +59,7 @@ public final class DiscordMessageCreator { return new DiscordMessageCreator(webhook, messageType); } - public DiscordMessageCreator seller(@NonNull final OfflinePlayer seller) { + public DiscordMessageCreator seller(final OfflinePlayer seller) { this.seller = seller; return this; } @@ -88,7 +88,7 @@ public final class DiscordMessageCreator { final DiscordWebhook hook = generateBaseHook(); DiscordWebhook.EmbedObject embed = generateBaseEmbed(); - embed.addField(Settings.DISCORD_MSG_FIELD_SELLER_NAME.getString(), Settings.DISCORD_MSG_FIELD_SELLER_VALUE.getString().replace("%seller%", this.seller.getName()), Settings.DISCORD_MSG_FIELD_SELLER_INLINE.getBoolean()); + embed.addField(Settings.DISCORD_MSG_FIELD_SELLER_NAME.getString(), Settings.DISCORD_MSG_FIELD_SELLER_VALUE.getString().replace("%seller%", this.listing.isServerItem() ? AuctionCreator.SERVER_LISTING_NAME : this.seller.getName()), Settings.DISCORD_MSG_FIELD_SELLER_INLINE.getBoolean()); embed.addField(Settings.DISCORD_MSG_FIELD_ITEM_NAME.getString(), Settings.DISCORD_MSG_FIELD_ITEM_VALUE.getString().replace("%item_name%", "x" + this.listing.getItem().getAmount() + " " + ChatColor.stripColor(ItemUtil.getItemName(this.listing.getItem()))), Settings.DISCORD_MSG_FIELD_SELLER_INLINE.getBoolean()); switch (this.messageType) { diff --git a/src/main/java/ca/tweetzy/auctionhouse/listeners/AuctionListeners.java b/src/main/java/ca/tweetzy/auctionhouse/listeners/AuctionListeners.java index 1df890d..30262ec 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/listeners/AuctionListeners.java +++ b/src/main/java/ca/tweetzy/auctionhouse/listeners/AuctionListeners.java @@ -51,7 +51,10 @@ public class AuctionListeners implements Listener { // new stat system final Player seller = e.getSeller(); final AuctionedItem auctionedItem = e.getAuctionItem(); - new AuctionStatistic(seller.getUniqueId(), auctionedItem.isBidItem() ? AuctionStatisticType.CREATED_AUCTION : AuctionStatisticType.CREATED_BIN, 1).store(null); + + // ignore if server item + if (!auctionedItem.isServerItem()) + new AuctionStatistic(seller.getUniqueId(), auctionedItem.isBidItem() ? AuctionStatisticType.CREATED_AUCTION : AuctionStatisticType.CREATED_BIN, 1).store(null); if (Settings.DISCORD_ENABLED.getBoolean()) { @@ -85,8 +88,12 @@ public class AuctionListeners implements Listener { final OfflinePlayer originalOwner = e.getOriginalOwner(), buyer = e.getBuyer(); final UUID originalOwnerUUID = originalOwner.getUniqueId(), buyerUUID = buyer.getUniqueId(); final AuctionedItem auctionedItem = e.getAuctionItem(); - new AuctionStatistic(originalOwnerUUID, auctionedItem.isBidItem() ? AuctionStatisticType.SOLD_AUCTION : AuctionStatisticType.SOLD_BIN, 1).store(null); - new AuctionStatistic(originalOwnerUUID, AuctionStatisticType.MONEY_EARNED, e.getSaleType() == AuctionSaleType.USED_BIDDING_SYSTEM ? auctionedItem.getCurrentPrice() : auctionedItem.getBasePrice()).store(null); + + if (!auctionedItem.isServerItem()) { + new AuctionStatistic(originalOwnerUUID, auctionedItem.isBidItem() ? AuctionStatisticType.SOLD_AUCTION : AuctionStatisticType.SOLD_BIN, 1).store(null); + new AuctionStatistic(originalOwnerUUID, AuctionStatisticType.MONEY_EARNED, e.getSaleType() == AuctionSaleType.USED_BIDDING_SYSTEM ? auctionedItem.getCurrentPrice() : auctionedItem.getBasePrice()).store(null); + } + new AuctionStatistic(buyerUUID, AuctionStatisticType.MONEY_SPENT, e.getSaleType() == AuctionSaleType.USED_BIDDING_SYSTEM ? auctionedItem.getCurrentPrice() : auctionedItem.getBasePrice()).store(null); AuctionHouse.newChain().async(() -> {