🪧 winning bids gui

Took 15 seconds
This commit is contained in:
Kiran Hart 2023-03-09 23:56:19 -05:00
parent 344976203d
commit 744bb74717
No known key found for this signature in database
GPG Key ID: 5F36C7BC79D3EBC3
6 changed files with 198 additions and 2 deletions

View File

@ -27,6 +27,7 @@ import ca.tweetzy.auctionhouse.database.DataManager;
import ca.tweetzy.auctionhouse.database.migrations.*;
import ca.tweetzy.auctionhouse.listeners.AuctionListeners;
import ca.tweetzy.auctionhouse.listeners.CMIListener;
import ca.tweetzy.auctionhouse.listeners.ChestShopListener;
import ca.tweetzy.auctionhouse.listeners.PlayerListeners;
import ca.tweetzy.auctionhouse.managers.*;
import ca.tweetzy.auctionhouse.settings.LocaleSettings;
@ -184,6 +185,9 @@ public class AuctionHouse extends TweetyPlugin {
Bukkit.getServer().getPluginManager().registerEvents(new PlayerListeners(), this);
Bukkit.getServer().getPluginManager().registerEvents(new AuctionListeners(), this);
if (getServer().getPluginManager().isPluginEnabled("ChestShop"))
Bukkit.getServer().getPluginManager().registerEvents(new ChestShopListener(), this);
if (getServer().getPluginManager().isPluginEnabled("CMI"))
Bukkit.getServer().getPluginManager().registerEvents(new CMIListener(), this);
@ -279,7 +283,8 @@ public class AuctionHouse extends TweetyPlugin {
new CommandUpload(),
new CommandMinPrice(),
new CommandStats(),
new CommandPayments()
new CommandPayments(),
new CommandBids()
);
// Placeholder API

View File

@ -0,0 +1,78 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
package ca.tweetzy.auctionhouse.commands;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.auction.AuctionPlayer;
import ca.tweetzy.auctionhouse.guis.GUIActiveBids;
import ca.tweetzy.core.commands.AbstractCommand;
import ca.tweetzy.core.utils.TextUtils;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.List;
/**
* The current file has been created by Kiran Hart
* Date Created: March 15 2021
* Time Created: 4:32 p.m.
* Usage of any code found within this class is prohibited unless given explicit permission otherwise
*/
public class CommandBids extends AbstractCommand {
public CommandBids() {
super(CommandType.PLAYER_ONLY, "bids");
}
@Override
protected ReturnType runCommand(CommandSender sender, String... args) {
final Player player = (Player) sender;
if (CommandMiddleware.handle(player) == ReturnType.FAILURE) return ReturnType.FAILURE;
final AuctionHouse instance = AuctionHouse.getInstance();
if (instance.getAuctionPlayerManager().getPlayer(player.getUniqueId()) == 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));
}
instance.getGuiManager().showGUI(player, new GUIActiveBids(instance.getAuctionPlayerManager().getPlayer(player.getUniqueId())));
return ReturnType.SUCCESS;
}
@Override
public String getPermissionNode() {
return "auctionhouse.cmd.bids";
}
@Override
public String getSyntax() {
return "bids";
}
@Override
public String getDescription() {
return "Opens a menu to show your winning bids";
}
@Override
protected List<String> onTab(CommandSender sender, String... args) {
return null;
}
}

View File

