re-write another menu

This commit is contained in:
Ryder Belserion 2024-10-11 16:36:19 -04:00
parent cf29c17f67
commit 2de346d989
No known key found for this signature in database
2 changed files with 128 additions and 216 deletions

View File

@ -44,7 +44,7 @@ public class AuctionsMenu extends Holder {
private Category category;
public AuctionsMenu(final Player player, final ShopType shopType, final Category category, final String title, final int size, final int page) {
super(player, shopType, title, size, page);
super(player, shopType, title + " #" + page, size, page);
this.items = new ArrayList<>();
this.options = new ArrayList<>();
@ -59,7 +59,17 @@ public class AuctionsMenu extends Holder {
Files.data.save();
}
HolderManager.addShopCategory(player, this.category = category);
if (category != null) {
HolderManager.addShopCategory(player, this.category = category);
}
}
private String target;
public AuctionsMenu(final Player player, final String target, final String title, final int size, final int page) {
this(player, null, null, title, size, page);
this.target = target;
}
public AuctionsMenu() {}
@ -68,16 +78,20 @@ public class AuctionsMenu extends Holder {
public final Holder build() {
Methods.updateAuction();
this.options.addAll(List.of(
"SellingItems",
"Cancelled/ExpiredItems",
"PreviousPage",
"Refresh",
"Refesh",
"NextPage",
"Category1",
"Category2"
));
if (this.target != null) {
this.options.add("WhatIsThis.Viewing");
} else {
this.options.addAll(List.of(
"SellingItems",
"Cancelled/ExpiredItems",
"PreviousPage",
"Refresh",
"Refesh",
"NextPage",
"Category1",
"Category2"
));
}
getItems(); // populates the lists
@ -174,65 +188,67 @@ public class AuctionsMenu extends Holder {
if (container.has(Keys.auction_button.getNamespacedKey())) {
click();
String type = container.getOrDefault(Keys.auction_button.getNamespacedKey(), PersistentDataType.STRING, "Refresh");
String type = container.getOrDefault(Keys.auction_button.getNamespacedKey(), PersistentDataType.STRING, this.target == null ? "Refresh" : "");
final String title = event.getView().getTitle();
switch (type) {
case "NextPage", "Your-Item", "Top-Bidder", "Cant-Afford" -> {
return;
}
if (this.target == null && !type.isEmpty()) {
switch (type) {
case "NextPage", "Your-Item", "Top-Bidder", "Cant-Afford" -> {
return;
}
case "PreviousPage" -> {
Methods.updateAuction();
case "PreviousPage" -> {
Methods.updateAuction();
int page = Integer.parseInt(title.split("#")[1]);
int page = Integer.parseInt(title.split("#")[1]);
if (page == 1) page++;
if (page == 1) page++;
GuiListener.openShop(player, HolderManager.getShopType(player), HolderManager.getShopCategory(player), page - 1);
GuiListener.openShop(player, HolderManager.getShopType(player), HolderManager.getShopCategory(player), page - 1);
return;
}
return;
}
case "Refesh", "Refresh" -> {
Methods.updateAuction();
case "Refesh", "Refresh" -> {
Methods.updateAuction();
int page = Integer.parseInt(title.split("#")[1]);
int page = Integer.parseInt(title.split("#")[1]);
GuiListener.openShop(player, HolderManager.getShopType(player), HolderManager.getShopCategory(player), page);
GuiListener.openShop(player, HolderManager.getShopType(player), HolderManager.getShopCategory(player), page);
return;
}
return;
}
case "Bidding/Selling.Selling" -> {
GuiListener.openShop(player, ShopType.BID, HolderManager.getShopCategory(player), 1);
case "Bidding/Selling.Selling" -> {
GuiListener.openShop(player, ShopType.BID, HolderManager.getShopCategory(player), 1);
return;
}
return;
}
case "Bidding/Selling.Bidding" -> {
GuiListener.openShop(player, ShopType.SELL, HolderManager.getShopCategory(player), 1);
case "Bidding/Selling.Bidding" -> {
GuiListener.openShop(player, ShopType.SELL, HolderManager.getShopCategory(player), 1);
return;
}
return;
}
case "Cancelled/ExpiredItems" -> {
openPlayersExpiredList(player, 1);
case "Cancelled/ExpiredItems" -> {
openPlayersExpiredList(player, 1);
return;
}
return;
}
case "SellingItems" -> {
openPlayersCurrentList(player, 1);
case "SellingItems" -> {
openPlayersCurrentList(player, 1);
return;
}
return;
}
case "Category1", "Category2" -> {
openCategories(player, HolderManager.getShopType(player));
case "Category1", "Category2" -> {
openCategories(player, HolderManager.getShopType(player));
return;
return;
}
}
}
}
@ -394,67 +410,75 @@ public class AuctionsMenu extends Holder {
if (auction == null) continue;
final String item = auction.getString("Item", "");
if (item.isEmpty()) continue;
final ItemBuilder itemBuilder = ItemBuilder.convertItemStack(item);
if (this.category != Category.NONE && !this.category.getItems().contains(itemBuilder.getMaterial())) continue;
final String seller = auction.getString("Seller", "");
if (seller.isEmpty()) continue;
final long price = auction.getLong("Price");
if (this.target != null && !this.target.isEmpty() && seller.equalsIgnoreCase(this.target)) {
fetch(auction, seller);
final String priceFormat = String.format(Locale.ENGLISH, "%,d", price);
final OfflinePlayer player = Methods.getOfflinePlayer(seller);
final String time = Methods.convertToTime(auction.getLong("Time-Till-Expire"));
final List<String> lore = new ArrayList<>(itemBuilder.getUpdatedLore());
lore.add(" ");
if (this.shopType == ShopType.BID && auction.getBoolean("Biddable")) {
final String bidder = auction.getString("TopBidder", "None");
final OfflinePlayer top_bidder = bidder.equalsIgnoreCase("None") ? null : Methods.getOfflinePlayer(bidder);
for (final String line : this.config.getStringList("Settings.GUISettings.Bidding")) {
String newLine = line.replace("%TopBid%", priceFormat).replace("%topbid%", priceFormat);
final String targetName = player.getName() == null ? "N/A" : player.getName();
newLine = line.replace("%Seller%", targetName).replace("%seller%", targetName);
final String bidderName = top_bidder == null ? "N/A" : top_bidder.getName() == null ? "N/A" : top_bidder.getName();
newLine = line.replace("%TopBidder%", bidderName).replace("%topbid%", bidderName);
lore.add(newLine.replace("%Time%", time).replace("%time%", time).replace("%price%", priceFormat).replace("%Price%", priceFormat));
}
return;
}
if (this.shopType == ShopType.SELL) {
for (final String line : this.config.getStringList("Settings.GUISettings.SellingItemLore")) {
String newLine = line.replace("%TopBid%", priceFormat).replace("%topbid%", priceFormat);
final String targetName = player.getName() == null ? "N/A" : player.getName();
newLine = line.replace("%Seller%", targetName).replace("%seller%", targetName);
lore.add(newLine.replace("%Time%", time).replace("%time%", time).replace("%price%", priceFormat).replace("%Price%", priceFormat));
}
}
itemBuilder.setLore(lore);
this.items.add(itemBuilder.build());
this.ids.add(auction.getInt("StoreID"));
fetch(auction, seller);
}
}
private void fetch(final ConfigurationSection auction, final String seller) {
final String item = auction.getString("Item", "");
if (item.isEmpty()) return;
final ItemBuilder itemBuilder = ItemBuilder.convertItemStack(item);
if (this.category != Category.NONE && !this.category.getItems().contains(itemBuilder.getMaterial())) return;
final long price = auction.getLong("Price");
final String priceFormat = String.format(Locale.ENGLISH, "%,d", price);
final OfflinePlayer player = Methods.getOfflinePlayer(seller);
final String time = Methods.convertToTime(auction.getLong("Time-Till-Expire"));
final List<String> lore = new ArrayList<>(itemBuilder.getUpdatedLore());
lore.add(" ");
if (this.shopType != null && this.shopType == ShopType.BID && auction.getBoolean("Biddable") || auction.getBoolean("Biddable")) {
final String bidder = auction.getString("TopBidder", "None");
final OfflinePlayer top_bidder = bidder.equalsIgnoreCase("None") ? null : Methods.getOfflinePlayer(bidder);
for (final String line : this.config.getStringList("Settings.GUISettings.Bidding")) {
String newLine = line.replace("%TopBid%", priceFormat).replace("%topbid%", priceFormat);
final String targetName = player.getName() == null ? "N/A" : player.getName();
newLine = line.replace("%Seller%", targetName).replace("%seller%", targetName);
final String bidderName = top_bidder == null ? "N/A" : top_bidder.getName() == null ? "N/A" : top_bidder.getName();
newLine = line.replace("%TopBidder%", bidderName).replace("%topbid%", bidderName);
lore.add(newLine.replace("%Time%", time).replace("%time%", time));
}
} else {
for (final String line : this.config.getStringList("Settings.GUISettings.SellingItemLore")) {
String newLine = line.replace("%TopBid%", priceFormat).replace("%topbid%", priceFormat);
final String targetName = player.getName() == null ? "N/A" : player.getName();
newLine = line.replace("%Seller%", targetName).replace("%seller%", targetName);
lore.add(newLine.replace("%Time%", time).replace("%time%", time).replace("%price%", priceFormat).replace("%Price%", priceFormat));
}
}
itemBuilder.setLore(lore);
this.items.add(itemBuilder.build());
this.ids.add(auction.getInt("StoreID"));
}
}

View File

@ -7,7 +7,6 @@ import com.badbones69.crazyauctions.api.enums.Category;
import com.badbones69.crazyauctions.api.enums.misc.Files;
import com.badbones69.crazyauctions.api.enums.Messages;
import com.badbones69.crazyauctions.api.enums.ShopType;
import com.badbones69.crazyauctions.api.events.AuctionBuyEvent;
import com.badbones69.crazyauctions.api.events.AuctionNewBidEvent;
import com.badbones69.crazyauctions.api.guis.HolderManager;
import com.badbones69.crazyauctions.api.guis.types.AuctionsMenu;
@ -24,12 +23,10 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -108,118 +105,9 @@ public class GuiListener implements Listener {
}
public static void openViewer(Player player, String other, int page) {
Methods.updateAuction();
FileConfiguration config = Files.config.getConfiguration();
FileConfiguration data = Files.data.getConfiguration();
List<ItemStack> items = new ArrayList<>();
List<Integer> ID = new ArrayList<>();
if (!data.contains("Items")) {
data.set("Items.Clear", null);
Files.data.save();
}
if (data.contains("Items")) {
for (String i : data.getConfigurationSection("Items").getKeys(false)) {
if (data.getString("Items." + i + ".Seller").equalsIgnoreCase(other)) {
ItemBuilder itemBuilder = ItemBuilder.convertItemStack(data.getString("Items." + ID + ".Item"));
List<String> lore = new ArrayList<>(itemBuilder.getUpdatedLore());
lore.add(" ");
String price = Methods.getPrice(i, false);
String time = Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire"));
OfflinePlayer target = null;
String id = data.getString("Items." + i + ".Seller");
if (id != null) {
target = Methods.getOfflinePlayer(id);
}
OfflinePlayer bidder = null;
String bid = data.getString("Items." + i + ".TopBidder");
if (id != null) {
bidder = Methods.getOfflinePlayer(bid);
}
if (data.getBoolean("Items." + i + ".Biddable")) {
for (String l : config.getStringList("Settings.GUISettings.Bidding")) {
lore.add(l.replace("%TopBid%", price)
.replace("%topbid%", price)
.replace("%Seller%", target != null ? target.getName() : "N/A")
.replace("%seller%", target != null ? target.getName() : "N/A")
.replace("%TopBidder%", bidder != null ? bidder.getName() : "N/A")
.replace("%topbidder%", bidder != null ? bidder.getName() : "N/A")
.replace("%Time%", time)
.replace("%time%", time));
}
} else {
for (String l : config.getStringList("Settings.GUISettings.SellingItemLore")) {
lore.add(l.replace("%Price%", price)
.replace("%price%", price)
.replace("%Seller%", target != null ? target.getName() : "N/A")
.replace("%seller%", target != null ? target.getName() : "N/A")
.replace("%Time%", time)
.replace("%time%", time));
}
}
itemBuilder.setLore(lore);
items.add(itemBuilder.build());
ID.add(data.getInt("Items." + i + ".StoreID"));
}
}
}
int maxPage = Methods.getMaxPage(items);
for (; page > maxPage; page--);
Inventory inv = plugin.getServer().createInventory(null, 54, Methods.color(config.getString("Settings.GUIName") + " #" + page));
List<String> options = new ArrayList<>();
options.add("WhatIsThis.Viewing");
for (String o : options) {
if (config.contains("Settings.GUISettings.OtherSettings." + o + ".Toggle")) {
if (!config.getBoolean("Settings.GUISettings.OtherSettings." + o + ".Toggle")) {
continue;
}
}
String id = config.getString("Settings.GUISettings.OtherSettings." + o + ".Item");
String name = config.getString("Settings.GUISettings.OtherSettings." + o + ".Name");
int slot = config.getInt("Settings.GUISettings.OtherSettings." + o + ".Slot");
ItemBuilder itemBuilder = new ItemBuilder().setMaterial(id).setName(name).setAmount(1);
if (config.contains("Settings.GUISettings.OtherSettings." + o + ".Lore")) {
itemBuilder.setLore(config.getStringList("Settings.GUISettings.OtherSettings." + o + ".Lore"));
}
inv.setItem(slot - 1, itemBuilder.build());
}
for (ItemStack item : Methods.getPage(items, page)) {
int slot = inv.firstEmpty();
inv.setItem(slot, item);
}
HolderManager.addPages(player, Methods.getPageInts(ID, page));
player.openInventory(inv);
new AuctionsMenu(player, other, config.getString("Settings.GUIName") + " #" + page, 54, page).build();
}
private static ItemStack getBiddingGlass(Player player, String ID) {