🗃️ transactions filter options

Took 24 minutes
This commit is contained in:
Kiran Hart 2023-06-20 19:30:17 -04:00
parent 0040ae890b
commit ff715baacc
No known key found for this signature in database
GPG Key ID: 5F36C7BC79D3EBC3
5 changed files with 134 additions and 32 deletions

View File

@ -52,6 +52,12 @@ public class AuctionPlayer {
private AuctionItemCategory selectedFilter;
private AuctionSortType auctionSortType;
private String currentSearchPhrase;
private AuctionSaleType selectedTransactionSaleType;
private AuctionItemCategory selectedTransactionFilter;
private AuctionSortType transactionSortType;
private boolean showListingInfo;
private long lastListedItem;
@ -59,7 +65,7 @@ public class AuctionPlayer {
private int assignedTaskId;
public AuctionPlayer(UUID uuid) {
this(uuid, Bukkit.getPlayer(uuid), AuctionSaleType.BOTH, AuctionItemCategory.ALL, AuctionSortType.RECENT, "", true, -1, null, -1);
this(uuid, Bukkit.getPlayer(uuid), AuctionSaleType.BOTH, AuctionItemCategory.ALL, AuctionSortType.RECENT, "", AuctionSaleType.BOTH, AuctionItemCategory.ALL, AuctionSortType.RECENT, true, -1, null, -1);
}
public AuctionPlayer(Player player) {
@ -127,6 +133,12 @@ public class AuctionPlayer {
this.currentSearchPhrase = "";
}
public void resetTransactionFilter() {
this.selectedTransactionFilter = AuctionItemCategory.ALL;
this.transactionSortType = AuctionSortType.RECENT;
this.selectedTransactionSaleType = AuctionSaleType.BOTH;
}
public int getSellLimit() {
// fall back

View File

@ -29,28 +29,30 @@ import ca.tweetzy.auctionhouse.settings.Settings;
*/
public enum AuctionItemCategory {
ALL("All", false, Settings.ALL_FILTER_ENABLED.getBoolean()),
FOOD("Food", true, Settings.FOOD_FILTER_ENABLED.getBoolean()),
ARMOR("Armor", true, Settings.ARMOR_FILTER_ENABLED.getBoolean()),
BLOCKS("Blocks", true, Settings.BLOCKS_FILTER_ENABLED.getBoolean()),
TOOLS("Tools", true, Settings.TOOLS_FILTER_ENABLED.getBoolean()),
WEAPONS("Weapons", true, Settings.WEAPONS_FILTER_ENABLED.getBoolean()),
POTIONS("Potions", true, Settings.POTIONS_FILTER_ENABLED.getBoolean()),
SPAWNERS("Spawners", true, Settings.SPAWNERS_FILTER_ENABLED.getBoolean()),
ENCHANTS("Enchants", true, Settings.ENCHANTS_FILTER_ENABLED.getBoolean()),
MISC("Misc", true, Settings.MISC_FILTER_ENABLED.getBoolean()),
SEARCH("Search", false, Settings.SEARCH_FILTER_ENABLED.getBoolean()),
SELF("Self", false, Settings.SELF_FILTER_ENABLED.getBoolean());
ALL("All", false, Settings.ALL_FILTER_ENABLED.getBoolean(), true),
FOOD("Food", true, Settings.FOOD_FILTER_ENABLED.getBoolean(), true),
ARMOR("Armor", true, Settings.ARMOR_FILTER_ENABLED.getBoolean(), true),
BLOCKS("Blocks", true, Settings.BLOCKS_FILTER_ENABLED.getBoolean(), true),
TOOLS("Tools", true, Settings.TOOLS_FILTER_ENABLED.getBoolean(), true),
WEAPONS("Weapons", true, Settings.WEAPONS_FILTER_ENABLED.getBoolean(), true),
POTIONS("Potions", true, Settings.POTIONS_FILTER_ENABLED.getBoolean(), true),
SPAWNERS("Spawners", true, Settings.SPAWNERS_FILTER_ENABLED.getBoolean(), true),
ENCHANTS("Enchants", true, Settings.ENCHANTS_FILTER_ENABLED.getBoolean(), true),
MISC("Misc", true, Settings.MISC_FILTER_ENABLED.getBoolean(), true),
SEARCH("Search", false, Settings.SEARCH_FILTER_ENABLED.getBoolean(), false),
SELF("Self", false, Settings.SELF_FILTER_ENABLED.getBoolean(), false);
private final String type;
private final boolean whitelistAllowed;
private final boolean enabled;
private final boolean transactionFilterable;
AuctionItemCategory(String type, boolean whitelistAllowed, boolean enabled) {
AuctionItemCategory(String type, boolean whitelistAllowed, boolean enabled, boolean transactionFilterable) {
this.type = type;
this.whitelistAllowed = whitelistAllowed;
this.enabled = enabled;
this.transactionFilterable = transactionFilterable;
}
public String getType() {

View File

@ -691,6 +691,9 @@ public class DataManager extends DataManagerAbstract {
AuctionItemCategory.valueOf(resultSet.getString("filter_item_category")),
AuctionSortType.valueOf(resultSet.getString("filter_sort_type")),
"",
AuctionSaleType.BOTH,
AuctionItemCategory.ALL,
AuctionSortType.RECENT,
true,
resultSet.getLong("last_listed_item"),
null,

View File

@ -21,15 +21,20 @@ 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.auction.enums.AuctionItemCategory;
import ca.tweetzy.auctionhouse.auction.enums.AuctionSaleType;
import ca.tweetzy.auctionhouse.auction.enums.AuctionSortType;
import ca.tweetzy.auctionhouse.guis.AbstractPlaceholderGui;
import ca.tweetzy.auctionhouse.guis.GUIAuctionHouse;
import ca.tweetzy.auctionhouse.helpers.ConfigurationItemHelper;
import ca.tweetzy.auctionhouse.helpers.MaterialCategorizer;
import ca.tweetzy.auctionhouse.settings.Settings;
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.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
@ -46,7 +51,7 @@ import java.util.stream.Collectors;
*/
public class GUITransactionList extends AbstractPlaceholderGui {
final List<Transaction> transactions;
List<Transaction> transactions;
final AuctionPlayer auctionPlayer;
final Player player;
final boolean showAll;
@ -63,6 +68,7 @@ public class GUITransactionList extends AbstractPlaceholderGui {
else
this.transactions = instance.getTransactionManager().getTransactions().values().stream().filter(transaction -> transaction.getSeller().equals(player.getUniqueId()) || transaction.getBuyer().equals(player.getUniqueId())).collect(Collectors.toList());
setTitle(TextUtils.formatText(showAll ? Settings.GUI_TRANSACTIONS_TITLE_ALL.getString() : Settings.GUI_TRANSACTIONS_TITLE.getString()));
setRows(6);
setAcceptsItems(false);
@ -73,11 +79,51 @@ public class GUITransactionList extends AbstractPlaceholderGui {
private void draw() {
reset();
pages = (int) Math.max(1, Math.ceil(this.transactions.size() / (double) 45));
setPrevPage(5, 3, getPreviousPageItem());
setButton(5, 4, getRefreshButtonItem(), e -> e.manager.showGUI(e.player, new GUITransactionList(this.player, this.showAll)));
setNextPage(5, 5, getNextPageItem());
setOnPage(e -> draw());
AuctionHouse.newChain().asyncFirst(() -> {
// perform filter
if (this.auctionPlayer.getSelectedTransactionFilter() != AuctionItemCategory.ALL && this.auctionPlayer.getSelectedTransactionFilter() != AuctionItemCategory.SEARCH && this.auctionPlayer.getSelectedTransactionFilter() != AuctionItemCategory.SELF) {
this.transactions = this.transactions.stream().filter(item -> MaterialCategorizer.getMaterialCategory(item.getItem()) == this.auctionPlayer.getSelectedTransactionFilter()).collect(Collectors.toList());
}
if (this.auctionPlayer.getSelectedTransactionSaleType() == AuctionSaleType.USED_BIDDING_SYSTEM) {
this.transactions = this.transactions.stream().filter(transaction -> transaction.getAuctionSaleType() == AuctionSaleType.USED_BIDDING_SYSTEM).collect(Collectors.toList());
}
if (this.auctionPlayer.getSelectedTransactionSaleType() == AuctionSaleType.WITHOUT_BIDDING_SYSTEM) {
this.transactions = this.transactions.stream().filter(transaction -> transaction.getAuctionSaleType() == AuctionSaleType.WITHOUT_BIDDING_SYSTEM).collect(Collectors.toList());
}
if (this.auctionPlayer.getTransactionSortType() == AuctionSortType.PRICE) {
this.transactions = this.transactions.stream().sorted(Comparator.comparingDouble(Transaction::getFinalPrice).reversed()).collect(Collectors.toList());
}
if (this.auctionPlayer.getTransactionSortType() == AuctionSortType.RECENT) {
this.transactions = this.transactions.stream().sorted(Comparator.comparingLong(Transaction::getTransactionTime).reversed()).collect(Collectors.toList());
}
return this.transactions.stream().skip((page - 1) * 45L).limit(45).collect(Collectors.toList());
}).asyncLast((data) -> {
pages = (int) Math.max(1, Math.ceil(this.transactions.size() / (double) 45L));
setPrevPage(5, 3, getPreviousPageItem());
setButton(5, 4, getRefreshButtonItem(), e -> e.manager.showGUI(e.player, new GUITransactionList(this.player, this.showAll)));
setNextPage(5, 5, getNextPageItem());
setOnPage(e -> draw());
int slot = 0;
for (Transaction transaction : data) {
final ItemStack item = transaction.getItem().clone();
setButton(slot++, ConfigurationItemHelper.createConfigurationItem(this.player, item, 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()));
put("%item_name%", AuctionAPI.getInstance().getItemName(item));
}}), e -> e.manager.showGUI(e.player, new GUITransactionView(this.auctionPlayer, transaction, this.showAll)));
}
}).execute();
// Other Buttons
setButton(5, 0, getBackButtonItem(), e -> {
@ -88,18 +134,43 @@ public class GUITransactionList extends AbstractPlaceholderGui {
}
});
int slot = 0;
List<Transaction> data = this.transactions.stream().sorted(Comparator.comparingLong(Transaction::getTransactionTime).reversed()).skip((page - 1) * 45L).limit(45).collect(Collectors.toList());
setButton(Settings.GUI_TRANSACTIONS_ITEMS_FILTER_SLOT.getInt(), ConfigurationItemHelper.createConfigurationItem(
this.player,
Settings.GUI_TRANSACTIONS_ITEMS_FILTER_ITEM.getString(),
Settings.GUI_TRANSACTIONS_ITEMS_FILTER_NAME.getString(),
Settings.GUI_TRANSACTIONS_ITEMS_FILTER_LORE.getStringList(),
new HashMap<String, Object>(){{
put("%filter_category%", auctionPlayer.getSelectedTransactionFilter().getTranslatedType());
put("%filter_auction_type%", auctionPlayer.getSelectedTransactionSaleType().getTranslatedType());
put("%filter_sort_order%", auctionPlayer.getTransactionSortType().getTranslatedType());
}}
), click -> {
for (Transaction transaction : data) {
final ItemStack item = transaction.getItem().clone();
setButton(slot++, ConfigurationItemHelper.createConfigurationItem(this.player, item, 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()));
put("%item_name%", AuctionAPI.getInstance().getItemName(item));
}}), e -> e.manager.showGUI(e.player, new GUITransactionView(this.auctionPlayer, transaction, this.showAll)));
}
if (click.clickType == ClickType.valueOf(Settings.CLICKS_FILTER_CATEGORY.getString().toUpperCase())) {
this.auctionPlayer.setSelectedTransactionFilter(this.auctionPlayer.getSelectedTransactionFilter().next());
draw();
}
if (click.clickType == ClickType.valueOf(Settings.CLICKS_FILTER_RESET.getString().toUpperCase())) {
this.auctionPlayer.resetTransactionFilter();
click.manager.showGUI(click.player, new GUITransactionList(click.player, this.showAll));
return;
}
if (click.clickType == ClickType.valueOf(Settings.CLICKS_FILTER_SORT_SALE_TYPE.getString().toUpperCase())) {
if (Settings.ALLOW_USAGE_OF_BID_SYSTEM.getBoolean()) {
this.auctionPlayer.setSelectedTransactionSaleType(this.auctionPlayer.getSelectedTransactionSaleType().next());
draw();
}
return;
}
if (click.clickType == ClickType.valueOf(Settings.CLICKS_FILTER_SORT_PRICE_OR_RECENT.getString().toUpperCase())) {
this.auctionPlayer.setTransactionSortType(this.auctionPlayer.getTransactionSortType().next());
draw();
}
});
}
}

View File

@ -786,6 +786,20 @@ public class Settings {
"&7Click to view more details"
));
public static final ConfigSetting GUI_TRANSACTIONS_ITEMS_FILTER_SLOT = new ConfigSetting(config, "gui.transactions.items.filter.slot", 47, "Valid Slots: 45 - 53");
public static final ConfigSetting GUI_TRANSACTIONS_ITEMS_FILTER_ITEM = new ConfigSetting(config, "gui.transactions.items.filter.item", "NETHER_STAR");
public static final ConfigSetting GUI_TRANSACTIONS_ITEMS_FILTER_NAME = new ConfigSetting(config, "gui.transactions.items.filter.name", "&e&lFilter Options");
public static final ConfigSetting GUI_TRANSACTIONS_ITEMS_FILTER_LORE = new ConfigSetting(config, "gui.transactions.items.filter.lore", Arrays.asList(
"&eItem Category&f: &7%filter_category%",
"&eAuction Type&f: &7%filter_auction_type%",
"&eSort Order&f: &7%filter_sort_order%",
"",
"&7Left-Click to change item category",
"&7Right-Click to change change auction type",
"&7Shift Right-Click to change sort order",
"&7Press Drop to reset filters"
));
/* ===============================
* TRANSACTIONS VIEW GUI
* ===============================*/