mirror of
https://github.com/Crazy-Crew/CrazyAuctions.git
synced 2025-02-16 01:42:18 +01:00
migrate another menu
This commit is contained in:
parent
c503d7f04b
commit
ce99603c08
@ -6,6 +6,7 @@ import com.badbones69.crazyauctions.api.enums.Messages;
|
||||
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.support.MetricsWrapper;
|
||||
import com.badbones69.crazyauctions.commands.AuctionCommand;
|
||||
import com.badbones69.crazyauctions.commands.AuctionTab;
|
||||
@ -121,6 +122,7 @@ 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 GuiListener(), this);
|
||||
manager.registerEvents(new MarcoListener(), this);
|
||||
|
@ -50,6 +50,10 @@ public abstract class Holder implements InventoryHolder, Listener {
|
||||
this(player, shopType, title, size, 1);
|
||||
}
|
||||
|
||||
public Holder(final Player player, final String title, final int size, final int page) {
|
||||
this(player, null, title, size, page);
|
||||
}
|
||||
|
||||
public Holder() {}
|
||||
|
||||
public abstract Holder build();
|
||||
|
@ -0,0 +1,239 @@
|
||||
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.Category;
|
||||
import com.badbones69.crazyauctions.api.enums.Messages;
|
||||
import com.badbones69.crazyauctions.api.enums.Reasons;
|
||||
import com.badbones69.crazyauctions.api.enums.ShopType;
|
||||
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.OfflinePlayer;
|
||||
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 CurrentMenu extends Holder {
|
||||
|
||||
private List<ItemStack> items;
|
||||
private List<String> options;
|
||||
private List<Integer> ids;
|
||||
|
||||
private FileConfiguration config;
|
||||
private FileConfiguration data;
|
||||
|
||||
public CurrentMenu(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 CurrentMenu() {}
|
||||
|
||||
@Override
|
||||
public final Holder build() {
|
||||
Methods.updateAuction();
|
||||
|
||||
this.options.addAll(List.of(
|
||||
"Back",
|
||||
"WhatIsThis.CurrentItems"
|
||||
));
|
||||
|
||||
getItems();
|
||||
|
||||
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 CurrentMenu 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;
|
||||
}
|
||||
|
||||
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("Items");
|
||||
|
||||
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) {
|
||||
player.sendMessage(Messages.CANCELLED_ITEM.getMessage(player));
|
||||
|
||||
final String item = auction.getString("Item");
|
||||
|
||||
AuctionCancelledEvent auctionCancelledEvent = new AuctionCancelledEvent(player, Methods.fromBase64(item), Reasons.PLAYER_FORCE_CANCEL);
|
||||
this.plugin.getServer().getPluginManager().callEvent(auctionCancelledEvent);
|
||||
|
||||
int num = 1;
|
||||
for (; data.contains("OutOfTime/Cancelled." + num); num++) ;
|
||||
|
||||
data.set("OutOfTime/Cancelled." + num + ".Seller", auction.getString("Seller"));
|
||||
data.set("OutOfTime/Cancelled." + num + ".Full-Time", auction.getString("Full-Time"));
|
||||
data.set("OutOfTime/Cancelled." + num + ".StoreID",config_id);
|
||||
data.set("OutOfTime/Cancelled." + num + ".Item", item);
|
||||
|
||||
data.set("Items." + key, null);
|
||||
|
||||
Files.data.save();
|
||||
|
||||
click();
|
||||
|
||||
GuiListener.openPlayersCurrentList(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("Items");
|
||||
|
||||
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.CurrentLore")) {
|
||||
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"));
|
||||
}
|
||||
}
|
||||
}
|
@ -6,14 +6,13 @@ import com.badbones69.crazyauctions.api.builders.ItemBuilder;
|
||||
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.Reasons;
|
||||
import com.badbones69.crazyauctions.api.enums.ShopType;
|
||||
import com.badbones69.crazyauctions.api.events.AuctionBuyEvent;
|
||||
import com.badbones69.crazyauctions.api.events.AuctionCancelledEvent;
|
||||
import com.badbones69.crazyauctions.api.events.AuctionNewBidEvent;
|
||||
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 org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.Sound;
|
||||
@ -51,79 +50,9 @@ public class GuiListener implements Listener {
|
||||
}
|
||||
|
||||
public static void openPlayersCurrentList(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<>();
|
||||
|
||||
Inventory inv = plugin.getServer().createInventory(null, 54, Methods.color(config.getString("Settings.Players-Current-Items")));
|
||||
|
||||
List<String> options = new ArrayList<>();
|
||||
|
||||
options.add("Back");
|
||||
options.add("WhatIsThis.CurrentItems");
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
if (data.contains("Items")) {
|
||||
for (String i : data.getConfigurationSection("Items").getKeys(false)) {
|
||||
if (data.getString("Items." + i + ".Seller").equalsIgnoreCase(player.getUniqueId().toString())) {
|
||||
ItemBuilder itemBuilder = ItemBuilder.convertItemStack(data.getString("Items." + i + ".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"));
|
||||
|
||||
for (String l : config.getStringList("Settings.GUISettings.CurrentLore")) {
|
||||
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("Items." + i + ".StoreID"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 CurrentMenu(player, config.getString("Settings.Players-Current-Items", "N/A"), 54, page);
|
||||
}
|
||||
|
||||
public static void openPlayersExpiredList(Player player, int page) {
|
||||
@ -754,70 +683,6 @@ public class GuiListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
if (strippedTitle.contains(Methods.strip(config.getString("Settings.Players-Current-Items")))) {
|
||||
e.setCancelled(true);
|
||||
|
||||
int slot = e.getRawSlot();
|
||||
|
||||
if (slot > inv.getSize()) return;
|
||||
|
||||
if (strippedDisplayName.equalsIgnoreCase(Methods.strip(config.getString("Settings.GUISettings.OtherSettings.Back.Name")))) {
|
||||
openShop(player, HolderManager.getShopType(player), HolderManager.getShopCategory(player), 1);
|
||||
|
||||
playClick(player);
|
||||
|
||||
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("Items")) {
|
||||
for (String i : data.getConfigurationSection("Items").getKeys(false)) {
|
||||
int ID = data.getInt("Items." + i + ".StoreID");
|
||||
if (id == ID) {
|
||||
player.sendMessage(Messages.CANCELLED_ITEM.getMessage(player));
|
||||
|
||||
AuctionCancelledEvent event = new AuctionCancelledEvent(player, Methods.fromBase64(data.getString("Items." + i + ".Item")), Reasons.PLAYER_FORCE_CANCEL);
|
||||
plugin.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
int num = 1;
|
||||
for (; data.contains("OutOfTime/Cancelled." + num); num++) ;
|
||||
|
||||
data.set("OutOfTime/Cancelled." + num + ".Seller", data.getString("Items." + i + ".Seller"));
|
||||
data.set("OutOfTime/Cancelled." + num + ".Full-Time", data.getLong("Items." + i + ".Full-Time"));
|
||||
data.set("OutOfTime/Cancelled." + num + ".StoreID", data.getInt("Items." + i + ".StoreID"));
|
||||
data.set("OutOfTime/Cancelled." + num + ".Item", data.getString("Items." + i + ".Item"));
|
||||
|
||||
data.set("Items." + i, null);
|
||||
|
||||
Files.data.save();
|
||||
|
||||
playClick(player);
|
||||
|
||||
openPlayersCurrentList(player, 1);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!T) {
|
||||
playClick(player);
|
||||
|
||||
openShop(player, HolderManager.getShopType(player), HolderManager.getShopCategory(player), 1);
|
||||
|
||||
player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage(player));
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (strippedTitle.contains(Methods.strip(config.getString("Settings.Cancelled/Expired-Items")))) {
|
||||
e.setCancelled(true);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user