mirror of
https://github.com/Crazy-Crew/CrazyAuctions.git
synced 2024-11-22 11:55:12 +01:00
re-work bid menu
This commit is contained in:
parent
d1223e87a1
commit
6647935d01
@ -9,6 +9,7 @@ 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;
|
||||
|
||||
@ -26,7 +27,7 @@ public class GuiManager {
|
||||
new CategoriesMenu(player, shopType, config.getString("Settings.Categories", "N/A"), 54).build();
|
||||
}
|
||||
|
||||
public static void openPlayersCurrentList(Player player, int page) {
|
||||
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();
|
||||
@ -38,16 +39,16 @@ public class GuiManager {
|
||||
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) {
|
||||
public static void openBuying(Player player, String id, AuctionItem auction) {
|
||||
final FileConfiguration config = Files.config.getConfiguration();
|
||||
|
||||
new BuyingMenu(player, ID, config.getString("Settings.Buying-Item", "N/A")).build();
|
||||
new BuyingMenu(auction, player, id, config.getString("Settings.Buying-Item", "N/A")).build();
|
||||
}
|
||||
|
||||
public static void openBidding(Player player, String ID) {
|
||||
public static void openBidding(Player player, String id, AuctionItem auction) {
|
||||
FileConfiguration config = Files.config.getConfiguration();
|
||||
|
||||
new BidMenu(player, ID, config.getString("Settings.Bidding-On-Item")).build();
|
||||
new BidMenu(auction, player, id, config.getString("Settings.Bidding-On-Item", "N/A")).build();
|
||||
}
|
||||
|
||||
public static void openViewer(Player player, String other, int page) {
|
||||
|
@ -351,14 +351,14 @@ public class AuctionsMenu extends Holder {
|
||||
|
||||
menu.click(player);
|
||||
|
||||
GuiManager.openBidding(player, auction_id);
|
||||
GuiManager.openBidding(player, auction_id, auction);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
menu.click(player);
|
||||
|
||||
GuiManager.openBuying(player, auction_id);
|
||||
GuiManager.openBuying(player, auction_id, auction);
|
||||
}
|
||||
|
||||
public void calculateItems() {
|
||||
|
@ -11,30 +11,37 @@ 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;
|
||||
import java.util.UUID;
|
||||
|
||||
public class BidMenu extends Holder {
|
||||
|
||||
private FileConfiguration config;
|
||||
private FileConfiguration data;
|
||||
|
||||
private AuctionItem auction;
|
||||
private String id;
|
||||
|
||||
public BidMenu(final Player player, final String id, final String title) {
|
||||
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();
|
||||
|
||||
@ -45,20 +52,24 @@ public class BidMenu extends Holder {
|
||||
|
||||
@Override
|
||||
public final Holder build() {
|
||||
if (!this.data.contains("Items." + this.id)) {
|
||||
final UUID uuid = this.player.getUniqueId();
|
||||
|
||||
if (!this.data.contains("active_auctions." + uuid + "." + 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;
|
||||
}
|
||||
|
||||
if (!HolderManager.containsBidding(this.player)) HolderManager.addBidding(this.player, 0);
|
||||
final ItemStack item = this.auction.getActiveItem(ShopType.BID).getItemStack();
|
||||
|
||||
final ItemBuilder builder = new ItemBuilder().setMaterial(Material.LIME_STAINED_GLASS_PANE).setAmount(1);
|
||||
|
||||
NamespacedKey auction_button = Keys.auction_button.getNamespacedKey();
|
||||
NamespacedKey auction_price = Keys.auction_price.getNamespacedKey();
|
||||
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());
|
||||
@ -68,12 +79,13 @@ public class BidMenu extends Holder {
|
||||
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, getBiddingGlass(this.player, this.id));
|
||||
|
||||
this.inventory.setItem(13, getGlass(null));
|
||||
|
||||
this.inventory.setItem(22, new ItemBuilder().addString("bid_item", auction_button).setMaterial(this.config.getString("Settings.GUISettings.OtherSettings.Bid.Item")).setAmount(1)
|
||||
.setName(this.config.getString("Settings.GUISettings.OtherSettings.Bid.Name")).setLore(this.config.getStringList("Settings.GUISettings.OtherSettings.Bid.Lore")).build());
|
||||
|
||||
this.inventory.setItem(4, getBiddingItem(this.id));
|
||||
this.inventory.setItem(4, item);
|
||||
|
||||
this.player.openInventory(this.inventory);
|
||||
|
||||
@ -82,13 +94,13 @@ public class BidMenu extends Holder {
|
||||
|
||||
@Override
|
||||
public void run(InventoryClickEvent event) {
|
||||
if (!(event.getInventory().getHolder(false) instanceof BidMenu menu)) return;
|
||||
if (!(event.getInventory().getHolder(false) instanceof BidMenu bidMenu)) return;
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
final int slot = event.getSlot();
|
||||
|
||||
final Inventory inventory = menu.getInventory();
|
||||
final Inventory inventory = bidMenu.getInventory();
|
||||
|
||||
if (slot > inventory.getSize()) return;
|
||||
|
||||
@ -106,20 +118,22 @@ public class BidMenu extends Holder {
|
||||
|
||||
if (type.isEmpty()) return;
|
||||
|
||||
final FileConfiguration data = Files.data.getConfiguration();
|
||||
final Player player = (Player) event.getWhoClicked();
|
||||
final VaultSupport support = this.plugin.getSupport();
|
||||
final Player player = bidMenu.player;
|
||||
|
||||
final ItemStack item = bidMenu.auction.getActiveItem(ShopType.BID).getItemStack();
|
||||
|
||||
final AuctionItem auction = bidMenu.auction;
|
||||
|
||||
switch (type) {
|
||||
case "bid_item" -> {
|
||||
String id = menu.id;
|
||||
final VaultSupport support = this.plugin.getSupport();
|
||||
|
||||
int bid = HolderManager.getBidding(player);
|
||||
|
||||
String topBidder = data.getString("Items." + id + ".TopBidder", "None");
|
||||
final long bid = auction.getTopBid();
|
||||
|
||||
final long money = support.getMoney(player);
|
||||
|
||||
final String topBidder = auction.getBidderName();
|
||||
|
||||
if (money < bid) {
|
||||
final Map<String, String> placeholders = new HashMap<>();
|
||||
|
||||
@ -131,90 +145,94 @@ public class BidMenu extends Holder {
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.getLong("Items." + id + ".Price") > bid) {
|
||||
if (auction.getPrice() > bid) {
|
||||
player.sendMessage(Messages.BID_MORE_MONEY.getMessage(player));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.getLong("Items." + id + ".Price") >= bid && !topBidder.equalsIgnoreCase("None")) {
|
||||
if (auction.getPrice() >= bid && !topBidder.equalsIgnoreCase("None")) {
|
||||
player.sendMessage(Messages.BID_MORE_MONEY.getMessage(player));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
this.server.getPluginManager().callEvent(new AuctionNewBidEvent(player, Methods.fromBase64(data.getString("Items." + id + ".Item")), bid));
|
||||
|
||||
data.set("Items." + id + ".Price", bid);
|
||||
data.set("Items." + id + ".TopBidder", player.getUniqueId().toString());
|
||||
data.set("Items." + id + ".TopBidderName", player.getName());
|
||||
this.server.getPluginManager().callEvent(new AuctionNewBidEvent(player, auction.asItemStack(), bid));
|
||||
|
||||
final Map<String, String> placeholders = new HashMap<>();
|
||||
placeholders.put("%Bid%", String.valueOf(bid));
|
||||
|
||||
player.sendMessage(Messages.BID_MESSAGE.getMessage(player, placeholders));
|
||||
|
||||
Files.data.save();
|
||||
auction.setBidderName(player.getName());
|
||||
auction.setBidderUUID(player.getUniqueId().toString());
|
||||
auction.setPrice(bid);
|
||||
|
||||
HolderManager.addBidding(player, 0);
|
||||
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();
|
||||
menu.click(player);
|
||||
|
||||
bidMenu.click(player);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
this.userManager.addActiveAuction(auction.getUuid().toString(), section);
|
||||
|
||||
player.closeInventory();
|
||||
bidMenu.click(player);
|
||||
}
|
||||
|
||||
case "+1", "+10", "+100", "+1000" -> {
|
||||
try {
|
||||
final int price = container.getOrDefault(Keys.auction_price.getNamespacedKey(), PersistentDataType.INTEGER, 10);
|
||||
|
||||
HolderManager.addBidding(player, HolderManager.getBidding(player) + price);
|
||||
auction.setTopBid(auction.getTopBid() + price);
|
||||
|
||||
this.inventory.setItem(4, getBiddingItem(menu.id));
|
||||
this.inventory.setItem(13, getBiddingGlass(player, menu.id));
|
||||
} catch (Exception exception) {
|
||||
player.closeInventory();
|
||||
|
||||
player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage(player));
|
||||
}
|
||||
this.inventory.setItem(4, auction.getActiveItem(ShopType.BID).getItemStack());
|
||||
this.inventory.setItem(13, getGlass(bidMenu));
|
||||
}
|
||||
|
||||
case "-1", "-10", "-100", "-1000" -> {
|
||||
try {
|
||||
final int price = container.getOrDefault(Keys.auction_price.getNamespacedKey(), PersistentDataType.INTEGER, -10);
|
||||
|
||||
HolderManager.addBidding(player, HolderManager.getBidding(player) + price);
|
||||
auction.setTopBid(auction.getTopBid() + price);
|
||||
|
||||
this.inventory.setItem(4, getBiddingItem(menu.id));
|
||||
this.inventory.setItem(13, getBiddingGlass(player, menu.id));
|
||||
} catch (Exception exception) {
|
||||
player.closeInventory();
|
||||
|
||||
player.sendMessage(Messages.ITEM_DOESNT_EXIST.getMessage(player));
|
||||
}
|
||||
this.inventory.setItem(4, auction.getActiveItem(ShopType.BID).getItemStack());
|
||||
this.inventory.setItem(13, getGlass(bidMenu));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ItemStack getBiddingGlass(Player player, String id) {
|
||||
FileConfiguration config = Files.config.getConfiguration();
|
||||
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);
|
||||
|
||||
int bid = HolderManager.getBidding(player);
|
||||
final AuctionItem auction = bidMenu != null ? bidMenu.auction : this.auction;
|
||||
|
||||
String price = Methods.getPrice(id, false);
|
||||
final long bid = auction.getPrice();
|
||||
final long topBid = auction.getTopBid();
|
||||
|
||||
if (config.contains("Settings.GUISettings.OtherSettings.Bidding.Lore")) {
|
||||
List<String> lore = new ArrayList<>(itemBuilder.getUpdatedLore());
|
||||
|
||||
lore.add(" ");
|
||||
|
||||
for (String l : config.getStringList("Settings.GUISettings.OtherSettings.Bidding.Lore")) {
|
||||
lore.add(l.replace("%Bid%", String.valueOf(bid))
|
||||
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%", price)
|
||||
.replace("%topbid%", price));
|
||||
.replace("%TopBid%", String.valueOf(topBid))
|
||||
.replace("%topbid%", String.valueOf(topBid)));
|
||||
}
|
||||
|
||||
itemBuilder.setLore(lore);
|
||||
@ -222,36 +240,4 @@ public class BidMenu extends Holder {
|
||||
|
||||
return itemBuilder.build();
|
||||
}
|
||||
|
||||
private ItemStack getBiddingItem(final String id) {
|
||||
FileConfiguration config = Files.config.getConfiguration();
|
||||
FileConfiguration data = Files.data.getConfiguration();
|
||||
|
||||
ItemStack item = Methods.fromBase64(data.getString("Items." + id + ".Item"));
|
||||
|
||||
ItemBuilder itemBuilder = ItemBuilder.convertItemStack(item);
|
||||
|
||||
List<String> lore = new ArrayList<>(itemBuilder.getUpdatedLore());
|
||||
|
||||
lore.add(" ");
|
||||
|
||||
String price = Methods.getPrice(id, false);
|
||||
String time = Methods.convertToTime(data.getLong("Items." + id + ".Time-Till-Expire"));
|
||||
|
||||
String seller = data.getString("Items." + id + ".Name", "None");
|
||||
String bidder = data.getString("Items." + id + ".TopBidderName", "None");
|
||||
|
||||
for (String l : config.getStringList("Settings.GUISettings.Bidding")) {
|
||||
lore.add(l.replace("%TopBid%", price)
|
||||
.replace("%topbid%", price)
|
||||
.replace("%Seller%", seller).replace("%seller%", seller)
|
||||
.replace("%TopBidder%", bidder).replace("%topbidder%", bidder)
|
||||
.replace("%Time%", time)
|
||||
.replace("%time%", time));
|
||||
}
|
||||
|
||||
itemBuilder.setLore(lore);
|
||||
|
||||
return itemBuilder.build();
|
||||
}
|
||||
}
|
@ -22,15 +22,17 @@ public class AuctionItem {
|
||||
|
||||
private final String store_id;
|
||||
private final ItemStack itemStack;
|
||||
private final long price;
|
||||
private long price;
|
||||
private final long time_till_expire;
|
||||
private final long full_expire;
|
||||
|
||||
private final String bidder_uuid;
|
||||
private final String bidder_name;
|
||||
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 boolean biddable) {
|
||||
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;
|
||||
@ -45,6 +47,8 @@ public class AuctionItem {
|
||||
|
||||
this.bidder_uuid = bidder_uuid;
|
||||
this.bidder_name = bidder_name;
|
||||
this.topBid = topBid;
|
||||
|
||||
this.isBiddable = biddable;
|
||||
}
|
||||
|
||||
@ -68,6 +72,10 @@ public class AuctionItem {
|
||||
return this.price;
|
||||
}
|
||||
|
||||
public void setPrice(final long price) {
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public final long getTimeTillExpire() {
|
||||
return this.time_till_expire;
|
||||
}
|
||||
@ -80,10 +88,26 @@ public class AuctionItem {
|
||||
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(final long topBid) {
|
||||
this.topBid = topBid;
|
||||
}
|
||||
|
||||
public final boolean isBiddable() {
|
||||
return this.isBiddable;
|
||||
}
|
||||
@ -101,8 +125,6 @@ public class AuctionItem {
|
||||
|
||||
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());
|
||||
@ -110,6 +132,8 @@ public class AuctionItem {
|
||||
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);
|
||||
@ -118,12 +142,14 @@ public class AuctionItem {
|
||||
.replace("%seller%", getName());
|
||||
|
||||
newLine = line.replace("%TopBidder%", getBidderName())
|
||||
.replace("%topbid%", 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);
|
||||
@ -137,8 +163,7 @@ public class AuctionItem {
|
||||
}
|
||||
}
|
||||
|
||||
itemBuilder.setLore(lore)
|
||||
.addString(getStoreID(), Keys.auction_store_id.getNamespacedKey());
|
||||
itemBuilder.setLore(lore).addString(getStoreID(), Keys.auction_store_id.getNamespacedKey());
|
||||
|
||||
return itemBuilder;
|
||||
}
|
||||
@ -162,8 +187,7 @@ public class AuctionItem {
|
||||
.replace("%Price%", priceFormat));
|
||||
}
|
||||
|
||||
itemBuilder.setLore(lore)
|
||||
.addString(getStoreID(), Keys.auction_store_id.getNamespacedKey());;
|
||||
itemBuilder.setLore(lore).addString(getStoreID(), Keys.auction_store_id.getNamespacedKey());;
|
||||
|
||||
return itemBuilder;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user