fix more merge conflicts

This commit is contained in:
Ryder Belserion 2024-11-27 18:42:47 -05:00
parent 37459fc720
commit 966f43f13c
No known key found for this signature in database
20 changed files with 22 additions and 2515 deletions

View File

@ -118,7 +118,7 @@ public class CrazyAuctions extends Vital {
registerCommand(getCommand("crazyauctions"), new AuctionTab(), new AuctionCommand());
this.support = new VaultSupport();
this.support.loadVault();
this.support.setupEconomy();
new FoliaRunnable(getServer().getGlobalRegionScheduler()) {
@Override

View File

@ -1,59 +0,0 @@
package com.badbones69.crazyauctions.api;
import com.badbones69.crazyauctions.api.enums.Category;
import com.badbones69.crazyauctions.api.enums.misc.Files;
import com.badbones69.crazyauctions.api.enums.ShopType;
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.guis.types.other.BidMenu;
import com.badbones69.crazyauctions.api.guis.types.other.BuyingMenu;
import com.badbones69.crazyauctions.tasks.objects.AuctionItem;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
public class GuiManager {
public static void openShop(Player player, ShopType shopType, Category category, int page) {
FileConfiguration config = Files.config.getConfiguration();
new AuctionsMenu(player, shopType, category, config.getString("Settings.GUIName", "&4Crazy &bAuctions&8 #{page}").replaceAll("\\{page}", String.valueOf(page)), 54, page).build();
}
public static void openCategories(Player player, ShopType shopType) {
FileConfiguration config = Files.config.getConfiguration();
new CategoriesMenu(player, shopType, config.getString("Settings.Categories", "N/A"), 54).build();
}
public static void openPlayersCurrentList(final Player player, int page) {
FileConfiguration config = Files.config.getConfiguration();
new CurrentMenu(player, config.getString("Settings.Players-Current-Items", "N/A"), 54, page).build();
}
public static void openPlayersExpiredList(Player player, int page) {
FileConfiguration config = Files.config.getConfiguration();
new ExpiredMenu(player, config.getString("Settings.Cancelled/Expired-Items", "&8Cancelled/Expired Listings #{page}").replaceAll("\\{page}", String.valueOf(page)), 54, page).build();
}
public static void openBuying(Player player, String id, AuctionItem auction) {
final FileConfiguration config = Files.config.getConfiguration();
new BuyingMenu(auction, player, id, config.getString("Settings.Buying-Item", "N/A")).build();
}
public static void openBidding(Player player, String id, AuctionItem auction) {
FileConfiguration config = Files.config.getConfiguration();
new BidMenu(auction, player, id, config.getString("Settings.Bidding-On-Item", "N/A")).build();
}
public static void openViewer(Player player, String other, int page) {
FileConfiguration config = Files.config.getConfiguration();
new AuctionsMenu(player, other, config.getString("Settings.GUIName", "&4Crazy &bAuctions&8 #{page}").replaceAll("\\{page}", String.valueOf(page)), 54, page).build();
}
}

View File

@ -3,7 +3,6 @@ package com.badbones69.crazyauctions.api.enums.misc;
import com.badbones69.crazyauctions.CrazyAuctions;
import com.ryderbelserion.vital.paper.api.files.FileManager;
import org.bukkit.configuration.file.YamlConfiguration;
import org.jetbrains.annotations.NotNull;
import java.io.File;
public enum Files {
@ -16,9 +15,9 @@ public enum Files {
private final String fileName;
private final String strippedName;
private @NotNull final CrazyAuctions plugin = CrazyAuctions.getPlugin();
private final CrazyAuctions plugin = CrazyAuctions.get();
private @NotNull final FileManager fileManager = this.plugin.getFileManager();
private final FileManager fileManager = this.plugin.getFileManager();
/**
* A constructor to build a file

View File

@ -22,7 +22,7 @@ public enum Keys {
// contains the auction item price
auction_price("auction_price", PersistentDataType.INTEGER);
private final CrazyAuctions plugin = CrazyAuctions.getPlugin();
private final CrazyAuctions plugin = CrazyAuctions.get();
private final String NamespacedKey;
private final PersistentDataType type;

View File

@ -44,7 +44,7 @@ public enum Permissions {
private final boolean register;
private final PluginManager manager = CrazyAuctions.getPlugin().getServer().getPluginManager();
private final PluginManager manager = CrazyAuctions.get().getServer().getPluginManager();
Permissions(String node, String description, PermissionDefault isDefault, Map<String, Boolean> children, boolean register) {
this.node = node;

View File

@ -1,190 +0,0 @@
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.builders.ItemBuilder;
import com.badbones69.crazyauctions.api.enums.ShopType;
import com.badbones69.crazyauctions.api.enums.misc.Files;
import com.badbones69.crazyauctions.tasks.UserManager;
import com.badbones69.crazyauctions.tasks.objects.AuctionItem;
import com.badbones69.crazyauctions.tasks.objects.ExpiredItem;
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;
import java.util.ArrayList;
import java.util.List;
public abstract class Holder implements InventoryHolder, Listener {
protected final CrazyAuctions plugin = CrazyAuctions.getPlugin();
protected final CrazyManager crazyManager = this.plugin.getCrazyManager();
protected final UserManager userManager = this.plugin.getUserManager();
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(final Player player, final ShopType shopType, final String title, final int size) {
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(Player player, String title, int size) {
this(player, null, title, size, 1);
}
public Holder() {}
public abstract Holder build();
public abstract void run(InventoryClickEvent event);
public void setSize(final int size) {
this.size = size;
}
public final int getSize() {
return this.size - 9;
}
public void setPage(int page) {
if (page <= 0) page = 1;
this.page = page;
}
public void nextPage() {
setPage(getPage() + 1);
}
public void backPage() {
setPage(getPage() - 1);
}
public final int getPage() {
return this.page;
}
public final List<ExpiredItem> getPageItem(final List<ExpiredItem> list, int page, final int size) {
List<ExpiredItem> items = new ArrayList<>();
if (page <= 0) page = 1;
int index = page * size - size;
int endIndex = index >= list.size() ? list.size() - 1 : index + size;
for (;index < endIndex; index++) {
if (index < list.size()) items.add(list.get(index));
}
for (;items.isEmpty(); page--) {
if (page <= 0) break;
index = page * size - size;
endIndex = index >= list.size() ? list.size() - 1 : index + size;
for (; index < endIndex; index++) {
if (index < list.size()) items.add(list.get(index));
}
}
return items;
}
public final List<AuctionItem> getPageItems(final List<AuctionItem> list, int page, final int size) {
List<AuctionItem> items = new ArrayList<>();
if (page <= 0) page = 1;
int index = page * size - size;
int endIndex = index >= list.size() ? list.size() - 1 : index + size;
for (;index < endIndex; index++) {
if (index < list.size()) items.add(list.get(index));
}
for (;items.isEmpty(); page--) {
if (page <= 0) break;
index = page * size - size;
endIndex = index >= list.size() ? list.size() - 1 : index + size;
for (; index < endIndex; index++) {
if (index < list.size()) items.add(list.get(index));
}
}
return items;
}
public final int getExpiredMaxPages(final List<ExpiredItem> list) {
final int size = list.size();
return (int) Math.ceil((double) size / getSize());
}
public final int getMaxPage(final List<AuctionItem> list) {
final int size = list.size();
return (int) Math.ceil((double) size / getSize());
}
@EventHandler
public void onPlayerClick(InventoryClickEvent event) {
run(event);
}
@Override
public @NotNull final Inventory getInventory() {
return this.inventory;
}
public void click(final Player player) {
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 {
player.playSound(player.getLocation(), Sound.valueOf(sound), 1, 1);
} catch (Exception e) {
player.playSound(player.getLocation(), Sound.UI_BUTTON_CLICK, SoundCategory.PLAYERS, 1F, 1F);
}
}
}
}

View File

@ -1,55 +0,0 @@
package com.badbones69.crazyauctions.api.guis;
import com.badbones69.crazyauctions.api.enums.Category;
import com.badbones69.crazyauctions.api.enums.ShopType;
import org.bukkit.entity.Player;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class HolderManager {
private static final Map<UUID, Integer> bidding = new HashMap<>();
private static final Map<UUID, ShopType> shopTypes = new HashMap<>();
private static final Map<UUID, Category> shopCategory = new HashMap<>();
public static void addShopCategory(final Player player, final Category category) {
shopCategory.put(player.getUniqueId(), category);
}
public static void removeShopCategory(final Player player) {
shopCategory.remove(player.getUniqueId());
}
public static Category getShopCategory(final Player player) {
return shopCategory.get(player.getUniqueId());
}
public static void addBidding(final Player player, final int amount) {
bidding.put(player.getUniqueId(), amount);
}
public static void removeBidding(final Player player) {
bidding.remove(player.getUniqueId());
}
public static int getBidding(final Player player) {
return bidding.get(player.getUniqueId());
}
public static boolean containsBidding(final Player player) {
return bidding.containsKey(player.getUniqueId());
}
public static void addShopType(final Player player, final ShopType shopType) {
shopTypes.put(player.getUniqueId(), shopType);
}
public static void removeShopType(final Player player) {
shopTypes.remove(player.getUniqueId());
}
public static ShopType getShopType(final Player player) {
return shopTypes.get(player.getUniqueId());
}
}

View File

@ -1,381 +0,0 @@
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.api.GuiManager;
import com.badbones69.crazyauctions.currency.VaultSupport;
import com.badbones69.crazyauctions.tasks.InventoryManager;
import com.badbones69.crazyauctions.tasks.objects.AuctionItem;
import com.ryderbelserion.vital.paper.util.scheduler.FoliaRunnable;
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;
import java.util.UUID;
public class AuctionsMenu extends Holder {
private List<AuctionItem> items;
private List<String> options;
private int maxPages;
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.config = Files.config.getConfiguration();
this.data = Files.data.getConfiguration();
if (!this.data.contains("Items")) {
this.data.set("Items.Clear", null);
Files.data.save();
}
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() {}
@Override
public final Holder build() {
if (this.target != null) {
this.options.add("WhatIsThis.Viewing");
} else {
this.options.addAll(List.of(
"SellingItems",
"Cancelled/ExpiredItems",
"PreviousPage",
"Refresh",
"Refesh",
"NextPage",
"Category1",
"Category2"
));
}
calculateItems();
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)) {
continue;
}
if (!this.config.getBoolean("Settings.GUISettings.OtherSettings." + key + ".Toggle", true)) {
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).getName() + ".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));
}
}
switch (key) {
case "NextPage" -> this.inventory.setItem(slot - 1, InventoryManager.getNextButton(this.player, this).setLore(lore).build());
case "PreviousPage" -> this.inventory.setItem(slot - 1, InventoryManager.getBackButton(this.player, this).setLore(lore).build());
default -> this.inventory.setItem(slot - 1, itemBuilder.setLore(lore).addString(key, Keys.auction_button.getNamespacedKey()).build());
}
}
for (final AuctionItem item : getPageItems(this.items, getPage(), getSize())) {
int slot = this.inventory.firstEmpty();
this.inventory.setItem(slot, item.getActiveItem(this.shopType).build());
}
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;
final PersistentDataContainerView container = itemStack.getPersistentDataContainer();
final Player player = (Player) event.getWhoClicked();
FileConfiguration config = Files.config.getConfiguration();
if (container.has(Keys.auction_button.getNamespacedKey())) {
String type = container.getOrDefault(Keys.auction_button.getNamespacedKey(), PersistentDataType.STRING, menu.target == null ? "Refresh" : "");
if (menu.target == null && !type.isEmpty()) {
switch (type) {
case "Your-Item", "Top-Bidder", "Cant-Afford" -> {
menu.click(player);
return;
}
case "NextPage" -> {
menu.click(player);
if (menu.getPage() >= menu.maxPages) {
return;
}
menu.nextPage();
GuiManager.openShop(player, HolderManager.getShopType(player), HolderManager.getShopCategory(player), menu.getPage());
return;
}
case "PreviousPage" -> {
menu.click(player);
final int page = menu.getPage();
if (page <= 1) {
return;
}
menu.backPage();
GuiManager.openShop(player, HolderManager.getShopType(player), HolderManager.getShopCategory(player), menu.getPage());
return;
}
case "Refesh", "Refresh" -> {
menu.click(player);
GuiManager.openShop(player, HolderManager.getShopType(player), HolderManager.getShopCategory(player), menu.getPage());
return;
}
case "Bidding/Selling.Selling" -> {
menu.click(player);
GuiManager.openShop(player, ShopType.BID, HolderManager.getShopCategory(player), 1);
return;
}
case "Bidding/Selling.Bidding" -> {
menu.click(player);
GuiManager.openShop(player, ShopType.SELL, HolderManager.getShopCategory(player), 1);
return;
}
case "Cancelled/ExpiredItems" -> {
menu.click(player);
GuiManager.openPlayersExpiredList(player, 1);
return;
}
case "SellingItems" -> {
menu.click(player);
GuiManager.openPlayersCurrentList(player, 1);
return;
}
case "Category1", "Category2" -> {
menu.click(player);
GuiManager.openCategories(player, HolderManager.getShopType(player));
return;
}
}
}
}
final UUID uuid = player.getUniqueId();
final String target_uuid = container.getOrDefault(Keys.auction_uuid.getNamespacedKey(), PersistentDataType.STRING, "");
if (target_uuid.isEmpty()) return;
final AuctionItem auction = this.userManager.getAuctionItemById(UUID.fromString(target_uuid), container.getOrDefault(Keys.auction_store_id.getNamespacedKey(), PersistentDataType.STRING, ""));
if (auction == null) return;
if (uuid.toString().equalsIgnoreCase(auction.getUuid().toString())) {
String itemName = config.getString("Settings.GUISettings.OtherSettings.Your-Item.Item");
String name = config.getString("Settings.GUISettings.OtherSettings.Your-Item.Name");
ItemBuilder itemBuilder = new ItemBuilder().setMaterial(itemName).setName(name).setAmount(1);
if (config.contains("Settings.GUISettings.OtherSettings.Your-Item.Lore")) {
itemBuilder.setLore(config.getStringList("Settings.GUISettings.OtherSettings.Your-Item.Lore"));
}
inventory.setItem(slot, itemBuilder.build());
menu.click(player);
new FoliaRunnable(this.plugin.getServer().getGlobalRegionScheduler()) {
@Override
public void run() {
inventory.setItem(slot, itemStack);
}
}.runDelayed(this.plugin, 3 * 20);
return;
}
final long price = auction.getPrice();
if (price == 0L) return;
final VaultSupport support = this.plugin.getSupport();
if (support.getMoney(player) < price) {
String itemName = config.getString("Settings.GUISettings.OtherSettings.Cant-Afford.Item");
String name = config.getString("Settings.GUISettings.OtherSettings.Cant-Afford.Name");
ItemBuilder itemBuilder = new ItemBuilder().setMaterial(itemName).setName(name).setAmount(1);
if (config.contains("Settings.GUISettings.OtherSettings.Cant-Afford.Lore")) {
itemBuilder.setLore(config.getStringList("Settings.GUISettings.OtherSettings.Cant-Afford.Lore"));
}
inventory.setItem(slot, itemBuilder.build());
menu.click(player);
new FoliaRunnable(this.plugin.getServer().getGlobalRegionScheduler()) {
@Override
public void run() {
inventory.setItem(slot, itemStack);
}
}.runDelayed(this.plugin, 3 * 20);
return;
}
final String auction_id = auction.getId();
if (auction.isBiddable()) {
if (uuid.toString().equalsIgnoreCase(auction.getUuid().toString())) {
String itemName = config.getString("Settings.GUISettings.OtherSettings.Top-Bidder.Item");
String name = config.getString("Settings.GUISettings.OtherSettings.Top-Bidder.Name");
ItemBuilder itemBuilder = new ItemBuilder().setMaterial(itemName).setName(name).setAmount(1);
if (config.contains("Settings.GUISettings.OtherSettings.Top-Bidder.Lore")) {
itemBuilder.setLore(config.getStringList("Settings.GUISettings.OtherSettings.Top-Bidder.Lore"));
}
inventory.setItem(slot, itemBuilder.build());
menu.click(player);
new FoliaRunnable(this.plugin.getServer().getGlobalRegionScheduler()) {
@Override
public void run() {
inventory.setItem(slot, itemStack);
}
}.runDelayed(this.plugin, 3 * 20);
return;
}
menu.click(player);
GuiManager.openBidding(player, auction_id, auction);
return;
}
menu.click(player);
GuiManager.openBuying(player, auction_id, auction);
}
public void calculateItems() {
this.userManager.getAuctions().forEach(((uuid, auctions) -> auctions.forEach(auction -> {
final ItemBuilder itemBuilder = auction.getActiveItem(this.shopType);
if (this.category != null && this.category != Category.NONE && !this.category.getItems().contains(itemBuilder.getMaterial())) {
return;
}
this.items.add(auction);
})));
this.maxPages = getMaxPage(this.items == null ? new ArrayList<>() : this.items);
}
}

View File

@ -1,113 +0,0 @@
package com.badbones69.crazyauctions.api.guis.types;
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.api.GuiManager;
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() {
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, Keys.auction_button.getNamespacedKey()).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.replace("Category-Settings.", ""));
GuiManager.openShop(player, HolderManager.getShopType(player), category, 1);
menu.click(player);
}
}

View File

@ -1,180 +0,0 @@
package com.badbones69.crazyauctions.api.guis.types;
import com.badbones69.crazyauctions.api.builders.ItemBuilder;
import com.badbones69.crazyauctions.api.enums.Messages;
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.api.GuiManager;
import com.badbones69.crazyauctions.tasks.objects.AuctionItem;
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;
import java.util.UUID;
public class CurrentMenu extends Holder {
private FileConfiguration config;
private List<String> options;
private List<AuctionItem> items;
private int maxPages;
public CurrentMenu(final Player player, final String title, final int size, final int page) {
super(player, title, size, page);
this.config = Files.config.getConfiguration();
this.options = new ArrayList<>();
this.items = new ArrayList<>();
}
public CurrentMenu() {}
@Override
public final Holder build() {
this.options.addAll(List.of(
"Back",
"PreviousPage",
"NextPage",
"WhatIsThis.CurrentItems"
));
calculateItems();
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, Keys.auction_button.getNamespacedKey()).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 AuctionItem item : getPageItems(this.items, getPage(), getSize())) {
int slot = this.inventory.firstEmpty();
this.inventory.setItem(slot, item.getCurrentItem().build());
}
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();
final Player player = (Player) event.getWhoClicked();
if (container.has(Keys.auction_button.getNamespacedKey())) {
final String type = container.getOrDefault(Keys.auction_button.getNamespacedKey(), PersistentDataType.STRING, "");
if (!type.isEmpty()) {
switch (type) {
case "NextPage" -> {
menu.click(player);
if (menu.getPage() >= menu.maxPages) {
return;
}
menu.nextPage();
GuiManager.openPlayersCurrentList(player, menu.getPage());
return;
}
case "PreviousPage" -> {
menu.click(player);
final int page = menu.getPage();
if (page <= 1) {
return;
}
menu.backPage();
GuiManager.openPlayersCurrentList(player, menu.getPage());
return;
}
case "Back" -> {
GuiManager.openShop(player, HolderManager.getShopType(player), HolderManager.getShopCategory(player), 1);
menu.click(player);
return;
}
}
}
}
// return early, fixes npe
if (!container.has(Keys.auction_store_id.getNamespacedKey())) {
return;
}
final UUID uuid = player.getUniqueId();
final AuctionItem auction = this.userManager.getAuctionItemById(uuid, container.getOrDefault(Keys.auction_store_id.getNamespacedKey(), PersistentDataType.STRING, ""));
if (auction == null) return;
this.userManager.addExpiredItem(player, auction);
player.sendMessage(Messages.CANCELLED_ITEM.getMessage(player));
menu.click(player);
GuiManager.openPlayersCurrentList(player, menu.getPage());
}
public void calculateItems() {
final UUID uuid = this.player.getUniqueId();
if (this.userManager.hasAuction(uuid)) {
this.items = this.userManager.getAuctions(uuid);
}
this.maxPages = getMaxPage(this.items);
}
}

View File

@ -1,245 +0,0 @@
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.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.api.GuiManager;
import com.badbones69.crazyauctions.tasks.InventoryManager;
import com.badbones69.crazyauctions.tasks.objects.ExpiredItem;
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.UUID;
public class ExpiredMenu extends Holder {
private List<ExpiredItem> items;
private List<String> options;
private FileConfiguration config;
private int maxPages;
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.config = Files.config.getConfiguration();
}
public ExpiredMenu() {}
@Override
public final Holder build() {
this.options.addAll(List.of(
"Back",
"PreviousPage",
"Return",
"NextPage",
"WhatIsThis.Cancelled/ExpiredItems"
));
final UUID uuid = this.player.getUniqueId();
if (this.userManager.hasExpiredItem(uuid)) {
this.items = this.userManager.getExpiredItems(uuid);
}
this.maxPages = getExpiredMaxPages(this.items == null ? new ArrayList<>() : this.items);
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).setAmount(1);
if (this.config.contains("Settings.GUISettings.OtherSettings." + key + ".Lore")) {
itemBuilder.setLore(this.config.getStringList("Settings.GUISettings.OtherSettings." + key + ".Lore"));
}
switch (key) {
case "NextPage" -> this.inventory.setItem(slot - 1, InventoryManager.getNextButton(this.player, this).build());
case "PreviousPage" -> this.inventory.setItem(slot - 1, InventoryManager.getBackButton(this.player, this).build());
default -> this.inventory.setItem(slot - 1, itemBuilder.addString(key, Keys.auction_button.getNamespacedKey()).build());
}
}
for (final ExpiredItem item : getPageItem(this.items, getPage(), getSize())) {
int slot = this.inventory.firstEmpty();
this.inventory.setItem(slot, item.getExpiredItem().build());
}
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();
final Player player = (Player) event.getWhoClicked();
if (container.has(Keys.auction_button.getNamespacedKey())) {
final String type = container.getOrDefault(Keys.auction_button.getNamespacedKey(), PersistentDataType.STRING, "");
if (type.isEmpty()) return;
switch (type) {
case "Back" -> {
menu.click(player);
GuiManager.openShop(player, HolderManager.getShopType(player), HolderManager.getShopCategory(player), 1);
return;
}
case "PreviousPage" -> {
menu.click(player);
final int page = menu.getPage();
if (page > 1 && page <= menu.maxPages) {
return;
}
menu.backPage();
GuiManager.openPlayersExpiredList(player, menu.getPage());
return;
}
case "NextPage" -> {
menu.click(player);
if (menu.getPage() >= menu.maxPages) {
return;
}
menu.nextPage();
GuiManager.openPlayersExpiredList(player, menu.getPage());
return;
}
case "Return" -> {
if (Methods.isInvFull(player)) { // run this first obviously, just because
player.sendMessage(Messages.INVENTORY_FULL.getMessage(player));
return;
}
final FileConfiguration data = Files.data.getConfiguration();
final ConfigurationSection section = data.getConfigurationSection("expired_auctions");
if (section == null) return;
final ConfigurationSection player_section = section.getConfigurationSection(player.getUniqueId().toString());
if (player_section == null) return;
final Inventory player_inventory = player.getInventory();
for (final String key : section.getKeys(false)) {
if (Methods.isInvFull(player)) { // run this here obviously as well
player.sendMessage(Messages.INVENTORY_FULL.getMessage(player));
break;
}
final ConfigurationSection auction_section = section.getConfigurationSection(key);
if (auction_section == null) continue;
final ItemStack auction_item = Methods.fromBase64(auction_section.getString("item"));
if (auction_item == null) continue;
player_inventory.addItem(auction_item);
}
this.userManager.removeExpiredItems(player);
Files.data.save();
player.sendMessage(Messages.GOT_ITEM_BACK.getMessage(player));
menu.click(player);
GuiManager.openPlayersExpiredList(player, menu.getPage());
return;
}
}
}
if (!container.has(Keys.auction_store_id.getNamespacedKey())) { // do not run, if there is no key.
return;
}
if (Methods.isInvFull(player)) { // run this here obviously as well
player.sendMessage(Messages.INVENTORY_FULL.getMessage(player));
return;
}
final UUID uuid = player.getUniqueId();
final ExpiredItem auction = this.userManager.getExpiredItemById(uuid, container.getOrDefault(Keys.auction_store_id.getNamespacedKey(), PersistentDataType.STRING, ""));
if (auction == null) return;
player.getInventory().addItem(auction.asItemStack());
this.userManager.removeExpiredItem(auction);
Files.data.save();
menu.click(player);
GuiManager.openPlayersExpiredList(player, menu.getPage());
}
}

View File

@ -1,242 +0,0 @@
package com.badbones69.crazyauctions.api.guis.types.other;
import com.badbones69.crazyauctions.api.builders.ItemBuilder;
import com.badbones69.crazyauctions.api.enums.Messages;
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.AuctionNewBidEvent;
import com.badbones69.crazyauctions.api.guis.Holder;
import com.badbones69.crazyauctions.api.guis.HolderManager;
import com.badbones69.crazyauctions.api.GuiManager;
import com.badbones69.crazyauctions.currency.VaultSupport;
import com.badbones69.crazyauctions.tasks.objects.AuctionItem;
import io.papermc.paper.persistence.PersistentDataContainerView;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
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 org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class BidMenu extends Holder {
private FileConfiguration config;
private FileConfiguration data;
private AuctionItem auction;
private long current_bid = 0;
private String id;
public BidMenu(final AuctionItem auction, final Player player, final String id, final String title) {
super(player, title, 27);
this.auction = auction;
this.config = Files.config.getConfiguration();
this.data = Files.data.getConfiguration();
this.id = id;
}
public BidMenu() {}
@Override
public final Holder build() {
if (!this.data.contains("active_auctions." + this.auction.getUuid() + "." + this.id)) {
GuiManager.openShop(this.player, ShopType.BID, HolderManager.getShopCategory(this.player), 1);
this.player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage(this.player));
this.userManager.removeAuctionItem(this.auction); // remove auction item, as it's not in the active_auctions
return this;
}
final ItemStack item = this.auction.getActiveItem(ShopType.BID).getItemStack();
final ItemBuilder builder = new ItemBuilder().setMaterial(Material.LIME_STAINED_GLASS_PANE).setAmount(1);
final NamespacedKey auction_button = Keys.auction_button.getNamespacedKey();
final NamespacedKey auction_price = Keys.auction_price.getNamespacedKey();
this.inventory.setItem(9, builder.addString("+1", auction_button).addInteger(1, auction_price).setName("&a+1").build());
this.inventory.setItem(10, builder.addString("+10", auction_button).addInteger(10, auction_price).setName("&a+10").build());
this.inventory.setItem(11, builder.addString("+100", auction_button).addInteger(100, auction_price).setName("&a+100").build());
this.inventory.setItem(12, builder.addString("+1000", auction_button).addInteger(1000, auction_price).setName("&a+1000").build());
this.inventory.setItem(14, builder.addString("-1000", auction_button).addInteger(-1000, auction_price).setName("&c-1000").build());
this.inventory.setItem(15, builder.addString("-100", auction_button).addInteger(-100, auction_price).setName("&c-100").build());
this.inventory.setItem(16, builder.addString("-10", auction_button).addInteger(-10, auction_price).setName("&c-10").build());
this.inventory.setItem(17, builder.addString("-1", auction_button).addInteger(-1, auction_price).setName("&c-1").build());
this.inventory.setItem(13, getGlass(null));
this.inventory.setItem(22, new ItemBuilder().setMaterial(this.config.getString("Settings.GUISettings.OtherSettings.Bid.Item")).setAmount(1).addString("bid_item", auction_button)
.setName(this.config.getString("Settings.GUISettings.OtherSettings.Bid.Name")).setLore(this.config.getStringList("Settings.GUISettings.OtherSettings.Bid.Lore")).build());
this.inventory.setItem(4, item);
this.player.openInventory(this.inventory);
return this;
}
@Override
public void run(InventoryClickEvent event) {
if (!(event.getInventory().getHolder(false) instanceof BidMenu bidMenu)) return;
event.setCancelled(true);
final int slot = event.getSlot();
final Inventory inventory = bidMenu.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 = bidMenu.player;
final AuctionItem auction = this.userManager.getAuctionItemById(bidMenu.auction.getUuid(), bidMenu.auction.getStoreID());
if (auction == null) { // if auction is null, someone else bid it. or the person cancelled it
GuiManager.openShop(player, ShopType.BID, HolderManager.getShopCategory(player), 1);
player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage(player));
return;
}
switch (type) {
case "bid_item" -> {
final VaultSupport support = this.plugin.getSupport();
final long top_bid = auction.getTopBid();
final long money = support.getMoney(player);
final String topBidder = auction.getBidderName();
if (money < top_bid) {
final Map<String, String> placeholders = new HashMap<>();
placeholders.put("%Money_Needed%", String.valueOf(top_bid - money));
placeholders.put("%money_needed%", String.valueOf(top_bid - money));
player.sendMessage(Messages.NEED_MORE_MONEY.getMessage(player, placeholders));
return;
}
final long current_bid = bidMenu.current_bid;
if (current_bid < top_bid && !topBidder.equalsIgnoreCase("None")) {
player.sendMessage(Messages.BID_MORE_MONEY.getMessage(player));
return;
}
this.server.getPluginManager().callEvent(new AuctionNewBidEvent(player, auction.asItemStack(), top_bid));
final Map<String, String> placeholders = new HashMap<>();
placeholders.put("%Bid%", String.valueOf(top_bid));
player.sendMessage(Messages.BID_MESSAGE.getMessage(player, placeholders));
auction.setBidderName(player.getName());
auction.setBidderUUID(player.getUniqueId().toString());
auction.setPrice(current_bid);
this.userManager.removeAuctionItem(auction); // remove it
final FileConfiguration data = bidMenu.data;
final String uuid = auction.getUuid().toString();
final ConfigurationSection section = data.getConfigurationSection("active_auctions." + uuid + "." + bidMenu.id);
if (section == null) { // do not add if not found in data.yml
player.closeInventory();
bidMenu.click(player);
return;
}
this.userManager.addActiveAuction(uuid, section);
player.closeInventory();
bidMenu.click(player);
}
case "+1", "+10", "+100", "+1000" -> {
final int price = container.getOrDefault(Keys.auction_price.getNamespacedKey(), PersistentDataType.INTEGER, 10);
bidMenu.current_bid = bidMenu.current_bid + price;
inventory.setItem(4, auction.getActiveItem(ShopType.BID).getItemStack());
inventory.setItem(13, getGlass(bidMenu));
}
case "-1", "-10", "-100", "-1000" -> {
final int price = container.getOrDefault(Keys.auction_price.getNamespacedKey(), PersistentDataType.INTEGER, -10);
bidMenu.current_bid = bidMenu.current_bid + price;
inventory.setItem(4, auction.getActiveItem(ShopType.BID).getItemStack());
inventory.setItem(13, getGlass(bidMenu));
}
}
}
private ItemStack getGlass(@Nullable final BidMenu bidMenu) {
FileConfiguration config = bidMenu != null ? bidMenu.config : this.config;
String item = config.getString("Settings.GUISettings.OtherSettings.Bidding.Item");
String name = config.getString("Settings.GUISettings.OtherSettings.Bidding.Name");
ItemBuilder itemBuilder = new ItemBuilder().setMaterial(item).setName(name).setAmount(1);
final AuctionItem auction = bidMenu != null ? bidMenu.auction : this.auction;
final long bid = bidMenu != null ? bidMenu.current_bid : this.current_bid;
final long topBid = auction.getTopBid();
if (config.contains("Settings.GUISettings.OtherSettings.Bidding.Lore")) {
List<String> lore = new ArrayList<>(itemBuilder.getUpdatedLore());
lore.add(" ");
for (String line : config.getStringList("Settings.GUISettings.OtherSettings.Bidding.Lore")) {
lore.add(line.replace("%Bid%", String.valueOf(bid))
.replace("%bid%", String.valueOf(bid))
.replace("%TopBid%", String.valueOf(topBid))
.replace("%topbid%", String.valueOf(topBid)));
}
itemBuilder.setLore(lore);
}
return itemBuilder.build();
}
}

View File

@ -1,252 +0,0 @@
package com.badbones69.crazyauctions.api.guis.types.other;
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.ShopType;
import com.badbones69.crazyauctions.api.enums.misc.Files;
import com.badbones69.crazyauctions.api.enums.misc.Keys;
import com.badbones69.crazyauctions.api.events.AuctionBuyEvent;
import com.badbones69.crazyauctions.api.guis.Holder;
import com.badbones69.crazyauctions.api.guis.HolderManager;
import com.badbones69.crazyauctions.api.GuiManager;
import com.badbones69.crazyauctions.currency.VaultSupport;
import com.badbones69.crazyauctions.tasks.objects.AuctionItem;
import io.papermc.paper.persistence.PersistentDataContainerView;
import org.bukkit.Sound;
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.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
public class BuyingMenu extends Holder {
private FileConfiguration config;
private FileConfiguration data;
private AuctionItem auction;
private List<String> options;
private String id;
public BuyingMenu(final AuctionItem auction, final Player player, final String id, final String title) {
super(player, title, 9);
this.auction = auction;
this.config = Files.config.getConfiguration();
this.data = Files.data.getConfiguration();
this.options = new ArrayList<>();
this.id = id;
}
public BuyingMenu() {}
@Override
public final Holder build() {
if (!this.data.contains("active_auctions." + this.auction.getUuid() + "." + this.id)) { // this grabs the uuid of the person who auctioned it
GuiManager.openShop(this.player, ShopType.BID, HolderManager.getShopCategory(this.player), 1);
this.player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage(this.player));
this.userManager.removeAuctionItem(this.auction); // remove auction item, as it's not in the active_auctions
return this;
}
this.options.addAll(List.of(
"Confirm",
"Cancel"
));
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;
}
final String id = this.config.getString("Settings.GUISettings.OtherSettings." + key + ".Item");
final String name = this.config.getString("Settings.GUISettings.OtherSettings." + key + ".Name");
final ItemBuilder itemBuilder = new ItemBuilder().setMaterial(id).setName(name).setAmount(1);
if (this.config.contains("Settings.GUISettings.OtherSettings." + key + ".Lore")) {
itemBuilder.setLore(this.config.getStringList("Settings.GUISettings.OtherSettings." + key + ".Lore")).addString(key, Keys.auction_button.getNamespacedKey());
}
switch (key) {
case "Confirm" -> {
final ItemStack itemStack = itemBuilder.addString("Confirm", Keys.auction_button.getNamespacedKey()).build();
this.inventory.setItem(0, itemStack);
this.inventory.setItem(1, itemStack);
this.inventory.setItem(2, itemStack);
this.inventory.setItem(3, itemStack);
}
case "Cancel" -> {
final ItemStack itemStack = itemBuilder.addString("Cancel", Keys.auction_button.getNamespacedKey()).build();
this.inventory.setItem(5, itemStack);
this.inventory.setItem(6, itemStack);
this.inventory.setItem(7, itemStack);
this.inventory.setItem(8, itemStack);
}
}
}
this.inventory.setItem(4, this.auction.getActiveItem(ShopType.SELL).build());
this.player.openInventory(this.inventory);
return this;
}
@Override
public void run(InventoryClickEvent event) {
if (!(event.getInventory().getHolder(false) instanceof BuyingMenu buyingMenu)) return;
event.setCancelled(true);
final int slot = event.getSlot();
final Inventory inventory = buyingMenu.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 FileConfiguration data = buyingMenu.data;
final Player player = buyingMenu.player;
final AuctionItem auction = buyingMenu.auction;
switch (type) {
case "Confirm" -> {
final UUID uuid = auction.getUuid();
final String id = buyingMenu.id;
if (!data.contains("active_auctions." + uuid + "." + id)) {
buyingMenu.click(player);
GuiManager.openShop(player, HolderManager.getShopType(player), HolderManager.getShopCategory(player), 1);
player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage(player));
this.userManager.removeAuctionItem(auction); // remove auction item, as it's not in the active_auctions
return;
}
if (Methods.isInvFull(player)) {
buyingMenu.click(player);
player.closeInventory();
player.sendMessage(Messages.INVENTORY_FULL.getMessage(player));
return;
}
final long cost = auction.getPrice();
final VaultSupport support = this.plugin.getSupport();
Map<String, String> placeholders = new HashMap<>();
if (support.getMoney(player) < cost) {
buyingMenu.click(player);
player.closeInventory();
placeholders.put("%Money_Needed%", (cost - support.getMoney(player)) + "");
placeholders.put("%money_needed%", (cost - support.getMoney(player)) + "");
player.sendMessage(Messages.NEED_MORE_MONEY.getMessage(player, placeholders));
return;
}
final ItemStack item = auction.asItemStack();
this.server.getPluginManager().callEvent(new AuctionBuyEvent(player, item, cost));
if (!support.removeMoney(player, cost)) {
buyingMenu.click(player);
player.closeInventory();
placeholders.put("%Money_Needed%", (cost - support.getMoney(player)) + "");
placeholders.put("%money_needed%", (cost - support.getMoney(player)) + "");
player.sendMessage(Messages.NEED_MORE_MONEY.getMessage(player, placeholders));
return;
}
support.addMoney(Methods.getOfflinePlayer(String.valueOf(uuid)), cost);
String price = String.valueOf(auction.getPrice());
placeholders.put("%Price%", price);
placeholders.put("%price%", price);
placeholders.put("%Player%", player.getName());
placeholders.put("%player%", player.getName());
player.sendMessage(Messages.BOUGHT_ITEM.getMessage(player, placeholders));
final Player originalSeller = Methods.getPlayer(String.valueOf(uuid));
if (originalSeller != null && originalSeller.isOnline()) {
originalSeller.sendMessage(Messages.PLAYER_BOUGHT_ITEM.getMessage(player, placeholders));
FileConfiguration config = Files.config.getConfiguration();
String sound = config.getString("Settings.Sold-Item-Sound", "UI_BUTTON_CLICK");
if (sound.isEmpty()) return;
player.playSound(player.getLocation(), Sound.valueOf(sound), 1f, 1f);
}
player.getInventory().addItem(item);
//data.set("active_auctions." + uuid + "." + id, null); // removeAuctionItem already handles this.
this.userManager.removeAuctionItem(auction);
Files.data.save();
buyingMenu.click(player);
GuiManager.openShop(player, HolderManager.getShopType(player), HolderManager.getShopCategory(player), 1);
}
case "Cancel" -> {
GuiManager.openShop(player, HolderManager.getShopType(player), HolderManager.getShopCategory(player), 1);
buyingMenu.click(player);
}
}
}
}

View File

@ -35,17 +35,17 @@ import java.util.Map;
import java.util.UUID;
public class GuiListener implements Listener {
private static final CrazyAuctions plugin = CrazyAuctions.get();
private static final CrazyManager crazyManager = plugin.getCrazyManager();
private static final Map<UUID, Integer> bidding = new HashMap<>();
private static final Map<UUID, String> biddingID = new HashMap<>();
private static final Map<UUID, ShopType> shopType = new HashMap<>(); // Shop Type
private static final Map<UUID, Category> shopCategory = new HashMap<>(); // Category Type
private static final Map<UUID, List<Integer>> List = new HashMap<>();
private static final Map<UUID, String> IDs = new HashMap<>();
public static void openShop(Player player, ShopType sell, Category cat, int page) {
Methods.updateAuction();
@ -213,7 +213,7 @@ public class GuiListener implements Listener {
player.openInventory(inv);
}
public static void openCategories(Player player, ShopType shop) {
Methods.updateAuction();
FileConfiguration config = Files.config.getConfiguration();
@ -256,7 +256,7 @@ public class GuiListener implements Listener {
shopType.put(player.getUniqueId(), shop);
player.openInventory(inv);
}
public static void openPlayersCurrentList(Player player, int page) {
Methods.updateAuction();
@ -330,7 +330,7 @@ public class GuiListener implements Listener {
player.openInventory(inv);
}
public static void openPlayersExpiredList(Player player, int page) {
Methods.updateAuction();
@ -413,7 +413,7 @@ public class GuiListener implements Listener {
player.openInventory(inv);
}
public static void openBuying(Player player, String ID) {
Methods.updateAuction();
@ -494,7 +494,7 @@ public class GuiListener implements Listener {
player.openInventory(inv);
}
public static void openBidding(Player player, String ID) {
Methods.updateAuction();
@ -525,12 +525,12 @@ public class GuiListener implements Listener {
inv.setItem(22, new ItemBuilder().setMaterial(config.getString("Settings.GUISettings.OtherSettings.Bid.Item")).setAmount(1)
.setName(config.getString("Settings.GUISettings.OtherSettings.Bid.Name")).setLore(config.getStringList("Settings.GUISettings.OtherSettings.Bid.Lore")).build());
inv.setItem(4, getBiddingItem(ID));
player.openInventory(inv);
}
public static void openViewer(Player player, String other, int page) {
Methods.updateAuction();
@ -643,7 +643,7 @@ public class GuiListener implements Listener {
player.openInventory(inv);
}
private static ItemStack getBiddingGlass(Player player, String ID) {
FileConfiguration config = Files.config.getConfiguration();
@ -671,7 +671,7 @@ public class GuiListener implements Listener {
return itemBuilder.build();
}
private static ItemStack getBiddingItem(String ID) {
FileConfiguration config = Files.config.getConfiguration();
FileConfiguration data = Files.data.getConfiguration();
@ -714,7 +714,7 @@ public class GuiListener implements Listener {
return itemBuilder.build();
}
private static void playClick(Player player) {
FileConfiguration config = Files.config.getConfiguration();
@ -740,7 +740,7 @@ public class GuiListener implements Listener {
player.playSound(player.getLocation(), Sound.valueOf(sound), 1, 1);
} catch (Exception ignored) {}
}
@EventHandler
public void onInvClose(InventoryCloseEvent e) {
FileConfiguration config = Files.config.getConfiguration();
@ -749,7 +749,7 @@ public class GuiListener implements Listener {
if (e.getView().getTitle().contains(Methods.color(config.getString("Settings.Bidding-On-Item")))) bidding.remove(player);
}
@EventHandler
public void onInvClick(InventoryClickEvent e) {
FileConfiguration config = Files.config.getConfiguration();
@ -1440,4 +1440,4 @@ public class GuiListener implements Listener {
}
}
}
}
}

View File

@ -1,28 +0,0 @@
package com.badbones69.crazyauctions.controllers;
import com.badbones69.crazyauctions.api.guis.HolderManager;
import com.badbones69.crazyauctions.api.guis.types.other.BidMenu;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.player.PlayerQuitEvent;
public class MiscListener implements Listener {
@EventHandler
public void onInventoryClose(InventoryCloseEvent event) {
Player player = (Player) event.getPlayer();
if (event.getInventory().getHolder(false) instanceof BidMenu) HolderManager.removeBidding(player);
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
Player player = event.getPlayer();
HolderManager.removeBidding(player);
HolderManager.removeShopCategory(player);
HolderManager.removeShopType(player);
}
}

View File

@ -10,7 +10,7 @@ import org.jetbrains.annotations.NotNull;
public class VaultSupport {
private final CrazyAuctions plugin = CrazyAuctions.getPlugin();
private final CrazyAuctions plugin = CrazyAuctions.get();
private Economy vault = null;

View File

@ -1,40 +0,0 @@
package com.badbones69.crazyauctions.tasks;
import com.badbones69.crazyauctions.api.builders.ItemBuilder;
import com.badbones69.crazyauctions.api.enums.misc.Files;
import com.badbones69.crazyauctions.api.enums.misc.Keys;
import com.badbones69.crazyauctions.api.guis.Holder;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
public class InventoryManager {
private static ItemBuilder nextButton;
private static ItemBuilder backButton;
public static void loadButtons() {
FileConfiguration config = Files.config.getConfiguration();
String next = "Settings.GUISettings.OtherSettings.NextPage";
nextButton = new ItemBuilder().setMaterial(config.getString(next + ".Item"))
.setName(config.getString(next + ".Name"))
.setLore(config.getStringList(next + ".Lore"))
.addString("NextPage", Keys.auction_button.getNamespacedKey());
final String back = "Settings.GUISettings.OtherSettings.PreviousPage";
backButton = new ItemBuilder().setMaterial(config.getString(back + ".Item"))
.setName(config.getString(back + ".Name"))
.setLore(config.getStringList(back + ".Lore"))
.addString("PreviousPage", Keys.auction_button.getNamespacedKey());
}
public static ItemBuilder getNextButton(final Player player, final Holder holder) {
return nextButton.addLorePlaceholder("{page}", String.valueOf(holder.getPage() - 1)).setTarget(player);
}
public static ItemBuilder getBackButton(final Player player, final Holder holder) {
return backButton.addLorePlaceholder("{page}", String.valueOf(holder.getPage() - 1)).setTarget(player);
}
}

View File

@ -1,409 +0,0 @@
package com.badbones69.crazyauctions.tasks;
import com.badbones69.crazyauctions.CrazyAuctions;
import com.badbones69.crazyauctions.Methods;
import com.badbones69.crazyauctions.api.enums.Reasons;
import com.badbones69.crazyauctions.api.enums.misc.Files;
import com.badbones69.crazyauctions.api.events.AuctionCancelledEvent;
import com.badbones69.crazyauctions.tasks.objects.AuctionItem;
import com.badbones69.crazyauctions.tasks.objects.ExpiredItem;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
public class UserManager {
private final CrazyAuctions plugin = CrazyAuctions.getPlugin();
private final Map<UUID, List<AuctionItem>> auctions = new HashMap<>();
private final Map<UUID, List<ExpiredItem>> expired_items = new HashMap<>();
public final void updateAuctionsCache() {
this.auctions.clear();
final FileConfiguration data = Files.data.getConfiguration();
final ConfigurationSection section = data.getConfigurationSection("active_auctions");
if (section == null) return;
for (String key : section.getKeys(false)) {
final ConfigurationSection player = section.getConfigurationSection(key);
if (player == null) continue;
for (String number : player.getKeys(false)) {
final ConfigurationSection auction = player.getConfigurationSection(number);
if (auction == null) continue;
addActiveAuction(key, auction);
}
}
}
public void addAuctionItem(final Player player, final ItemStack itemStack, final long price, final boolean isBiddable) {
final FileConfiguration data = Files.data.getConfiguration();
final FileConfiguration config = Files.config.getConfiguration();
final String uuid = player.getUniqueId().toString();
int current_auction = 1;
if (!data.contains("active_auctions." + uuid)) {
data.set("active_auctions." + uuid + "." + current_auction + ".name", player.getName());
final ConfigurationSection section = data.getConfigurationSection("active_auctions." + uuid + "." + current_auction);
if (section == null) return;
addItem(itemStack, uuid, price, isBiddable, config, section);
return;
}
for (;data.contains("active_auctions." + uuid + "." + current_auction); current_auction++);
data.set("active_auctions." + uuid + "." + current_auction + ".name", player.getName());
final ConfigurationSection section = data.getConfigurationSection("active_auctions." + uuid + "." + current_auction);
if (section == null) return;
addItem(itemStack, uuid, price, isBiddable, config, section);
}
public void removeAuctionItem(final AuctionItem auction) {
final FileConfiguration data = Files.data.getConfiguration();
final ConfigurationSection section = data.getConfigurationSection("active_auctions");
boolean isNuked = false;
final UUID uuid = auction.getUuid();
if (section != null) {
final ConfigurationSection player_section = section.getConfigurationSection(uuid.toString());
final String id = auction.getId();
if (player_section != null && player_section.contains(id)) {
player_section.set(id, null);
isNuked = true;
}
}
if (!isNuked || !this.auctions.containsKey(uuid)) return; // only remove from the cache, if the data file removal was successful!
final List<AuctionItem> auctions = this.auctions.get(uuid);
auctions.remove(auction);
this.auctions.put(uuid, auctions);
}
public void removeActiveItems(final Player player) {
final UUID uuid = player.getUniqueId();
final FileConfiguration data = Files.data.getConfiguration();
final ConfigurationSection section = data.getConfigurationSection("active_auctions");
boolean isNuked = false;
if (section != null) {
final ConfigurationSection player_section = section.getConfigurationSection(uuid.toString());
if (player_section != null) {
section.set(uuid.toString(), null);
isNuked = true;
}
}
if (!isNuked || !this.auctions.containsKey(uuid)) return; // only remove from cache, if successfully removed from file.
this.auctions.remove(uuid);
}
public final AuctionItem getAuctionItemById(final UUID uuid, final String store_id) {
AuctionItem key = null;
for (final AuctionItem auction : this.auctions.get(uuid)) {
if (!auction.getStoreID().equals(store_id)) continue;
key = auction;
break;
}
return key;
}
public final Map<UUID, List<AuctionItem>> getAuctions() {
return this.auctions;
}
public final boolean hasAuction(final UUID uuid) {
return this.auctions.containsKey(uuid);
}
public final List<AuctionItem> getAuctions(final UUID uuid) {
return this.auctions.get(uuid);
}
public final void updateExpiredCache() {
this.expired_items.clear();
final FileConfiguration data = Files.data.getConfiguration();
final ConfigurationSection section = data.getConfigurationSection("expired_auctions");
if (section == null) return;
for (String key : section.getKeys(false)) {
final ConfigurationSection player = section.getConfigurationSection(key);
if (player == null) continue;
for (String number : player.getKeys(false)) {
final ConfigurationSection auction = player.getConfigurationSection(number);
if (auction == null) continue;
addExpiredAuction(key, auction);
}
}
}
public void addExpiredItem(final Player player, final AuctionItem auction) {
final AuctionCancelledEvent auctionCancelledEvent = new AuctionCancelledEvent(player, auction.asItemStack(), Reasons.PLAYER_FORCE_CANCEL);
this.plugin.getServer().getPluginManager().callEvent(auctionCancelledEvent);
final UUID uuid = player.getUniqueId();
final FileConfiguration data = Files.data.getConfiguration();
int number = 1;
for (;data.contains("expired_auctions." + uuid + "." + number); number++);
data.set("expired_auctions." + uuid + "." + number + ".name", auction.getName());
final ConfigurationSection section = data.getConfigurationSection("expired_auctions." + uuid + "." + number);
if (section == null) return;
section.set("item", auction.asBase64());
section.set("store_id", auction.getStoreID());
section.set("full_time", auction.getFullExpire());
section.set("price", auction.getPrice());
// data.set("active_auctions." + uuid + "." + auction.getId(), null);
if (data.contains("active_auctions." + uuid + "." + auction.getId())) {
removeAuctionItem(auction);
}
Files.data.save();
final ExpiredItem expiredItem = new ExpiredItem(
auction.getUuid().toString(),
auction.getName(),
String.valueOf(number),
auction.asBase64(),
auction.getStoreID(),
auction.getFullExpire(),
auction.getPrice()
);
if (this.expired_items.containsKey(uuid)) {
final List<ExpiredItem> items = this.expired_items.get(uuid);
items.add(expiredItem);
this.expired_items.put(uuid, items);
return;
}
this.expired_items.put(uuid, new ArrayList<>() {{
add(expiredItem);
}});
}
public void removeExpiredItem(final ExpiredItem expiredItem) {
final FileConfiguration data = Files.data.getConfiguration();
final ConfigurationSection section = data.getConfigurationSection("expired_auctions");
boolean isNuked = false;
final UUID uuid = expiredItem.getUuid();
if (section != null) {
final ConfigurationSection player_section = section.getConfigurationSection(uuid.toString());
final String id = expiredItem.getId();
if (player_section != null && player_section.contains(id)) {
player_section.set(id, null);
isNuked = true;
}
}
if (!isNuked || !this.expired_items.containsKey(uuid)) return; // only remove from the cache, if the data file removal was successful!
final List<ExpiredItem> auctions = this.expired_items.get(uuid);
auctions.remove(expiredItem);
this.expired_items.put(expiredItem.getUuid(), auctions);
}
public void removeExpiredItems(final Player player) {
final UUID uuid = player.getUniqueId();
final FileConfiguration data = Files.data.getConfiguration();
final ConfigurationSection section = data.getConfigurationSection("expired_auctions");
boolean isNuked = false;
if (section != null) {
final ConfigurationSection player_section = section.getConfigurationSection(uuid.toString());
if (player_section != null) {
section.set(uuid.toString(), null);
isNuked = true;
}
}
if (!isNuked || !this.expired_items.containsKey(uuid)) return; // only remove from cache, if successfully removed from file.
this.expired_items.remove(uuid);
}
public final ExpiredItem getExpiredItemById(final UUID uuid, final String store_id) {
ExpiredItem key = null;
for (final ExpiredItem auction : this.expired_items.get(uuid)) {
if (!auction.getStoreID().equals(store_id)) continue;
key = auction;
break;
}
return key;
}
public final Map<UUID, List<ExpiredItem>> getExpiredItems() {
return this.expired_items;
}
public final boolean hasExpiredItem(final UUID uuid) {
return this.expired_items.containsKey(uuid);
}
public final List<ExpiredItem> getExpiredItems(final UUID uuid) {
return this.expired_items.get(uuid);
}
public void addActiveAuction(final String uuid, final ConfigurationSection section) {
final AuctionItem new_auction = new AuctionItem(uuid, section.getString("name"),
section.getName(),
section.getString("item"),
section.getString("store_id"),
section.getLong("price"),
section.getLong("time.expire"),
section.getLong("time.full"),
section.getString("status.top_bidder.uuid", "None"),
section.getString("status.top_bidder.name", "None"),
section.getLong("status.top_bidder.price", 0),
section.getBoolean("status.biddable")
);
final UUID fromString = UUID.fromString(uuid);
if (this.auctions.containsKey(fromString)) {
final List<AuctionItem> auctions = this.auctions.get(fromString);
auctions.add(new_auction);
this.auctions.put(fromString, auctions);
} else {
this.auctions.put(fromString, new ArrayList<>() {{
add(new_auction);
}});
}
}
/**
* Adds an item to the configuration section
*
* @param itemStack {@link ItemStack}
* @param price the price
* @param isBiddable true or false
* @param config the config.yml
* @param section the section in the data.yml
*/
private void addItem(final ItemStack itemStack, final String uuid, final long price, final boolean isBiddable, final FileConfiguration config, final ConfigurationSection section) {
section.set("item", Methods.toBase64(itemStack));
section.set("store_id", UUID.randomUUID().toString().replace("-", "").substring(0, 8));
section.set("price", price);
if (isBiddable) {
section.set("time.expire", Methods.convertToMill(config.getString("Settings.Bid-Time", "2m 30s")));
} else {
section.set("time.expire", Methods.convertToMill(config.getString("Settings.Sell-Time", "2d")));
}
section.set("time.full", Methods.convertToMill(config.getString("Settings.Full-Expire-Time", "10d")));
section.set("status.top_bidder.uuid", "None");
section.set("status.top_bidder.name", "None");
section.set("status.top_bidder.price", 0);
section.set("status.biddable", isBiddable);
addActiveAuction(uuid, section);
Files.data.save();
}
private void addExpiredAuction(final String uuid, final ConfigurationSection section) {
final ExpiredItem expired_item = new ExpiredItem(
uuid,
section.getString("name"),
section.getName(),
section.getString("item"),
section.getString("store_id"),
section.getLong("full_time"),
section.getLong("price")
);
final UUID fromString = UUID.fromString(uuid);
if (this.expired_items.containsKey(fromString)) {
final List<ExpiredItem> auctions = this.expired_items.get(fromString);
auctions.add(expired_item);
this.expired_items.put(fromString, auctions);
} else {
this.expired_items.put(fromString, new ArrayList<>() {{
add(expired_item);
}});
}
}
}

View File

@ -1,203 +0,0 @@
package com.badbones69.crazyauctions.tasks.objects;
import com.badbones69.crazyauctions.Methods;
import com.badbones69.crazyauctions.api.builders.ItemBuilder;
import com.badbones69.crazyauctions.api.enums.ShopType;
import com.badbones69.crazyauctions.api.enums.misc.Files;
import com.badbones69.crazyauctions.api.enums.misc.Keys;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.UUID;
@SuppressWarnings("UnusedAssignment")
public class AuctionItem {
private final UUID uuid;
private final String name;
private final String id;
private final String store_id;
private final ItemStack itemStack;
private long price;
private final long time_till_expire;
private final long full_expire;
private String bidder_uuid;
private String bidder_name;
private long topBid;
private final boolean isBiddable;
public AuctionItem(final String uuid, final String name, final String id, final String item, final String store_id, final long price, final long time_till_expire, final long full_expire, final String bidder_uuid, final String bidder_name, final long topBid, final boolean biddable) {
this.uuid = UUID.fromString(uuid);
this.name = name;
this.id = id;
this.itemStack = Methods.fromBase64(item);
this.store_id = store_id;
this.price = price;
this.time_till_expire = time_till_expire;
this.full_expire = full_expire;
this.bidder_uuid = bidder_uuid;
this.bidder_name = bidder_name;
this.topBid = topBid;
this.isBiddable = biddable;
}
public final UUID getUuid() {
return this.uuid;
}
public final String getId() {
return this.id;
}
public final String getName() {
return this.name;
}
public final String getStoreID() {
return this.store_id;
}
public final long getPrice() {
return this.price;
}
public void setPrice(final long price) {
this.price = price;
}
public final long getTimeTillExpire() {
return this.time_till_expire;
}
public final long getFullExpire() {
return this.full_expire;
}
public final String getBidderUUID() {
return this.bidder_uuid;
}
public void setBidderUUID(final String uuid) {
this.bidder_uuid = uuid;
}
public final String getBidderName() {
return this.bidder_name;
}
public void setBidderName(String name) {
this.bidder_name = name;
}
public final long getTopBid() {
return this.topBid;
}
public void setTopBid(long topBid) {
if (topBid <= 0L) topBid = this.topBid;
this.topBid = topBid;
}
public final boolean isBiddable() {
return this.isBiddable;
}
public final ItemStack asItemStack() {
return this.itemStack;
}
public final ItemBuilder asItemBuilder() {
return new ItemBuilder(this.itemStack);
}
public final String asBase64() {
return Methods.toBase64(asItemStack());
}
public final ItemBuilder getActiveItem(final ShopType shopType) {
final FileConfiguration configuration = Files.config.getConfiguration();
final ItemBuilder itemBuilder = ItemBuilder.convertItemStack(this.itemStack.clone());
final String time = Methods.convertToTime(getTimeTillExpire());
final List<String> lore = new ArrayList<>(itemBuilder.getUpdatedLore());
lore.add(" ");
if (shopType == ShopType.BID && isBiddable()) {
final String priceFormat = String.format(Locale.ENGLISH, "%,d", this.topBid);
for (final String line : configuration.getStringList("Settings.GUISettings.Bidding")) {
String newLine = line.replace("%TopBid%", priceFormat)
.replace("%topbid%", priceFormat);
newLine = line.replace("%Seller%", getName())
.replace("%seller%", getName());
newLine = line.replace("%TopBidder%", getBidderName())
.replace("%topbidder%", getBidderName());
lore.add(newLine.replace("%Time%", time)
.replace("%time%", time));
}
} else {
final String priceFormat = String.format(Locale.ENGLISH, "%,d", this.price);
for (final String line : configuration.getStringList("Settings.GUISettings.SellingItemLore")) {
String newLine = line.replace("%TopBid%", priceFormat)
.replace("%topbid%", priceFormat);
newLine = line.replace("%Seller%", getName())
.replace("%seller%", getName());
lore.add(newLine.replace("%Time%", time)
.replace("%time%", time)
.replace("%price%", priceFormat).replace("%Price%", priceFormat));
}
}
itemBuilder.setLore(lore)
.addString(this.id, Keys.auction_number.getNamespacedKey())
.addString(getStoreID(), Keys.auction_store_id.getNamespacedKey())
.addString(this.uuid.toString(), Keys.auction_uuid.getNamespacedKey());
return itemBuilder;
}
public final ItemBuilder getCurrentItem() {
final FileConfiguration configuration = Files.config.getConfiguration();
final ItemBuilder itemBuilder = ItemBuilder.convertItemStack(this.itemStack.clone());
final String priceFormat = String.format(Locale.ENGLISH, "%,d", this.price);
final String time = Methods.convertToTime(getTimeTillExpire());
final List<String> lore = new ArrayList<>(itemBuilder.getUpdatedLore());
lore.add(" ");
for (final String line : configuration.getStringList("Settings.GUISettings.CurrentLore")) {
lore.add(line.replace("%Time%", time).replace("%time%", time)
.replace("%price%", priceFormat)
.replace("%Price%", priceFormat));
}
itemBuilder.setLore(lore).addString(getStoreID(), Keys.auction_store_id.getNamespacedKey());;
return itemBuilder;
}
}

View File

@ -1,95 +0,0 @@
package com.badbones69.crazyauctions.tasks.objects;
import com.badbones69.crazyauctions.Methods;
import com.badbones69.crazyauctions.api.builders.ItemBuilder;
import com.badbones69.crazyauctions.api.enums.misc.Files;
import com.badbones69.crazyauctions.api.enums.misc.Keys;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.UUID;
public class ExpiredItem {
private final UUID uuid;
private final String name;
private final String id;
private final String store_id;
private final ItemStack itemStack;
private final long full_expire;
private final long price;
public ExpiredItem(final String uuid, final String name, final String id, final String item, final String store_id, final long full_expire, final long price) {
this.uuid = UUID.fromString(uuid);
this.name = name;
this.id = id;
this.itemStack = Methods.fromBase64(item);
this.store_id = store_id;
this.full_expire = full_expire;
this.price = price;
}
public final UUID getUuid() {
return this.uuid;
}
public final String getId() {
return this.id;
}
public final String getName() {
return this.name;
}
public final String getStoreID() {
return this.store_id;
}
public final long getFullExpire() {
return this.full_expire;
}
public final ItemStack asItemStack() {
return this.itemStack;
}
public final long getPrice() {
return this.price;
}
public final String asBase64() {
return Methods.toBase64(asItemStack());
}
public final ItemBuilder getExpiredItem() {
final FileConfiguration configuration = Files.config.getConfiguration();
final ItemBuilder itemBuilder = ItemBuilder.convertItemStack(this.itemStack.clone());
final String priceFormat = String.format(Locale.ENGLISH, "%,d", this.price);
final String time = Methods.convertToTime(getFullExpire());
final List<String> lore = new ArrayList<>(itemBuilder.getUpdatedLore());
lore.add(" ");
for (final String line : configuration.getStringList("Settings.GUISettings.Cancelled/ExpiredLore")) {
lore.add(line.replace("%Time%", time).replace("%time%", time)
.replace("%price%", priceFormat)
.replace("%Price%", priceFormat));
}
itemBuilder.setLore(lore)
.addString(getStoreID(), Keys.auction_store_id.getNamespacedKey());;
return itemBuilder;
}
}