From e24b87180412fec866802083532ef20b4c6e3d46 Mon Sep 17 00:00:00 2001 From: Kiran Hart Date: Mon, 22 Mar 2021 23:13:09 -0400 Subject: [PATCH] transaction list, the ConfigurationItemHelper.java now replaces the title as well --- .../tweetzy/auctionhouse/api/AuctionAPI.java | 14 +++ .../auctionhouse/guis/GUIAuctionHouse.java | 20 +++-- .../guis/transaction/GUITransactionList.java | 85 +++++++++++++++++++ .../guis/transaction/GUITransactionView.java | 22 +++++ .../helpers/ConfigurationItemHelper.java | 5 ++ .../auctionhouse/settings/Settings.java | 24 ++++++ 6 files changed, 161 insertions(+), 9 deletions(-) create mode 100644 src/main/java/ca/tweetzy/auctionhouse/guis/transaction/GUITransactionList.java create mode 100644 src/main/java/ca/tweetzy/auctionhouse/guis/transaction/GUITransactionView.java diff --git a/src/main/java/ca/tweetzy/auctionhouse/api/AuctionAPI.java b/src/main/java/ca/tweetzy/auctionhouse/api/AuctionAPI.java index 3ad2696..a055939 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/api/AuctionAPI.java +++ b/src/main/java/ca/tweetzy/auctionhouse/api/AuctionAPI.java @@ -12,7 +12,9 @@ import java.awt.*; import java.io.*; import java.text.DecimalFormat; import java.text.NumberFormat; +import java.text.SimpleDateFormat; import java.util.Base64; +import java.util.Date; import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.TimeUnit; @@ -72,6 +74,18 @@ public class AuctionAPI { return vals; } + /** + * Used to convert milliseconds (usually System.currentMillis) into a readable date format + * + * @param milliseconds is the total milliseconds + * @return a readable date format + */ + public String convertMillisToDate(long milliseconds) { + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MMM dd, yyyy hh:mm aa"); + Date date = new Date(milliseconds); + return simpleDateFormat.format(date); + } + /** * Used to convert a serializable object into a base64 string * diff --git a/src/main/java/ca/tweetzy/auctionhouse/guis/GUIAuctionHouse.java b/src/main/java/ca/tweetzy/auctionhouse/guis/GUIAuctionHouse.java index 501e902..1b7f4cf 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/guis/GUIAuctionHouse.java +++ b/src/main/java/ca/tweetzy/auctionhouse/guis/GUIAuctionHouse.java @@ -2,6 +2,7 @@ package ca.tweetzy.auctionhouse.guis; import ca.tweetzy.auctionhouse.AuctionHouse; import ca.tweetzy.auctionhouse.auction.*; +import ca.tweetzy.auctionhouse.guis.transaction.GUITransactionList; import ca.tweetzy.auctionhouse.helpers.ConfigurationItemHelper; import ca.tweetzy.auctionhouse.managers.SoundManager; import ca.tweetzy.auctionhouse.settings.Settings; @@ -10,7 +11,6 @@ import ca.tweetzy.core.utils.TextUtils; import ca.tweetzy.core.utils.items.TItemBuilder; import org.bukkit.Bukkit; -import javax.security.auth.login.Configuration; import java.util.Comparator; import java.util.HashMap; import java.util.List; @@ -63,7 +63,7 @@ public class GUIAuctionHouse extends Gui { // Pagination pages = (int) Math.max(1, Math.ceil(this.items.size() / (double) 45)); setPrevPage(5, 3, new TItemBuilder(Objects.requireNonNull(Settings.GUI_BACK_BTN_ITEM.getMaterial().parseMaterial())).setName(Settings.GUI_BACK_BTN_NAME.getString()).setLore(Settings.GUI_BACK_BTN_LORE.getStringList()).toItemStack()); - setButton(5, 4, new TItemBuilder(Objects.requireNonNull(Settings.GUI_REFRESH_BTN_ITEM.getMaterial().parseMaterial())).setName(Settings.GUI_REFRESH_BTN_NAME.getString()).setLore(Settings.GUI_REFRESH_BTN_LORE.getStringList()).toItemStack(), e -> e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer))); + setButton(5, 4, new TItemBuilder(Objects.requireNonNull(Settings.GUI_REFRESH_BTN_ITEM.getMaterial().parseMaterial())).setName(Settings.GUI_REFRESH_BTN_NAME.getString()).setLore(Settings.GUI_REFRESH_BTN_LORE.getStringList()).toItemStack(), e -> e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer, this.filterCategory, this.filterAuctionType))); setNextPage(5, 5, new TItemBuilder(Objects.requireNonNull(Settings.GUI_NEXT_BTN_ITEM.getMaterial().parseMaterial())).setName(Settings.GUI_NEXT_BTN_NAME.getString()).setLore(Settings.GUI_NEXT_BTN_LORE.getStringList()).toItemStack()); setOnPage(e -> { draw(); @@ -71,15 +71,15 @@ public class GUIAuctionHouse extends Gui { }); // Other Buttons - setButton(5, 0, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_AUCTION_HOUSE_ITEMS_YOUR_AUCTIONS_ITEM.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_YOUR_AUCTIONS_NAME.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_YOUR_AUCTIONS_LORE.getStringList(), new HashMap(){{ + setButton(5, 0, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_AUCTION_HOUSE_ITEMS_YOUR_AUCTIONS_ITEM.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_YOUR_AUCTIONS_NAME.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_YOUR_AUCTIONS_LORE.getStringList(), new HashMap() {{ put("%active_player_auctions%", auctionPlayer.getItems(false).size()); }}), e -> e.manager.showGUI(e.player, new GUIActiveAuctions(this.auctionPlayer))); - setButton(5, 1, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_AUCTION_HOUSE_ITEMS_COLLECTION_BIN_ITEM.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_COLLECTION_BIN_NAME.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_COLLECTION_BIN_LORE.getStringList(), new HashMap(){{ + setButton(5, 1, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_AUCTION_HOUSE_ITEMS_COLLECTION_BIN_ITEM.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_COLLECTION_BIN_NAME.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_COLLECTION_BIN_LORE.getStringList(), new HashMap() {{ put("%expired_player_auctions%", auctionPlayer.getItems(true).size()); }}), e -> e.manager.showGUI(e.player, new GUIExpiredItems(this.auctionPlayer))); - setButton(5, 2, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_AUCTION_HOUSE_ITEMS_FILTER_ITEM.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_FILTER_NAME.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_FILTER_LORE.getStringList(), new HashMap(){{ + setButton(5, 2, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_AUCTION_HOUSE_ITEMS_FILTER_ITEM.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_FILTER_NAME.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_FILTER_LORE.getStringList(), new HashMap() {{ put("%filter_category%", filterCategory.getType()); put("%filter_auction_type%", filterAuctionType.getType()); }}), e -> { @@ -94,7 +94,7 @@ public class GUIAuctionHouse extends Gui { break; case RIGHT: this.filterAuctionType = this.filterAuctionType.next(); - if (Settings.REFRESH_GUI_ON_FILTER_CHANGE.getBoolean()){ + if (Settings.REFRESH_GUI_ON_FILTER_CHANGE.getBoolean()) { e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer)); } else { draw(); @@ -103,7 +103,7 @@ public class GUIAuctionHouse extends Gui { } }); - setButton(5, 6, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_AUCTION_HOUSE_ITEMS_TRANSACTIONS_ITEM.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_TRANSACTIONS_NAME.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_TRANSACTIONS_LORE.getStringList(), null), null); + setButton(5, 6, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_AUCTION_HOUSE_ITEMS_TRANSACTIONS_ITEM.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_TRANSACTIONS_NAME.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_TRANSACTIONS_LORE.getStringList(), null), e -> e.manager.showGUI(e.player, new GUITransactionList(this.auctionPlayer))); setButton(5, 7, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_AUCTION_HOUSE_ITEMS_HOW_TO_SELL_ITEM.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_HOW_TO_SELL_NAME.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_HOW_TO_SELL_LORE.getStringList(), null), null); setButton(5, 8, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_AUCTION_HOUSE_ITEMS_GUIDE_ITEM.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_GUIDE_NAME.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_GUIDE_LORE.getStringList(), null), null); @@ -111,8 +111,10 @@ public class GUIAuctionHouse extends Gui { int slot = 0; List data = this.items.stream().sorted(Comparator.comparingInt(AuctionItem::getRemainingTime).reversed()).skip((page - 1) * 45L).limit(45).collect(Collectors.toList()); // Apply any filtering, there is probably a cleaner way of doing this, but I'm blanking - if (this.filterCategory != AuctionItemCategory.ALL) data = data.stream().filter(item -> item.getCategory() == this.filterCategory).collect(Collectors.toList()); - if (this.filterAuctionType != AuctionSaleType.BOTH) data = data.stream().filter(item -> this.filterAuctionType == AuctionSaleType.USED_BIDDING_SYSTEM ? item.getBidStartPrice() >= Settings.MIN_AUCTION_START_PRICE.getDouble() : item.getBidStartPrice() <= 0).collect(Collectors.toList()); + if (this.filterCategory != AuctionItemCategory.ALL) + data = data.stream().filter(item -> item.getCategory() == this.filterCategory).collect(Collectors.toList()); + if (this.filterAuctionType != AuctionSaleType.BOTH) + data = data.stream().filter(item -> this.filterAuctionType == AuctionSaleType.USED_BIDDING_SYSTEM ? item.getBidStartPrice() >= Settings.MIN_AUCTION_START_PRICE.getDouble() : item.getBidStartPrice() <= 0).collect(Collectors.toList()); for (AuctionItem auctionItem : data) { setButton(slot++, auctionItem.getDisplayStack(AuctionStackType.MAIN_AUCTION_HOUSE), e -> { diff --git a/src/main/java/ca/tweetzy/auctionhouse/guis/transaction/GUITransactionList.java b/src/main/java/ca/tweetzy/auctionhouse/guis/transaction/GUITransactionList.java new file mode 100644 index 0000000..d322a06 --- /dev/null +++ b/src/main/java/ca/tweetzy/auctionhouse/guis/transaction/GUITransactionList.java @@ -0,0 +1,85 @@ +package ca.tweetzy.auctionhouse.guis.transaction; + +import ca.tweetzy.auctionhouse.AuctionHouse; +import ca.tweetzy.auctionhouse.api.AuctionAPI; +import ca.tweetzy.auctionhouse.auction.AuctionPlayer; +import ca.tweetzy.auctionhouse.guis.GUIAuctionHouse; +import ca.tweetzy.auctionhouse.helpers.ConfigurationItemHelper; +import ca.tweetzy.auctionhouse.managers.SoundManager; +import ca.tweetzy.auctionhouse.settings.Settings; +import ca.tweetzy.auctionhouse.transaction.Transaction; +import ca.tweetzy.core.gui.Gui; +import ca.tweetzy.core.utils.TextUtils; +import ca.tweetzy.core.utils.items.TItemBuilder; +import org.bukkit.Bukkit; + +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + +/** + * The current file has been created by Kiran Hart + * Date Created: March 22 2021 + * Time Created: 7:03 p.m. + * Usage of any code found within this class is prohibited unless given explicit permission otherwise + */ +public class GUITransactionList extends Gui { + + final List transactions; + final AuctionPlayer auctionPlayer; + + private boolean showOwnOnly; + + public GUITransactionList(AuctionPlayer auctionPlayer) { + this.auctionPlayer = auctionPlayer; + this.transactions = AuctionHouse.getInstance().getTransactionManager().getTransactions(); + this.showOwnOnly = false; + setTitle(TextUtils.formatText(Settings.GUI_TRANSACTIONS_TITLE.getString())); + setRows(6); + setAcceptsItems(false); + draw(); + } + + private void draw() { + reset(); + + // Pagination + pages = (int) Math.max(1, Math.ceil(this.transactions.size() / (double) 45)); + setPrevPage(5, 3, new TItemBuilder(Objects.requireNonNull(Settings.GUI_BACK_BTN_ITEM.getMaterial().parseMaterial())).setName(Settings.GUI_BACK_BTN_NAME.getString()).setLore(Settings.GUI_BACK_BTN_LORE.getStringList()).toItemStack()); + setButton(5, 4, new TItemBuilder(Objects.requireNonNull(Settings.GUI_REFRESH_BTN_ITEM.getMaterial().parseMaterial())).setName(Settings.GUI_REFRESH_BTN_NAME.getString()).setLore(Settings.GUI_REFRESH_BTN_LORE.getStringList()).toItemStack(), e -> e.manager.showGUI(e.player, new GUITransactionList(this.auctionPlayer))); + setNextPage(5, 5, new TItemBuilder(Objects.requireNonNull(Settings.GUI_NEXT_BTN_ITEM.getMaterial().parseMaterial())).setName(Settings.GUI_NEXT_BTN_NAME.getString()).setLore(Settings.GUI_NEXT_BTN_LORE.getStringList()).toItemStack()); + setOnPage(e -> { + draw(); + SoundManager.getInstance().playSound(this.auctionPlayer.getPlayer(), Settings.SOUNDS_NAVIGATE_GUI_PAGES.getString(), 1.0F, 1.0F); + }); + + // Other Buttons + setButton(5, 0, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_CLOSE_BTN_ITEM.getString(), Settings.GUI_CLOSE_BTN_NAME.getString(), Settings.GUI_CLOSE_BTN_LORE.getStringList(), null), e -> e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer))); + setButton(5, 1, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_TRANSACTIONS_ITEM_TOGGLE_OWN_ITEM.getString(), Settings.GUI_TRANSACTIONS_ITEM_TOGGLE_OWN_NAME.getString(), Settings.GUI_TRANSACTIONS_ITEM_TOGGLE_OWN_LORE.getStringList(), null), e -> { + this.showOwnOnly = !this.showOwnOnly; + draw(); + }); + + if (this.showOwnOnly) { + highlightItem(5, 1); + } else { + removeHighlight(5, 1); + } + + int slot = 0; + List data = this.transactions.stream().sorted(Comparator.comparingLong(Transaction::getTransactionTime).reversed()).skip((page - 1) * 45L).limit(45).collect(Collectors.toList()); + if (this.showOwnOnly) + data = data.stream().filter(transaction -> transaction.getSeller().equals(this.auctionPlayer.getPlayer().getUniqueId())).collect(Collectors.toList()); + + for (Transaction transaction : data) { + setButton(slot++, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_TRANSACTIONS_ITEM_TRANSACTION_ITEM.getString(), 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("%buyer%", Bukkit.getOfflinePlayer(transaction.getBuyer()).getName()); + put("%date%", AuctionAPI.getInstance().convertMillisToDate(transaction.getTransactionTime())); + }}), e -> e.manager.showGUI(e.player, new GUITransactionView(this.auctionPlayer, transaction))); + } + } +} diff --git a/src/main/java/ca/tweetzy/auctionhouse/guis/transaction/GUITransactionView.java b/src/main/java/ca/tweetzy/auctionhouse/guis/transaction/GUITransactionView.java new file mode 100644 index 0000000..2d30d52 --- /dev/null +++ b/src/main/java/ca/tweetzy/auctionhouse/guis/transaction/GUITransactionView.java @@ -0,0 +1,22 @@ +package ca.tweetzy.auctionhouse.guis.transaction; + +import ca.tweetzy.auctionhouse.auction.AuctionPlayer; +import ca.tweetzy.auctionhouse.transaction.Transaction; +import ca.tweetzy.core.gui.Gui; + +/** + * The current file has been created by Kiran Hart + * Date Created: March 22 2021 + * Time Created: 7:04 p.m. + * Usage of any code found within this class is prohibited unless given explicit permission otherwise + */ +public class GUITransactionView extends Gui { + + final AuctionPlayer auctionPlayer; + final Transaction transaction; + + public GUITransactionView(AuctionPlayer auctionPlayer, Transaction transaction) { + this.auctionPlayer = auctionPlayer; + this.transaction = transaction; + } +} diff --git a/src/main/java/ca/tweetzy/auctionhouse/helpers/ConfigurationItemHelper.java b/src/main/java/ca/tweetzy/auctionhouse/helpers/ConfigurationItemHelper.java index a92a9df..ab2152c 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/helpers/ConfigurationItemHelper.java +++ b/src/main/java/ca/tweetzy/auctionhouse/helpers/ConfigurationItemHelper.java @@ -23,6 +23,10 @@ public class ConfigurationItemHelper { meta.setDisplayName(TextUtils.formatText(title)); if (replacements != null) { + for (String key : replacements.keySet()) { + if (title.contains(key)) title = title.replace(key, String.valueOf(replacements.get(key))); + } + for (int i = 0; i < lore.size(); i++) { for (String key : replacements.keySet()) { if (lore.get(i).contains(key)) { @@ -32,6 +36,7 @@ public class ConfigurationItemHelper { } } + meta.setDisplayName(TextUtils.formatText(title)); meta.setLore(lore.stream().map(TextUtils::formatText).collect(Collectors.toList())); stack.setItemMeta(meta); return stack; diff --git a/src/main/java/ca/tweetzy/auctionhouse/settings/Settings.java b/src/main/java/ca/tweetzy/auctionhouse/settings/Settings.java index 342e4cc..c6a04db 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/settings/Settings.java +++ b/src/main/java/ca/tweetzy/auctionhouse/settings/Settings.java @@ -226,6 +226,30 @@ public class Settings { "&7Click here to claim all of your expired auctions" )); + /* =============================== + * TRANSACTIONS LIST GUI + * ===============================*/ + public static final ConfigSetting GUI_TRANSACTIONS_TITLE = new ConfigSetting(config, "gui.transactions.title", "&7Transaction History"); + + public static final ConfigSetting GUI_TRANSACTIONS_ITEM_TOGGLE_OWN_ITEM = new ConfigSetting(config, "gui.transactions.items.toggle own.item", "NETHER_STAR"); + public static final ConfigSetting GUI_TRANSACTIONS_ITEM_TOGGLE_OWN_NAME = new ConfigSetting(config, "gui.transactions.items.toggle own.name", "&e<oggle Your Transactions"); + public static final ConfigSetting GUI_TRANSACTIONS_ITEM_TOGGLE_OWN_LORE = new ConfigSetting(config, "gui.transactions.items.toggle own.lore", Arrays.asList( + "&7Click to toggle whether you see", + "&7only your transactions or all", + "&7the transactions ever made." + )); + + public static final ConfigSetting GUI_TRANSACTIONS_ITEM_TRANSACTION_ITEM = new ConfigSetting(config, "gui.transactions.items.transaction.item", "PAPER"); + public static final ConfigSetting GUI_TRANSACTIONS_ITEM_TRANSACTION_NAME = new ConfigSetting(config, "gui.transactions.items.transaction.name", "&e%transaction_id%"); + public static final ConfigSetting GUI_TRANSACTIONS_ITEM_TRANSACTION_LORE = new ConfigSetting(config, "gui.transactions.items.transaction.lore", Arrays.asList( + "&7Seller&F: &e%seller%", + "&7Buyer&F: &e%buyer%", + "&7Date&F: &e%date%", + "", + "&7Click to view more details" + )); + + /* =============================== * AUCTION STACKS * ===============================*/