transaction list, the ConfigurationItemHelper.java now replaces the title as well

This commit is contained in:
Kiran Hart 2021-03-22 23:13:09 -04:00
parent 1c4e29e725
commit e24b871804
6 changed files with 161 additions and 9 deletions

View File

@ -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
*

View File

@ -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<String, Object>(){{
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<String, Object>() {{
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<String, Object>(){{
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<String, Object>() {{
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<String, Object>(){{
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<String, Object>() {{
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<AuctionItem> 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 -> {

View File

@ -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<Transaction> 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<Transaction> 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<String, Object>() {{
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)));
}
}
}

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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&LToggle 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
* ===============================*/