From 75b24c2b482a1c13211eb08b4d1118370f40b2e0 Mon Sep 17 00:00:00 2001 From: Kiran Hart Date: Fri, 3 May 2024 12:30:01 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=97=83=EF=B8=8F=20statistic=20menus=20mov?= =?UTF-8?q?ed=20to=20new=20template=20&=20combine=20target/self=20view=20i?= =?UTF-8?q?nto=20one?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Took 30 minutes --- .../auctionhouse/commands/CommandStats.java | 10 +- .../statistics/GUIStatisticLeaderboard.java | 109 +++++++----------- .../guis/statistics/GUIStatisticSelf.java | 84 -------------- .../guis/statistics/GUIStatisticTarget.java | 85 -------------- .../guis/statistics/GUIStatisticView.java | 88 ++++++++++++++ .../statistics/GUIStatisticViewSelect.java | 41 +++---- 6 files changed, 151 insertions(+), 266 deletions(-) delete mode 100644 src/main/java/ca/tweetzy/auctionhouse/guis/statistics/GUIStatisticSelf.java delete mode 100644 src/main/java/ca/tweetzy/auctionhouse/guis/statistics/GUIStatisticTarget.java create mode 100644 src/main/java/ca/tweetzy/auctionhouse/guis/statistics/GUIStatisticView.java diff --git a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandStats.java b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandStats.java index 73c68cc..0cda53a 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandStats.java +++ b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandStats.java @@ -20,7 +20,7 @@ package ca.tweetzy.auctionhouse.commands; import ca.tweetzy.auctionhouse.AuctionHouse; import ca.tweetzy.auctionhouse.auction.AuctionPlayer; -import ca.tweetzy.auctionhouse.guis.statistics.GUIStatisticTarget; +import ca.tweetzy.auctionhouse.guis.statistics.GUIStatisticView; import ca.tweetzy.auctionhouse.guis.statistics.GUIStatisticViewSelect; import ca.tweetzy.core.commands.AbstractCommand; import ca.tweetzy.core.utils.TextUtils; @@ -49,11 +49,13 @@ public class CommandStats extends AbstractCommand { if (CommandMiddleware.handle(player) == ReturnType.FAILURE) return ReturnType.FAILURE; final AuctionHouse instance = AuctionHouse.getInstance(); - final AuctionPlayer user = instance.getAuctionPlayerManager().getPlayer(player.getUniqueId()); + AuctionPlayer user = instance.getAuctionPlayerManager().getPlayer(player.getUniqueId()); if (user == null) { instance.getLocale().newMessage(TextUtils.formatText("&cCould not find auction player instance for&f: &e" + player.getName() + "&c creating one now.")).sendPrefixedMessage(Bukkit.getConsoleSender()); - instance.getAuctionPlayerManager().addPlayer(new AuctionPlayer(player)); + AuctionPlayer newAHPlayer = new AuctionPlayer(player); + user = newAHPlayer; + instance.getAuctionPlayerManager().addPlayer(newAHPlayer); } if (args.length == 0) { @@ -69,7 +71,7 @@ public class CommandStats extends AbstractCommand { } final AuctionPlayer targetAuctionPlayer = instance.getAuctionPlayerManager().getPlayer(target.getUniqueId()); - instance.getGuiManager().showGUI(player, new GUIStatisticTarget(user, targetAuctionPlayer)); + instance.getGuiManager().showGUI(player, new GUIStatisticView(user, targetAuctionPlayer)); return ReturnType.SUCCESS; } diff --git a/src/main/java/ca/tweetzy/auctionhouse/guis/statistics/GUIStatisticLeaderboard.java b/src/main/java/ca/tweetzy/auctionhouse/guis/statistics/GUIStatisticLeaderboard.java index 2b69b84..80f7684 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/guis/statistics/GUIStatisticLeaderboard.java +++ b/src/main/java/ca/tweetzy/auctionhouse/guis/statistics/GUIStatisticLeaderboard.java @@ -22,97 +22,72 @@ import ca.tweetzy.auctionhouse.AuctionHouse; import ca.tweetzy.auctionhouse.api.AuctionAPI; import ca.tweetzy.auctionhouse.auction.AuctionPlayer; import ca.tweetzy.auctionhouse.auction.enums.AuctionStatisticType; -import ca.tweetzy.auctionhouse.guis.AbstractPlaceholderGui; -import ca.tweetzy.auctionhouse.helpers.ConfigurationItemHelper; +import ca.tweetzy.auctionhouse.guis.abstraction.AuctionPagedGUI; import ca.tweetzy.auctionhouse.settings.Settings; -import ca.tweetzy.core.compatibility.XSound; +import ca.tweetzy.core.gui.events.GuiClickEvent; +import ca.tweetzy.flight.utils.Pair; +import ca.tweetzy.flight.utils.QuickItem; +import ca.tweetzy.flight.utils.Replacer; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.inventory.ItemStack; -import java.util.HashMap; +import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.Map; import java.util.UUID; import java.util.stream.Collectors; -public final class GUIStatisticLeaderboard extends AbstractPlaceholderGui { +public final class GUIStatisticLeaderboard extends AuctionPagedGUI> { private final AuctionPlayer auctionPlayer; private final AuctionStatisticType statisticType; - private Map statisticsMap; - public GUIStatisticLeaderboard(AuctionPlayer player, AuctionStatisticType statisticType) { - super(player); + super(new GUIStatisticViewSelect(player), player.getPlayer(), Settings.GUI_STATS_LEADERBOARD_TITLE.getString(), 6, new ArrayList<>()); this.auctionPlayer = player; this.statisticType = statisticType; - setTitle(Settings.GUI_STATS_LEADERBOARD_TITLE.getString()); - setDefaultItem(ConfigurationItemHelper.createConfigurationItem(this.player, Settings.GUI_STATS_LEADERBOARD_BG_ITEM.getString())); - setUseLockedCells(true); - setAcceptsItems(false); - setAllowDrops(false); - setRows(6); - setNavigateSound(XSound.matchXSound(Settings.SOUNDS_NAVIGATE_GUI_PAGES.getString()).orElse(XSound.ENTITY_BAT_TAKEOFF).parseSound()); + setDefaultItem(QuickItem.bg(QuickItem.of(Settings.GUI_STATS_LEADERBOARD_BG_ITEM.getString()).make())); draw(); } - private void draw() { - - AuctionHouse.newChain().asyncFirst(() -> { - this.statisticsMap = AuctionHouse.getInstance().getAuctionStatisticManager().getStatisticMap(this.statisticType) - .entrySet() - .stream() - .sorted(Map.Entry.comparingByValue().reversed()) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (a, b) -> b, LinkedHashMap::new)); - - - return this.statisticsMap.entrySet().stream().skip((page - 1) * 45L).limit(45L).collect(Collectors.toList()); - }).asyncLast((data) -> { - pages = (int) Math.max(1, Math.ceil(this.statisticsMap.size() / (double) 45L)); - drawPaginationButtons(); - - int slot = 0; - for (Map.Entry playerStat : data) { - final OfflinePlayer targetUser = Bukkit.getOfflinePlayer(playerStat.getKey()); - - final ItemStack head = AuctionAPI.getInstance().getPlayerHead(targetUser.getName()); - - setItem(slot++, ConfigurationItemHelper.createConfigurationItem(this.player, - head, - Settings.GUI_STATS_LEADERBOARD_ITEMS_PLAYER_NAME.getString(), - Settings.GUI_STATS_LEADERBOARD_ITEMS_PLAYER_LORE.getStringList(), - new HashMap() {{ - put("%player_name%", targetUser.getName() == null ? "&e&lUsername not found" : targetUser.getName()); - put("%auction_statistic_name%", statisticType.getTranslatedType()); - put("%auction_statistic_value%", AuctionAPI.getInstance().formatNumber(playerStat.getValue())); - }} - )); - } - }).execute(); - - setButton(5, 0, getBackButtonItem(), e -> { - e.manager.showGUI(e.player, new GUIStatisticViewSelect(this.auctionPlayer)); - }); - - drawStatisticTypeButton(); + @Override + protected void prePopulate() { + AuctionHouse.getInstance().getAuctionStatisticManager().getStatisticMap(this.statisticType) + .entrySet() + .stream() + .sorted(Map.Entry.comparingByValue().reversed()) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (a, b) -> b, LinkedHashMap::new)).forEach((key, value) -> this.items.add(new Pair<>(key, value))); } - private void drawPaginationButtons() { - setPrevPage(5, 3, getPreviousPageItem()); - setNextPage(5, 5, getNextPageItem()); - setOnPage(e -> draw()); + @Override + protected void drawFixed() { + applyBackExit(); + + setButton(5, 4, QuickItem.of(Settings.GUI_STATS_LEADERBOARD_ITEMS_STAT_ITEM.getString()) + .name(Settings.GUI_STATS_LEADERBOARD_ITEMS_STAT_NAME.getString()) + .lore(Replacer.replaceVariables(Settings.GUI_STATS_LEADERBOARD_ITEMS_STAT_LORE.getStringList(), "statistic_name", statisticType.getTranslatedType())) + .make(), click -> click.manager.showGUI(click.player, new GUIStatisticLeaderboard(this.auctionPlayer, this.statisticType.next()))); } - private void drawStatisticTypeButton() { - setButton(5, 4, ConfigurationItemHelper.createConfigurationItem(this.player, - Settings.GUI_STATS_LEADERBOARD_ITEMS_STAT_ITEM.getString(), - Settings.GUI_STATS_LEADERBOARD_ITEMS_STAT_NAME.getString(), - Settings.GUI_STATS_LEADERBOARD_ITEMS_STAT_LORE.getStringList(), new HashMap() {{ - put("%statistic_name%", statisticType.getTranslatedType()); - }}), click -> { + @Override + protected ItemStack makeDisplayItem(Pair entry) { + final OfflinePlayer targetUser = Bukkit.getOfflinePlayer(entry.getFirst()); + final ItemStack head = AuctionAPI.getInstance().getPlayerHead(targetUser.getName()); + + + return QuickItem + .of(head) + .name(Settings.GUI_STATS_LEADERBOARD_ITEMS_PLAYER_NAME.getString().replace("%player_name%", targetUser.getName() == null ? "&e&lUsername not found" : targetUser.getName())) + .lore(Replacer.replaceVariables(Settings.GUI_STATS_LEADERBOARD_ITEMS_PLAYER_LORE.getStringList(), + "player_name", targetUser.getName() == null ? "&e&lUsername not found" : targetUser.getName(), + "auction_statistic_name", statisticType.getTranslatedType(), + "auction_statistic_value", AuctionAPI.getInstance().formatNumber(entry.getSecond()) + )).make(); + } + + @Override + protected void onClick(Pair object, GuiClickEvent clickEvent) { - click.manager.showGUI(click.player, new GUIStatisticLeaderboard(this.auctionPlayer, this.statisticType.next())); - }); } } diff --git a/src/main/java/ca/tweetzy/auctionhouse/guis/statistics/GUIStatisticSelf.java b/src/main/java/ca/tweetzy/auctionhouse/guis/statistics/GUIStatisticSelf.java deleted file mode 100644 index 2f5d0ef..0000000 --- a/src/main/java/ca/tweetzy/auctionhouse/guis/statistics/GUIStatisticSelf.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Auction House - * Copyright 2018-2022 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 . - */ - -package ca.tweetzy.auctionhouse.guis.statistics; - -import ca.tweetzy.auctionhouse.AuctionHouse; -import ca.tweetzy.auctionhouse.api.AuctionAPI; -import ca.tweetzy.auctionhouse.auction.AuctionPlayer; -import ca.tweetzy.auctionhouse.auction.enums.AuctionStatisticType; -import ca.tweetzy.auctionhouse.guis.AbstractPlaceholderGui; -import ca.tweetzy.auctionhouse.helpers.ConfigurationItemHelper; -import ca.tweetzy.auctionhouse.settings.Settings; - -import java.util.HashMap; - -public final class GUIStatisticSelf extends AbstractPlaceholderGui { - - private final AuctionPlayer auctionPlayer; - - public GUIStatisticSelf(AuctionPlayer player) { - super(player); - this.auctionPlayer = player; - setTitle(Settings.GUI_STATS_SELF_TITLE.getString()); - setDefaultItem(ConfigurationItemHelper.createConfigurationItem(this.player, Settings.GUI_STATS_SELF_BG_ITEM.getString())); - setUseLockedCells(true); - setAcceptsItems(false); - setAllowDrops(false); - setRows(6); - draw(); - } - - private void draw() { - final AuctionHouse instance = AuctionHouse.getInstance(); - - // created auction - setItem(1, 1, ConfigurationItemHelper.createConfigurationItem(this.player, Settings.GUI_STATS_SELF_ITEMS_CREATED_AUCTION_ITEM.getString(), Settings.GUI_STATS_SELF_ITEMS_CREATED_AUCTION_NAME.getString(), Settings.GUI_STATS_SELF_ITEMS_CREATED_AUCTION_LORE.getStringList(), new HashMap() {{ - put("%created_auctions%", (int) instance.getAuctionStatisticManager().getStatisticByPlayer(player.getUniqueId(), AuctionStatisticType.CREATED_AUCTION)); - }})); - - // sold auction - setItem(3, 1, ConfigurationItemHelper.createConfigurationItem(this.player, Settings.GUI_STATS_SELF_ITEMS_SOLD_AUCTION_ITEM.getString(), Settings.GUI_STATS_SELF_ITEMS_SOLD_AUCTION_NAME.getString(), Settings.GUI_STATS_SELF_ITEMS_SOLD_AUCTION_LORE.getStringList(), new HashMap() {{ - put("%sold_auctions%", (int) instance.getAuctionStatisticManager().getStatisticByPlayer(player.getUniqueId(), AuctionStatisticType.SOLD_AUCTION)); - }})); - - // created bin - setItem(1, 4, ConfigurationItemHelper.createConfigurationItem(this.player, Settings.GUI_STATS_SELF_ITEMS_CREATED_BIN_ITEM.getString(), Settings.GUI_STATS_SELF_ITEMS_CREATED_BIN_NAME.getString(), Settings.GUI_STATS_SELF_ITEMS_CREATED_BIN_LORE.getStringList(), new HashMap() {{ - put("%created_bins%", (int) instance.getAuctionStatisticManager().getStatisticByPlayer(player.getUniqueId(), AuctionStatisticType.CREATED_BIN)); - }})); - - // sold bin - setItem(3, 4, ConfigurationItemHelper.createConfigurationItem(this.player, Settings.GUI_STATS_SELF_ITEMS_SOLD_BIN_ITEM.getString(), Settings.GUI_STATS_SELF_ITEMS_SOLD_BIN_NAME.getString(), Settings.GUI_STATS_SELF_ITEMS_SOLD_BIN_LORE.getStringList(), new HashMap() {{ - put("%sold_bins%", (int) instance.getAuctionStatisticManager().getStatisticByPlayer(player.getUniqueId(), AuctionStatisticType.SOLD_BIN)); - }})); - - // money earned - setItem(1, 7, ConfigurationItemHelper.createConfigurationItem(this.player, Settings.GUI_STATS_SELF_ITEMS_MONEY_EARNED_ITEM.getString(), Settings.GUI_STATS_SELF_ITEMS_MONEY_EARNED_NAME.getString(), Settings.GUI_STATS_SELF_ITEMS_MONEY_EARNED_LORE.getStringList(), new HashMap() {{ - put("%money_earned%", AuctionAPI.getInstance().formatNumber(instance.getAuctionStatisticManager().getStatisticByPlayer(player.getUniqueId(), AuctionStatisticType.MONEY_EARNED))); - }})); - - // money spent - setItem(3, 7, ConfigurationItemHelper.createConfigurationItem(this.player, Settings.GUI_STATS_SELF_ITEMS_MONEY_SPENT_ITEM.getString(), Settings.GUI_STATS_SELF_ITEMS_MONEY_SPENT_NAME.getString(), Settings.GUI_STATS_SELF_ITEMS_MONEY_SPENT_LORE.getStringList(), new HashMap() {{ - put("%money_spent%", AuctionAPI.getInstance().formatNumber(instance.getAuctionStatisticManager().getStatisticByPlayer(player.getUniqueId(), AuctionStatisticType.MONEY_SPENT))); - }})); - - setButton(5, 4, getBackButtonItem(), e -> { - e.manager.showGUI(e.player, new GUIStatisticViewSelect(this.auctionPlayer)); - }); - } -} diff --git a/src/main/java/ca/tweetzy/auctionhouse/guis/statistics/GUIStatisticTarget.java b/src/main/java/ca/tweetzy/auctionhouse/guis/statistics/GUIStatisticTarget.java deleted file mode 100644 index 679a62b..0000000 --- a/src/main/java/ca/tweetzy/auctionhouse/guis/statistics/GUIStatisticTarget.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Auction House - * Copyright 2018-2022 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 . - */ - -package ca.tweetzy.auctionhouse.guis.statistics; - -import ca.tweetzy.auctionhouse.AuctionHouse; -import ca.tweetzy.auctionhouse.api.AuctionAPI; -import ca.tweetzy.auctionhouse.auction.AuctionPlayer; -import ca.tweetzy.auctionhouse.auction.enums.AuctionStatisticType; -import ca.tweetzy.auctionhouse.guis.AbstractPlaceholderGui; -import ca.tweetzy.auctionhouse.helpers.ConfigurationItemHelper; -import ca.tweetzy.auctionhouse.settings.Settings; - -import java.util.HashMap; - -public final class GUIStatisticTarget extends AbstractPlaceholderGui { - - private final AuctionPlayer auctionPlayer; - private final AuctionPlayer targetPlayer; - - public GUIStatisticTarget(AuctionPlayer player, AuctionPlayer targetPlayer) { - super(player); - this.auctionPlayer = player; - this.targetPlayer = targetPlayer; - setTitle(Settings.GUI_STATS_SEARCH_TITLE.getString().replace("%player_name%", targetPlayer.getPlayer().getName())); - setDefaultItem(ConfigurationItemHelper.createConfigurationItem(this.player, Settings.GUI_STATS_SEARCH_BG_ITEM.getString())); - setUseLockedCells(true); - setAcceptsItems(false); - setAllowDrops(false); - setRows(6); - draw(); - } - - private void draw() { - - // created auction - setItem(1, 1, ConfigurationItemHelper.createConfigurationItem(this.player, Settings.GUI_STATS_SEARCH_ITEMS_CREATED_AUCTION_ITEM.getString(), Settings.GUI_STATS_SEARCH_ITEMS_CREATED_AUCTION_NAME.getString(), Settings.GUI_STATS_SEARCH_ITEMS_CREATED_AUCTION_LORE.getStringList(), new HashMap() {{ - put("%created_auctions%", (int) AuctionHouse.getInstance().getAuctionStatisticManager().getStatisticByPlayer(targetPlayer.getUuid(), AuctionStatisticType.CREATED_AUCTION)); - }})); - - // sold auction - setItem(3, 1, ConfigurationItemHelper.createConfigurationItem(this.player, Settings.GUI_STATS_SEARCH_ITEMS_SOLD_AUCTION_ITEM.getString(), Settings.GUI_STATS_SEARCH_ITEMS_SOLD_AUCTION_NAME.getString(), Settings.GUI_STATS_SEARCH_ITEMS_SOLD_AUCTION_LORE.getStringList(), new HashMap() {{ - put("%sold_auctions%", (int) AuctionHouse.getInstance().getAuctionStatisticManager().getStatisticByPlayer(targetPlayer.getUuid(), AuctionStatisticType.SOLD_AUCTION)); - }})); - - // created bin - setItem(1, 4, ConfigurationItemHelper.createConfigurationItem(this.player, Settings.GUI_STATS_SEARCH_ITEMS_CREATED_BIN_ITEM.getString(), Settings.GUI_STATS_SEARCH_ITEMS_CREATED_BIN_NAME.getString(), Settings.GUI_STATS_SEARCH_ITEMS_CREATED_BIN_LORE.getStringList(), new HashMap() {{ - put("%created_bins%", (int) AuctionHouse.getInstance().getAuctionStatisticManager().getStatisticByPlayer(targetPlayer.getUuid(), AuctionStatisticType.CREATED_BIN)); - }})); - - // sold bin - setItem(3, 4, ConfigurationItemHelper.createConfigurationItem(this.player, Settings.GUI_STATS_SEARCH_ITEMS_SOLD_BIN_ITEM.getString(), Settings.GUI_STATS_SEARCH_ITEMS_SOLD_BIN_NAME.getString(), Settings.GUI_STATS_SEARCH_ITEMS_SOLD_BIN_LORE.getStringList(), new HashMap() {{ - put("%sold_bins%", (int) AuctionHouse.getInstance().getAuctionStatisticManager().getStatisticByPlayer(targetPlayer.getUuid(), AuctionStatisticType.SOLD_BIN)); - }})); - - // money earned - setItem(1, 7, ConfigurationItemHelper.createConfigurationItem(this.player, Settings.GUI_STATS_SEARCH_ITEMS_MONEY_EARNED_ITEM.getString(), Settings.GUI_STATS_SEARCH_ITEMS_MONEY_EARNED_NAME.getString(), Settings.GUI_STATS_SEARCH_ITEMS_MONEY_EARNED_LORE.getStringList(), new HashMap() {{ - put("%money_earned%", AuctionAPI.getInstance().formatNumber(AuctionHouse.getInstance().getAuctionStatisticManager().getStatisticByPlayer(targetPlayer.getUuid(), AuctionStatisticType.MONEY_EARNED))); - }})); - - // money spent - setItem(3, 7, ConfigurationItemHelper.createConfigurationItem(this.player, Settings.GUI_STATS_SEARCH_ITEMS_MONEY_SPENT_ITEM.getString(), Settings.GUI_STATS_SEARCH_ITEMS_MONEY_SPENT_NAME.getString(), Settings.GUI_STATS_SEARCH_ITEMS_MONEY_SPENT_LORE.getStringList(), new HashMap() {{ - put("%money_spent%", AuctionAPI.getInstance().formatNumber(AuctionHouse.getInstance().getAuctionStatisticManager().getStatisticByPlayer(targetPlayer.getUuid(), AuctionStatisticType.MONEY_SPENT))); - }})); - - setButton(5, 4, ConfigurationItemHelper.createConfigurationItem(this.player, Settings.GUI_CLOSE_BTN_ITEM.getString(), Settings.GUI_CLOSE_BTN_NAME.getString(), Settings.GUI_CLOSE_BTN_LORE.getStringList(), null), e -> { - e.gui.close(); - }); - } -} diff --git a/src/main/java/ca/tweetzy/auctionhouse/guis/statistics/GUIStatisticView.java b/src/main/java/ca/tweetzy/auctionhouse/guis/statistics/GUIStatisticView.java new file mode 100644 index 0000000..3173e7c --- /dev/null +++ b/src/main/java/ca/tweetzy/auctionhouse/guis/statistics/GUIStatisticView.java @@ -0,0 +1,88 @@ +/* + * Auction House + * Copyright 2018-2022 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 . + */ + +package ca.tweetzy.auctionhouse.guis.statistics; + +import ca.tweetzy.auctionhouse.AuctionHouse; +import ca.tweetzy.auctionhouse.auction.AuctionPlayer; +import ca.tweetzy.auctionhouse.auction.enums.AuctionStatisticType; +import ca.tweetzy.auctionhouse.guis.abstraction.AuctionBaseGUI; +import ca.tweetzy.auctionhouse.settings.Settings; +import ca.tweetzy.flight.utils.QuickItem; +import ca.tweetzy.flight.utils.Replacer; + +public final class GUIStatisticView extends AuctionBaseGUI { + + private final AuctionPlayer targetPlayer; + private final boolean isSelf; + + public GUIStatisticView(AuctionPlayer player, AuctionPlayer targetPlayer) { + super(new GUIStatisticViewSelect(player), player.getPlayer(), player.getUuid().equals(targetPlayer.getUuid()) ? Settings.GUI_STATS_SELF_TITLE.getString() : Settings.GUI_STATS_SEARCH_TITLE.getString().replace("%player_name%", targetPlayer.getPlayer().getName()), 6); + this.targetPlayer = targetPlayer; + this.isSelf = player.getUuid().equals(targetPlayer.getUuid()); + setDefaultItem(QuickItem.bg(QuickItem.of(isSelf ? Settings.GUI_STATS_SELF_BG_ITEM.getString() : Settings.GUI_STATS_SEARCH_BG_ITEM.getString()).make())); + draw(); + } + + @Override + protected void draw() { + applyBackExit(); + + // created auction + setItem(1, 1, QuickItem + .of(isSelf ? Settings.GUI_STATS_SELF_ITEMS_CREATED_AUCTION_ITEM.getString() : Settings.GUI_STATS_SEARCH_ITEMS_CREATED_AUCTION_ITEM.getString()) + .name(isSelf ? Settings.GUI_STATS_SELF_ITEMS_CREATED_AUCTION_NAME.getString() : Settings.GUI_STATS_SEARCH_ITEMS_CREATED_AUCTION_NAME.getString()) + .lore(Replacer.replaceVariables(isSelf ? Settings.GUI_STATS_SELF_ITEMS_CREATED_AUCTION_LORE.getStringList() : Settings.GUI_STATS_SEARCH_ITEMS_CREATED_AUCTION_LORE.getStringList(), "created_auctions", (int) AuctionHouse.getInstance().getAuctionStatisticManager().getStatisticByPlayer(targetPlayer.getUuid(), AuctionStatisticType.CREATED_AUCTION))) + .make()); + + // sold auction + setItem(3, 1, QuickItem + .of(isSelf ? Settings.GUI_STATS_SELF_ITEMS_SOLD_AUCTION_ITEM.getString() : Settings.GUI_STATS_SEARCH_ITEMS_SOLD_AUCTION_ITEM.getString()) + .name(isSelf ? Settings.GUI_STATS_SELF_ITEMS_SOLD_AUCTION_NAME.getString() : Settings.GUI_STATS_SEARCH_ITEMS_SOLD_AUCTION_NAME.getString()) + .lore(Replacer.replaceVariables(isSelf ? Settings.GUI_STATS_SELF_ITEMS_SOLD_AUCTION_LORE.getStringList() : Settings.GUI_STATS_SEARCH_ITEMS_SOLD_AUCTION_LORE.getStringList(), "sold_auctions", (int) AuctionHouse.getInstance().getAuctionStatisticManager().getStatisticByPlayer(targetPlayer.getUuid(), AuctionStatisticType.SOLD_AUCTION))) + .make()); + + // created bin + setItem(1, 4, QuickItem + .of(isSelf ? Settings.GUI_STATS_SELF_ITEMS_CREATED_BIN_ITEM.getString() : Settings.GUI_STATS_SEARCH_ITEMS_CREATED_BIN_ITEM.getString()) + .name(isSelf ? Settings.GUI_STATS_SELF_ITEMS_CREATED_BIN_NAME.getString() : Settings.GUI_STATS_SEARCH_ITEMS_CREATED_BIN_NAME.getString()) + .lore(Replacer.replaceVariables(isSelf ? Settings.GUI_STATS_SELF_ITEMS_CREATED_BIN_LORE.getStringList() : Settings.GUI_STATS_SEARCH_ITEMS_CREATED_BIN_LORE.getStringList(), "created_bins", (int) AuctionHouse.getInstance().getAuctionStatisticManager().getStatisticByPlayer(targetPlayer.getUuid(), AuctionStatisticType.CREATED_BIN))) + .make()); + + // sold bin + setItem(3, 4, QuickItem + .of(isSelf ? Settings.GUI_STATS_SELF_ITEMS_SOLD_BIN_ITEM.getString() : Settings.GUI_STATS_SEARCH_ITEMS_SOLD_BIN_ITEM.getString()) + .name(isSelf ? Settings.GUI_STATS_SELF_ITEMS_SOLD_BIN_NAME.getString() : Settings.GUI_STATS_SEARCH_ITEMS_SOLD_BIN_NAME.getString()) + .lore(Replacer.replaceVariables(isSelf ? Settings.GUI_STATS_SELF_ITEMS_SOLD_BIN_LORE.getStringList() : Settings.GUI_STATS_SEARCH_ITEMS_SOLD_BIN_LORE.getStringList(), "sold_bins", (int) AuctionHouse.getInstance().getAuctionStatisticManager().getStatisticByPlayer(targetPlayer.getUuid(), AuctionStatisticType.SOLD_BIN))) + .make()); + + // money earned + setItem(1, 7, QuickItem + .of(isSelf ? Settings.GUI_STATS_SELF_ITEMS_MONEY_EARNED_ITEM.getString() : Settings.GUI_STATS_SEARCH_ITEMS_MONEY_EARNED_ITEM.getString()) + .name(isSelf ? Settings.GUI_STATS_SELF_ITEMS_MONEY_EARNED_NAME.getString() : Settings.GUI_STATS_SEARCH_ITEMS_MONEY_EARNED_NAME.getString()) + .lore(Replacer.replaceVariables(isSelf ? Settings.GUI_STATS_SELF_ITEMS_MONEY_EARNED_LORE.getStringList() : Settings.GUI_STATS_SEARCH_ITEMS_MONEY_EARNED_LORE.getStringList(), "money_earned", (int) AuctionHouse.getInstance().getAuctionStatisticManager().getStatisticByPlayer(targetPlayer.getUuid(), AuctionStatisticType.MONEY_EARNED))) + .make()); + + // money spent + setItem(3, 7, QuickItem + .of(isSelf ? Settings.GUI_STATS_SELF_ITEMS_MONEY_SPENT_ITEM.getString() : Settings.GUI_STATS_SEARCH_ITEMS_MONEY_SPENT_ITEM.getString()) + .name(isSelf ? Settings.GUI_STATS_SELF_ITEMS_MONEY_SPENT_NAME.getString() : Settings.GUI_STATS_SEARCH_ITEMS_MONEY_SPENT_NAME.getString()) + .lore(Replacer.replaceVariables(isSelf ? Settings.GUI_STATS_SELF_ITEMS_MONEY_SPENT_LORE.getStringList() : Settings.GUI_STATS_SEARCH_ITEMS_MONEY_SPENT_LORE.getStringList(), "money_spent", (int) AuctionHouse.getInstance().getAuctionStatisticManager().getStatisticByPlayer(targetPlayer.getUuid(), AuctionStatisticType.MONEY_SPENT))) + .make()); + } +} diff --git a/src/main/java/ca/tweetzy/auctionhouse/guis/statistics/GUIStatisticViewSelect.java b/src/main/java/ca/tweetzy/auctionhouse/guis/statistics/GUIStatisticViewSelect.java index ed239e4..05009a6 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/guis/statistics/GUIStatisticViewSelect.java +++ b/src/main/java/ca/tweetzy/auctionhouse/guis/statistics/GUIStatisticViewSelect.java @@ -21,43 +21,32 @@ package ca.tweetzy.auctionhouse.guis.statistics; import ca.tweetzy.auctionhouse.api.AuctionAPI; import ca.tweetzy.auctionhouse.auction.AuctionPlayer; import ca.tweetzy.auctionhouse.auction.enums.AuctionStatisticType; -import ca.tweetzy.auctionhouse.guis.AbstractPlaceholderGui; -import ca.tweetzy.auctionhouse.helpers.ConfigurationItemHelper; +import ca.tweetzy.auctionhouse.guis.abstraction.AuctionBaseGUI; import ca.tweetzy.auctionhouse.settings.Settings; -import ca.tweetzy.core.compatibility.XMaterial; +import ca.tweetzy.flight.utils.QuickItem; -public final class GUIStatisticViewSelect extends AbstractPlaceholderGui { +public final class GUIStatisticViewSelect extends AuctionBaseGUI { private final AuctionPlayer auctionPlayer; public GUIStatisticViewSelect(AuctionPlayer player) { - super(player); + super(null, player.getPlayer(), Settings.GUI_STATS_VIEW_SELECT_TITLE.getString(), 3); this.auctionPlayer = player; - setTitle(Settings.GUI_STATS_VIEW_SELECT_TITLE.getString()); - setDefaultItem(ConfigurationItemHelper.createConfigurationItem(this.player, Settings.GUI_STATS_VIEW_SELECT_BG_ITEM.getString())); - setUseLockedCells(true); - setAcceptsItems(false); - setAllowDrops(false); - setRows(3); + setDefaultItem(QuickItem.bg(QuickItem.of(Settings.GUI_STATS_VIEW_SELECT_BG_ITEM.getString()).make())); draw(); } - private void draw() { - + @Override + protected void draw() { // self - setButton(1, 2, ConfigurationItemHelper.createConfigurationItem(this.player, - Settings.GUI_STATS_VIEW_SELECT_ITEMS_PERSONAL_USE_HEAD.getBoolean() ? - AuctionAPI.getInstance().getPlayerHead(this.player.getName()) : XMaterial.matchXMaterial(Settings.GUI_STATS_VIEW_SELECT_ITEMS_PERSONAL_ITEM.getString()).orElse(XMaterial.STONE).parseItem(), - Settings.GUI_STATS_VIEW_SELECT_ITEMS_PERSONAL_NAME.getString(), - Settings.GUI_STATS_VIEW_SELECT_ITEMS_PERSONAL_LORE.getStringList(), - null - ), click -> click.manager.showGUI(click.player, new GUIStatisticSelf(this.auctionPlayer))); + setButton(1, 2, QuickItem.of(Settings.GUI_STATS_VIEW_SELECT_ITEMS_PERSONAL_USE_HEAD.getBoolean() ? AuctionAPI.getInstance().getPlayerHead(this.player.getName()) : QuickItem.of(Settings.GUI_STATS_VIEW_SELECT_ITEMS_PERSONAL_ITEM.getString()).make()) + .name(Settings.GUI_STATS_VIEW_SELECT_ITEMS_PERSONAL_NAME.getString()) + .lore(Settings.GUI_STATS_VIEW_SELECT_ITEMS_PERSONAL_LORE.getStringList()) + .make(), click -> click.manager.showGUI(click.player, new GUIStatisticView(this.auctionPlayer, this.auctionPlayer))); - setButton(1, 6, ConfigurationItemHelper.createConfigurationItem(this.player, - XMaterial.matchXMaterial(Settings.GUI_STATS_VIEW_SELECT_ITEMS_LEADERBOARD_ITEM.getString()).orElse(XMaterial.STONE).parseItem(), - Settings.GUI_STATS_VIEW_SELECT_ITEMS_LEADERBOARD_NAME.getString(), - Settings.GUI_STATS_VIEW_SELECT_ITEMS_LEADERBOARD_LORE.getStringList(), - null - ), click -> click.manager.showGUI(click.player, new GUIStatisticLeaderboard(this.auctionPlayer, AuctionStatisticType.MONEY_EARNED))); + setButton(1, 6, QuickItem.of(Settings.GUI_STATS_VIEW_SELECT_ITEMS_LEADERBOARD_ITEM.getString()) + .name(Settings.GUI_STATS_VIEW_SELECT_ITEMS_LEADERBOARD_NAME.getString()) + .lore(Settings.GUI_STATS_VIEW_SELECT_ITEMS_LEADERBOARD_LORE.getStringList()) + .make(), click -> click.manager.showGUI(click.player, new GUIStatisticLeaderboard(this.auctionPlayer, AuctionStatisticType.MONEY_EARNED))); } }