@ -0,0 +1,99 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
package ca.tweetzy.auctionhouse.guis;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.auction.AuctionPlayer;
import ca.tweetzy.auctionhouse.auction.AuctionedItem;
import ca.tweetzy.auctionhouse.auction.enums.AuctionStackType;
import ca.tweetzy.auctionhouse.helpers.ConfigurationItemHelper;
import ca.tweetzy.auctionhouse.managers.SoundManager;
import ca.tweetzy.auctionhouse.settings.Settings;
import ca.tweetzy.core.utils.TextUtils;
import org.bukkit.scheduler.BukkitTask;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
/**
* The current file has been created by Kiran Hart
* Date Created: March 9th 2023
* Time Created: 11:55 p.m.
* Usage of any code found within this class is prohibited unless given explicit permission otherwise
*/
public class GUIActiveBids extends AbstractPlaceholderGui {
private final AuctionPlayer auctionPlayer;
private BukkitTask task;
private List<AuctionedItem> items;
public GUIActiveBids(AuctionPlayer auctionPlayer) {
super(auctionPlayer);
this.auctionPlayer = auctionPlayer;
setTitle(TextUtils.formatText(Settings.GUI_ACTIVE_BIDS_TITLE.getString()));
setRows(6);
setAcceptsItems(false);
draw();
}
private void draw() {
reset();
drawFixedButtons();
drawItems();
}
private void drawItems() {
AuctionHouse.newChain().asyncFirst(() -> {
this.items = AuctionHouse.getInstance().getAuctionItemManager().getHighestBidItems(this.player);
// per world check
if (Settings.PER_WORLD_ITEMS.getBoolean()) {
this.items = this.items.stream().filter(item -> item.getListedWorld() == null || this.auctionPlayer.getPlayer().getWorld().getName().equals(item.getListedWorld())).collect(Collectors.toList());
}
return this.items.stream().sorted(Comparator.comparingLong(AuctionedItem::getExpiresAt).reversed()).skip((page - 1) * 45L).limit(45).collect(Collectors.toList());
}).asyncLast((data) -> {
pages = (int) Math.max(1, Math.ceil(this.items.size() / (double) 45L));
drawPaginationButtons();
int slot = 0;
for (AuctionedItem item : data) {
setItem(slot++, item.getDisplayStack(AuctionStackType.LISTING_PREVIEW));
}
}).execute();
}
private void drawFixedButtons() {
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));
});
}
private void drawPaginationButtons() {
setPrevPage(5, 3, getPreviousPageItem());
setNextPage(5, 5, getNextPageItem());
setOnPage(e -> {
draw();
SoundManager.getInstance().playSound(this.auctionPlayer.getPlayer(), Settings.SOUNDS_NAVIGATE_GUI_PAGES.getString());
});
}
}

View File

@ -22,9 +22,12 @@ import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.auction.AuctionedItem;
import lombok.Getter;
import lombok.NonNull;
import org.bukkit.entity.Player;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
/**
* The current file has been created by Kiran Hart
@ -47,6 +50,10 @@ public class AuctionItemManager {
@Getter
private final ConcurrentHashMap<UUID, AuctionedItem> deletedItems = new ConcurrentHashMap<>();
public List<AuctionedItem> getHighestBidItems(Player player) {
return getItems().values().stream().filter(item -> item.isBidItem() && !item.isExpired() && !item.getOwner().equals(player.getUniqueId()) && item.getHighestBidder().equals(player.getUniqueId())).collect(Collectors.toList());
}
public void start() {
AuctionHouse.getInstance().getDataManager().getItems((error, results) -> {

View File

@ -653,6 +653,13 @@ public class Settings {
"&7that you have posted."
));
/* ===============================
* ACTIVE BIDS GUI
* ===============================*/
public static final ConfigSetting GUI_ACTIVE_BIDS_TITLE = new ConfigSetting(config, "gui.active bids.title", "&7Your Winning Bids");
/* ===============================
* EXPIRED AUCTION GUI
* ===============================*/

View File

@ -5,7 +5,7 @@ main: ca.tweetzy.auctionhouse.AuctionHouse
description: Auction House is a premium auction solution for your server.
website: https://tweetzy.ca/
authors: [ Kiran Hart ]
softdepend: [ Vault, PlayerPoints, PlaceholderAPIHook, MMOItemsHook, UltraEconomy, CMI, Essentials, CityBuildStuff ]
softdepend: [ Vault, PlayerPoints, PlaceholderAPIHook, MMOItemsHook, UltraEconomy, CMI, Essentials, CityBuildStuff, ChestShop ]
commands:
auctionhouse: