Option to filter transactions by bought, sold, all

Took 18 minutes
This commit is contained in:
Kiran Hart 2023-09-20 15:44:06 -04:00
parent 356a4a30af
commit 7cf21d2758
No known key found for this signature in database
GPG Key ID: 5F36C7BC79D3EBC3
4 changed files with 78 additions and 2 deletions

View File

@ -24,6 +24,7 @@ import ca.tweetzy.auctionhouse.auction.enums.AuctionSaleType;
import ca.tweetzy.auctionhouse.auction.enums.AuctionSortType;
import ca.tweetzy.auctionhouse.helpers.BundleUtil;
import ca.tweetzy.auctionhouse.settings.Settings;
import ca.tweetzy.auctionhouse.transaction.TransactionViewFilter;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
@ -56,6 +57,7 @@ public class AuctionPlayer {
private AuctionSaleType selectedTransactionSaleType;
private AuctionItemCategory selectedTransactionFilter;
private AuctionSortType transactionSortType;
private TransactionViewFilter transactionViewFilter;
private boolean showListingInfo;
@ -65,7 +67,7 @@ public class AuctionPlayer {
private int assignedTaskId;
public AuctionPlayer(UUID uuid) {
this(uuid, Bukkit.getPlayer(uuid), AuctionSaleType.BOTH, AuctionItemCategory.ALL, AuctionSortType.RECENT, "", 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, TransactionViewFilter.ALL, true, -1, null, -1);
}
public AuctionPlayer(Player player) {

View File

@ -30,6 +30,7 @@ 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.auctionhouse.transaction.TransactionViewFilter;
import ca.tweetzy.core.compatibility.XSound;
import ca.tweetzy.core.utils.TextUtils;
import org.bukkit.Bukkit;
@ -94,6 +95,14 @@ public class GUITransactionList extends AbstractPlaceholderGui {
this.transactions = this.transactions.stream().filter(transaction -> transaction.getAuctionSaleType() == AuctionSaleType.WITHOUT_BIDDING_SYSTEM).collect(Collectors.toList());
}
if (this.auctionPlayer.getTransactionViewFilter() != TransactionViewFilter.ALL) {
if (this.auctionPlayer.getTransactionViewFilter() == TransactionViewFilter.BOUGHT)
this.transactions = this.transactions.stream().filter(transaction -> transaction.getBuyer().equals(this.player.getUniqueId())).collect(Collectors.toList());
if (this.auctionPlayer.getTransactionViewFilter() == TransactionViewFilter.SOLD)
this.transactions = this.transactions.stream().filter(transaction -> transaction.getSeller().equals(this.player.getUniqueId())).collect(Collectors.toList());
}
if (this.auctionPlayer.getTransactionSortType() == AuctionSortType.PRICE) {
this.transactions = this.transactions.stream().sorted(Comparator.comparingDouble(Transaction::getFinalPrice).reversed()).collect(Collectors.toList());
}
@ -121,7 +130,7 @@ public class GUITransactionList extends AbstractPlaceholderGui {
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%",seller.hasPlayedBefore() ? seller.getName() : SERVER_LISTING_NAME);
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));
@ -148,6 +157,7 @@ public class GUITransactionList extends AbstractPlaceholderGui {
put("%filter_category%", auctionPlayer.getSelectedTransactionFilter().getTranslatedType());
put("%filter_auction_type%", auctionPlayer.getSelectedTransactionSaleType().getTranslatedType());
put("%filter_sort_order%", auctionPlayer.getTransactionSortType().getTranslatedType());
put("%filter_buy_type%", auctionPlayer.getTransactionViewFilter().getTranslatedType());
}}
), click -> {
@ -172,6 +182,12 @@ public class GUITransactionList extends AbstractPlaceholderGui {
return;
}
if (click.clickType == ClickType.valueOf(Settings.CLICKS_FILTER_TRANSACTION_BUY_TYPE.getString().toUpperCase())) {
this.auctionPlayer.setTransactionViewFilter(this.auctionPlayer.getTransactionViewFilter().next());
click.manager.showGUI(click.player, new GUITransactionList(click.player, this.showAll));
return;
}
if (click.clickType == ClickType.valueOf(Settings.CLICKS_FILTER_SORT_PRICE_OR_RECENT.getString().toUpperCase())) {
this.auctionPlayer.setTransactionSortType(this.auctionPlayer.getTransactionSortType().next());
click.manager.showGUI(click.player, new GUITransactionList(click.player, this.showAll));

View File

@ -168,6 +168,11 @@ public class LocaleSettings {
languageNodes.put("auction_filter.sort_order.recent", "Recent");
languageNodes.put("auction_filter.sort_order.price", "Price");
languageNodes.put("transaction_filter.buy_type.sold", "Sold");
languageNodes.put("transaction_filter.buy_type.bought", "Bought");
languageNodes.put("transaction_filter.buy_type.all", "All");
languageNodes.put("auction_statistic.created_auction", "Created Auction");
languageNodes.put("auction_statistic.created_bin", "Created Bin");
languageNodes.put("auction_statistic.sold_auctions", "Sold Auctions");

View File

@ -0,0 +1,53 @@
/*
* Auction House
* Copyright 2023 Kiran Hart
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package ca.tweetzy.auctionhouse.transaction;
import ca.tweetzy.auctionhouse.AuctionHouse;
public enum TransactionViewFilter {
SOLD("Sold"), BOUGHT("Bought"), ALL("All");
final String type;
TransactionViewFilter(String type) {
this.type = type;
}
public String getTranslatedType() {
switch (this) {
case SOLD:
return AuctionHouse.getInstance().getLocale().getMessage("transaction_filter.buy_type.sold").getMessage();
case BOUGHT:
return AuctionHouse.getInstance().getLocale().getMessage("transaction_filter.buy_type.bought").getMessage();
case ALL:
return AuctionHouse.getInstance().getLocale().getMessage("transaction_filter.buy_type.all").getMessage();
default:
return getType();
}
}
public String getType() {
return type;
}
public TransactionViewFilter next() {
return values()[(this.ordinal() + 1) % values().length];
}
}