diff --git a/src/main/java/ca/tweetzy/auctionhouse/api/AuctionAPI.java b/src/main/java/ca/tweetzy/auctionhouse/api/AuctionAPI.java index 84f19aa..7222e40 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/api/AuctionAPI.java +++ b/src/main/java/ca/tweetzy/auctionhouse/api/AuctionAPI.java @@ -221,7 +221,6 @@ public class AuctionAPI { YamlConfiguration config = new YamlConfiguration(); config.set("i", itemStack); return config.saveToString(); -// return DatatypeConverter.printBase64Binary(config.saveToString().getBytes(StandardCharsets.UTF_8)); } public static ItemStack decodeItem(String string) { @@ -581,7 +580,7 @@ public class AuctionAPI { Objects.requireNonNull(items, "Cannot create a bundled item with no items"); ItemStack item = QuickItem .of(Settings.ITEM_BUNDLE_ITEM.getString()) - .name(Settings.ITEM_BUNDLE_NAME.getString()) + .name(Replacer.replaceVariables(Settings.ITEM_BUNDLE_NAME.getString(),"item_name", getItemName(baseItem))) .lore(Replacer.replaceVariables(Settings.ITEM_BUNDLE_LORE.getStringList(), "item_name", getItemName(baseItem))) .make(); diff --git a/src/main/java/ca/tweetzy/auctionhouse/database/DataManager.java b/src/main/java/ca/tweetzy/auctionhouse/database/DataManager.java index 679c282..22ed3b1 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/database/DataManager.java +++ b/src/main/java/ca/tweetzy/auctionhouse/database/DataManager.java @@ -31,6 +31,7 @@ import ca.tweetzy.auctionhouse.transaction.TransactionViewFilter; import ca.tweetzy.flight.database.*; import lombok.NonNull; import org.bukkit.Bukkit; +import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; @@ -261,7 +262,10 @@ public class DataManager extends DataManagerAbstract { try (PreparedStatement statement = connection.prepareStatement("SELECT * FROM " + this.getTablePrefix() + "transactions")) { ResultSet resultSet = statement.executeQuery(); while (resultSet.next()) { - transactions.add(extractTransaction(resultSet)); + + final Transaction transaction = extractTransaction(resultSet); + if (transaction != null) + transactions.add(transaction); } callback.accept(null, transactions); @@ -291,7 +295,10 @@ public class DataManager extends DataManagerAbstract { if (callback != null) { ResultSet res = fetch.executeQuery(); res.next(); - callback.accept(null, extractTransaction(res)); + + final Transaction inserted = extractTransaction(res); + + callback.accept(null, inserted); } } catch (Exception e) { @@ -539,21 +546,37 @@ public class DataManager extends DataManagerAbstract { public void insertAuctionPlayer(AuctionPlayer auctionPlayer, Callback callback) { this.runAsync(() -> this.databaseConnector.connect(connection -> { - try (PreparedStatement statement = connection.prepareStatement("INSERT INTO " + getTablePrefix() + "player (uuid, filter_sale_type, filter_item_category, filter_sort_type, last_listed_item) VALUES (?, ?, ?, ?, ?)")) { - PreparedStatement fetch = connection.prepareStatement("SELECT * FROM " + this.getTablePrefix() + "player WHERE uuid = ?"); + try (PreparedStatement statement = connection.prepareStatement( + "INSERT INTO " + getTablePrefix() + "player (uuid, filter_sale_type, filter_item_category, filter_sort_type, last_listed_item) VALUES (?,?,?,?,?)" + )) { + PreparedStatement fetch = connection.prepareStatement( + "SELECT * FROM " + this.getTablePrefix() + "player WHERE uuid =?" + ); + // Set parameters for the fetch query fetch.setString(1, auctionPlayer.getUuid().toString()); - statement.setString(1, auctionPlayer.getPlayer().getUniqueId().toString()); - statement.setString(2, auctionPlayer.getSelectedSaleType().name()); - statement.setString(3, auctionPlayer.getSelectedFilter().name()); - statement.setString(4, auctionPlayer.getAuctionSortType().name()); - statement.setLong(5, auctionPlayer.getLastListedItem()); - statement.executeUpdate(); - if (callback != null) { - ResultSet res = fetch.executeQuery(); - res.next(); - callback.accept(null, extractAuctionPlayer(res)); + // Execute the fetch query + ResultSet res = fetch.executeQuery(); + + // Check if the UUID already exists + if (!res.next()) { + // UUID does not exist, proceed with insertion + statement.setString(1, auctionPlayer.getPlayer().getUniqueId().toString()); + statement.setString(2, auctionPlayer.getSelectedSaleType().name()); + statement.setString(3, auctionPlayer.getSelectedFilter().name()); + statement.setString(4, auctionPlayer.getAuctionSortType().name()); + statement.setLong(5, auctionPlayer.getLastListedItem()); + statement.executeUpdate(); + + // After successful insertion, call the callback with the newly inserted player + if (callback != null) { + AuctionPlayer insertedPlayer = extractAuctionPlayer(res); + callback.accept(null, insertedPlayer); + } + } else { + // UUID already exists, handle accordingly (e.g., log, notify) + System.out.println("UUID already exists, skipping insertion."); } } catch (Exception e) { diff --git a/src/main/java/ca/tweetzy/auctionhouse/helpers/AuctionCreator.java b/src/main/java/ca/tweetzy/auctionhouse/helpers/AuctionCreator.java index a9ebd4d..50317fb 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/helpers/AuctionCreator.java +++ b/src/main/java/ca/tweetzy/auctionhouse/helpers/AuctionCreator.java @@ -31,6 +31,7 @@ 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.utils.Common; import lombok.NonNull; import lombok.experimental.UtilityClass; import org.bukkit.Bukkit; diff --git a/src/main/java/ca/tweetzy/auctionhouse/helpers/discord/DiscordMessageCreator.java b/src/main/java/ca/tweetzy/auctionhouse/helpers/discord/DiscordMessageCreator.java index d8d0386..2d9f85c 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/helpers/discord/DiscordMessageCreator.java +++ b/src/main/java/ca/tweetzy/auctionhouse/helpers/discord/DiscordMessageCreator.java @@ -90,7 +90,7 @@ public final class DiscordMessageCreator { DiscordWebhook.EmbedObject embed = generateBaseEmbed(); 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(Settings.FORCE_MATERIAL_NAMES_FOR_DISCORD.getBoolean() ? ChatUtil.capitalize(this.listing.getItem().getType()) : ItemUtil.getItemName(this.listing.getItem()))), 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(Settings.FORCE_MATERIAL_NAMES_FOR_DISCORD.getBoolean() ? ChatUtil.capitalize(this.listing.getItem().getType()) : ItemUtil.getItemName(this.listing.getItem()))), Settings.DISCORD_MSG_FIELD_ITEM_INLINE.getBoolean()); switch (this.messageType) { case NEW_AUCTION_LISTING: