mirror of
https://github.com/Crazy-Crew/CrazyAuctions.git
synced 2024-11-25 12:25:20 +01:00
re-work main menu
This commit is contained in:
parent
8a0702344b
commit
ecc820e487
@ -4,6 +4,7 @@ import com.badbones69.crazyauctions.api.CrazyManager;
|
||||
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.support.MetricsWrapper;
|
||||
import com.badbones69.crazyauctions.commands.AuctionCommand;
|
||||
import com.badbones69.crazyauctions.commands.AuctionTab;
|
||||
@ -19,6 +20,7 @@ import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@ -114,8 +116,11 @@ public class CrazyAuctions extends Vital {
|
||||
|
||||
this.crazyManager.load();
|
||||
|
||||
getServer().getPluginManager().registerEvents(new GuiListener(), this);
|
||||
getServer().getPluginManager().registerEvents(new MarcoListener(), this);
|
||||
final PluginManager manager = getServer().getPluginManager();
|
||||
|
||||
manager.registerEvents(new AuctionsMenu(), this); // register new menu
|
||||
manager.registerEvents(new GuiListener(), this);
|
||||
manager.registerEvents(new MarcoListener(), this);
|
||||
|
||||
registerCommand(getCommand("crazyauctions"), new AuctionTab(), new AuctionCommand());
|
||||
|
||||
|
@ -0,0 +1,78 @@
|
||||
package com.badbones69.crazyauctions.api.guis;
|
||||
|
||||
import com.badbones69.crazyauctions.CrazyAuctions;
|
||||
import com.badbones69.crazyauctions.Methods;
|
||||
import com.badbones69.crazyauctions.api.CrazyManager;
|
||||
import com.badbones69.crazyauctions.api.enums.ShopType;
|
||||
import com.badbones69.crazyauctions.api.enums.misc.Files;
|
||||
import com.ryderbelserion.vital.paper.api.enums.Support;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.SoundCategory;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class Holder implements InventoryHolder, Listener {
|
||||
|
||||
protected final CrazyAuctions plugin = CrazyAuctions.getPlugin();
|
||||
|
||||
protected final CrazyManager crazyManager = this.plugin.getCrazyManager();
|
||||
|
||||
protected final Server server = this.plugin.getServer();
|
||||
|
||||
protected Inventory inventory;
|
||||
protected ShopType shopType;
|
||||
protected Player player;
|
||||
protected String title;
|
||||
protected int size;
|
||||
protected int page;
|
||||
|
||||
public Holder(final Player player, final ShopType shopType, final String title, final int size, final int page) {
|
||||
this.player = player;
|
||||
this.shopType = shopType;
|
||||
this.title = title;
|
||||
this.size = size;
|
||||
this.page = page;
|
||||
|
||||
final String inventoryTitle = Support.placeholder_api.isEnabled() ? PlaceholderAPI.setPlaceholders(this.player, this.title) : this.title;
|
||||
|
||||
this.inventory = this.server.createInventory(this, this.size, Methods.color(inventoryTitle));
|
||||
}
|
||||
|
||||
public Holder() {}
|
||||
|
||||
public abstract Holder build();
|
||||
|
||||
public abstract void run(InventoryClickEvent event);
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerClick(InventoryClickEvent event) {
|
||||
run(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull final Inventory getInventory() {
|
||||
return this.inventory;
|
||||
}
|
||||
|
||||
public void click() {
|
||||
final FileConfiguration config = Files.config.getConfiguration();
|
||||
|
||||
if (config.getBoolean("Settings.Sounds.Toggle", false)) {
|
||||
final String sound = config.getString("Settings.Sounds.Sound", "UI_BUTTON_CLICK");
|
||||
|
||||
try {
|
||||
this.player.playSound(this.player.getLocation(), Sound.valueOf(sound), 1, 1);
|
||||
} catch (Exception e) {
|
||||
this.player.playSound(this.player.getLocation(), Sound.UI_BUTTON_CLICK, SoundCategory.PLAYERS, 1F, 1F);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,476 @@
|
||||
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.events.AuctionCancelledEvent;
|
||||
import com.badbones69.crazyauctions.api.guis.Holder;
|
||||
import com.badbones69.crazyauctions.api.guis.HolderManager;
|
||||
import com.ryderbelserion.vital.paper.util.scheduler.FoliaRunnable;
|
||||
import org.bukkit.ChatColor;
|
||||
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.InventoryAction;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.UUID;
|
||||
|
||||
@SuppressWarnings("FieldCanBeLocal")
|
||||
public class AuctionsMenu extends Holder {
|
||||
|
||||
private List<ItemStack> items;
|
||||
private List<String> options;
|
||||
private List<Integer> ids;
|
||||
|
||||
private FileConfiguration config;
|
||||
private FileConfiguration data;
|
||||
|
||||
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);
|
||||
|
||||
this.items = new ArrayList<>();
|
||||
this.options = new ArrayList<>();
|
||||
this.ids = new ArrayList<>();
|
||||
|
||||
this.config = Files.config.getConfiguration();
|
||||
this.data = Files.data.getConfiguration();
|
||||
|
||||
if (!this.data.contains("Items")) {
|
||||
this.data.set("Items.Clear", null);
|
||||
|
||||
Files.data.save();
|
||||
}
|
||||
|
||||
HolderManager.addShopCategory(player, this.category = category);
|
||||
}
|
||||
|
||||
public AuctionsMenu() {}
|
||||
|
||||
@Override
|
||||
public final Holder build() {
|
||||
Methods.updateAuction();
|
||||
|
||||
this.options.addAll(List.of(
|
||||
"SellingItems",
|
||||
"Cancelled/ExpiredItems",
|
||||
"PreviousPage",
|
||||
"Refresh",
|
||||
"Refesh",
|
||||
"NextPage",
|
||||
"Category1",
|
||||
"Category2"
|
||||
));
|
||||
|
||||
getItems(); // populates the lists
|
||||
|
||||
HolderManager.addShopType(this.player, this.shopType);
|
||||
|
||||
switch (this.shopType) {
|
||||
case SELL -> {
|
||||
if (this.crazyManager.isSellingEnabled()) {
|
||||
this.options.add("Bidding/Selling.Selling");
|
||||
}
|
||||
|
||||
this.options.add("WhatIsThis.SellingShop");
|
||||
}
|
||||
|
||||
case BID -> {
|
||||
if (this.crazyManager.isBiddingEnabled()) {
|
||||
this.options.add("Bidding/Selling.Bidding");
|
||||
}
|
||||
|
||||
this.options.add("WhatIsThis.BiddingShop");
|
||||
}
|
||||
}
|
||||
|
||||
for (final String key : this.options) {
|
||||
if (this.config.contains("Settings.GUISettings.OtherSettings." + key + ".Toggle")) {
|
||||
if (!this.config.getBoolean("Settings.GUISettings.OtherSettings." + key + ".Toggle")) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
final String id = this.config.getString("Settings.GUISettings.OtherSettings." + key + ".Item");
|
||||
final String name = this.config.getString("Settings.GUISettings.OtherSettings." + key + ".Name");
|
||||
final List<String> lore = new ArrayList<>();
|
||||
final int slot = this.config.getInt("Settings.GUISettings.OtherSettings." + key + ".Slot");
|
||||
final String cName = Methods.color(this.config.getString("Settings.GUISettings.Category-Settings." + HolderManager.getShopCategory(this.player) + ".Name"));
|
||||
|
||||
final ItemBuilder itemBuilder = new ItemBuilder().setMaterial(id).setName(name).setAmount(1);
|
||||
|
||||
if (this.config.contains("Settings.GUISettings.OtherSettings." + key + ".Lore")) {
|
||||
for (final String line : this.config.getStringList("Settings.GUISettings.OtherSettings." + key + ".Lore")) {
|
||||
lore.add(line.replace("%Category%", cName).replace("%category%", cName));
|
||||
}
|
||||
|
||||
this.inventory.setItem(slot - 1, itemBuilder.setLore(lore).build());
|
||||
} else {
|
||||
this.inventory.setItem(slot - 1, itemBuilder.setLore(lore).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 AuctionsMenu 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;
|
||||
|
||||
if (!itemStack.hasItemMeta()) return;
|
||||
|
||||
final ItemMeta meta = itemStack.getItemMeta();
|
||||
|
||||
final String displayName = ChatColor.stripColor(meta.getDisplayName());
|
||||
|
||||
if (displayName.equals(config.getString("Settings.GUISettings.OtherSettings.NextPage.Name"))) {
|
||||
click();
|
||||
}
|
||||
|
||||
if (displayName.equals(config.getString("Settings.GUISettings.OtherSettings.PreviousPage.Name"))) {
|
||||
//Methods.updateAuction();
|
||||
|
||||
//int page = Integer.parseInt(e.getView().getTitle().split("#")[1]);
|
||||
|
||||
//if (page == 1) page++;
|
||||
|
||||
//openShop(player, shopType.get(player.getUniqueId()), shopCategory.get(player.getUniqueId()), page - 1);
|
||||
|
||||
click();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (displayName.equals(config.getString("Settings.GUISettings.OtherSettings.Refesh.Name"))) {
|
||||
//Methods.updateAuction();
|
||||
|
||||
//int page = Integer.parseInt(e.getView().getTitle().split("#")[1]);
|
||||
|
||||
//openShop(player, shopType.get(player.getUniqueId()), shopCategory.get(player.getUniqueId()), page);
|
||||
|
||||
click();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (displayName.equals(config.getString("Settings.GUISettings.OtherSettings.Bidding/Selling.Selling.Name"))) {
|
||||
//openShop(player, ShopType.BID, shopCategory.get(player.getUniqueId()), 1);
|
||||
|
||||
click();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (displayName.equals(config.getString("Settings.GUISettings.OtherSettings.Bidding/Selling.Bidding.Name"))) {
|
||||
//openShop(player, ShopType.SELL, shopCategory.get(player.getUniqueId()), 1);
|
||||
|
||||
click();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (displayName.equals(config.getString("Settings.GUISettings.OtherSettings.Cancelled/ExpiredItems.Name"))) {
|
||||
//openPlayersExpiredList(player, 1);
|
||||
|
||||
click();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (displayName.equals(config.getString("Settings.GUISettings.OtherSettings.SellingItems.Name"))) {
|
||||
//openPlayersCurrentList(player, 1);
|
||||
|
||||
click();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (displayName.equals(config.getString("Settings.GUISettings.OtherSettings.Category1.Name"))) {
|
||||
//openCategories(player, shopType.get(player.getUniqueId()));
|
||||
|
||||
click();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (displayName.equals(config.getString("Settings.GUISettings.OtherSettings.Category2.Name"))) {
|
||||
//openCategories(player, shopType.get(player.getUniqueId()));
|
||||
|
||||
click();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (displayName.equals(config.getString("Settings.GUISettings.OtherSettings.Your-Item.Name"))) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (displayName.equals(config.getString("Settings.GUISettings.OtherSettings.Cant-Afford.Name"))) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (displayName.equals(config.getString("Settings.GUISettings.OtherSettings.Top-Bidder.Name"))) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!HolderManager.containsPage(this.player)) return;
|
||||
|
||||
if (!this.data.contains("Items")) return;
|
||||
|
||||
final ConfigurationSection section = this.data.getConfigurationSection("Items");
|
||||
|
||||
if (section == null) return;
|
||||
|
||||
final List<Integer> pages = HolderManager.getPages(player);
|
||||
|
||||
if (pages.size() < slot) return;
|
||||
|
||||
final int id = pages.get(slot);
|
||||
|
||||
final UUID uuid = this.player.getUniqueId();
|
||||
|
||||
for (String i : section.getKeys(false)) {
|
||||
int ID = data.getInt("Items." + i + ".StoreID");
|
||||
|
||||
if (id != ID) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.player.hasPermission("crazyauctions.admin") || this.player.hasPermission("crazyauctions.force-end")) {
|
||||
if (event.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY) {
|
||||
int num = 1;
|
||||
|
||||
for (;this.data.contains("OutOfTime/Cancelled." + num); num++);
|
||||
|
||||
String seller = this.data.getString("Items." + i + ".Seller");
|
||||
|
||||
Player sellerPlayer = Methods.getPlayer(seller);
|
||||
|
||||
if (Methods.isOnline(seller) && sellerPlayer != null) {
|
||||
sellerPlayer.sendMessage(Messages.ADMIN_FORCE_CANCELLED_TO_PLAYER.getMessage(this.player));
|
||||
}
|
||||
|
||||
AuctionCancelledEvent auctionCancelledEvent = new AuctionCancelledEvent((sellerPlayer != null ? sellerPlayer : Methods.getOfflinePlayer(seller)), Methods.fromBase64(this.data.getString("Items." + ID + ".Item")), Reasons.ADMIN_FORCE_CANCEL);
|
||||
this.server.getPluginManager().callEvent(auctionCancelledEvent);
|
||||
|
||||
this.data.set("OutOfTime/Cancelled." + num + ".Seller", section.getString("Seller"));
|
||||
this.data.set("OutOfTime/Cancelled." + num + ".Full-Time", section.getLong("Full-Time"));
|
||||
this.data.set("OutOfTime/Cancelled." + num + ".StoreID", section.getInt("StoreID"));
|
||||
this.data.set("OutOfTime/Cancelled." + num + ".Item", this.data.getString("Items." + ID + ".Item"));
|
||||
this.data.set("Items." + i, null);
|
||||
|
||||
Files.data.save();
|
||||
|
||||
this.player.sendMessage(Messages.ADMIN_FORCE_CANCELLED.getMessage(this.player));
|
||||
|
||||
click();
|
||||
|
||||
int page = Integer.parseInt(event.getView().getTitle().split("#")[1]);
|
||||
|
||||
//openShop(player, shopType.get(player.getUniqueId()), shopCategory.get(player.getUniqueId()), page);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.data.getString("Items." + i + ".Seller", "").equalsIgnoreCase(uuid.toString())) {
|
||||
String itemName = this.config.getString("Settings.GUISettings.OtherSettings.Your-Item.Item");
|
||||
String name = this.config.getString("Settings.GUISettings.OtherSettings.Your-Item.Name");
|
||||
|
||||
ItemBuilder itemBuilder = new ItemBuilder().setMaterial(itemName).setName(name).setAmount(1);
|
||||
|
||||
if (this.config.contains("Settings.GUISettings.OtherSettings.Your-Item.Lore")) {
|
||||
itemBuilder.setLore(this.config.getStringList("Settings.GUISettings.OtherSettings.Your-Item.Lore"));
|
||||
}
|
||||
|
||||
inventory.setItem(slot, itemBuilder.build());
|
||||
|
||||
click();
|
||||
|
||||
new FoliaRunnable(this.plugin.getServer().getGlobalRegionScheduler()) {
|
||||
@Override
|
||||
public void run() {
|
||||
//inventory.setItem(slot, item);
|
||||
}
|
||||
}.runDelayed(this.plugin, 3 * 20);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
long cost = this.data.getLong("Items." + i + ".Price");
|
||||
|
||||
if (this.plugin.getSupport().getMoney(this.player) < cost) {
|
||||
String itemName = this.config.getString("Settings.GUISettings.OtherSettings.Cant-Afford.Item");
|
||||
String name = this.config.getString("Settings.GUISettings.OtherSettings.Cant-Afford.Name");
|
||||
|
||||
ItemBuilder itemBuilder = new ItemBuilder().setMaterial(itemName).setName(name).setAmount(1);
|
||||
|
||||
if (this.config.contains("Settings.GUISettings.OtherSettings.Cant-Afford.Lore")) {
|
||||
itemBuilder.setLore(this.config.getStringList("Settings.GUISettings.OtherSettings.Cant-Afford.Lore"));
|
||||
}
|
||||
|
||||
inventory.setItem(slot, itemBuilder.build());
|
||||
click();
|
||||
|
||||
new FoliaRunnable(this.plugin.getServer().getGlobalRegionScheduler()) {
|
||||
@Override
|
||||
public void run() {
|
||||
//inventory.setItem(slot, item);
|
||||
}
|
||||
}.runDelayed(this.plugin, 3 * 20);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.data.getBoolean("Items." + i + ".Biddable")) {
|
||||
if (this.player.getUniqueId().toString().equalsIgnoreCase(this.data.getString("Items." + i + ".TopBidder"))) {
|
||||
String itemName = this.config.getString("Settings.GUISettings.OtherSettings.Top-Bidder.Item");
|
||||
String name = this.config.getString("Settings.GUISettings.OtherSettings.Top-Bidder.Name");
|
||||
|
||||
ItemBuilder itemBuilder = new ItemBuilder().setMaterial(itemName).setName(name).setAmount(1);
|
||||
|
||||
if (this.config.contains("Settings.GUISettings.OtherSettings.Top-Bidder.Lore")) {
|
||||
itemBuilder.setLore(this.config.getStringList("Settings.GUISettings.OtherSettings.Top-Bidder.Lore"));
|
||||
}
|
||||
|
||||
inventory.setItem(slot, itemBuilder.build());
|
||||
|
||||
click();
|
||||
|
||||
new FoliaRunnable(this.plugin.getServer().getGlobalRegionScheduler()) {
|
||||
@Override
|
||||
public void run() {
|
||||
//inventory.setItem(slot, item);
|
||||
}
|
||||
}.runDelayed(this.plugin, 3 * 20);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
click();
|
||||
|
||||
//openBidding(player, i);
|
||||
|
||||
HolderManager.addBidId(this.player, i);
|
||||
} else {
|
||||
click();
|
||||
|
||||
//openBuying(player, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void getItems() {
|
||||
final ConfigurationSection section = this.data.getConfigurationSection("Items");
|
||||
|
||||
if (section == null) return;
|
||||
|
||||
for (String key : section.getKeys(false)) {
|
||||
final ConfigurationSection auction = section.getConfigurationSection(key);
|
||||
|
||||
if (auction == null) continue;
|
||||
|
||||
final String item = auction.getString("Item", "");
|
||||
|
||||
if (item.isEmpty()) continue;
|
||||
|
||||
final ItemBuilder itemBuilder = ItemBuilder.convertItemStack(item);
|
||||
|
||||
if (itemBuilder == null) continue;
|
||||
|
||||
if (!this.category.getItems().contains(itemBuilder.getMaterial())) continue;
|
||||
|
||||
final String seller = auction.getString("Seller", "");
|
||||
|
||||
if (seller.isEmpty()) continue;
|
||||
|
||||
final String price = section.getString("Price", "");
|
||||
|
||||
if (price.isEmpty()) continue;
|
||||
|
||||
final String priceFormat = String.format(Locale.ENGLISH, "%,d", Long.parseLong(price));
|
||||
|
||||
final OfflinePlayer player = Methods.getOfflinePlayer(seller);
|
||||
|
||||
final String time = Methods.convertToTime(section.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));
|
||||
}
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
itemBuilder.setLore(lore);
|
||||
|
||||
this.items.add(itemBuilder.build());
|
||||
|
||||
this.ids.add(auction.getInt("StoreID"));
|
||||
}
|
||||
}
|
||||
}
|
@ -8,6 +8,7 @@ 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.AuctionListEvent;
|
||||
import com.badbones69.crazyauctions.api.guis.types.AuctionsMenu;
|
||||
import com.badbones69.crazyauctions.controllers.GuiListener;
|
||||
import com.ryderbelserion.vital.paper.api.files.FileManager;
|
||||
import org.bukkit.Material;
|
||||
@ -58,9 +59,9 @@ public class AuctionCommand implements CommandExecutor {
|
||||
}
|
||||
|
||||
if (crazyManager.isSellingEnabled()) {
|
||||
GuiListener.openShop(player, ShopType.SELL, Category.NONE, 1);
|
||||
new AuctionsMenu(player, ShopType.SELL, Category.NONE, config.getString("Settings.GUIName", "N/A"), 54, 1).build();
|
||||
} else if (crazyManager.isBiddingEnabled()) {
|
||||
GuiListener.openShop(player, ShopType.BID, Category.NONE, 1);
|
||||
new AuctionsMenu(player, ShopType.BID, Category.NONE, config.getString("Settings.GUIName", "N/A"), 54, 1).build();
|
||||
} else {
|
||||
player.sendMessage(Methods.getPrefix() + Methods.color("&cThe bidding and selling options are both disabled. Please contact the admin about this."));
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package com.badbones69.crazyauctions.controllers;
|
||||
|
||||
import com.badbones69.crazyauctions.CrazyAuctions;
|
||||
import com.badbones69.crazyauctions.Methods;
|
||||
import com.badbones69.crazyauctions.api.CrazyManager;
|
||||
import com.badbones69.crazyauctions.api.builders.ItemBuilder;
|
||||
import com.badbones69.crazyauctions.api.enums.Category;
|
||||
import com.badbones69.crazyauctions.api.enums.misc.Files;
|
||||
@ -13,6 +12,7 @@ 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 org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.Sound;
|
||||
@ -29,176 +29,16 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public class GuiListener implements Listener {
|
||||
|
||||
@NotNull
|
||||
private static final CrazyAuctions plugin = CrazyAuctions.getPlugin();
|
||||
private static final CrazyManager crazyManager = plugin.getCrazyManager();
|
||||
|
||||
public static void openShop(Player player, ShopType sell, Category cat, int page) {
|
||||
Methods.updateAuction();
|
||||
|
||||
public static void openShop(Player player, ShopType shopType, Category category, int page) {
|
||||
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();
|
||||
}
|
||||
|
||||
HolderManager.addShopCategory(player, cat == null ? Category.NONE : cat);
|
||||
|
||||
if (data.contains("Items")) {
|
||||
for (String i : data.getConfigurationSection("Items").getKeys(false)) {
|
||||
ItemBuilder itemBuilder = ItemBuilder.convertItemStack(data.getString("Items." + i + ".Item"));
|
||||
|
||||
if (itemBuilder != null && data.contains("Items." + i + ".Item") && (cat.getItems().contains(itemBuilder.getItemStack().getType()) || cat == Category.NONE)) {
|
||||
List<String> lore = new ArrayList<>(itemBuilder.getUpdatedLore());
|
||||
|
||||
lore.add(" ");
|
||||
|
||||
if (data.getBoolean("Items." + i + ".Biddable")) {
|
||||
if (sell == ShopType.BID) {
|
||||
String seller = data.getString("Items." + i + ".Seller");
|
||||
|
||||
OfflinePlayer target = null;
|
||||
|
||||
if (seller != null) {
|
||||
target = Methods.getOfflinePlayer(seller);
|
||||
}
|
||||
|
||||
String price = Methods.getPrice(i, false);
|
||||
String time = Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire"));
|
||||
|
||||
OfflinePlayer bidder = null;
|
||||
|
||||
String topbidder = data.getString("Items." + i + ".TopBidder");
|
||||
|
||||
if (topbidder != null && !topbidder.equals("None")) {
|
||||
bidder = Methods.getOfflinePlayer(topbidder);
|
||||
}
|
||||
|
||||
for (String key : config.getStringList("Settings.GUISettings.Bidding")) {
|
||||
String line = key.replace("%TopBid%", price).replace("%topbid%", price);
|
||||
|
||||
line = target != null ? line.replace("%Seller%", target.getName()).replace("%seller%", target.getName()) : line.replace("%Seller%", "N/A").replace("%seller%", "N/A");
|
||||
|
||||
line = bidder != null ? line.replace("%TopBidder%", bidder.getName()).replace("%topbidder%", bidder.getName()) : line.replace("%TopBidder%", "N/A").replace("%topbidder%", "N/A");
|
||||
|
||||
lore.add(line.replace("%Time%", time).replace("%time%", time));
|
||||
}
|
||||
|
||||
itemBuilder.setLore(lore);
|
||||
|
||||
items.add(itemBuilder.build());
|
||||
|
||||
ID.add(data.getInt("Items." + i + ".StoreID"));
|
||||
}
|
||||
} else {
|
||||
if (sell == ShopType.SELL) {
|
||||
String seller = data.getString("Items." + i + ".Seller");
|
||||
|
||||
OfflinePlayer target = null;
|
||||
|
||||
if (seller != null) {
|
||||
target = Methods.getOfflinePlayer(seller);
|
||||
}
|
||||
|
||||
String price = Methods.getPrice(i, false);
|
||||
String time = Methods.convertToTime(data.getLong("Items." + i + ".Time-Till-Expire"));
|
||||
|
||||
String format = String.format(Locale.ENGLISH, "%,d", Long.parseLong(price));
|
||||
|
||||
for (String l : config.getStringList("Settings.GUISettings.SellingItemLore")) {
|
||||
lore.add(l.replace("%Price%", format).replace("%price%", format)
|
||||
.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("SellingItems");
|
||||
options.add("Cancelled/ExpiredItems");
|
||||
options.add("PreviousPage");
|
||||
options.add("Refesh");
|
||||
options.add("Refresh");
|
||||
options.add("NextPage");
|
||||
options.add("Category1");
|
||||
options.add("Category2");
|
||||
|
||||
if (sell == ShopType.SELL) {
|
||||
if (crazyManager.isBiddingEnabled()) {
|
||||
options.add("Bidding/Selling.Selling");
|
||||
}
|
||||
}
|
||||
|
||||
HolderManager.addShopType(player, sell == ShopType.BID ? ShopType.BID : ShopType.SELL);
|
||||
|
||||
options.add(sell == ShopType.BID ? "WhatIsThis.BiddingShop" : "WhatIsThis.SellingShop");
|
||||
|
||||
if (sell == ShopType.BID) {
|
||||
if (crazyManager.isSellingEnabled()) {
|
||||
options.add("Bidding/Selling.Bidding");
|
||||
}
|
||||
}
|
||||
|
||||
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");
|
||||
List<String> lore = new ArrayList<>();
|
||||
int slot = config.getInt("Settings.GUISettings.OtherSettings." + o + ".Slot");
|
||||
String cName = Methods.color(config.getString("Settings.GUISettings.Category-Settings." + HolderManager.getShopCategory(player).getName() + ".Name"));
|
||||
|
||||
ItemBuilder itemBuilder = new ItemBuilder().setMaterial(id).setName(name).setAmount(1);
|
||||
|
||||
if (config.contains("Settings.GUISettings.OtherSettings." + o + ".Lore")) {
|
||||
for (String l : config.getStringList("Settings.GUISettings.OtherSettings." + o + ".Lore")) {
|
||||
lore.add(l.replace("%Category%", cName).replace("%category%", cName));
|
||||
}
|
||||
|
||||
inv.setItem(slot - 1, itemBuilder.setLore(lore).build());
|
||||
} else {
|
||||
inv.setItem(slot - 1, itemBuilder.setLore(lore).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 AuctionsMenu(player, shopType, category, config.getString("Settings.GUIName", "N/A"), 54, page);
|
||||
}
|
||||
|
||||
public static void openCategories(Player player, ShopType shop) {
|
||||
|
Loading…
Reference in New Issue
Block a user