mirror of
https://github.com/Crazy-Crew/CrazyAuctions.git
synced 2024-11-21 11:45:11 +01:00
register expired menu
This commit is contained in:
parent
ce99603c08
commit
3b57365c1f
@ -7,6 +7,7 @@ import com.badbones69.crazyauctions.api.enums.other.Permissions;
|
||||
import com.badbones69.crazyauctions.api.guis.types.AuctionsMenu;
|
||||
import com.badbones69.crazyauctions.api.guis.types.CategoriesMenu;
|
||||
import com.badbones69.crazyauctions.api.guis.types.CurrentMenu;
|
||||
import com.badbones69.crazyauctions.api.guis.types.ExpiredMenu;
|
||||
import com.badbones69.crazyauctions.api.support.MetricsWrapper;
|
||||
import com.badbones69.crazyauctions.commands.AuctionCommand;
|
||||
import com.badbones69.crazyauctions.commands.AuctionTab;
|
||||
@ -122,7 +123,8 @@ public class CrazyAuctions extends Vital {
|
||||
|
||||
manager.registerEvents(new AuctionsMenu(), this); // register main menu
|
||||
manager.registerEvents(new CategoriesMenu(), this); // register categories menu
|
||||
manager.registerEvents(new CurrentMenu(), this);
|
||||
manager.registerEvents(new CurrentMenu(), this); // register current listings menu
|
||||
manager.registerEvents(new ExpiredMenu(), this); // register expired menu
|
||||
|
||||
manager.registerEvents(new GuiListener(), this);
|
||||
manager.registerEvents(new MarcoListener(), this);
|
||||
|
@ -0,0 +1,300 @@
|
||||
package com.badbones69.crazyauctions.api.guis.types;
|
||||
|
||||
import com.badbones69.crazyauctions.Methods;
|
||||
import com.badbones69.crazyauctions.api.builders.ItemBuilder;
|
||||
import com.badbones69.crazyauctions.api.enums.Messages;
|
||||
import com.badbones69.crazyauctions.api.enums.Reasons;
|
||||
import com.badbones69.crazyauctions.api.enums.misc.Files;
|
||||
import com.badbones69.crazyauctions.api.enums.misc.Keys;
|
||||
import com.badbones69.crazyauctions.api.events.AuctionCancelledEvent;
|
||||
import com.badbones69.crazyauctions.api.guis.Holder;
|
||||
import com.badbones69.crazyauctions.api.guis.HolderManager;
|
||||
import com.badbones69.crazyauctions.controllers.GuiListener;
|
||||
import io.papermc.paper.persistence.PersistentDataContainerView;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ExpiredMenu extends Holder {
|
||||
|
||||
private List<ItemStack> items;
|
||||
private List<String> options;
|
||||
private List<Integer> ids;
|
||||
|
||||
private FileConfiguration config;
|
||||
private FileConfiguration data;
|
||||
|
||||
public ExpiredMenu(final Player player, final String title, final int size, final int page) {
|
||||
super(player, title, size, page);
|
||||
|
||||
this.items = new ArrayList<>();
|
||||
this.options = new ArrayList<>();
|
||||
this.ids = new ArrayList<>();
|
||||
|
||||
this.config = Files.config.getConfiguration();
|
||||
this.data = Files.data.getConfiguration();
|
||||
}
|
||||
|
||||
public ExpiredMenu() {}
|
||||
|
||||
@Override
|
||||
public final Holder build() {
|
||||
Methods.updateAuction();
|
||||
|
||||
this.options.addAll(List.of(
|
||||
"Back",
|
||||
"PreviousPage",
|
||||
"Return",
|
||||
"NextPage",
|
||||
"WhatIsThis.Cancelled/ExpiredItems"
|
||||
));
|
||||
|
||||
getItems();
|
||||
|
||||
int maxPage = Methods.getMaxPage(this.items);
|
||||
|
||||
for (;this.page > maxPage; this.page--);
|
||||
|
||||
for (final String key : this.options) {
|
||||
if (!this.config.contains("Settings.GUISettings.OtherSettings." + key)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!this.config.getBoolean("Settings.GUISettings.OtherSettings." + key + ".Toggle", true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String id = this.config.getString("Settings.GUISettings.OtherSettings." + key + ".Item");
|
||||
String name = this.config.getString("Settings.GUISettings.OtherSettings." + key + ".Name");
|
||||
int slot = this.config.getInt("Settings.GUISettings.OtherSettings." + key + ".Slot");
|
||||
|
||||
ItemBuilder itemBuilder = new ItemBuilder().setMaterial(id).setName(name).addString(key).setAmount(1);
|
||||
|
||||
if (this.config.contains("Settings.GUISettings.OtherSettings." + key + ".Lore")) {
|
||||
itemBuilder.setLore(this.config.getStringList("Settings.GUISettings.OtherSettings." + key + ".Lore"));
|
||||
}
|
||||
|
||||
this.inventory.setItem(slot - 1, itemBuilder.build());
|
||||
}
|
||||
|
||||
for (final ItemStack item : Methods.getPage(this.items, this.page)) {
|
||||
int slot = this.inventory.firstEmpty();
|
||||
|
||||
this.inventory.setItem(slot, item);
|
||||
}
|
||||
|
||||
HolderManager.addPages(this.player, Methods.getPageInts(this.ids, this.page));
|
||||
|
||||
this.player.openInventory(this.inventory);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(InventoryClickEvent event) {
|
||||
if (!(event.getInventory().getHolder(false) instanceof ExpiredMenu menu)) return;
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
final int slot = event.getSlot();
|
||||
|
||||
final Inventory inventory = menu.getInventory();
|
||||
|
||||
if (slot > inventory.getSize()) return;
|
||||
|
||||
if (event.getCurrentItem() == null) return;
|
||||
|
||||
final ItemStack itemStack = event.getCurrentItem();
|
||||
|
||||
if (itemStack == null) return;
|
||||
|
||||
final PersistentDataContainerView container = itemStack.getPersistentDataContainer();
|
||||
|
||||
if (!container.has(Keys.auction_button.getNamespacedKey())) return;
|
||||
|
||||
final String type = container.getOrDefault(Keys.auction_button.getNamespacedKey(), PersistentDataType.STRING, "");
|
||||
|
||||
if (type.isEmpty()) return;
|
||||
|
||||
final Player player = (Player) event.getWhoClicked();
|
||||
|
||||
if (type.equalsIgnoreCase("Back")) {
|
||||
GuiListener.openShop(player, HolderManager.getShopType(player), HolderManager.getShopCategory(player), 1);
|
||||
|
||||
click();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case "Back" -> {
|
||||
//playClick(player);
|
||||
|
||||
//openShop(player, HolderManager.getShopType(player), HolderManager.getShopCategory(player), 1);
|
||||
}
|
||||
|
||||
case "PreviousPage" -> {
|
||||
//Methods.updateAuction();
|
||||
|
||||
//int page = Integer.parseInt(title.split("#")[1]);
|
||||
|
||||
//if (page == 1) page++;
|
||||
|
||||
//playClick(player);
|
||||
|
||||
//openPlayersExpiredList(player, (page - 1));
|
||||
}
|
||||
|
||||
case "Return" -> {
|
||||
/*Methods.updateAuction();
|
||||
|
||||
int page = Integer.parseInt(title.split("#")[1]);
|
||||
|
||||
if (data.contains("OutOfTime/Cancelled")) {
|
||||
for (String i : data.getConfigurationSection("OutOfTime/Cancelled").getKeys(false)) {
|
||||
if (data.getString("OutOfTime/Cancelled." + i + ".Seller").equalsIgnoreCase(player.getUniqueId().toString())) {
|
||||
if (Methods.isInvFull(player)) {
|
||||
player.sendMessage(Messages.INVENTORY_FULL.getMessage(player));
|
||||
|
||||
break;
|
||||
} else {
|
||||
player.getInventory().addItem(Methods.fromBase64(data.getString("OutOfTime/Cancelled." + i + ".Item")));
|
||||
|
||||
data.set("OutOfTime/Cancelled." + i, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
player.sendMessage(Messages.GOT_ITEM_BACK.getMessage(player));
|
||||
|
||||
Files.data.save();
|
||||
|
||||
playClick(player);
|
||||
|
||||
openPlayersExpiredList(player, page);*/
|
||||
}
|
||||
|
||||
case "NextPage" -> {
|
||||
/*Methods.updateAuction();
|
||||
|
||||
int page = Integer.parseInt(title.split("#")[1]);
|
||||
|
||||
playClick(player);
|
||||
|
||||
openPlayersExpiredList(player, (page + 1));*/
|
||||
}
|
||||
|
||||
default -> click();
|
||||
}
|
||||
|
||||
if (!HolderManager.containsPage(player)) return;
|
||||
|
||||
final List<Integer> pages = HolderManager.getPages(player);
|
||||
|
||||
if (pages.size() >= slot) {
|
||||
int id = pages.get(slot);
|
||||
|
||||
boolean valid = false;
|
||||
|
||||
final FileConfiguration data = Files.data.getConfiguration();
|
||||
|
||||
final ConfigurationSection section = this.data.getConfigurationSection("OutOfTime/Cancelled");
|
||||
|
||||
if (section != null) {
|
||||
for (String key : section.getKeys(false)) {
|
||||
final ConfigurationSection auction = section.getConfigurationSection(key);
|
||||
|
||||
if (auction == null) continue;
|
||||
|
||||
int config_id = auction.getInt("StoreID");
|
||||
|
||||
if (id == config_id) {
|
||||
if (Methods.isInvFull(player)) {
|
||||
player.sendMessage(Messages.INVENTORY_FULL.getMessage(player));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
player.sendMessage(Messages.GOT_ITEM_BACK.getMessage(player));
|
||||
|
||||
player.getInventory().addItem(Methods.fromBase64(auction.getString("Item")));
|
||||
|
||||
data.set("OutOfTime/Cancelled." + key, null);
|
||||
|
||||
Files.data.save();
|
||||
|
||||
click();
|
||||
|
||||
GuiListener.openPlayersExpiredList(player, 1);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!valid) {
|
||||
click();
|
||||
|
||||
GuiListener.openShop(player, HolderManager.getShopType(player), HolderManager.getShopCategory(player), 1);
|
||||
|
||||
player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage(player));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void getItems() {
|
||||
final ConfigurationSection section = this.data.getConfigurationSection("OutOfTime/Cancelled");
|
||||
|
||||
if (section == null) return;
|
||||
|
||||
final UUID uuid = this.player.getUniqueId();
|
||||
|
||||
for (String key : section.getKeys(false)) {
|
||||
final ConfigurationSection auction = section.getConfigurationSection(key);
|
||||
|
||||
if (auction == null) continue;
|
||||
|
||||
final String seller = auction.getString("Seller", "");
|
||||
|
||||
if (seller.isEmpty()) continue;
|
||||
|
||||
if (!seller.equalsIgnoreCase(uuid.toString())) continue;
|
||||
|
||||
final String item = auction.getString("Item", "");
|
||||
|
||||
if (item.isEmpty()) continue;
|
||||
|
||||
final ItemBuilder itemBuilder = ItemBuilder.convertItemStack(item);
|
||||
|
||||
final long price = auction.getLong("Price");
|
||||
|
||||
final String priceFormat = String.format(Locale.ENGLISH, "%,d", price);
|
||||
|
||||
final String time = Methods.convertToTime(auction.getLong("Time-Till-Expire"));
|
||||
|
||||
final List<String> lore = new ArrayList<>(itemBuilder.getUpdatedLore());
|
||||
|
||||
lore.add(" ");
|
||||
|
||||
for (final String line : this.config.getStringList("Settings.GUISettings.Cancelled/ExpiredLore")) {
|
||||
lore.add(line.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"));
|
||||
}
|
||||
}
|
||||
}
|
@ -13,6 +13,7 @@ import com.badbones69.crazyauctions.api.guis.HolderManager;
|
||||
import com.badbones69.crazyauctions.api.guis.types.AuctionsMenu;
|
||||
import com.badbones69.crazyauctions.api.guis.types.CategoriesMenu;
|
||||
import com.badbones69.crazyauctions.api.guis.types.CurrentMenu;
|
||||
import com.badbones69.crazyauctions.api.guis.types.ExpiredMenu;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.Sound;
|
||||
@ -56,88 +57,9 @@ public class GuiListener implements Listener {
|
||||
}
|
||||
|
||||
public static void openPlayersExpiredList(Player player, 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("OutOfTime/Cancelled")) {
|
||||
for (String i : data.getConfigurationSection("OutOfTime/Cancelled").getKeys(false)) {
|
||||
if (data.getString("OutOfTime/Cancelled." + i + ".Seller") != null) {
|
||||
if (data.getString("OutOfTime/Cancelled." + i + ".Seller").equalsIgnoreCase(player.getUniqueId().toString())) {
|
||||
ItemBuilder itemBuilder = ItemBuilder.convertItemStack(data.getString("OutOfTime/Cancelled." + i + ".Item"));
|
||||
|
||||
List<String> lore = new ArrayList<>(itemBuilder.getUpdatedLore());
|
||||
|
||||
lore.add(" ");
|
||||
|
||||
String price = Methods.getPrice(i, true);
|
||||
String time = Methods.convertToTime(data.getLong("OutOfTime/Cancelled." + i + ".Full-Time"));
|
||||
|
||||
for (String l : config.getStringList("Settings.GUISettings.Cancelled/ExpiredLore")) {
|
||||
lore.add(l.replace("%Price%", price)
|
||||
.replace("%price%", price)
|
||||
.replace("%Time%", time)
|
||||
.replace("%time%", time));
|
||||
}
|
||||
|
||||
itemBuilder.setLore(lore);
|
||||
|
||||
items.add(itemBuilder.build());
|
||||
|
||||
ID.add(data.getInt("OutOfTime/Cancelled." + i + ".StoreID"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int maxPage = Methods.getMaxPage(items);
|
||||
|
||||
for (; page > maxPage; page--);
|
||||
|
||||
Inventory inv = plugin.getServer().createInventory(null, 54, Methods.color(config.getString("Settings.Cancelled/Expired-Items") + " #" + page));
|
||||
|
||||
List<String> options = new ArrayList<>();
|
||||
options.add("Back");
|
||||
options.add("PreviousPage");
|
||||
options.add("Return");
|
||||
options.add("NextPage");
|
||||
options.add("WhatIsThis.Cancelled/ExpiredItems");
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
List<Integer> Id = new ArrayList<>(Methods.getPageInts(ID, page));
|
||||
|
||||
HolderManager.addPages(player, Id);
|
||||
|
||||
player.openInventory(inv);
|
||||
new ExpiredMenu(player, config.getString("Settings.Cancelled/Expired-Items") + " #" + page, 54, page).build();
|
||||
}
|
||||
|
||||
public static void openBuying(Player player, String ID) {
|
||||
@ -682,126 +604,6 @@ public class GuiListener implements Listener {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (strippedTitle.contains(Methods.strip(config.getString("Settings.Cancelled/Expired-Items")))) {
|
||||
e.setCancelled(true);
|
||||
|
||||
final int slot = e.getRawSlot();
|
||||
|
||||
if (slot > inv.getSize()) return;
|
||||
|
||||
if (strippedDisplayName.equalsIgnoreCase(Methods.strip(config.getString("Settings.GUISettings.OtherSettings.Back.Name")))) {
|
||||
Methods.updateAuction();
|
||||
|
||||
playClick(player);
|
||||
|
||||
openShop(player, HolderManager.getShopType(player), HolderManager.getShopCategory(player), 1);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (strippedDisplayName.equalsIgnoreCase(Methods.strip(config.getString("Settings.GUISettings.OtherSettings.PreviousPage.Name")))) {
|
||||
Methods.updateAuction();
|
||||
|
||||
int page = Integer.parseInt(title.split("#")[1]);
|
||||
|
||||
if (page == 1) page++;
|
||||
|
||||
playClick(player);
|
||||
|
||||
openPlayersExpiredList(player, (page - 1));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (strippedDisplayName.equalsIgnoreCase(Methods.strip(config.getString("Settings.GUISettings.OtherSettings.Return.Name")))) {
|
||||
Methods.updateAuction();
|
||||
|
||||
int page = Integer.parseInt(title.split("#")[1]);
|
||||
|
||||
if (data.contains("OutOfTime/Cancelled")) {
|
||||
for (String i : data.getConfigurationSection("OutOfTime/Cancelled").getKeys(false)) {
|
||||
if (data.getString("OutOfTime/Cancelled." + i + ".Seller").equalsIgnoreCase(player.getUniqueId().toString())) {
|
||||
if (Methods.isInvFull(player)) {
|
||||
player.sendMessage(Messages.INVENTORY_FULL.getMessage(player));
|
||||
|
||||
break;
|
||||
} else {
|
||||
player.getInventory().addItem(Methods.fromBase64(data.getString("OutOfTime/Cancelled." + i + ".Item")));
|
||||
|
||||
data.set("OutOfTime/Cancelled." + i, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
player.sendMessage(Messages.GOT_ITEM_BACK.getMessage(player));
|
||||
|
||||
Files.data.save();
|
||||
|
||||
playClick(player);
|
||||
|
||||
openPlayersExpiredList(player, page);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (strippedDisplayName.equalsIgnoreCase(Methods.strip(config.getString("Settings.GUISettings.OtherSettings.NextPage.Name")))) {
|
||||
Methods.updateAuction();
|
||||
|
||||
int page = Integer.parseInt(title.split("#")[1]);
|
||||
|
||||
playClick(player);
|
||||
|
||||
openPlayersExpiredList(player, (page + 1));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (HolderManager.containsPage(player)) {
|
||||
final List<Integer> pages = HolderManager.getPages(player);
|
||||
|
||||
if (pages.size() >= slot) {
|
||||
int id = pages.get(slot);
|
||||
|
||||
boolean T = false;
|
||||
|
||||
if (data.contains("OutOfTime/Cancelled")) {
|
||||
for (String i : data.getConfigurationSection("OutOfTime/Cancelled").getKeys(false)) {
|
||||
int ID = data.getInt("OutOfTime/Cancelled." + i + ".StoreID");
|
||||
|
||||
if (id == ID) {
|
||||
if (!Methods.isInvFull(player)) {
|
||||
player.sendMessage(Messages.GOT_ITEM_BACK.getMessage(player));
|
||||
|
||||
player.getInventory().addItem(Methods.fromBase64(data.getString("OutOfTime/Cancelled." + i + ".Item")));
|
||||
|
||||
data.set("OutOfTime/Cancelled." + i, null);
|
||||
|
||||
Files.data.save();
|
||||
|
||||
playClick(player);
|
||||
|
||||
openPlayersExpiredList(player, 1);
|
||||
} else {
|
||||
player.sendMessage(Messages.INVENTORY_FULL.getMessage(player));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!T) {
|
||||
playClick(player);
|
||||
|
||||
openShop(player, HolderManager.getShopType(player), HolderManager.getShopCategory(player), 1);
|
||||
|
||||
player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage(player));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void playClick(Player player) {
|
||||
|
Loading…
Reference in New Issue
Block a user