mirror of
https://github.com/Crazy-Crew/CrazyAuctions.git
synced 2025-01-08 19:38:15 +01:00
replace categories menu
This commit is contained in:
parent
ddced9e299
commit
815dd2e375
@ -5,6 +5,7 @@ import com.badbones69.crazyauctions.api.enums.misc.Files;
|
||||
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.support.MetricsWrapper;
|
||||
import com.badbones69.crazyauctions.commands.AuctionCommand;
|
||||
import com.badbones69.crazyauctions.commands.AuctionTab;
|
||||
@ -118,7 +119,9 @@ public class CrazyAuctions extends Vital {
|
||||
|
||||
final PluginManager manager = getServer().getPluginManager();
|
||||
|
||||
manager.registerEvents(new AuctionsMenu(), this); // register new menu
|
||||
manager.registerEvents(new AuctionsMenu(), this); // register main menu
|
||||
manager.registerEvents(new CategoriesMenu(), this); // register categories menu
|
||||
|
||||
manager.registerEvents(new GuiListener(), this);
|
||||
manager.registerEvents(new MarcoListener(), this);
|
||||
|
||||
|
@ -46,6 +46,10 @@ public abstract class Holder implements InventoryHolder, Listener {
|
||||
this.inventory = this.server.createInventory(this, this.size, Methods.color(inventoryTitle));
|
||||
}
|
||||
|
||||
public Holder(final Player player, final ShopType shopType, final String title, final int size) {
|
||||
this(player, shopType, title, size, 1);
|
||||
}
|
||||
|
||||
public Holder() {}
|
||||
|
||||
public abstract Holder build();
|
||||
|
@ -0,0 +1,116 @@
|
||||
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.ShopType;
|
||||
import com.badbones69.crazyauctions.api.enums.misc.Files;
|
||||
import com.badbones69.crazyauctions.api.enums.misc.Keys;
|
||||
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.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;
|
||||
|
||||
public class CategoriesMenu extends Holder {
|
||||
|
||||
private List<String> options;
|
||||
|
||||
private FileConfiguration config;
|
||||
|
||||
public CategoriesMenu(final Player player, final ShopType shopType, final String title, final int size) {
|
||||
super(player, shopType, title, size);
|
||||
|
||||
this.options = new ArrayList<>();
|
||||
|
||||
this.config = Files.config.getConfiguration();
|
||||
}
|
||||
|
||||
public CategoriesMenu() {}
|
||||
|
||||
@Override
|
||||
public final Holder build() {
|
||||
Methods.updateAuction();
|
||||
|
||||
this.options.addAll(List.of(
|
||||
"OtherSettings.Back",
|
||||
"OtherSettings.WhatIsThis.Categories",
|
||||
"Category-Settings.Armor",
|
||||
"Category-Settings.Weapons",
|
||||
"Category-Settings.Tools",
|
||||
"Category-Settings.Food",
|
||||
"Category-Settings.Potions",
|
||||
"Category-Settings.Blocks",
|
||||
"Category-Settings.Other",
|
||||
"Category-Settings.None"
|
||||
));
|
||||
|
||||
for (final String key : this.options) {
|
||||
if (!this.config.contains("Settings.GUISettings." + key)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!this.config.getBoolean("Settings.GUISettings." + key + ".Toggle", true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String id = this.config.getString("Settings.GUISettings." + key + ".Item");
|
||||
String name = this.config.getString("Settings.GUISettings." + key + ".Name");
|
||||
int slot = this.config.getInt("Settings.GUISettings." + key + ".Slot");
|
||||
|
||||
ItemBuilder itemBuilder = new ItemBuilder().setMaterial(id).setName(name).addString(key).setAmount(1);
|
||||
|
||||
if (this.config.contains("Settings.GUISettings." + key + ".Lore")) {
|
||||
itemBuilder.setLore(this.config.getStringList("Settings.GUISettings." + key + ".Lore"));
|
||||
}
|
||||
|
||||
this.inventory.setItem(slot - 1, itemBuilder.build());
|
||||
}
|
||||
|
||||
HolderManager.addShopType(this.player, this.shopType);
|
||||
|
||||
this.player.openInventory(this.inventory);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(InventoryClickEvent event) {
|
||||
if (!(event.getInventory().getHolder(false) instanceof CategoriesMenu 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 Player player = (Player) event.getWhoClicked();
|
||||
|
||||
final String type = container.getOrDefault(Keys.auction_button.getNamespacedKey(), PersistentDataType.STRING, "Category-Settings.None");
|
||||
|
||||
final Category category = Category.getFromName(type);
|
||||
|
||||
GuiListener.openShop(player, HolderManager.getShopType(player), HolderManager.getShopCategory(player) != null ? HolderManager.getShopCategory(player) : category, 1);
|
||||
|
||||
click();
|
||||
}
|
||||
}
|
@ -13,6 +13,7 @@ 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 org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.Sound;
|
||||
@ -43,47 +44,10 @@ public class GuiListener implements Listener {
|
||||
new AuctionsMenu(player, shopType, category, config.getString("Settings.GUIName", "N/A"), 54, page);
|
||||
}
|
||||
|
||||
public static void openCategories(Player player, ShopType shop) {
|
||||
Methods.updateAuction();
|
||||
public static void openCategories(Player player, ShopType shopType) {
|
||||
FileConfiguration config = Files.config.getConfiguration();
|
||||
|
||||
Inventory inv = plugin.getServer().createInventory(null, 54, Methods.color(config.getString("Settings.Categories")));
|
||||
|
||||
List<String> options = new ArrayList<>();
|
||||
|
||||
options.add("OtherSettings.Back");
|
||||
options.add("OtherSettings.WhatIsThis.Categories");
|
||||
options.add("Category-Settings.Armor");
|
||||
options.add("Category-Settings.Weapons");
|
||||
options.add("Category-Settings.Tools");
|
||||
options.add("Category-Settings.Food");
|
||||
options.add("Category-Settings.Potions");
|
||||
options.add("Category-Settings.Blocks");
|
||||
options.add("Category-Settings.Other");
|
||||
options.add("Category-Settings.None");
|
||||
|
||||
for (String o : options) {
|
||||
if (config.contains("Settings.GUISettings." + o + ".Toggle")) {
|
||||
if (!config.getBoolean("Settings.GUISettings." + o + ".Toggle")) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
String id = config.getString("Settings.GUISettings." + o + ".Item");
|
||||
String name = config.getString("Settings.GUISettings." + o + ".Name");
|
||||
int slot = config.getInt("Settings.GUISettings." + o + ".Slot");
|
||||
|
||||
ItemBuilder itemBuilder = new ItemBuilder().setMaterial(id).setName(name).setAmount(1);
|
||||
|
||||
if (config.contains("Settings.GUISettings." + o + ".Lore")) {
|
||||
itemBuilder.setLore(config.getStringList("Settings.GUISettings." + o + ".Lore"));
|
||||
}
|
||||
|
||||
inv.setItem(slot - 1, itemBuilder.build());
|
||||
}
|
||||
|
||||
HolderManager.addShopType(player, shop);
|
||||
player.openInventory(inv);
|
||||
new CategoriesMenu(player, shopType, config.getString("Settings.Categories", "N/A"), 54).build();
|
||||
}
|
||||
|
||||
public static void openPlayersCurrentList(Player player, int page) {
|
||||
@ -615,33 +579,6 @@ public class GuiListener implements Listener {
|
||||
|
||||
final String strippedDisplayName = Methods.strip(displayName);
|
||||
|
||||
if (strippedTitle.contains(Methods.strip(config.getString("Settings.Categories")))) {
|
||||
|
||||
e.setCancelled(true);
|
||||
|
||||
int slot = e.getRawSlot();
|
||||
|
||||
if (slot > inv.getSize()) return;
|
||||
|
||||
for (Category cat : Category.values()) {
|
||||
if (strippedDisplayName.equalsIgnoreCase(Methods.strip(config.getString("Settings.GUISettings.Category-Settings." + cat.getName() + ".Name")))) {
|
||||
openShop(player, HolderManager.getShopType(player), cat, 1);
|
||||
|
||||
playClick(player);
|
||||
|
||||
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 (strippedTitle.contains(Methods.strip(config.getString("Settings.Bidding-On-Item")))) {
|
||||
e.setCancelled(true);
|
||||
int slot = e.getRawSlot();
|
||||
|
Loading…
Reference in New Issue
Block a user