From 24c244d501d0af9dc81202f14954673934310572 Mon Sep 17 00:00:00 2001 From: Kiran Hart Date: Mon, 3 Oct 2022 20:44:33 -0400 Subject: [PATCH] finish new statistic system guis Took 14 minutes --- .../auctionhouse/commands/CommandStats.java | 21 ++++- .../statistics/GUIStatisticLeaderboard.java | 59 ++++++++++--- .../guis/statistics/GUIStatisticTarget.java | 85 +++++++++++++++++++ 3 files changed, 149 insertions(+), 16 deletions(-) create mode 100644 src/main/java/ca/tweetzy/auctionhouse/guis/statistics/GUIStatisticTarget.java diff --git a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandStats.java b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandStats.java index 8e93360..8a8000f 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandStats.java +++ b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandStats.java @@ -2,6 +2,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.GUIStatisticViewSelect; import ca.tweetzy.core.commands.AbstractCommand; import ca.tweetzy.core.utils.TextUtils; @@ -29,12 +30,28 @@ public class CommandStats extends AbstractCommand { if (CommandMiddleware.handle(player) == ReturnType.FAILURE) return ReturnType.FAILURE; - if (AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(player.getUniqueId()) == null) { + final AuctionPlayer user = AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(player.getUniqueId()); + + if (user == null) { AuctionHouse.getInstance().getLocale().newMessage(TextUtils.formatText("&cCould not find auction player instance for&f: &e" + player.getName() + "&c creating one now.")).sendPrefixedMessage(Bukkit.getConsoleSender()); AuctionHouse.getInstance().getAuctionPlayerManager().addPlayer(new AuctionPlayer(player)); } - AuctionHouse.getInstance().getGuiManager().showGUI(player, new GUIStatisticViewSelect(AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(player.getUniqueId()))); + if (args.length == 0) { + AuctionHouse.getInstance().getGuiManager().showGUI(player, new GUIStatisticViewSelect(user)); + return ReturnType.SUCCESS; + } + + final Player target = Bukkit.getPlayerExact(args[0]); + + if (target == null) { + AuctionHouse.getInstance().getLocale().getMessage("general.playernotfound").processPlaceholder("player", args[0]).sendPrefixedMessage(sender); + return ReturnType.FAILURE; + } + + final AuctionPlayer targetAuctionPlayer = AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(target.getUniqueId()); + AuctionHouse.getInstance().getGuiManager().showGUI(player, new GUIStatisticTarget(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 438c173..1025aa7 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/guis/statistics/GUIStatisticLeaderboard.java +++ b/src/main/java/ca/tweetzy/auctionhouse/guis/statistics/GUIStatisticLeaderboard.java @@ -24,14 +24,14 @@ 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.managers.SoundManager; import ca.tweetzy.auctionhouse.settings.Settings; +import ca.tweetzy.core.utils.items.TItemBuilder; import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; import org.bukkit.inventory.ItemStack; -import java.util.Arrays; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.UUID; +import java.util.*; import java.util.stream.Collectors; public final class GUIStatisticLeaderboard extends AbstractPlaceholderGui { @@ -45,8 +45,8 @@ public final class GUIStatisticLeaderboard extends AbstractPlaceholderGui { super(player); this.auctionPlayer = player; this.statisticType = statisticType; - setTitle(Settings.GUI_STATS_VIEW_SELECT_TITLE.getString()); - setDefaultItem(Settings.GUI_STATS_VIEW_SELECT_BG_ITEM.getMaterial().parseItem()); + setTitle(Settings.GUI_STATS_LEADERBOARD_TITLE.getString()); + setDefaultItem(Settings.GUI_STATS_LEADERBOARD_BG_ITEM.getMaterial().parseItem()); setUseLockedCells(true); setAcceptsItems(false); setAllowDrops(false); @@ -64,24 +64,55 @@ public final class GUIStatisticLeaderboard extends AbstractPlaceholderGui { .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (a, b) -> b, LinkedHashMap::new)); - - return this.statisticsMap; + 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.entrySet()) { - final ItemStack head = AuctionAPI.getInstance().getPlayerHead(Bukkit.getOfflinePlayer(playerStat.getKey()).getName()); + for (Map.Entry playerStat : data) { + final OfflinePlayer targetUser = Bukkit.getOfflinePlayer(playerStat.getKey()); - setItem(slot++, ConfigurationItemHelper.createConfigurationItem(head, "STAT", Arrays.asList( - playerStat.getKey() + " == uuid", - playerStat.getValue() + " == val" - ), null)); + final ItemStack head = AuctionAPI.getInstance().getPlayerHead(targetUser.getName()); + + setItem(slot++, ConfigurationItemHelper.createConfigurationItem( + 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, 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 GUIStatisticViewSelect(this.auctionPlayer)); }); + + drawStatisticTypeButton(); + } + + private void drawPaginationButtons() { + 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()); + 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); + }); + } + + private void drawStatisticTypeButton() { + setButton(5, 4, ConfigurationItemHelper.createConfigurationItem( + 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 -> { + + click.manager.showGUI(click.player, new GUIStatisticLeaderboard(this.auctionPlayer, this.statisticType.next())); + }); } } diff --git a/src/main/java/ca/tweetzy/auctionhouse/guis/statistics/GUIStatisticTarget.java b/src/main/java/ca/tweetzy/auctionhouse/guis/statistics/GUIStatisticTarget.java new file mode 100644 index 0000000..e8c9633 --- /dev/null +++ b/src/main/java/ca/tweetzy/auctionhouse/guis/statistics/GUIStatisticTarget.java @@ -0,0 +1,85 @@ +/* + * Auction House + * Copyright 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(Settings.GUI_STATS_SEARCH_BG_ITEM.getMaterial().parseItem()); + setUseLockedCells(true); + setAcceptsItems(false); + setAllowDrops(false); + setRows(6); + draw(); + } + + private void draw() { + + // created auction + setItem(1, 1, ConfigurationItemHelper.createConfigurationItem(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(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(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(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(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(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(Settings.GUI_CLOSE_BTN_ITEM.getString(), Settings.GUI_CLOSE_BTN_NAME.getString(), Settings.GUI_CLOSE_BTN_LORE.getStringList(), null), e -> { + e.gui.close(); + }); + } +}