mirror of
https://github.com/kiranhart/Auction-House.git
synced 2024-11-22 05:25:11 +01:00
you can now specify what click type should be used for the auction page. you can now accept a bid through your active listings menu.
This commit is contained in:
parent
a13761ebce
commit
fd67e2ae43
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>ca.tweetzy</groupId>
|
||||
<artifactId>auctionhouse</artifactId>
|
||||
<version>2.9.0</version>
|
||||
<version>2.10.0</version>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
@ -1,12 +1,15 @@
|
||||
package ca.tweetzy.auctionhouse.api;
|
||||
|
||||
import ca.tweetzy.auctionhouse.AuctionHouse;
|
||||
import ca.tweetzy.auctionhouse.api.events.AuctionEndEvent;
|
||||
import ca.tweetzy.auctionhouse.auction.AuctionItem;
|
||||
import ca.tweetzy.auctionhouse.auction.AuctionSaleType;
|
||||
import ca.tweetzy.auctionhouse.settings.Settings;
|
||||
import ca.tweetzy.core.compatibility.XMaterial;
|
||||
import ca.tweetzy.core.utils.PlayerUtils;
|
||||
import ca.tweetzy.core.utils.TextUtils;
|
||||
import org.apache.commons.lang.WordUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
@ -88,7 +91,7 @@ public class AuctionAPI {
|
||||
* @return a readable date format
|
||||
*/
|
||||
public String convertMillisToDate(long milliseconds) {
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MMM dd, yyyy hh:mm aa");
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(Settings.DATE_FORMAT.getString());
|
||||
Date date = new Date(milliseconds);
|
||||
return simpleDateFormat.format(date);
|
||||
}
|
||||
@ -252,4 +255,90 @@ public class AuctionAPI {
|
||||
if (index == -1) return string;
|
||||
return string.substring(0, index) + replacement + string.substring(index + substring.length());
|
||||
}
|
||||
|
||||
public void endAuction(AuctionItem item) {
|
||||
// check if the auction item owner is the same as the highest bidder
|
||||
if (item.getOwner().equals(item.getHighestBidder())) {
|
||||
// was not sold
|
||||
item.setExpired(true);
|
||||
} else {
|
||||
// the item was sold ?? then do the checks
|
||||
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(item.getHighestBidder());
|
||||
AuctionEndEvent auctionEndEvent;
|
||||
if (offlinePlayer.isOnline()) {
|
||||
if (AuctionHouse.getInstance().getEconomy().has(offlinePlayer, item.getCurrentPrice())) {
|
||||
auctionEndEvent = new AuctionEndEvent(Bukkit.getOfflinePlayer(item.getOwner()), offlinePlayer, item, AuctionSaleType.USED_BIDDING_SYSTEM);
|
||||
AuctionHouse.getInstance().getServer().getPluginManager().callEvent(auctionEndEvent);
|
||||
|
||||
if (!auctionEndEvent.isCancelled()) {
|
||||
// withdraw money and give to the owner
|
||||
AuctionHouse.getInstance().getEconomy().withdrawPlayer(offlinePlayer, item.getCurrentPrice());
|
||||
AuctionHouse.getInstance().getEconomy().depositPlayer(Bukkit.getOfflinePlayer(item.getOwner()), item.getCurrentPrice());
|
||||
// send a message to each of them
|
||||
AuctionHouse.getInstance().getLocale().getMessage("auction.bidwon")
|
||||
.processPlaceholder("item", WordUtils.capitalizeFully(AuctionAPI.getInstance().deserializeItem(item.getRawItem()).getType().name().replace("_", " ")))
|
||||
.processPlaceholder("amount", AuctionAPI.getInstance().deserializeItem(item.getRawItem()).getAmount())
|
||||
.processPlaceholder("price", AuctionAPI.getInstance().formatNumber(item.getCurrentPrice()))
|
||||
.sendPrefixedMessage(offlinePlayer.getPlayer());
|
||||
AuctionHouse.getInstance().getLocale().getMessage("pricing.moneyremove").processPlaceholder("price", AuctionAPI.getInstance().formatNumber(item.getCurrentPrice())).sendPrefixedMessage(offlinePlayer.getPlayer());
|
||||
// if the original owner is online, let them know they sold an item
|
||||
if (Bukkit.getOfflinePlayer(item.getOwner()).isOnline()) {
|
||||
AuctionHouse.getInstance().getLocale().getMessage("auction.itemsold")
|
||||
.processPlaceholder("item", WordUtils.capitalizeFully(AuctionAPI.getInstance().deserializeItem(item.getRawItem()).getType().name().replace("_", " ")))
|
||||
.processPlaceholder("price", AuctionAPI.getInstance().formatNumber(item.getCurrentPrice()))
|
||||
.processPlaceholder("buyer_name", Bukkit.getOfflinePlayer(item.getHighestBidder()).getName())
|
||||
.sendPrefixedMessage(Bukkit.getOfflinePlayer(item.getOwner()).getPlayer());
|
||||
AuctionHouse.getInstance().getLocale().getMessage("pricing.moneyadd").processPlaceholder("price", AuctionAPI.getInstance().formatNumber(item.getCurrentPrice())).sendPrefixedMessage(Bukkit.getOfflinePlayer(item.getOwner()).getPlayer());
|
||||
}
|
||||
|
||||
// since they're online, try to add the item to their inventory
|
||||
// TODO CLEAN THIS UP A BIT
|
||||
if (Settings.ALLOW_PURCHASE_IF_INVENTORY_FULL.getBoolean()) {
|
||||
PlayerUtils.giveItem(offlinePlayer.getPlayer(), AuctionAPI.getInstance().deserializeItem(item.getRawItem()));
|
||||
AuctionHouse.getInstance().getAuctionItemManager().removeItem(item.getKey());
|
||||
} else {
|
||||
if (offlinePlayer.getPlayer().getInventory().firstEmpty() == -1) {
|
||||
item.setOwner(offlinePlayer.getUniqueId());
|
||||
item.setExpired(true);
|
||||
} else {
|
||||
PlayerUtils.giveItem(offlinePlayer.getPlayer(), AuctionAPI.getInstance().deserializeItem(item.getRawItem()));
|
||||
AuctionHouse.getInstance().getAuctionItemManager().removeItem(item.getKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// they don't have enough money to buy it, so send it back to the original owner
|
||||
item.setExpired(true);
|
||||
}
|
||||
} else {
|
||||
// offline, so save their purchase in the collection inventory
|
||||
if (AuctionHouse.getInstance().getEconomy().has(offlinePlayer, item.getCurrentPrice())) {
|
||||
auctionEndEvent = new AuctionEndEvent(Bukkit.getOfflinePlayer(item.getOwner()), offlinePlayer, item, AuctionSaleType.USED_BIDDING_SYSTEM);
|
||||
AuctionHouse.getInstance().getServer().getPluginManager().callEvent(auctionEndEvent);
|
||||
|
||||
if (!auctionEndEvent.isCancelled()) {
|
||||
// withdraw money and give to the owner
|
||||
AuctionHouse.getInstance().getEconomy().withdrawPlayer(offlinePlayer, item.getCurrentPrice());
|
||||
AuctionHouse.getInstance().getEconomy().depositPlayer(Bukkit.getOfflinePlayer(item.getOwner()), item.getCurrentPrice());
|
||||
|
||||
if (Bukkit.getOfflinePlayer(item.getOwner()).isOnline()) {
|
||||
AuctionHouse.getInstance().getLocale().getMessage("auction.itemsold")
|
||||
.processPlaceholder("item", WordUtils.capitalizeFully(AuctionAPI.getInstance().deserializeItem(item.getRawItem()).getType().name().replace("_", " ")))
|
||||
.processPlaceholder("price", AuctionAPI.getInstance().formatNumber(item.getCurrentPrice()))
|
||||
.processPlaceholder("buyer_name", Bukkit.getOfflinePlayer(item.getHighestBidder()).getName())
|
||||
.sendPrefixedMessage(Bukkit.getOfflinePlayer(item.getOwner()).getPlayer());
|
||||
AuctionHouse.getInstance().getLocale().getMessage("pricing.moneyadd").processPlaceholder("price", AuctionAPI.getInstance().formatNumber(item.getCurrentPrice())).sendPrefixedMessage(Bukkit.getOfflinePlayer(item.getOwner()).getPlayer());
|
||||
}
|
||||
|
||||
item.setOwner(offlinePlayer.getUniqueId());
|
||||
item.setExpired(true);
|
||||
}
|
||||
} else {
|
||||
// they don't have enough money to buy it, so send it back to the original owner
|
||||
item.setExpired(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -108,6 +108,10 @@ public class AuctionItem implements Serializable {
|
||||
}
|
||||
|
||||
lore.addAll(Settings.AUCTION_PURCHASE_CONTROL_FOOTER.getStringList().stream().map(TextUtils::formatText).collect(Collectors.toList()));
|
||||
} else {
|
||||
if (Settings.ALLOW_PLAYERS_TO_ACCEPT_BID.getBoolean()) {
|
||||
lore.addAll(Settings.AUCTION_PURCHASE_CONTROLS_ACCEPT_BID.getStringList().stream().map(TextUtils::formatText).collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
|
||||
meta.setLore(lore);
|
||||
|
@ -1,8 +1,11 @@
|
||||
package ca.tweetzy.auctionhouse.commands;
|
||||
|
||||
import ca.tweetzy.auctionhouse.AuctionHouse;
|
||||
import ca.tweetzy.auctionhouse.auction.AuctionPlayer;
|
||||
import ca.tweetzy.auctionhouse.guis.GUIAuctionHouse;
|
||||
import ca.tweetzy.core.commands.AbstractCommand;
|
||||
import ca.tweetzy.core.utils.TextUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -30,6 +33,11 @@ public class CommandSearch extends AbstractCommand {
|
||||
builder.append(arg).append(" ");
|
||||
}
|
||||
|
||||
if (AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(player.getUniqueId()) == null) {
|
||||
AuctionHouse.getInstance().getLocale().newMessage(TextUtils.formatText("&cCould not find auction player instance for&f: &e" + player.getName() + "&c creating one now.")).sendPrefixedMessage(Bukkit.getConsoleSender());
|
||||
AuctionHouse.getInstance().getAuctionPlayerManager().addPlayer(new AuctionPlayer(player));
|
||||
}
|
||||
|
||||
AuctionHouse.getInstance().getGuiManager().showGUI(player, new GUIAuctionHouse(AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(player.getUniqueId()), builder.toString().trim()));
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
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;
|
||||
@ -31,6 +32,8 @@ public class GUIActiveAuctions extends Gui {
|
||||
private BukkitTask task;
|
||||
private int taskId;
|
||||
|
||||
List<AuctionItem> items;
|
||||
|
||||
public GUIActiveAuctions(AuctionPlayer auctionPlayer) {
|
||||
this.auctionPlayer = auctionPlayer;
|
||||
setTitle(TextUtils.formatText(Settings.GUI_ACTIVE_AUCTIONS_TITLE.getString()));
|
||||
@ -46,66 +49,76 @@ public class GUIActiveAuctions extends Gui {
|
||||
|
||||
private void draw() {
|
||||
reset();
|
||||
drawFixedButtons();
|
||||
drawItems();
|
||||
}
|
||||
|
||||
// Pagination
|
||||
pages = (int) Math.max(1, Math.ceil(this.auctionPlayer.getItems(false).size() / (double) 45));
|
||||
private void drawItems() {
|
||||
AuctionHouse.newChain().asyncFirst(() -> {
|
||||
this.items = this.auctionPlayer.getItems(false);
|
||||
return this.items.stream().sorted(Comparator.comparingInt(AuctionItem::getRemainingTime).reversed()).skip((page - 1) * 45L).limit(45).collect(Collectors.toList());
|
||||
}).asyncLast((data) -> {
|
||||
pages = (int) Math.max(1, Math.ceil(this.items.size() / (double) 45L));
|
||||
drawPaginationButtons();
|
||||
|
||||
int slot = 0;
|
||||
for (AuctionItem item : data) {
|
||||
setButton(slot++, item.getDisplayStack(AuctionStackType.ACTIVE_AUCTIONS_LIST), e -> {
|
||||
switch (e.clickType) {
|
||||
case LEFT:
|
||||
item.setExpired(true);
|
||||
draw();
|
||||
break;
|
||||
case RIGHT:
|
||||
if (Settings.ALLOW_PLAYERS_TO_ACCEPT_BID.getBoolean() && item.getBidStartPrice() != 0) {
|
||||
AuctionHouse.newChain().async(() -> AuctionAPI.getInstance().endAuction(item)).sync(this::draw).execute();
|
||||
}
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
}).execute();
|
||||
}
|
||||
|
||||
private void drawFixedButtons() {
|
||||
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 -> {
|
||||
cleanup();
|
||||
e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer));
|
||||
});
|
||||
|
||||
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 -> e.manager.showGUI(e.player, new GUIActiveAuctions(this.auctionPlayer)));
|
||||
|
||||
setButton(5, 1, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_ACTIVE_AUCTIONS_ITEM.getString(), Settings.GUI_ACTIVE_AUCTIONS_NAME.getString(), Settings.GUI_ACTIVE_AUCTIONS_LORE.getStringList(), null), e -> {
|
||||
this.auctionPlayer.getItems(false).forEach(item -> item.setExpired(true));
|
||||
draw();
|
||||
});
|
||||
}
|
||||
|
||||
private void drawPaginationButtons() {
|
||||
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();
|
||||
SoundManager.getInstance().playSound(this.auctionPlayer.getPlayer(), Settings.SOUNDS_NAVIGATE_GUI_PAGES.getString(), 1.0F, 1.0F);
|
||||
});
|
||||
|
||||
// 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 -> {
|
||||
cleanup();
|
||||
e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer));
|
||||
});
|
||||
setButton(5, 1, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_ACTIVE_AUCTIONS_ITEM.getString(), Settings.GUI_ACTIVE_AUCTIONS_NAME.getString(), Settings.GUI_ACTIVE_AUCTIONS_LORE.getStringList(), null), e -> {
|
||||
this.auctionPlayer.getItems(false).forEach(item -> item.setExpired(true));
|
||||
draw();
|
||||
});
|
||||
|
||||
List<AuctionItem> data = this.auctionPlayer.getItems(false).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++, item.getDisplayStack(AuctionStackType.ACTIVE_AUCTIONS_LIST), e -> {
|
||||
item.setExpired(true);
|
||||
draw();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void startTask() {
|
||||
taskId = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(AuctionHouse.getInstance(), this::draw, 0L, (long) 20 * Settings.TICK_UPDATE_GUI_TIME.getInt());
|
||||
}
|
||||
|
||||
private void startTaskAsync() {
|
||||
task = Bukkit.getServer().getScheduler().runTaskTimerAsynchronously(AuctionHouse.getInstance(), this::draw, 0L, (long) 20 * Settings.TICK_UPDATE_GUI_TIME.getInt());
|
||||
}
|
||||
|
||||
private void killTask() {
|
||||
Bukkit.getServer().getScheduler().cancelTask(taskId);
|
||||
}
|
||||
|
||||
private void killAsyncTask() {
|
||||
task.cancel();
|
||||
}
|
||||
|
||||
/*
|
||||
====================== AUTO REFRESH ======================
|
||||
*/
|
||||
private void makeMess() {
|
||||
if (Settings.USE_ASYNC_GUI_REFRESH.getBoolean()) {
|
||||
startTaskAsync();
|
||||
task = Bukkit.getServer().getScheduler().runTaskTimerAsynchronously(AuctionHouse.getInstance(), this::drawItems, 0L, (long) 20 * Settings.TICK_UPDATE_GUI_TIME.getInt());
|
||||
} else {
|
||||
startTask();
|
||||
taskId = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(AuctionHouse.getInstance(), this::drawItems, 0L, (long) 20 * Settings.TICK_UPDATE_GUI_TIME.getInt());
|
||||
}
|
||||
}
|
||||
|
||||
private void cleanup() {
|
||||
if (Settings.USE_ASYNC_GUI_REFRESH.getBoolean()) {
|
||||
killAsyncTask();
|
||||
task.cancel();
|
||||
} else {
|
||||
killTask();
|
||||
Bukkit.getServer().getScheduler().cancelTask(taskId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,11 +10,13 @@ import ca.tweetzy.auctionhouse.settings.Settings;
|
||||
import ca.tweetzy.core.compatibility.ServerVersion;
|
||||
import ca.tweetzy.core.compatibility.XMaterial;
|
||||
import ca.tweetzy.core.gui.Gui;
|
||||
import ca.tweetzy.core.gui.events.GuiClickEvent;
|
||||
import ca.tweetzy.core.utils.TextUtils;
|
||||
import ca.tweetzy.core.utils.items.TItemBuilder;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.block.ShulkerBox;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.BlockStateMeta;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
@ -75,10 +77,9 @@ public class GUIAuctionHouse extends Gui {
|
||||
drawItems();
|
||||
}
|
||||
|
||||
|
||||
private void drawItems() {
|
||||
AuctionHouse.newChain().asyncFirst(() -> {
|
||||
this.items = AuctionHouse.getInstance().getAuctionItemManager().getAuctionItems().stream().filter(item -> !item.isExpired()).collect(Collectors.toList());
|
||||
this.items = AuctionHouse.getInstance().getAuctionItemManager().getAuctionItems().stream().filter(item -> !item.isExpired() && item.getRemainingTime() >= 1).collect(Collectors.toList());
|
||||
|
||||
if (this.searchPhrase.length() != 0) {
|
||||
this.items = this.items.stream().filter(auctionItem -> AuctionAPI.getInstance().match(this.searchPhrase, ChatColor.stripColor(auctionItem.getItemName())) || AuctionAPI.getInstance().match(this.searchPhrase, auctionItem.getCategory().getType()) || AuctionAPI.getInstance().match(this.searchPhrase, auctionItem.getCategory().getTranslatedType()) || AuctionAPI.getInstance().match(this.searchPhrase, Bukkit.getOfflinePlayer(auctionItem.getOwner()).getName())).collect(Collectors.toList());
|
||||
@ -97,110 +98,148 @@ public class GUIAuctionHouse extends Gui {
|
||||
}).execute();
|
||||
}
|
||||
|
||||
/*
|
||||
====================== CLICK HANDLES ======================
|
||||
*/
|
||||
private void handleNonBidItem(AuctionItem auctionItem, GuiClickEvent e, boolean buyingQuantity) {
|
||||
if (e.player.getUniqueId().equals(auctionItem.getOwner()) && !Settings.OWNER_CAN_PURCHASE_OWN_ITEM.getBoolean()) {
|
||||
AuctionHouse.getInstance().getLocale().getMessage("general.cantbuyown").sendPrefixedMessage(e.player);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!AuctionHouse.getInstance().getEconomy().has(e.player, auctionItem.getBasePrice())) {
|
||||
AuctionHouse.getInstance().getLocale().getMessage("general.notenoughmoney").sendPrefixedMessage(e.player);
|
||||
return;
|
||||
}
|
||||
|
||||
if (buyingQuantity) {
|
||||
if (auctionItem.getBidStartPrice() <= 0 || !Settings.ALLOW_USAGE_OF_BID_SYSTEM.getBoolean()) {
|
||||
if (!Settings.ALLOW_PURCHASE_OF_SPECIFIC_QUANTITIES.getBoolean()) return;
|
||||
}
|
||||
}
|
||||
|
||||
cleanup();
|
||||
e.manager.showGUI(e.player, new GUIConfirmPurchase(this.auctionPlayer, auctionItem, buyingQuantity));
|
||||
}
|
||||
|
||||
private void handleBidItem(AuctionItem auctionItem, GuiClickEvent e, boolean buyNow) {
|
||||
if (buyNow) {
|
||||
if (auctionItem.getBidStartPrice() >= Settings.MIN_AUCTION_START_PRICE.getDouble()) {
|
||||
if (!Settings.ALLOW_USAGE_OF_BUY_NOW_SYSTEM.getBoolean()) return;
|
||||
if (auctionItem.getBasePrice() <= -1) {
|
||||
AuctionHouse.getInstance().getLocale().getMessage("general.buynowdisabledonitem").sendPrefixedMessage(e.player);
|
||||
return;
|
||||
}
|
||||
|
||||
cleanup();
|
||||
e.manager.showGUI(e.player, new GUIConfirmPurchase(this.auctionPlayer, auctionItem, false));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.player.getUniqueId().equals(auctionItem.getOwner()) && !Settings.OWNER_CAN_BID_OWN_ITEM.getBoolean()) {
|
||||
AuctionHouse.getInstance().getLocale().getMessage("general.cantbidonown").sendPrefixedMessage(e.player);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Settings.PLAYER_NEEDS_TOTAL_PRICE_TO_BID.getBoolean() && !AuctionHouse.getInstance().getEconomy().has(e.player, auctionItem.getCurrentPrice() + auctionItem.getBidIncPrice())) {
|
||||
AuctionHouse.getInstance().getLocale().getMessage("general.notenoughmoney").sendPrefixedMessage(e.player);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Settings.ASK_FOR_BID_CONFIRMATION.getBoolean()) {
|
||||
cleanup();
|
||||
e.manager.showGUI(e.player, new GUIConfirmBid(this.auctionPlayer, auctionItem));
|
||||
} else {
|
||||
auctionItem.setHighestBidder(e.player.getUniqueId());
|
||||
auctionItem.setCurrentPrice(auctionItem.getCurrentPrice() + auctionItem.getBidIncPrice());
|
||||
if (Settings.SYNC_BASE_PRICE_TO_HIGHEST_PRICE.getBoolean() && auctionItem.getCurrentPrice() > auctionItem.getBasePrice()) {
|
||||
auctionItem.setBasePrice(auctionItem.getCurrentPrice());
|
||||
}
|
||||
|
||||
if (Settings.INCREASE_TIME_ON_BID.getBoolean()) {
|
||||
auctionItem.setRemainingTime(auctionItem.getRemainingTime() + Settings.TIME_TO_INCREASE_BY_ON_BID.getInt());
|
||||
}
|
||||
|
||||
if (Settings.REFRESH_GUI_WHEN_BID.getBoolean()) {
|
||||
cleanup();
|
||||
e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handleItemRemove(AuctionItem auctionItem, GuiClickEvent e) {
|
||||
if (e.player.isOp() || e.player.hasPermission("auctionhouse.admin")) {
|
||||
if (Settings.SEND_REMOVED_ITEM_BACK_TO_PLAYER.getBoolean()) {
|
||||
AuctionHouse.getInstance().getAuctionItemManager().getItem(auctionItem.getKey()).setExpired(true);
|
||||
} else {
|
||||
AuctionHouse.getInstance().getAuctionItemManager().removeItem(auctionItem.getKey());
|
||||
}
|
||||
|
||||
cleanup();
|
||||
e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer));
|
||||
}
|
||||
}
|
||||
|
||||
private void handleContainerInspect(GuiClickEvent e) {
|
||||
if (!ServerVersion.isServerVersionAtLeast(ServerVersion.V1_11)) return;
|
||||
if (e.player.isOp() || e.player.hasPermission("auctionhouse.admin") || e.player.hasPermission("auctionhouse.inspectshulker")) {
|
||||
ItemStack clicked = e.clickedItem;
|
||||
if (!(clicked.getItemMeta() instanceof BlockStateMeta)) return;
|
||||
|
||||
BlockStateMeta meta = (BlockStateMeta) clicked.getItemMeta();
|
||||
if (!(meta.getBlockState() instanceof ShulkerBox)) return;
|
||||
cleanup();
|
||||
e.manager.showGUI(e.player, new GUIContainerInspect(e.clickedItem));
|
||||
}
|
||||
}
|
||||
|
||||
private void placeItems(List<AuctionItem> data) {
|
||||
int slot = 0;
|
||||
for (AuctionItem auctionItem : data) {
|
||||
setButton(slot++, auctionItem.getDisplayStack(AuctionStackType.MAIN_AUCTION_HOUSE), e -> {
|
||||
switch (e.clickType) {
|
||||
case LEFT:
|
||||
if (auctionItem.getBidStartPrice() <= 0) {
|
||||
if (e.player.getUniqueId().equals(auctionItem.getOwner()) && !Settings.OWNER_CAN_PURCHASE_OWN_ITEM.getBoolean()) {
|
||||
AuctionHouse.getInstance().getLocale().getMessage("general.cantbuyown").sendPrefixedMessage(e.player);
|
||||
return;
|
||||
}
|
||||
// Non Type specific actions
|
||||
if (e.clickType == ClickType.valueOf(Settings.CLICKS_INSPECT_CONTAINER.getString().toUpperCase())) {
|
||||
handleContainerInspect(e);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!AuctionHouse.getInstance().getEconomy().has(e.player, auctionItem.getBasePrice())) {
|
||||
AuctionHouse.getInstance().getLocale().getMessage("general.notenoughmoney").sendPrefixedMessage(e.player);
|
||||
return;
|
||||
}
|
||||
if (e.clickType == ClickType.valueOf(Settings.CLICKS_REMOVE_ITEM.getString().toUpperCase())) {
|
||||
handleItemRemove(auctionItem, e);
|
||||
return;
|
||||
}
|
||||
|
||||
cleanup();
|
||||
e.manager.showGUI(e.player, new GUIConfirmPurchase(this.auctionPlayer, auctionItem, false));
|
||||
} else {
|
||||
if (e.player.getUniqueId().equals(auctionItem.getOwner()) && !Settings.OWNER_CAN_BID_OWN_ITEM.getBoolean()) {
|
||||
AuctionHouse.getInstance().getLocale().getMessage("general.cantbidonown").sendPrefixedMessage(e.player);
|
||||
return;
|
||||
}
|
||||
// Non Biddable Items
|
||||
if (auctionItem.getBidStartPrice() <= 0) {
|
||||
if (e.clickType == ClickType.valueOf(Settings.CLICKS_NON_BID_ITEM_PURCHASE.getString().toUpperCase())) {
|
||||
handleNonBidItem(auctionItem, e, false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Settings.PLAYER_NEEDS_TOTAL_PRICE_TO_BID.getBoolean() && !AuctionHouse.getInstance().getEconomy().has(e.player, auctionItem.getCurrentPrice() + auctionItem.getBidIncPrice())) {
|
||||
AuctionHouse.getInstance().getLocale().getMessage("general.notenoughmoney").sendPrefixedMessage(e.player);
|
||||
return;
|
||||
}
|
||||
if (e.clickType == ClickType.valueOf(Settings.CLICKS_NON_BID_ITEM_QTY_PURCHASE.getString().toUpperCase())) {
|
||||
handleNonBidItem(auctionItem, e, true);
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO CLEAN UP THIS
|
||||
if (Settings.ASK_FOR_BID_CONFIRMATION.getBoolean()) {
|
||||
cleanup();
|
||||
e.manager.showGUI(e.player, new GUIConfirmBid(this.auctionPlayer, auctionItem));
|
||||
} else {
|
||||
auctionItem.setHighestBidder(e.player.getUniqueId());
|
||||
auctionItem.setCurrentPrice(auctionItem.getCurrentPrice() + auctionItem.getBidIncPrice());
|
||||
if (Settings.SYNC_BASE_PRICE_TO_HIGHEST_PRICE.getBoolean() && auctionItem.getCurrentPrice() > auctionItem.getBasePrice()) {
|
||||
auctionItem.setBasePrice(auctionItem.getCurrentPrice());
|
||||
}
|
||||
// Biddable Items
|
||||
if (e.clickType == ClickType.valueOf(Settings.CLICKS_BID_ITEM_PLACE_BID.getString().toUpperCase())) {
|
||||
handleBidItem(auctionItem, e, false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Settings.INCREASE_TIME_ON_BID.getBoolean()) {
|
||||
auctionItem.setRemainingTime(auctionItem.getRemainingTime() + Settings.TIME_TO_INCREASE_BY_ON_BID.getInt());
|
||||
}
|
||||
|
||||
if (Settings.REFRESH_GUI_WHEN_BID.getBoolean()) {
|
||||
cleanup();
|
||||
e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer));
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MIDDLE:
|
||||
if (e.player.isOp() || e.player.hasPermission("auctionhouse.admin")) {
|
||||
if (Settings.SEND_REMOVED_ITEM_BACK_TO_PLAYER.getBoolean()) {
|
||||
AuctionHouse.getInstance().getAuctionItemManager().getItem(auctionItem.getKey()).setExpired(true);
|
||||
} else {
|
||||
AuctionHouse.getInstance().getAuctionItemManager().removeItem(auctionItem.getKey());
|
||||
}
|
||||
|
||||
cleanup();
|
||||
e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer));
|
||||
}
|
||||
break;
|
||||
case SHIFT_RIGHT:
|
||||
if (!ServerVersion.isServerVersionAtLeast(ServerVersion.V1_11)) return;
|
||||
if (e.player.isOp() || e.player.hasPermission("auctionhouse.admin") || e.player.hasPermission("auctionhouse.inspectshulker")) {
|
||||
ItemStack clicked = e.clickedItem;
|
||||
if (!(clicked.getItemMeta() instanceof BlockStateMeta)) return;
|
||||
|
||||
BlockStateMeta meta = (BlockStateMeta) clicked.getItemMeta();
|
||||
if (!(meta.getBlockState() instanceof ShulkerBox)) return;
|
||||
cleanup();
|
||||
e.manager.showGUI(e.player, new GUIContainerInspect(e.clickedItem));
|
||||
}
|
||||
break;
|
||||
case RIGHT:
|
||||
if (e.player.getUniqueId().equals(auctionItem.getOwner()) && !Settings.OWNER_CAN_PURCHASE_OWN_ITEM.getBoolean()) {
|
||||
AuctionHouse.getInstance().getLocale().getMessage("general.cantbuyown").sendPrefixedMessage(e.player);
|
||||
return;
|
||||
}
|
||||
|
||||
if (auctionItem.getBidStartPrice() <= 0 || !Settings.ALLOW_USAGE_OF_BID_SYSTEM.getBoolean()) {
|
||||
if (!Settings.ALLOW_PURCHASE_OF_SPECIFIC_QUANTITIES.getBoolean()) return;
|
||||
cleanup();
|
||||
e.manager.showGUI(e.player, new GUIConfirmPurchase(this.auctionPlayer, auctionItem, true));
|
||||
return;
|
||||
}
|
||||
|
||||
if (auctionItem.getBidStartPrice() >= Settings.MIN_AUCTION_START_PRICE.getDouble()) {
|
||||
if (!Settings.ALLOW_USAGE_OF_BUY_NOW_SYSTEM.getBoolean()) return;
|
||||
if (auctionItem.getBasePrice() <= -1) {
|
||||
AuctionHouse.getInstance().getLocale().getMessage("general.buynowdisabledonitem").sendPrefixedMessage(e.player);
|
||||
return;
|
||||
}
|
||||
cleanup();
|
||||
e.manager.showGUI(e.player, new GUIConfirmPurchase(this.auctionPlayer, auctionItem, false));
|
||||
}
|
||||
break;
|
||||
if (e.clickType == ClickType.valueOf(Settings.CLICKS_BID_ITEM_BUY_NOW.getString().toUpperCase())) {
|
||||
handleBidItem(auctionItem, e, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
====================== FIXED BUTTONS ======================
|
||||
*/
|
||||
|
||||
private void drawPaginationButtons() {
|
||||
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());
|
||||
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());
|
||||
|
@ -52,11 +52,77 @@ public class Settings {
|
||||
public static final ConfigSetting USE_REFRESH_COOL_DOWN = new ConfigSetting(config, "auction setting.use refresh cool down", true, "Should the refresh cooldown be enabled?");
|
||||
public static final ConfigSetting REFRESH_COOL_DOWN = new ConfigSetting(config, "auction setting.refresh cool down", 2, "How many seconds should pass before the player can refresh the auction house again?");
|
||||
public static final ConfigSetting ALLOW_PURCHASE_IF_INVENTORY_FULL = new ConfigSetting(config, "auction setting.allow purchase with full inventory", true, "Should auction house allow players to buy items even if their", "inventory is full, if true, items will be dropped on the floor if there is no room.");
|
||||
|
||||
public static final ConfigSetting ASK_FOR_BID_CONFIRMATION = new ConfigSetting(config, "auction setting.ask for bid confirmation", true, "Should Auction House open the confirmation menu for the user to confirm", "whether they actually meant to place a bid or not?");
|
||||
public static final ConfigSetting BASE_PRICE_MUST_BE_HIGHER_THAN_BID_START = new ConfigSetting(config, "auction setting.base price must be higher than bid start", true, "Should the base price (buy now price) be higher than the initial bid starting price?");
|
||||
public static final ConfigSetting SYNC_BASE_PRICE_TO_HIGHEST_PRICE = new ConfigSetting(config, "auction setting.sync the base price to the current price", true, "Ex. If the buy now price was 100, and the current price exceeds 100 to say 200, the buy now price will become 200.");
|
||||
public static final ConfigSetting USE_ALTERNATE_CURRENCY_FORMAT = new ConfigSetting(config, "auction setting.use alternate currency format", false, "If true, $123,456.78 will become $123.456,78");
|
||||
public static final ConfigSetting DATE_FORMAT = new ConfigSetting(config, "auction setting.date format", "MMM dd, yyyy hh:mm aa", "You can learn more about date formats by googling SimpleDateFormat patterns or visiting this link", "https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html");
|
||||
public static final ConfigSetting ALLOW_PLAYERS_TO_ACCEPT_BID = new ConfigSetting(config, "auction setting.allow players to accept bid", true, "If true, players can right click a biddable item inside their active listings menu to accept the current bid");
|
||||
|
||||
public static final ConfigSetting CLICKS_NON_BID_ITEM_PURCHASE = new ConfigSetting(config, "auction setting.clicks.non bid item purchase", "LEFT",
|
||||
"Valid Click Types",
|
||||
"LEFT",
|
||||
"RIGHT",
|
||||
"SHIFT_LEFT",
|
||||
"SHIFT_RIGHT",
|
||||
"MIDDLE",
|
||||
"",
|
||||
"&cIf you overlap click types (ex. LEFT for both inspect and buy) things will go crazy."
|
||||
);
|
||||
public static final ConfigSetting CLICKS_NON_BID_ITEM_QTY_PURCHASE = new ConfigSetting(config, "auction setting.clicks.non bid item qty purchase", "RIGHT",
|
||||
"Valid Click Types",
|
||||
"LEFT",
|
||||
"RIGHT",
|
||||
"SHIFT_LEFT",
|
||||
"SHIFT_RIGHT",
|
||||
"MIDDLE",
|
||||
"",
|
||||
"&cIf you overlap click types (ex. LEFT for both inspect and buy) things will go crazy."
|
||||
);
|
||||
|
||||
public static final ConfigSetting CLICKS_BID_ITEM_PLACE_BID = new ConfigSetting(config, "auction setting.clicks.bid item place bid", "LEFT",
|
||||
"Valid Click Types",
|
||||
"LEFT",
|
||||
"RIGHT",
|
||||
"SHIFT_LEFT",
|
||||
"SHIFT_RIGHT",
|
||||
"MIDDLE",
|
||||
"",
|
||||
"&cIf you overlap click types (ex. LEFT for both inspect and buy) things will go crazy."
|
||||
);
|
||||
public static final ConfigSetting CLICKS_BID_ITEM_BUY_NOW = new ConfigSetting(config, "auction setting.clicks.bid item buy now", "RIGHT",
|
||||
"Valid Click Types",
|
||||
"LEFT",
|
||||
"RIGHT",
|
||||
"SHIFT_LEFT",
|
||||
"SHIFT_RIGHT",
|
||||
"MIDDLE",
|
||||
"",
|
||||
"&cIf you overlap click types (ex. LEFT for both inspect and buy) things will go crazy."
|
||||
);
|
||||
|
||||
|
||||
public static final ConfigSetting CLICKS_INSPECT_CONTAINER = new ConfigSetting(config, "auction setting.clicks.inspect container", "SHIFT_RIGHT",
|
||||
"Valid Click Types",
|
||||
"LEFT",
|
||||
"RIGHT",
|
||||
"SHIFT_LEFT",
|
||||
"SHIFT_RIGHT",
|
||||
"MIDDLE",
|
||||
"",
|
||||
"&cIf you overlap click types (ex. LEFT for both inspect and buy) things will go crazy."
|
||||
);
|
||||
|
||||
public static final ConfigSetting CLICKS_REMOVE_ITEM = new ConfigSetting(config, "auction setting.clicks.remove item", "MIDDLE",
|
||||
"Valid Click Types",
|
||||
"LEFT",
|
||||
"RIGHT",
|
||||
"SHIFT_LEFT",
|
||||
"SHIFT_RIGHT",
|
||||
"MIDDLE",
|
||||
"",
|
||||
"&cIf you overlap click types (ex. LEFT for both inspect and buy) things will go crazy."
|
||||
);
|
||||
|
||||
/* ===============================
|
||||
* DATABASE OPTIONS
|
||||
@ -417,6 +483,7 @@ public class Settings {
|
||||
), "This will be appended at the end of the lore", "If the auction item is not using a bid, this will show");
|
||||
|
||||
public static final ConfigSetting AUCTION_PURCHASE_CONTROLS_INSPECTION = new ConfigSetting(config, "auction items.controls.inspection", Collections.singletonList("&eShift Right-Click to inspect"), "This will only be added to the control lore if the item can be inspected (skulker box)");
|
||||
public static final ConfigSetting AUCTION_PURCHASE_CONTROLS_ACCEPT_BID = new ConfigSetting(config, "auction items.controls.accept bid", Collections.singletonList("&eRight-Click to accept the current bid"), "This will only show on items within the active listings menu on biddable items.");
|
||||
public static final ConfigSetting AUCTION_PURCHASE_CONTROLS_BUY_NOW_OFF_FOR_BID = new ConfigSetting(config, "auction items.controls.buy now is off for bid", "&cN/A", "If they player sets the buy now price to -1 on a bid item, it will mean make the item", "a bid item, but users will not be able to use the buy now option on the item.");
|
||||
|
||||
/* ===============================
|
||||
|
@ -46,95 +46,9 @@ public class TickAuctionsTask extends BukkitRunnable {
|
||||
item.updateRemainingTime(Settings.TICK_UPDATE_TIME.getInt());
|
||||
}
|
||||
});
|
||||
|
||||
// filter items where the time is less than or equal to 0
|
||||
|
||||
AuctionHouse.getInstance().getAuctionItemManager().getAuctionItems().stream().filter(item -> item.getRemainingTime() <= 0).collect(Collectors.toList()).iterator().forEachRemaining(item -> {
|
||||
// call the auction end event
|
||||
AuctionEndEvent auctionEndEvent;
|
||||
|
||||
// check if the auction item owner is the same as the highest bidder
|
||||
if (item.getOwner().equals(item.getHighestBidder())) {
|
||||
// was not sold
|
||||
item.setExpired(true);
|
||||
} else {
|
||||
// the item was sold ?? then do the checks
|
||||
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(item.getHighestBidder());
|
||||
if (offlinePlayer.isOnline()) {
|
||||
if (AuctionHouse.getInstance().getEconomy().has(offlinePlayer, item.getCurrentPrice())) {
|
||||
auctionEndEvent = new AuctionEndEvent(Bukkit.getOfflinePlayer(item.getOwner()), offlinePlayer, item, AuctionSaleType.USED_BIDDING_SYSTEM);
|
||||
AuctionHouse.getInstance().getServer().getPluginManager().callEvent(auctionEndEvent);
|
||||
|
||||
if (!auctionEndEvent.isCancelled()) {
|
||||
// withdraw money and give to the owner
|
||||
AuctionHouse.getInstance().getEconomy().withdrawPlayer(offlinePlayer, item.getCurrentPrice());
|
||||
AuctionHouse.getInstance().getEconomy().depositPlayer(Bukkit.getOfflinePlayer(item.getOwner()), item.getCurrentPrice());
|
||||
// send a message to each of them
|
||||
AuctionHouse.getInstance().getLocale().getMessage("auction.bidwon")
|
||||
.processPlaceholder("item", WordUtils.capitalizeFully(AuctionAPI.getInstance().deserializeItem(item.getRawItem()).getType().name().replace("_", " ")))
|
||||
.processPlaceholder("amount", AuctionAPI.getInstance().deserializeItem(item.getRawItem()).getAmount())
|
||||
.processPlaceholder("price", AuctionAPI.getInstance().formatNumber(item.getCurrentPrice()))
|
||||
.sendPrefixedMessage(offlinePlayer.getPlayer());
|
||||
AuctionHouse.getInstance().getLocale().getMessage("pricing.moneyremove").processPlaceholder("price", AuctionAPI.getInstance().formatNumber(item.getCurrentPrice())).sendPrefixedMessage(offlinePlayer.getPlayer());
|
||||
// if the original owner is online, let them know they sold an item
|
||||
if (Bukkit.getOfflinePlayer(item.getOwner()).isOnline()) {
|
||||
AuctionHouse.getInstance().getLocale().getMessage("auction.itemsold")
|
||||
.processPlaceholder("item", WordUtils.capitalizeFully(AuctionAPI.getInstance().deserializeItem(item.getRawItem()).getType().name().replace("_", " ")))
|
||||
.processPlaceholder("price", AuctionAPI.getInstance().formatNumber(item.getCurrentPrice()))
|
||||
.processPlaceholder("buyer_name", Bukkit.getOfflinePlayer(item.getHighestBidder()).getPlayer().getName())
|
||||
.sendPrefixedMessage(Bukkit.getOfflinePlayer(item.getOwner()).getPlayer());
|
||||
AuctionHouse.getInstance().getLocale().getMessage("pricing.moneyadd").processPlaceholder("price", AuctionAPI.getInstance().formatNumber(item.getCurrentPrice())).sendPrefixedMessage(Bukkit.getOfflinePlayer(item.getOwner()).getPlayer());
|
||||
}
|
||||
|
||||
// since they're online, try to add the item to their inventory
|
||||
// TODO CLEAN THIS UP A BIT
|
||||
if (Settings.ALLOW_PURCHASE_IF_INVENTORY_FULL.getBoolean()) {
|
||||
PlayerUtils.giveItem(offlinePlayer.getPlayer(), AuctionAPI.getInstance().deserializeItem(item.getRawItem()));
|
||||
AuctionHouse.getInstance().getAuctionItemManager().removeItem(item.getKey());
|
||||
} else {
|
||||
if (offlinePlayer.getPlayer().getInventory().firstEmpty() == -1) {
|
||||
item.setOwner(offlinePlayer.getUniqueId());
|
||||
item.setExpired(true);
|
||||
} else {
|
||||
PlayerUtils.giveItem(offlinePlayer.getPlayer(), AuctionAPI.getInstance().deserializeItem(item.getRawItem()));
|
||||
AuctionHouse.getInstance().getAuctionItemManager().removeItem(item.getKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// they don't have enough money to buy it, so send it back to the original owner
|
||||
item.setExpired(true);
|
||||
}
|
||||
} else {
|
||||
// offline, so save their purchase in the collection inventory
|
||||
if (AuctionHouse.getInstance().getEconomy().has(offlinePlayer, item.getCurrentPrice())) {
|
||||
auctionEndEvent = new AuctionEndEvent(Bukkit.getOfflinePlayer(item.getOwner()), offlinePlayer, item, AuctionSaleType.USED_BIDDING_SYSTEM);
|
||||
AuctionHouse.getInstance().getServer().getPluginManager().callEvent(auctionEndEvent);
|
||||
|
||||
if (!auctionEndEvent.isCancelled()) {
|
||||
// withdraw money and give to the owner
|
||||
AuctionHouse.getInstance().getEconomy().withdrawPlayer(offlinePlayer, item.getCurrentPrice());
|
||||
AuctionHouse.getInstance().getEconomy().depositPlayer(Bukkit.getOfflinePlayer(item.getOwner()), item.getCurrentPrice());
|
||||
|
||||
if (Bukkit.getOfflinePlayer(item.getOwner()).isOnline()) {
|
||||
AuctionHouse.getInstance().getLocale().getMessage("auction.itemsold")
|
||||
.processPlaceholder("item", WordUtils.capitalizeFully(AuctionAPI.getInstance().deserializeItem(item.getRawItem()).getType().name().replace("_", " ")))
|
||||
.processPlaceholder("price", AuctionAPI.getInstance().formatNumber(item.getCurrentPrice()))
|
||||
.processPlaceholder("buyer_name", Bukkit.getOfflinePlayer(item.getHighestBidder()).getPlayer().getName())
|
||||
.sendPrefixedMessage(Bukkit.getOfflinePlayer(item.getOwner()).getPlayer());
|
||||
AuctionHouse.getInstance().getLocale().getMessage("pricing.moneyadd").processPlaceholder("price", AuctionAPI.getInstance().formatNumber(item.getCurrentPrice())).sendPrefixedMessage(Bukkit.getOfflinePlayer(item.getOwner()).getPlayer());
|
||||
}
|
||||
|
||||
item.setOwner(offlinePlayer.getUniqueId());
|
||||
item.setExpired(true);
|
||||
}
|
||||
} else {
|
||||
// they don't have enough money to buy it, so send it back to the original owner
|
||||
item.setExpired(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
AuctionHouse.getInstance().getAuctionItemManager().getAuctionItems().stream().filter(item -> item.getRemainingTime() <= 0).collect(Collectors.toList()).iterator().forEachRemaining(AuctionAPI.getInstance()::endAuction);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
Loading…
Reference in New Issue
Block a user