mirror of
https://github.com/kiranhart/Auction-House.git
synced 2025-01-22 15:11:20 +01:00
performance improvements, and feature additions
This commit is contained in:
parent
1c2864e063
commit
18857ef054
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>ca.tweetzy</groupId>
|
||||
<artifactId>auctionhouse</artifactId>
|
||||
<version>2.5.0</version>
|
||||
<version>2.6.0</version>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
@ -39,20 +39,8 @@ public class GUIActiveAuctions extends Gui {
|
||||
draw();
|
||||
|
||||
if (Settings.AUTO_REFRESH_AUCTION_PAGES.getBoolean()) {
|
||||
setOnOpen(e -> {
|
||||
if (Settings.USE_ASYNC_GUI_REFRESH.getBoolean()) {
|
||||
startTaskAsync();
|
||||
} else {
|
||||
startTask();
|
||||
}
|
||||
});
|
||||
setOnClose(e -> {
|
||||
if (Settings.USE_ASYNC_GUI_REFRESH.getBoolean()) {
|
||||
killAsyncTask();
|
||||
} else {
|
||||
killTask();
|
||||
}
|
||||
});
|
||||
setOnOpen(e -> makeMess());
|
||||
setOnClose(e -> cleanup());
|
||||
}
|
||||
}
|
||||
|
||||
@ -71,7 +59,7 @@ public class GUIActiveAuctions extends Gui {
|
||||
|
||||
// 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 -> {
|
||||
killTask();
|
||||
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 -> {
|
||||
@ -104,4 +92,20 @@ public class GUIActiveAuctions extends Gui {
|
||||
private void killAsyncTask() {
|
||||
task.cancel();
|
||||
}
|
||||
|
||||
private void makeMess() {
|
||||
if (Settings.USE_ASYNC_GUI_REFRESH.getBoolean()) {
|
||||
startTaskAsync();
|
||||
} else {
|
||||
startTask();
|
||||
}
|
||||
}
|
||||
|
||||
private void cleanup() {
|
||||
if (Settings.USE_ASYNC_GUI_REFRESH.getBoolean()) {
|
||||
killAsyncTask();
|
||||
} else {
|
||||
killTask();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,6 +30,8 @@ import java.util.stream.Collectors;
|
||||
* Time Created: 6:34 p.m.
|
||||
* Usage of any code found within this class is prohibited unless given explicit permission otherwise
|
||||
*/
|
||||
|
||||
// TODO CLEAN UP THE ENTIRE CLICK SYSTEM, IT'S KINDA MESSY
|
||||
public class GUIAuctionHouse extends Gui {
|
||||
|
||||
final AuctionPlayer auctionPlayer;
|
||||
@ -49,20 +51,8 @@ public class GUIAuctionHouse extends Gui {
|
||||
draw();
|
||||
|
||||
if (Settings.AUTO_REFRESH_AUCTION_PAGES.getBoolean()) {
|
||||
setOnOpen(e -> {
|
||||
if (Settings.USE_ASYNC_GUI_REFRESH.getBoolean()) {
|
||||
startTaskAsync();
|
||||
} else {
|
||||
startTask();
|
||||
}
|
||||
});
|
||||
setOnClose(e -> {
|
||||
if (Settings.USE_ASYNC_GUI_REFRESH.getBoolean()) {
|
||||
killAsyncTask();
|
||||
} else {
|
||||
killTask();
|
||||
}
|
||||
});
|
||||
setOnOpen(e -> makeMess());
|
||||
setOnClose(e -> cleanup());
|
||||
}
|
||||
}
|
||||
|
||||
@ -91,7 +81,15 @@ public class GUIAuctionHouse extends Gui {
|
||||
pages = (int) Math.max(1, Math.ceil(this.items.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 -> {
|
||||
killTask();
|
||||
if (Settings.USE_REFRESH_COOL_DOWN.getBoolean()) {
|
||||
if (AuctionHouse.getInstance().getAuctionPlayerManager().getCooldowns().containsKey(this.auctionPlayer.getPlayer().getUniqueId())) {
|
||||
if (AuctionHouse.getInstance().getAuctionPlayerManager().getCooldowns().get(this.auctionPlayer.getPlayer().getUniqueId()) > System.currentTimeMillis()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
AuctionHouse.getInstance().getAuctionPlayerManager().addCooldown(this.auctionPlayer.getPlayer().getUniqueId());
|
||||
}
|
||||
cleanup();
|
||||
e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer));
|
||||
});
|
||||
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());
|
||||
@ -104,14 +102,14 @@ public class GUIAuctionHouse extends Gui {
|
||||
setButton(5, 0, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_AUCTION_HOUSE_ITEMS_YOUR_AUCTIONS_ITEM.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_YOUR_AUCTIONS_NAME.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_YOUR_AUCTIONS_LORE.getStringList(), new HashMap<String, Object>() {{
|
||||
put("%active_player_auctions%", auctionPlayer.getItems(false).size());
|
||||
}}), e -> {
|
||||
killTask();
|
||||
cleanup();
|
||||
e.manager.showGUI(e.player, new GUIActiveAuctions(this.auctionPlayer));
|
||||
});
|
||||
|
||||
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());
|
||||
}}), e -> {
|
||||
killTask();
|
||||
cleanup();
|
||||
e.manager.showGUI(e.player, new GUIExpiredItems(this.auctionPlayer));
|
||||
});
|
||||
|
||||
@ -123,7 +121,7 @@ public class GUIAuctionHouse extends Gui {
|
||||
case LEFT:
|
||||
this.filterCategory = this.filterCategory.next();
|
||||
if (Settings.REFRESH_GUI_ON_FILTER_CHANGE.getBoolean()) {
|
||||
killTask();
|
||||
cleanup();
|
||||
e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer, this.filterCategory, this.filterAuctionType));
|
||||
} else {
|
||||
draw();
|
||||
@ -132,7 +130,7 @@ public class GUIAuctionHouse extends Gui {
|
||||
case RIGHT:
|
||||
this.filterAuctionType = this.filterAuctionType.next();
|
||||
if (Settings.REFRESH_GUI_ON_FILTER_CHANGE.getBoolean()) {
|
||||
killTask();
|
||||
cleanup();
|
||||
e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer, this.filterCategory, this.filterAuctionType));
|
||||
} else {
|
||||
draw();
|
||||
@ -146,8 +144,17 @@ public class GUIAuctionHouse extends Gui {
|
||||
setButton(5, 8, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_AUCTION_HOUSE_ITEMS_GUIDE_ITEM.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_GUIDE_NAME.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_GUIDE_LORE.getStringList(), null), null);
|
||||
|
||||
// Items
|
||||
int slot = 0;
|
||||
List<AuctionItem> data = this.items.stream().sorted(Comparator.comparingInt(AuctionItem::getRemainingTime).reversed()).skip((page - 1) * 45L).limit(45).collect(Collectors.toList());
|
||||
if (Settings.FILL_ITEMS_USING_ASYNC.getBoolean()) {
|
||||
Bukkit.getServer().getScheduler().runTaskAsynchronously(AuctionHouse.getInstance(), () -> placeItems(data));
|
||||
return;
|
||||
}
|
||||
|
||||
placeItems(data);
|
||||
}
|
||||
|
||||
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) {
|
||||
@ -158,8 +165,8 @@ public class GUIAuctionHouse extends Gui {
|
||||
return;
|
||||
}
|
||||
|
||||
killTask();
|
||||
e.manager.showGUI(e.player, new GUIConfirmPurchase(this.auctionPlayer, auctionItem));
|
||||
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);
|
||||
@ -179,7 +186,7 @@ public class GUIAuctionHouse extends Gui {
|
||||
}
|
||||
|
||||
if (Settings.REFRESH_GUI_WHEN_BID.getBoolean()) {
|
||||
killTask();
|
||||
cleanup();
|
||||
e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer));
|
||||
}
|
||||
}
|
||||
@ -191,7 +198,8 @@ public class GUIAuctionHouse extends Gui {
|
||||
} else {
|
||||
AuctionHouse.getInstance().getAuctionItemManager().removeItem(auctionItem.getKey());
|
||||
}
|
||||
killTask();
|
||||
|
||||
cleanup();
|
||||
e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer));
|
||||
}
|
||||
break;
|
||||
@ -203,21 +211,27 @@ public class GUIAuctionHouse extends Gui {
|
||||
|
||||
BlockStateMeta meta = (BlockStateMeta) clicked.getItemMeta();
|
||||
if (!(meta.getBlockState() instanceof ShulkerBox)) return;
|
||||
|
||||
killTask();
|
||||
cleanup();
|
||||
e.manager.showGUI(e.player, new GUIShulkerInspect(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 (e.player.getUniqueId().equals(auctionItem.getOwner()) && !Settings.OWNER_CAN_PURCHASE_OWN_ITEM.getBoolean()) {
|
||||
AuctionHouse.getInstance().getLocale().getMessage("general.cantbuyown").sendPrefixedMessage(e.player);
|
||||
return;
|
||||
}
|
||||
killTask();
|
||||
e.manager.showGUI(e.player, new GUIConfirmPurchase(this.auctionPlayer, auctionItem));
|
||||
cleanup();
|
||||
e.manager.showGUI(e.player, new GUIConfirmPurchase(this.auctionPlayer, auctionItem, false));
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -240,4 +254,20 @@ public class GUIAuctionHouse extends Gui {
|
||||
private void killAsyncTask() {
|
||||
task.cancel();
|
||||
}
|
||||
|
||||
private void makeMess() {
|
||||
if (Settings.USE_ASYNC_GUI_REFRESH.getBoolean()) {
|
||||
startTaskAsync();
|
||||
} else {
|
||||
startTask();
|
||||
}
|
||||
}
|
||||
|
||||
private void cleanup() {
|
||||
if (Settings.USE_ASYNC_GUI_REFRESH.getBoolean()) {
|
||||
killAsyncTask();
|
||||
} else {
|
||||
killTask();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,16 +6,21 @@ import ca.tweetzy.auctionhouse.api.events.AuctionEndEvent;
|
||||
import ca.tweetzy.auctionhouse.auction.AuctionItem;
|
||||
import ca.tweetzy.auctionhouse.auction.AuctionPlayer;
|
||||
import ca.tweetzy.auctionhouse.auction.AuctionSaleType;
|
||||
import ca.tweetzy.auctionhouse.helpers.ConfigurationItemHelper;
|
||||
import ca.tweetzy.auctionhouse.managers.SoundManager;
|
||||
import ca.tweetzy.auctionhouse.settings.Settings;
|
||||
import ca.tweetzy.core.gui.Gui;
|
||||
import ca.tweetzy.core.gui.events.GuiClickEvent;
|
||||
import ca.tweetzy.core.utils.PlayerUtils;
|
||||
import ca.tweetzy.core.utils.TextUtils;
|
||||
import ca.tweetzy.core.utils.items.TItemBuilder;
|
||||
import org.apache.commons.lang.WordUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
@ -29,60 +34,143 @@ public class GUIConfirmPurchase extends Gui {
|
||||
final AuctionPlayer auctionPlayer;
|
||||
final AuctionItem auctionItem;
|
||||
|
||||
public GUIConfirmPurchase(AuctionPlayer auctionPlayer, AuctionItem auctionItem) {
|
||||
boolean buyingSpecificQuantity;
|
||||
int purchaseQuantity = 0;
|
||||
int maxStackSize = 0;
|
||||
double pricePerItem = 0D;
|
||||
|
||||
public GUIConfirmPurchase(AuctionPlayer auctionPlayer, AuctionItem auctionItem, boolean buyingSpecificQuantity) {
|
||||
this.auctionPlayer = auctionPlayer;
|
||||
this.auctionItem = auctionItem;
|
||||
this.buyingSpecificQuantity = buyingSpecificQuantity;
|
||||
setTitle(TextUtils.formatText(Settings.GUI_CONFIRM_BUY_TITLE.getString()));
|
||||
setRows(1);
|
||||
setAcceptsItems(false);
|
||||
|
||||
int preAmount = AuctionAPI.getInstance().deserializeItem(auctionItem.getRawItem()).getAmount();
|
||||
if (preAmount == 1) {
|
||||
this.buyingSpecificQuantity = false;
|
||||
}
|
||||
|
||||
setRows(!this.buyingSpecificQuantity ? 1 : 5);
|
||||
|
||||
if (this.buyingSpecificQuantity) {
|
||||
setUseLockedCells(Settings.GUI_CONFIRM_FILL_BG_ON_QUANTITY.getBoolean());
|
||||
setDefaultItem(Settings.GUI_CONFIRM_BG_ITEM.getMaterial().parseItem());
|
||||
this.purchaseQuantity = preAmount;
|
||||
this.maxStackSize = preAmount;
|
||||
this.pricePerItem = this.auctionItem.getBasePrice() / this.maxStackSize;
|
||||
}
|
||||
|
||||
draw();
|
||||
}
|
||||
|
||||
private void draw() {
|
||||
setItems(0, 3, new TItemBuilder(Objects.requireNonNull(Settings.GUI_CONFIRM_BUY_YES_ITEM.getMaterial().parseMaterial())).setName(Settings.GUI_CONFIRM_BUY_YES_NAME.getString()).setLore(Settings.GUI_CONFIRM_BUY_YES_LORE.getStringList()).toItemStack());
|
||||
setItem(0, 4, AuctionAPI.getInstance().deserializeItem(this.auctionItem.getRawItem()));
|
||||
setItems(5, 8, new TItemBuilder(Objects.requireNonNull(Settings.GUI_CONFIRM_BUY_NO_ITEM.getMaterial().parseMaterial())).setName(Settings.GUI_CONFIRM_BUY_NO_NAME.getString()).setLore(Settings.GUI_CONFIRM_BUY_NO_LORE.getStringList()).toItemStack());
|
||||
setItems(this.buyingSpecificQuantity ? 9 : 0, this.buyingSpecificQuantity ? 12 : 3, new TItemBuilder(Objects.requireNonNull(Settings.GUI_CONFIRM_BUY_YES_ITEM.getMaterial().parseMaterial())).setName(Settings.GUI_CONFIRM_BUY_YES_NAME.getString()).setLore(Settings.GUI_CONFIRM_BUY_YES_LORE.getStringList()).toItemStack());
|
||||
setItem(this.buyingSpecificQuantity ? 1 : 0, 4, AuctionAPI.getInstance().deserializeItem(this.auctionItem.getRawItem()));
|
||||
setItems(this.buyingSpecificQuantity ? 14 : 5, this.buyingSpecificQuantity ? 17 : 8, new TItemBuilder(Objects.requireNonNull(Settings.GUI_CONFIRM_BUY_NO_ITEM.getMaterial().parseMaterial())).setName(Settings.GUI_CONFIRM_BUY_NO_NAME.getString()).setLore(Settings.GUI_CONFIRM_BUY_NO_LORE.getStringList()).toItemStack());
|
||||
|
||||
setActionForRange(5, 8, ClickType.LEFT, e -> e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer)));
|
||||
setActionForRange(0, 3, ClickType.LEFT, e -> {
|
||||
setActionForRange(this.buyingSpecificQuantity ? 14 : 5, this.buyingSpecificQuantity ? 17 : 8, ClickType.LEFT, e -> e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer)));
|
||||
setActionForRange(this.buyingSpecificQuantity ? 9 : 0, this.buyingSpecificQuantity ? 12 : 3, ClickType.LEFT, e -> {
|
||||
// Re-select the item to ensure that it's available
|
||||
AuctionItem located = AuctionHouse.getInstance().getAuctionItemManager().getItem(this.auctionItem.getKey());
|
||||
preItemChecks(e, located);
|
||||
|
||||
if (located == null || located.isExpired()) {
|
||||
AuctionHouse.getInstance().getLocale().getMessage("auction.itemnotavailable").sendPrefixedMessage(e.player);
|
||||
e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!AuctionHouse.getInstance().getEconomy().has(e.player, located.getBasePrice())) {
|
||||
AuctionHouse.getInstance().getLocale().getMessage("general.notenoughmoney").sendPrefixedMessage(e.player);
|
||||
SoundManager.getInstance().playSound(e.player, Settings.SOUNDS_NOT_ENOUGH_MONEY.getString(), 1.0F, 1.0F);
|
||||
e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer));
|
||||
return;
|
||||
}
|
||||
|
||||
Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(AuctionHouse.getInstance(), () -> {
|
||||
Bukkit.getServer().getScheduler().runTaskAsynchronously(AuctionHouse.getInstance(), () -> {
|
||||
AuctionEndEvent auctionEndEvent = new AuctionEndEvent(Bukkit.getOfflinePlayer(this.auctionItem.getOwner()), e.player, this.auctionItem, AuctionSaleType.WITHOUT_BIDDING_SYSTEM);
|
||||
Bukkit.getServer().getPluginManager().callEvent(auctionEndEvent);
|
||||
|
||||
if (auctionEndEvent.isCancelled()) return;
|
||||
|
||||
AuctionHouse.getInstance().getEconomy().withdrawPlayer(e.player, located.getBasePrice());
|
||||
AuctionHouse.getInstance().getEconomy().depositPlayer(Bukkit.getOfflinePlayer(this.auctionItem.getOwner()), located.getBasePrice());
|
||||
AuctionHouse.getInstance().getAuctionItemManager().removeItem(located.getKey());
|
||||
PlayerUtils.giveItem(e.player, AuctionAPI.getInstance().deserializeItem(located.getRawItem()));
|
||||
if (this.buyingSpecificQuantity) {
|
||||
ItemStack item = AuctionAPI.getInstance().deserializeItem(located.getRawItem());
|
||||
// Bukkit.broadcastMessage(String.format("Total Item Qty: %d\nTotal Purchase Qty: %d\nAmount of purchase: %d", item.getAmount(), this.purchaseQuantity, item.getAmount() - this.purchaseQuantity));
|
||||
|
||||
AuctionHouse.getInstance().getLocale().getMessage("pricing.moneyremove").processPlaceholder("price", String.format("%,.2f", located.getBasePrice())).sendPrefixedMessage(e.player);
|
||||
if (item.getAmount() - this.purchaseQuantity >= 1) {
|
||||
item.setAmount(item.getAmount() - this.purchaseQuantity);
|
||||
located.setRawItem(AuctionAPI.getInstance().serializeItem(item));
|
||||
located.setBasePrice(located.getBasePrice() - this.purchaseQuantity * this.pricePerItem);
|
||||
item.setAmount(this.purchaseQuantity);
|
||||
transferFunds(e.player, this.purchaseQuantity * this.pricePerItem);
|
||||
} else {
|
||||
transferFunds(e.player, located.getBasePrice());
|
||||
AuctionHouse.getInstance().getAuctionItemManager().removeItem(located.getKey());
|
||||
}
|
||||
|
||||
if (Bukkit.getOfflinePlayer(located.getOwner()).isOnline()) {
|
||||
AuctionHouse.getInstance().getLocale().getMessage("auction.itemsold")
|
||||
.processPlaceholder("item", WordUtils.capitalizeFully(AuctionAPI.getInstance().deserializeItem(located.getRawItem()).getType().name().replace("_", " ")))
|
||||
.processPlaceholder("price", String.format("%,.2f", located.getBasePrice()))
|
||||
.sendPrefixedMessage(Bukkit.getOfflinePlayer(located.getOwner()).getPlayer());
|
||||
AuctionHouse.getInstance().getLocale().getMessage("pricing.moneyadd").processPlaceholder("price", String.format("%,.2f", located.getBasePrice())).sendPrefixedMessage(Bukkit.getOfflinePlayer(located.getOwner()).getPlayer());
|
||||
PlayerUtils.giveItem(e.player, item);
|
||||
sendMessages(e, located, true, this.purchaseQuantity * this.pricePerItem);
|
||||
e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer));
|
||||
return;
|
||||
}
|
||||
|
||||
transferFunds(e.player, located.getBasePrice());
|
||||
AuctionHouse.getInstance().getAuctionItemManager().removeItem(located.getKey());
|
||||
PlayerUtils.giveItem(e.player, AuctionAPI.getInstance().deserializeItem(located.getRawItem()));
|
||||
sendMessages(e, located, false, 0);
|
||||
e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer));
|
||||
}, 1L);
|
||||
});
|
||||
});
|
||||
|
||||
drawPurchaseInfo(this.maxStackSize);
|
||||
|
||||
// Decrease Button
|
||||
setButton(3, 3, new TItemBuilder(Settings.GUI_CONFIRM_DECREASE_QTY_ITEM.getMaterial().parseMaterial()).setName(Settings.GUI_CONFIRM_DECREASE_QTY_NAME.getString()).setLore(Settings.GUI_CONFIRM_DECREASE_QTY_LORE.getStringList()).toItemStack(), e -> {
|
||||
if ((this.purchaseQuantity - 1) <= 0) return;
|
||||
this.purchaseQuantity -= 1;
|
||||
drawPurchaseInfo(this.purchaseQuantity);
|
||||
});
|
||||
|
||||
// Increase Button
|
||||
setButton(3, 5, new TItemBuilder(Settings.GUI_CONFIRM_INCREASE_QTY_ITEM.getMaterial().parseMaterial()).setName(Settings.GUI_CONFIRM_INCREASE_QTY_NAME.getString()).setLore(Settings.GUI_CONFIRM_INCREASE_QTY_LORE.getStringList()).toItemStack(), e -> {
|
||||
if ((this.purchaseQuantity + 1) > this.maxStackSize) return;
|
||||
this.purchaseQuantity += 1;
|
||||
drawPurchaseInfo(this.purchaseQuantity);
|
||||
});
|
||||
}
|
||||
|
||||
private void transferFunds(Player from, double amount) {
|
||||
AuctionHouse.getInstance().getEconomy().withdrawPlayer(from, amount);
|
||||
AuctionHouse.getInstance().getEconomy().depositPlayer(Bukkit.getOfflinePlayer(this.auctionItem.getOwner()), amount);
|
||||
}
|
||||
|
||||
private void sendMessages(GuiClickEvent e, AuctionItem located, boolean overwritePrice, double price) {
|
||||
AuctionHouse.getInstance().getLocale().getMessage("pricing.moneyremove").processPlaceholder("price", String.format("%,.2f", overwritePrice ? price : located.getBasePrice())).sendPrefixedMessage(e.player);
|
||||
if (Bukkit.getOfflinePlayer(located.getOwner()).isOnline()) {
|
||||
AuctionHouse.getInstance().getLocale().getMessage("auction.itemsold")
|
||||
.processPlaceholder("item", WordUtils.capitalizeFully(AuctionAPI.getInstance().deserializeItem(located.getRawItem()).getType().name().replace("_", " ")))
|
||||
.processPlaceholder("price", String.format("%,.2f", overwritePrice ? price : located.getBasePrice()))
|
||||
.sendPrefixedMessage(Bukkit.getOfflinePlayer(located.getOwner()).getPlayer());
|
||||
AuctionHouse.getInstance().getLocale().getMessage("pricing.moneyadd").processPlaceholder("price", String.format("%,.2f", overwritePrice ? price : located.getBasePrice())).sendPrefixedMessage(Bukkit.getOfflinePlayer(located.getOwner()).getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
private void drawPurchaseInfo(int amt) {
|
||||
setItem(3, 4, getPurchaseInfoItem(amt));
|
||||
}
|
||||
|
||||
private void preItemChecks(GuiClickEvent e, AuctionItem located) {
|
||||
if (located == null || located.isExpired()) {
|
||||
AuctionHouse.getInstance().getLocale().getMessage("auction.itemnotavailable").sendPrefixedMessage(e.player);
|
||||
e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!AuctionHouse.getInstance().getEconomy().has(e.player, located.getBasePrice())) {
|
||||
AuctionHouse.getInstance().getLocale().getMessage("general.notenoughmoney").sendPrefixedMessage(e.player);
|
||||
SoundManager.getInstance().playSound(e.player, Settings.SOUNDS_NOT_ENOUGH_MONEY.getString(), 1.0F, 1.0F);
|
||||
e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private ItemStack getPurchaseInfoItem(int qty) {
|
||||
ItemStack stack = ConfigurationItemHelper.createConfigurationItem(Settings.GUI_CONFIRM_QTY_INFO_ITEM.getString(), Settings.GUI_CONFIRM_QTY_INFO_NAME.getString(), Settings.GUI_CONFIRM_QTY_INFO_LORE.getStringList(), new HashMap<String, Object>() {{
|
||||
put("%original_stack_size%", maxStackSize);
|
||||
put("%original_stack_price%", String.format("%,.2f", auctionItem.getBasePrice()));
|
||||
put("%price_per_item%", String.format("%,.2f", pricePerItem));
|
||||
put("%purchase_quantity%", purchaseQuantity);
|
||||
put("%purchase_price%", String.format("%,.2f", pricePerItem * purchaseQuantity));
|
||||
}});
|
||||
stack.setAmount(qty);
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
|
@ -34,5 +34,6 @@ public class PlayerListeners implements Listener {
|
||||
public void onPlayerQuit(PlayerQuitEvent e) {
|
||||
Player player = e.getPlayer();
|
||||
AuctionHouse.getInstance().getAuctionPlayerManager().removePlayer(player.getUniqueId());
|
||||
AuctionHouse.getInstance().getAuctionPlayerManager().getCooldowns().remove(player.getUniqueId());
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,10 @@
|
||||
package ca.tweetzy.auctionhouse.managers;
|
||||
|
||||
import ca.tweetzy.auctionhouse.auction.AuctionPlayer;
|
||||
import ca.tweetzy.auctionhouse.settings.Settings;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* The current file has been created by Kiran Hart
|
||||
@ -19,6 +17,7 @@ import java.util.UUID;
|
||||
public class AuctionPlayerManager {
|
||||
|
||||
private final ArrayList<AuctionPlayer> auctionPlayers = new ArrayList<>();
|
||||
private final HashMap<UUID, Long> cooldowns = new HashMap<>();
|
||||
|
||||
public void addPlayer(AuctionPlayer auctionPlayer) {
|
||||
if (auctionPlayer == null) return;
|
||||
@ -38,4 +37,11 @@ public class AuctionPlayerManager {
|
||||
return Collections.unmodifiableList(auctionPlayers);
|
||||
}
|
||||
|
||||
public void addCooldown(UUID uuid) {
|
||||
this.cooldowns.put(uuid, System.currentTimeMillis() + (long) 1000 * Settings.REFRESH_COOL_DOWN.getInt());
|
||||
}
|
||||
|
||||
public HashMap<UUID, Long> getCooldowns() {
|
||||
return this.cooldowns;
|
||||
}
|
||||
}
|
||||
|
@ -49,6 +49,10 @@ public class Settings {
|
||||
public static final ConfigSetting ALLOW_USAGE_OF_BUY_NOW_SYSTEM = new ConfigSetting(config, "auction setting.allow buy now system usage", true, "Should players be allowed to use the right-click buy now feature on biddable items?");
|
||||
public static final ConfigSetting AUTO_SAVE_ENABLED = new ConfigSetting(config, "auction setting.auto save.enabled", true, "Should the auto save task be enabled?");
|
||||
public static final ConfigSetting AUTO_SAVE_EVERY = new ConfigSetting(config, "auction setting.auto save.time", 900, "How often should the auto save active? (in seconds. Ex. 900 = 15min)");
|
||||
public static final ConfigSetting FILL_ITEMS_USING_ASYNC = new ConfigSetting(config, "auction setting.fill auction items using async", true, "Should auction items be loaded into the gui asynchronously");
|
||||
public static final ConfigSetting ALLOW_PURCHASE_OF_SPECIFIC_QUANTITIES = new ConfigSetting(config, "auction setting.allow purchase of specific quantities", false, "When a buy now item is right-clicked should it open a", "special gui to specify the quantity of items to buy from the stack?");
|
||||
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?");
|
||||
|
||||
/* ===============================
|
||||
* DATABASE OPTIONS
|
||||
@ -207,6 +211,27 @@ public class Settings {
|
||||
* CONFIRM BUY GUI
|
||||
* ===============================*/
|
||||
public static final ConfigSetting GUI_CONFIRM_BUY_TITLE = new ConfigSetting(config, "gui.confirm buy.title", "&7Are you sure?");
|
||||
public static final ConfigSetting GUI_CONFIRM_FILL_BG_ON_QUANTITY = new ConfigSetting(config, "gui.confirm buy.fill background when buying quantity", true, "Should the empty slots be filled with an item", "when the player decides to buy a specific quantity of items?");
|
||||
public static final ConfigSetting GUI_CONFIRM_BG_ITEM = new ConfigSetting(config, "gui.confirm buy.bg item", XMaterial.BLACK_STAINED_GLASS_PANE.name(), "This will only show when buying specific item quantities");
|
||||
|
||||
public static final ConfigSetting GUI_CONFIRM_INCREASE_QTY_ITEM = new ConfigSetting(config, "gui.confirm buy.increase button.item", XMaterial.LIME_STAINED_GLASS_PANE.name());
|
||||
public static final ConfigSetting GUI_CONFIRM_INCREASE_QTY_NAME = new ConfigSetting(config, "gui.confirm buy.increase button.name", "&a&l+1");
|
||||
public static final ConfigSetting GUI_CONFIRM_INCREASE_QTY_LORE = new ConfigSetting(config, "gui.confirm buy.increase button.lore", Collections.singletonList("&7Click to add &a+1 &7to purchase quantity"));
|
||||
|
||||
public static final ConfigSetting GUI_CONFIRM_DECREASE_QTY_ITEM = new ConfigSetting(config, "gui.confirm buy.decrease button.item", XMaterial.RED_STAINED_GLASS_PANE.name());
|
||||
public static final ConfigSetting GUI_CONFIRM_DECREASE_QTY_NAME = new ConfigSetting(config, "gui.confirm buy.decrease button.name", "&c&l-1");
|
||||
public static final ConfigSetting GUI_CONFIRM_DECREASE_QTY_LORE = new ConfigSetting(config, "gui.confirm buy.decrease button.lore", Collections.singletonList("&7Click to remove &c-1 &7from the purchase quantity"));
|
||||
|
||||
public static final ConfigSetting GUI_CONFIRM_QTY_INFO_ITEM = new ConfigSetting(config, "gui.confirm buy.qty info.item", XMaterial.PAPER.name());
|
||||
public static final ConfigSetting GUI_CONFIRM_QTY_INFO_NAME = new ConfigSetting(config, "gui.confirm buy.qty info.name", "&ePurchase Information");
|
||||
public static final ConfigSetting GUI_CONFIRM_QTY_INFO_LORE = new ConfigSetting(config, "gui.confirm buy.qty info.lore", Arrays.asList(
|
||||
"&7Original Stack Size&f: &e%original_stack_size%",
|
||||
"&7Price for entire stack&f: &a$%original_stack_price%",
|
||||
"&7Price per item&f: &a$%price_per_item%",
|
||||
"",
|
||||
"&7Purchase Qty&f: &e%purchase_quantity%",
|
||||
"&7Total&f: &a$%purchase_price%"
|
||||
), "Valid Placeholders", "%original_stack_size%", "%original_stack_price%", "%price_per_item%", "%purchase_quantity%", "%purchase_price%");
|
||||
|
||||
public static final ConfigSetting GUI_CONFIRM_BUY_NO_ITEM = new ConfigSetting(config, "gui.confirm buy.no.item", "RED_STAINED_GLASS_PANE");
|
||||
public static final ConfigSetting GUI_CONFIRM_BUY_NO_NAME = new ConfigSetting(config, "gui.confirm buy.no.name", "&c&LCancel");
|
||||
|
Loading…
Reference in New Issue
Block a user