mirror of
https://github.com/kiranhart/Auction-House.git
synced 2025-02-23 20:31:30 +01:00
Expired Items GUI, active and expired commands added
This commit is contained in:
parent
a57e82a07b
commit
0c42f17534
@ -111,7 +111,7 @@ public class AuctionAPI {
|
|||||||
* @param data Data to deserialize.
|
* @param data Data to deserialize.
|
||||||
* @return Deserialized ItemStack.
|
* @return Deserialized ItemStack.
|
||||||
*/
|
*/
|
||||||
public static ItemStack deserializeItem(byte[] data) {
|
public ItemStack deserializeItem(byte[] data) {
|
||||||
ItemStack item = null;
|
ItemStack item = null;
|
||||||
try (BukkitObjectInputStream stream = new BukkitObjectInputStream(new ByteArrayInputStream(data))) {
|
try (BukkitObjectInputStream stream = new BukkitObjectInputStream(new ByteArrayInputStream(data))) {
|
||||||
item = (ItemStack) stream.readObject();
|
item = (ItemStack) stream.readObject();
|
||||||
@ -128,7 +128,7 @@ public class AuctionAPI {
|
|||||||
* @param item Item to serialize.
|
* @param item Item to serialize.
|
||||||
* @return Serialized data.
|
* @return Serialized data.
|
||||||
*/
|
*/
|
||||||
public static byte[] serializeItem(ItemStack item) {
|
public byte[] serializeItem(ItemStack item) {
|
||||||
try (ByteArrayOutputStream stream = new ByteArrayOutputStream(); BukkitObjectOutputStream bukkitStream = new BukkitObjectOutputStream(stream)) {
|
try (ByteArrayOutputStream stream = new ByteArrayOutputStream(); BukkitObjectOutputStream bukkitStream = new BukkitObjectOutputStream(stream)) {
|
||||||
bukkitStream.writeObject(item);
|
bukkitStream.writeObject(item);
|
||||||
return stream.toByteArray();
|
return stream.toByteArray();
|
||||||
|
@ -45,7 +45,7 @@ public class AuctionItem implements Serializable {
|
|||||||
public AuctionItem(UUID owner, UUID highestBidder, ItemStack originalItem, AuctionItemCategory category, UUID key, double basePrice, double bidStartPrice, double bidIncPrice, double currentPrice, int remainingTime, boolean expired) {
|
public AuctionItem(UUID owner, UUID highestBidder, ItemStack originalItem, AuctionItemCategory category, UUID key, double basePrice, double bidStartPrice, double bidIncPrice, double currentPrice, int remainingTime, boolean expired) {
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
this.highestBidder = highestBidder;
|
this.highestBidder = highestBidder;
|
||||||
this.rawItem = AuctionAPI.serializeItem(originalItem);
|
this.rawItem = AuctionAPI.getInstance().serializeItem(originalItem);
|
||||||
this.category = category;
|
this.category = category;
|
||||||
this.key = key;
|
this.key = key;
|
||||||
this.basePrice = basePrice;
|
this.basePrice = basePrice;
|
||||||
@ -62,7 +62,7 @@ public class AuctionItem implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack getDisplayStack(AuctionStackType type) {
|
public ItemStack getDisplayStack(AuctionStackType type) {
|
||||||
ItemStack itemStack = AuctionAPI.deserializeItem(this.rawItem).clone();
|
ItemStack itemStack = AuctionAPI.getInstance().deserializeItem(this.rawItem).clone();
|
||||||
itemStack.setAmount(Math.max(itemStack.getAmount(), 1));
|
itemStack.setAmount(Math.max(itemStack.getAmount(), 1));
|
||||||
ItemMeta meta = itemStack.getItemMeta();
|
ItemMeta meta = itemStack.getItemMeta();
|
||||||
List<String> lore = (meta.hasLore()) ? meta.getLore() : new ArrayList<>();
|
List<String> lore = (meta.hasLore()) ? meta.getLore() : new ArrayList<>();
|
||||||
|
@ -0,0 +1,50 @@
|
|||||||
|
package ca.tweetzy.auctionhouse.commands;
|
||||||
|
|
||||||
|
import ca.tweetzy.auctionhouse.AuctionHouse;
|
||||||
|
import ca.tweetzy.auctionhouse.guis.GUIActiveAuctions;
|
||||||
|
import ca.tweetzy.auctionhouse.guis.GUIAuctionHouse;
|
||||||
|
import ca.tweetzy.core.commands.AbstractCommand;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The current file has been created by Kiran Hart
|
||||||
|
* Date Created: March 15 2021
|
||||||
|
* Time Created: 4:32 p.m.
|
||||||
|
* Usage of any code found within this class is prohibited unless given explicit permission otherwise
|
||||||
|
*/
|
||||||
|
public class CommandActive extends AbstractCommand {
|
||||||
|
|
||||||
|
public CommandActive() {
|
||||||
|
super(CommandType.PLAYER_ONLY, "active");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||||
|
Player player = (Player) sender;
|
||||||
|
AuctionHouse.getInstance().getGuiManager().showGUI(player, new GUIActiveAuctions(AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(player.getUniqueId())));
|
||||||
|
return ReturnType.SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPermissionNode() {
|
||||||
|
return "auctionhouse.cmd.active";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getSyntax() {
|
||||||
|
return "active";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return "View all your auction listings";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<String> onTab(CommandSender sender, String... args) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,50 @@
|
|||||||
|
package ca.tweetzy.auctionhouse.commands;
|
||||||
|
|
||||||
|
import ca.tweetzy.auctionhouse.AuctionHouse;
|
||||||
|
import ca.tweetzy.auctionhouse.guis.GUIActiveAuctions;
|
||||||
|
import ca.tweetzy.auctionhouse.guis.GUIExpiredItems;
|
||||||
|
import ca.tweetzy.core.commands.AbstractCommand;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The current file has been created by Kiran Hart
|
||||||
|
* Date Created: March 15 2021
|
||||||
|
* Time Created: 4:32 p.m.
|
||||||
|
* Usage of any code found within this class is prohibited unless given explicit permission otherwise
|
||||||
|
*/
|
||||||
|
public class CommandExpired extends AbstractCommand {
|
||||||
|
|
||||||
|
public CommandExpired() {
|
||||||
|
super(CommandType.PLAYER_ONLY, "expired");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||||
|
Player player = (Player) sender;
|
||||||
|
AuctionHouse.getInstance().getGuiManager().showGUI(player, new GUIExpiredItems(AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(player.getUniqueId())));
|
||||||
|
return ReturnType.SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPermissionNode() {
|
||||||
|
return "auctionhouse.cmd.expired";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getSyntax() {
|
||||||
|
return "expired";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return "View all your expired/cancelled listings";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<String> onTab(CommandSender sender, String... args) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -7,8 +7,10 @@ import ca.tweetzy.auctionhouse.helpers.MaterialCategorizer;
|
|||||||
import ca.tweetzy.auctionhouse.helpers.PlayerHelper;
|
import ca.tweetzy.auctionhouse.helpers.PlayerHelper;
|
||||||
import ca.tweetzy.auctionhouse.settings.Settings;
|
import ca.tweetzy.auctionhouse.settings.Settings;
|
||||||
import ca.tweetzy.core.commands.AbstractCommand;
|
import ca.tweetzy.core.commands.AbstractCommand;
|
||||||
|
import ca.tweetzy.core.compatibility.CompatibleHand;
|
||||||
import ca.tweetzy.core.compatibility.XMaterial;
|
import ca.tweetzy.core.compatibility.XMaterial;
|
||||||
import ca.tweetzy.core.utils.NumberUtils;
|
import ca.tweetzy.core.utils.NumberUtils;
|
||||||
|
import ca.tweetzy.core.utils.PlayerUtils;
|
||||||
import org.apache.commons.lang.WordUtils;
|
import org.apache.commons.lang.WordUtils;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -106,6 +108,7 @@ public class CommandSell extends AbstractCommand {
|
|||||||
.processPlaceholder("base_price", basePrice)
|
.processPlaceholder("base_price", basePrice)
|
||||||
.sendPrefixedMessage(player);
|
.sendPrefixedMessage(player);
|
||||||
|
|
||||||
|
PlayerUtils.takeActiveItem(player, CompatibleHand.MAIN_HAND, itemToSell.getAmount());
|
||||||
} else {
|
} else {
|
||||||
// they want to use the bidding system, so make it a bid item
|
// they want to use the bidding system, so make it a bid item
|
||||||
if (!NumberUtils.isDouble(args[0])) {
|
if (!NumberUtils.isDouble(args[0])) {
|
||||||
@ -180,6 +183,8 @@ public class CommandSell extends AbstractCommand {
|
|||||||
.processPlaceholder("start_price", bidStartPrice)
|
.processPlaceholder("start_price", bidStartPrice)
|
||||||
.processPlaceholder("increment_price", bidIncPrice)
|
.processPlaceholder("increment_price", bidIncPrice)
|
||||||
.sendPrefixedMessage(player);
|
.sendPrefixedMessage(player);
|
||||||
|
|
||||||
|
PlayerUtils.takeActiveItem(player, CompatibleHand.MAIN_HAND, itemToSell.getAmount());
|
||||||
}
|
}
|
||||||
|
|
||||||
return ReturnType.SUCCESS;
|
return ReturnType.SUCCESS;
|
||||||
|
@ -1,111 +0,0 @@
|
|||||||
package ca.tweetzy.auctionhouse.guis;
|
|
||||||
|
|
||||||
import ca.tweetzy.auctionhouse.AuctionHouse;
|
|
||||||
import ca.tweetzy.auctionhouse.helpers.ConfigurationItemHelper;
|
|
||||||
import ca.tweetzy.auctionhouse.managers.SoundManager;
|
|
||||||
import ca.tweetzy.auctionhouse.settings.Settings;
|
|
||||||
import ca.tweetzy.core.compatibility.XMaterial;
|
|
||||||
import ca.tweetzy.core.inventory.TInventory;
|
|
||||||
import ca.tweetzy.core.utils.PlayerUtils;
|
|
||||||
import ca.tweetzy.core.utils.nms.NBTEditor;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The current file has been created by Kiran Hart
|
|
||||||
* Date Created: February 18 2021
|
|
||||||
* Time Created: 10:07 p.m.
|
|
||||||
* Usage of any code found within this class is prohibited unless given explicit permission otherwise
|
|
||||||
*/
|
|
||||||
public class ExpiredItemsGUI extends TInventory {
|
|
||||||
|
|
||||||
private final Player player;
|
|
||||||
private List<List<ItemStack>> items;
|
|
||||||
|
|
||||||
public ExpiredItemsGUI(Player player) {
|
|
||||||
this.player = player;
|
|
||||||
// this.items = Lists.partition(AuctionHouse.getInstance().getAuctionPlayerManager().locateAndSelectPlayer(player).getExpiredItems(player, true), 45);
|
|
||||||
setTitle(Settings.GUI_EXPIRED_AUCTIONS_TITLE.getString());
|
|
||||||
setPage(1);
|
|
||||||
setRows(6);
|
|
||||||
setDynamic(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onClick(InventoryClickEvent e, int slot) {
|
|
||||||
e.setCancelled(true);
|
|
||||||
Player player = (Player) e.getWhoClicked();
|
|
||||||
|
|
||||||
switch (slot) {
|
|
||||||
case 45:
|
|
||||||
// back button (send them to the main auction house page)
|
|
||||||
// player.openInventory(new AuctionHouseGUI(AuctionHouse.getInstance().getAuctionPlayerManager().locateAndSelectPlayer(player)).getInventory());
|
|
||||||
break;
|
|
||||||
case 46:
|
|
||||||
// claim all of the expired auctions
|
|
||||||
// PlayerUtils.giveItem(player, AuctionHouse.getInstance().getAuctionPlayerManager().locateAndSelectPlayer(player).getExpiredItems(player, false));
|
|
||||||
AuctionHouse.getInstance().getData().set("expired." + this.player.getUniqueId().toString(), null);
|
|
||||||
AuctionHouse.getInstance().getData().save();
|
|
||||||
|
|
||||||
// reopen the gui
|
|
||||||
player.openInventory(new ExpiredItemsGUI(this.player).getInventory());
|
|
||||||
break;
|
|
||||||
case 48:
|
|
||||||
if (getPage() > 1) {
|
|
||||||
player.openInventory(setPage(getPage() - 1).getInventory());
|
|
||||||
SoundManager.getInstance().playSound(player, Settings.SOUNDS_NAVIGATE_GUI_PAGES.getString(), 1f, 1f);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 49:
|
|
||||||
player.openInventory(new ExpiredItemsGUI(this.player).getInventory());
|
|
||||||
break;
|
|
||||||
case 50:
|
|
||||||
if (getPage() < this.items.size()) {
|
|
||||||
player.openInventory(setPage(getPage() + 1).getInventory());
|
|
||||||
SoundManager.getInstance().playSound(player, Settings.SOUNDS_NAVIGATE_GUI_PAGES.getString(), 1f, 1f);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if (e.getCurrentItem() != null && e.getCurrentItem().getType() != XMaterial.AIR.parseMaterial()) {
|
|
||||||
if (!NBTEditor.contains(e.getCurrentItem(), "AuctionItemKey")) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String key = NBTEditor.getString(e.getCurrentItem(), "AuctionItemKey");
|
|
||||||
if (!AuctionHouse.getInstance().getData().contains("expired." + player.getUniqueId().toString() + "." + key)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
PlayerUtils.giveItem(player, AuctionHouse.getInstance().getData().getItemStack("expired." + player.getUniqueId().toString() + "." + key + ".item"));
|
|
||||||
AuctionHouse.getInstance().getData().set("expired." + player.getUniqueId().toString() + "." + key, null);
|
|
||||||
AuctionHouse.getInstance().getData().save();
|
|
||||||
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Inventory getInventory() {
|
|
||||||
Inventory inventory = Bukkit.createInventory(this, getSize(), getTitle());
|
|
||||||
|
|
||||||
// set the buttons
|
|
||||||
inventory.setItem(45, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_BACK_BTN_ITEM.getString(), Settings.GUI_BACK_BTN_NAME.getString(), Settings.GUI_BACK_BTN_LORE.getStringList(), null));
|
|
||||||
inventory.setItem(46, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_EXPIRED_AUCTIONS_ITEM.getString(), Settings.GUI_EXPIRED_AUCTIONS_NAME.getString(), Settings.GUI_EXPIRED_AUCTIONS_LORE.getStringList(), null));
|
|
||||||
inventory.setItem(48, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_BACK_BTN_ITEM.getString(), Settings.GUI_BACK_BTN_NAME.getString(), Settings.GUI_BACK_BTN_LORE.getStringList(), null));
|
|
||||||
inventory.setItem(49, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_REFRESH_BTN_ITEM.getString(), Settings.GUI_REFRESH_BTN_NAME.getString(), Settings.GUI_REFRESH_BTN_LORE.getStringList(), null));
|
|
||||||
inventory.setItem(50, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_NEXT_BTN_ITEM.getString(), Settings.GUI_NEXT_BTN_NAME.getString(), Settings.GUI_NEXT_BTN_LORE.getStringList(), null));
|
|
||||||
|
|
||||||
// populate the gui with the active items
|
|
||||||
if (items.size() != 0) {
|
|
||||||
items.get(getPage() - 1).forEach(item -> inventory.setItem(inventory.firstEmpty(), item));
|
|
||||||
}
|
|
||||||
|
|
||||||
return inventory;
|
|
||||||
}
|
|
||||||
}
|
|
@ -56,7 +56,7 @@ public class GUIAuctionHouse extends Gui {
|
|||||||
|
|
||||||
setButton(5, 1, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_AUCTION_HOUSE_ITEMS_COLLECTION_BIN_ITEM.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_COLLECTION_BIN_NAME.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_COLLECTION_BIN_LORE.getStringList(), new HashMap<String, Object>(){{
|
setButton(5, 1, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_AUCTION_HOUSE_ITEMS_COLLECTION_BIN_ITEM.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_COLLECTION_BIN_NAME.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_COLLECTION_BIN_LORE.getStringList(), new HashMap<String, Object>(){{
|
||||||
put("%expired_player_auctions%", auctionPlayer.getItems(true).size());
|
put("%expired_player_auctions%", auctionPlayer.getItems(true).size());
|
||||||
}}), e -> e.manager.closeAll());
|
}}), e -> e.manager.showGUI(e.player, new GUIExpiredItems(this.auctionPlayer)));
|
||||||
|
|
||||||
setButton(5, 6, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_AUCTION_HOUSE_ITEMS_TRANSACTIONS_ITEM.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_TRANSACTIONS_NAME.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_TRANSACTIONS_LORE.getStringList(), null), null);
|
setButton(5, 6, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_AUCTION_HOUSE_ITEMS_TRANSACTIONS_ITEM.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_TRANSACTIONS_NAME.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_TRANSACTIONS_LORE.getStringList(), null), null);
|
||||||
setButton(5, 7, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_AUCTION_HOUSE_ITEMS_HOW_TO_SELL_ITEM.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_HOW_TO_SELL_NAME.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_HOW_TO_SELL_LORE.getStringList(), null), null);
|
setButton(5, 7, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_AUCTION_HOUSE_ITEMS_HOW_TO_SELL_ITEM.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_HOW_TO_SELL_NAME.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_HOW_TO_SELL_LORE.getStringList(), null), null);
|
||||||
|
@ -0,0 +1,70 @@
|
|||||||
|
package ca.tweetzy.auctionhouse.guis;
|
||||||
|
|
||||||
|
import ca.tweetzy.auctionhouse.AuctionHouse;
|
||||||
|
import ca.tweetzy.auctionhouse.api.AuctionAPI;
|
||||||
|
import ca.tweetzy.auctionhouse.auction.AuctionItem;
|
||||||
|
import ca.tweetzy.auctionhouse.auction.AuctionPlayer;
|
||||||
|
import ca.tweetzy.auctionhouse.auction.AuctionStackType;
|
||||||
|
import ca.tweetzy.auctionhouse.helpers.ConfigurationItemHelper;
|
||||||
|
import ca.tweetzy.auctionhouse.settings.Settings;
|
||||||
|
import ca.tweetzy.core.gui.Gui;
|
||||||
|
import ca.tweetzy.core.utils.PlayerUtils;
|
||||||
|
import ca.tweetzy.core.utils.TextUtils;
|
||||||
|
import ca.tweetzy.core.utils.items.TItemBuilder;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The current file has been created by Kiran Hart
|
||||||
|
* Date Created: March 15 2021
|
||||||
|
* Time Created: 3:19 p.m.
|
||||||
|
* Usage of any code found within this class is prohibited unless given explicit permission otherwise
|
||||||
|
*/
|
||||||
|
public class GUIExpiredItems extends Gui {
|
||||||
|
|
||||||
|
final AuctionPlayer auctionPlayer;
|
||||||
|
|
||||||
|
public GUIExpiredItems(AuctionPlayer auctionPlayer) {
|
||||||
|
this.auctionPlayer = auctionPlayer;
|
||||||
|
setTitle(TextUtils.formatText(Settings.GUI_EXPIRED_AUCTIONS_TITLE.getString()));
|
||||||
|
setRows(6);
|
||||||
|
setAcceptsItems(false);
|
||||||
|
draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void draw() {
|
||||||
|
reset();
|
||||||
|
|
||||||
|
// Pagination
|
||||||
|
pages = (int) Math.max(1, Math.ceil(this.auctionPlayer.getItems(true).size() / (double) 45));
|
||||||
|
setPrevPage(5, 3, new TItemBuilder(Objects.requireNonNull(Settings.GUI_BACK_BTN_ITEM.getMaterial().parseMaterial())).setName(Settings.GUI_BACK_BTN_NAME.getString()).setLore(Settings.GUI_BACK_BTN_LORE.getStringList()).toItemStack());
|
||||||
|
setButton(5, 4, new TItemBuilder(Objects.requireNonNull(Settings.GUI_REFRESH_BTN_ITEM.getMaterial().parseMaterial())).setName(Settings.GUI_REFRESH_BTN_NAME.getString()).setLore(Settings.GUI_REFRESH_BTN_LORE.getStringList()).toItemStack(), e -> draw());
|
||||||
|
setNextPage(5, 5, new TItemBuilder(Objects.requireNonNull(Settings.GUI_NEXT_BTN_ITEM.getMaterial().parseMaterial())).setName(Settings.GUI_NEXT_BTN_NAME.getString()).setLore(Settings.GUI_NEXT_BTN_LORE.getStringList()).toItemStack());
|
||||||
|
setOnPage(e -> draw());
|
||||||
|
|
||||||
|
// Other Buttons
|
||||||
|
setButton(5, 0, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_CLOSE_BTN_ITEM.getString(), Settings.GUI_CLOSE_BTN_NAME.getString(), Settings.GUI_CLOSE_BTN_LORE.getStringList(), null), e -> e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer)));
|
||||||
|
setButton(5, 1, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_EXPIRED_AUCTIONS_ITEM.getString(), Settings.GUI_EXPIRED_AUCTIONS_NAME.getString(), Settings.GUI_EXPIRED_AUCTIONS_LORE.getStringList(), null), e -> {
|
||||||
|
this.auctionPlayer.getItems(true).forEach(item -> {
|
||||||
|
AuctionHouse.getInstance().getAuctionItemManager().adjustItemsInFile(item, false);
|
||||||
|
AuctionHouse.getInstance().getAuctionItemManager().removeItem(item.getKey());
|
||||||
|
PlayerUtils.giveItem(e.player, AuctionAPI.getInstance().deserializeItem(item.getRawItem()));
|
||||||
|
});
|
||||||
|
draw();
|
||||||
|
});
|
||||||
|
|
||||||
|
List<AuctionItem> data = this.auctionPlayer.getItems(true).stream().sorted(Comparator.comparingInt(AuctionItem::getRemainingTime).reversed()).skip((page - 1) * 45L).limit(45).collect(Collectors.toList());
|
||||||
|
int slot = 0;
|
||||||
|
for (AuctionItem item : data) {
|
||||||
|
setButton(slot++, AuctionAPI.getInstance().deserializeItem(item.getRawItem()), e -> {
|
||||||
|
AuctionHouse.getInstance().getAuctionItemManager().adjustItemsInFile(item, false);
|
||||||
|
AuctionHouse.getInstance().getAuctionItemManager().removeItem(item.getKey());
|
||||||
|
PlayerUtils.giveItem(e.player, AuctionAPI.getInstance().deserializeItem(item.getRawItem()));
|
||||||
|
draw();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -47,7 +47,7 @@ public class AuctionItemManager {
|
|||||||
if (category == null) {
|
if (category == null) {
|
||||||
return Collections.unmodifiableList(this.auctionItems);
|
return Collections.unmodifiableList(this.auctionItems);
|
||||||
}
|
}
|
||||||
return Collections.unmodifiableList(auctionItems.stream().filter(auctionItem -> MaterialCategorizer.getMaterialCategory(AuctionAPI.deserializeItem(auctionItem.getRawItem())) == category).collect(Collectors.toList()));
|
return Collections.unmodifiableList(auctionItems.stream().filter(auctionItem -> MaterialCategorizer.getMaterialCategory(AuctionAPI.getInstance().deserializeItem(auctionItem.getRawItem())) == category).collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadItems() {
|
public void loadItems() {
|
||||||
@ -75,7 +75,7 @@ public class AuctionItemManager {
|
|||||||
|
|
||||||
List<AuctionItem> foundItems = AuctionHouse.getInstance().getData().getStringList("auction items").stream().map(AuctionAPI.getInstance()::convertBase64ToObject).map(object -> (AuctionItem) object).collect(Collectors.toList());
|
List<AuctionItem> foundItems = AuctionHouse.getInstance().getData().getStringList("auction items").stream().map(AuctionAPI.getInstance()::convertBase64ToObject).map(object -> (AuctionItem) object).collect(Collectors.toList());
|
||||||
foundItems.addAll(items);
|
foundItems.addAll(items);
|
||||||
AuctionHouse.getInstance().getData().set("auction items", foundItems);
|
AuctionHouse.getInstance().getData().set("auction items", foundItems.stream().map(AuctionAPI.getInstance()::convertToBase64).collect(Collectors.toList()));
|
||||||
AuctionHouse.getInstance().getData().save();
|
AuctionHouse.getInstance().getData().save();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,7 +87,7 @@ public class AuctionItemManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<AuctionItem> items = AuctionHouse.getInstance().getData().getStringList("auction items").stream().map(AuctionAPI.getInstance()::convertBase64ToObject).map(object -> (AuctionItem) object).collect(Collectors.toList());
|
List<AuctionItem> items = AuctionHouse.getInstance().getData().getStringList("auction items").stream().map(AuctionAPI.getInstance()::convertBase64ToObject).map(object -> (AuctionItem) object).collect(Collectors.toList());
|
||||||
if (items.stream().anyMatch(i -> i.getKey().equals(item.getKey())) && !add) {
|
if (items.stream().anyMatch(i -> i.getKey().equals(item.getKey())) || !add) {
|
||||||
items.removeIf(i -> i.getKey().equals(item.getKey()));
|
items.removeIf(i -> i.getKey().equals(item.getKey()));
|
||||||
} else {
|
} else {
|
||||||
items.add(item);
|
items.add(item);
|
||||||
|
@ -57,6 +57,7 @@ public class TickAuctionsTask extends BukkitRunnable {
|
|||||||
// check if the auction item owner is the same as the highest bidder
|
// check if the auction item owner is the same as the highest bidder
|
||||||
if (item.getOwner().equals(item.getHighestBidder())) {
|
if (item.getOwner().equals(item.getHighestBidder())) {
|
||||||
// was not sold
|
// was not sold
|
||||||
|
item.setExpired(true);
|
||||||
AuctionHouse.getInstance().getAuctionItemManager().adjustItemsInFile(item, true);
|
AuctionHouse.getInstance().getAuctionItemManager().adjustItemsInFile(item, true);
|
||||||
} else {
|
} else {
|
||||||
// the item was sold ?? then do the checks
|
// the item was sold ?? then do the checks
|
||||||
@ -64,29 +65,31 @@ public class TickAuctionsTask extends BukkitRunnable {
|
|||||||
if (offlinePlayer.isOnline()) {
|
if (offlinePlayer.isOnline()) {
|
||||||
if (AuctionHouse.getInstance().getEconomy().has(offlinePlayer, item.getCurrentPrice())) {
|
if (AuctionHouse.getInstance().getEconomy().has(offlinePlayer, item.getCurrentPrice())) {
|
||||||
// since they're online, try to add the item to their inventory
|
// since they're online, try to add the item to their inventory
|
||||||
PlayerUtils.giveItem(offlinePlayer.getPlayer(), AuctionAPI.deserializeItem(item.getRawItem()));
|
PlayerUtils.giveItem(offlinePlayer.getPlayer(), AuctionAPI.getInstance().deserializeItem(item.getRawItem()));
|
||||||
// withdraw money and give to the owner
|
// withdraw money and give to the owner
|
||||||
AuctionHouse.getInstance().getEconomy().withdrawPlayer(offlinePlayer, item.getCurrentPrice());
|
AuctionHouse.getInstance().getEconomy().withdrawPlayer(offlinePlayer, item.getCurrentPrice());
|
||||||
AuctionHouse.getInstance().getEconomy().depositPlayer(Bukkit.getOfflinePlayer(item.getOwner()), item.getCurrentPrice());
|
AuctionHouse.getInstance().getEconomy().depositPlayer(Bukkit.getOfflinePlayer(item.getOwner()), item.getCurrentPrice());
|
||||||
// send a message to each of them
|
// send a message to each of them
|
||||||
AuctionHouse.getInstance().getLocale().getMessage("auction.bidwon")
|
AuctionHouse.getInstance().getLocale().getMessage("auction.bidwon")
|
||||||
.processPlaceholder("item", WordUtils.capitalizeFully(AuctionAPI.deserializeItem(item.getRawItem()).getType().name().replace("_", " ")))
|
.processPlaceholder("item", WordUtils.capitalizeFully(AuctionAPI.getInstance().deserializeItem(item.getRawItem()).getType().name().replace("_", " ")))
|
||||||
.processPlaceholder("amount", AuctionAPI.deserializeItem(item.getRawItem()).getAmount())
|
.processPlaceholder("amount", AuctionAPI.getInstance().deserializeItem(item.getRawItem()).getAmount())
|
||||||
.processPlaceholder("price", String.format("%,.2f", item.getCurrentPrice()))
|
.processPlaceholder("price", String.format("%,.2f", item.getCurrentPrice()))
|
||||||
.sendPrefixedMessage(offlinePlayer.getPlayer());
|
.sendPrefixedMessage(offlinePlayer.getPlayer());
|
||||||
AuctionHouse.getInstance().getLocale().getMessage("pricing.moneyremove").processPlaceholder("price", String.format("%,.2f", item.getCurrentPrice())).sendPrefixedMessage(offlinePlayer.getPlayer());
|
AuctionHouse.getInstance().getLocale().getMessage("pricing.moneyremove").processPlaceholder("price", String.format("%,.2f", item.getCurrentPrice())).sendPrefixedMessage(offlinePlayer.getPlayer());
|
||||||
// if the original owner is online, let them know they sold an item
|
// if the original owner is online, let them know they sold an item
|
||||||
if (Bukkit.getOfflinePlayer(item.getOwner()).isOnline()) {
|
if (Bukkit.getOfflinePlayer(item.getOwner()).isOnline()) {
|
||||||
AuctionHouse.getInstance().getLocale().getMessage("auction.itemsold")
|
AuctionHouse.getInstance().getLocale().getMessage("auction.itemsold")
|
||||||
.processPlaceholder("item", WordUtils.capitalizeFully(AuctionAPI.deserializeItem(item.getRawItem()).getType().name().replace("_", " ")))
|
.processPlaceholder("item", WordUtils.capitalizeFully(AuctionAPI.getInstance().deserializeItem(item.getRawItem()).getType().name().replace("_", " ")))
|
||||||
.processPlaceholder("price", String.format("%,.2f", item.getCurrentPrice()))
|
.processPlaceholder("price", String.format("%,.2f", item.getCurrentPrice()))
|
||||||
.sendPrefixedMessage(Bukkit.getOfflinePlayer(item.getOwner()).getPlayer());
|
.sendPrefixedMessage(Bukkit.getOfflinePlayer(item.getOwner()).getPlayer());
|
||||||
AuctionHouse.getInstance().getLocale().getMessage("pricing.moneyadd").processPlaceholder("price", String.format("%,.2f", item.getCurrentPrice())).sendPrefixedMessage(Bukkit.getOfflinePlayer(item.getOwner()).getPlayer());
|
AuctionHouse.getInstance().getLocale().getMessage("pricing.moneyadd").processPlaceholder("price", String.format("%,.2f", item.getCurrentPrice())).sendPrefixedMessage(Bukkit.getOfflinePlayer(item.getOwner()).getPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AuctionHouse.getInstance().getAuctionItemManager().removeItem(item.getKey());
|
||||||
AuctionHouse.getInstance().getAuctionItemManager().adjustItemsInFile(item, false);
|
AuctionHouse.getInstance().getAuctionItemManager().adjustItemsInFile(item, false);
|
||||||
} else {
|
} else {
|
||||||
// they don't have enough money to buy it, so send it back to the original owner
|
// they don't have enough money to buy it, so send it back to the original owner
|
||||||
|
item.setExpired(true);
|
||||||
AuctionHouse.getInstance().getAuctionItemManager().adjustItemsInFile(item, true);
|
AuctionHouse.getInstance().getAuctionItemManager().adjustItemsInFile(item, true);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -96,9 +99,11 @@ public class TickAuctionsTask extends BukkitRunnable {
|
|||||||
AuctionHouse.getInstance().getEconomy().withdrawPlayer(offlinePlayer, item.getCurrentPrice());
|
AuctionHouse.getInstance().getEconomy().withdrawPlayer(offlinePlayer, item.getCurrentPrice());
|
||||||
AuctionHouse.getInstance().getEconomy().depositPlayer(Bukkit.getOfflinePlayer(item.getOwner()), item.getCurrentPrice());
|
AuctionHouse.getInstance().getEconomy().depositPlayer(Bukkit.getOfflinePlayer(item.getOwner()), item.getCurrentPrice());
|
||||||
item.setOwner(offlinePlayer.getUniqueId());
|
item.setOwner(offlinePlayer.getUniqueId());
|
||||||
|
item.setExpired(true);
|
||||||
AuctionHouse.getInstance().getAuctionItemManager().adjustItemsInFile(item, true);
|
AuctionHouse.getInstance().getAuctionItemManager().adjustItemsInFile(item, true);
|
||||||
} else {
|
} else {
|
||||||
// they don't have enough money to buy it, so send it back to the original owner
|
// they don't have enough money to buy it, so send it back to the original owner
|
||||||
|
item.setExpired(true);
|
||||||
AuctionHouse.getInstance().getAuctionItemManager().adjustItemsInFile(item, true);
|
AuctionHouse.getInstance().getAuctionItemManager().adjustItemsInFile(item, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user