mirror of
https://github.com/kiranhart/Auction-House.git
synced 2024-11-29 06:35:28 +01:00
possible fix for buy confirmation
This commit is contained in:
parent
0448a9a316
commit
36fc5feffe
2
pom.xml
2
pom.xml
@ -136,7 +136,7 @@
|
||||
<dependency>
|
||||
<groupId>ca.tweetzy</groupId>
|
||||
<artifactId>tweetycore</artifactId>
|
||||
<version>2.1.2</version>
|
||||
<version>2.2.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.MilkBowl</groupId>
|
||||
|
@ -22,6 +22,7 @@ import ca.tweetzy.core.database.DataMigrationManager;
|
||||
import ca.tweetzy.core.database.DatabaseConnector;
|
||||
import ca.tweetzy.core.database.MySQLConnector;
|
||||
import ca.tweetzy.core.gui.GuiManager;
|
||||
import ca.tweetzy.core.locale.Locale;
|
||||
import ca.tweetzy.core.utils.Metrics;
|
||||
import co.aikar.taskchain.BukkitTaskChainFactory;
|
||||
import co.aikar.taskchain.TaskChain;
|
||||
|
@ -29,14 +29,18 @@ public class AuctionEndEvent extends Event implements Cancellable {
|
||||
private AuctionItem auctionItem;
|
||||
private AuctionSaleType saleType;
|
||||
|
||||
public AuctionEndEvent(OfflinePlayer originalOwner, OfflinePlayer buyer, AuctionItem auctionItem, AuctionSaleType saleType) {
|
||||
super(true);
|
||||
public AuctionEndEvent(OfflinePlayer originalOwner, OfflinePlayer buyer, AuctionItem auctionItem, AuctionSaleType saleType, boolean async) {
|
||||
super(async);
|
||||
this.originalOwner = originalOwner;
|
||||
this.buyer = buyer;
|
||||
this.auctionItem = auctionItem;
|
||||
this.saleType = saleType;
|
||||
}
|
||||
|
||||
public AuctionEndEvent(OfflinePlayer originalOwner, OfflinePlayer buyer, AuctionItem auctionItem, AuctionSaleType saleType) {
|
||||
this(originalOwner, buyer, auctionItem, saleType, true);
|
||||
}
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ public class AuctionItem implements Serializable {
|
||||
lore.addAll(Settings.AUCTION_PURCHASE_CONTROL_HEADER.getStringList().stream().map(TextUtils::formatText).collect(Collectors.toList()));
|
||||
lore.addAll(this.bidStartPrice <= 0 || this.bidIncPrice <= 0 ? Settings.AUCTION_PURCHASE_CONTROLS_BID_OFF.getStringList().stream().map(TextUtils::formatText).collect(Collectors.toList()) : Settings.AUCTION_PURCHASE_CONTROLS_BID_ON.getStringList().stream().map(TextUtils::formatText).collect(Collectors.toList()));
|
||||
|
||||
if ((ServerVersion.isServerVersionAtLeast(ServerVersion.V1_11) && itemStack.getType() == XMaterial.SHULKER_BOX.parseMaterial()) || (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_14) && itemStack.getType() == XMaterial.SHULKER_BOX.parseMaterial() || itemStack.getType() == XMaterial.BARREL.parseMaterial())) {
|
||||
if ((ServerVersion.isServerVersionAtLeast(ServerVersion.V1_11) && itemStack.getType().name().contains("SHULKER_BOX")) || (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_14) && itemStack.getType() == XMaterial.SHULKER_BOX.parseMaterial() || itemStack.getType() == XMaterial.BARREL.parseMaterial())) {
|
||||
lore.addAll(Settings.AUCTION_PURCHASE_CONTROLS_INSPECTION.getStringList().stream().map(TextUtils::formatText).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
|
@ -119,6 +119,7 @@ public class GUIAuctionHouse extends Gui {
|
||||
|
||||
cleanup();
|
||||
e.manager.showGUI(e.player, new GUIConfirmPurchase(this.auctionPlayer, auctionItem, buyingQuantity));
|
||||
AuctionHouse.getInstance().getTransactionManager().addPrePurchase(e.player, auctionItem.getKey());
|
||||
}
|
||||
|
||||
private void handleBidItem(AuctionItem auctionItem, GuiClickEvent e, boolean buyNow) {
|
||||
|
@ -61,6 +61,12 @@ public class GUIConfirmPurchase extends Gui {
|
||||
this.pricePerItem = this.auctionItem.getBasePrice() / this.maxStackSize;
|
||||
}
|
||||
|
||||
setOnClose(close -> {
|
||||
AuctionHouse.getInstance().getTransactionManager().getPrePurchaseHolding().remove(close.player);
|
||||
close.manager.showGUI(close.player, new GUIAuctionHouse(this.auctionPlayer));
|
||||
AuctionHouse.getInstance().getLogger().info("Removed " + close.player.getName() + " from confirmation pre purchase");
|
||||
});
|
||||
|
||||
draw();
|
||||
}
|
||||
|
||||
@ -69,7 +75,7 @@ public class GUIConfirmPurchase extends Gui {
|
||||
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(this.buyingSpecificQuantity ? 14 : 5, this.buyingSpecificQuantity ? 17 : 8, ClickType.LEFT, e -> e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer)));
|
||||
setActionForRange(this.buyingSpecificQuantity ? 14 : 5, this.buyingSpecificQuantity ? 17 : 8, ClickType.LEFT, e -> e.gui.close());
|
||||
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());
|
||||
@ -79,14 +85,12 @@ public class GUIConfirmPurchase extends Gui {
|
||||
if (!AuctionHouse.getInstance().getEconomy().has(e.player, this.buyingSpecificQuantity ? this.purchaseQuantity * this.pricePerItem : 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));
|
||||
e.gui.close();
|
||||
return;
|
||||
}
|
||||
|
||||
Bukkit.getServer().getScheduler().runTaskAsynchronously(AuctionHouse.getInstance(), () -> {
|
||||
AuctionEndEvent auctionEndEvent = new AuctionEndEvent(Bukkit.getOfflinePlayer(this.auctionItem.getOwner()), e.player, this.auctionItem, AuctionSaleType.WITHOUT_BIDDING_SYSTEM);
|
||||
AuctionEndEvent auctionEndEvent = new AuctionEndEvent(Bukkit.getOfflinePlayer(this.auctionItem.getOwner()), e.player, this.auctionItem, AuctionSaleType.WITHOUT_BIDDING_SYSTEM, false);
|
||||
Bukkit.getServer().getPluginManager().callEvent(auctionEndEvent);
|
||||
|
||||
if (auctionEndEvent.isCancelled()) return;
|
||||
|
||||
if (!Settings.ALLOW_PURCHASE_IF_INVENTORY_FULL.getBoolean() && e.player.getInventory().firstEmpty() == -1) {
|
||||
@ -96,7 +100,6 @@ public class GUIConfirmPurchase extends Gui {
|
||||
|
||||
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));
|
||||
|
||||
if (item.getAmount() - this.purchaseQuantity >= 1) {
|
||||
item.setAmount(item.getAmount() - this.purchaseQuantity);
|
||||
@ -108,18 +111,19 @@ public class GUIConfirmPurchase extends Gui {
|
||||
transferFunds(e.player, located.getBasePrice());
|
||||
AuctionHouse.getInstance().getAuctionItemManager().removeItem(located.getKey());
|
||||
}
|
||||
|
||||
givePlayerItem(e.player, item);
|
||||
sendMessages(e, located, true, this.purchaseQuantity * this.pricePerItem);
|
||||
e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer));
|
||||
return;
|
||||
}
|
||||
|
||||
} else {
|
||||
transferFunds(e.player, located.getBasePrice());
|
||||
AuctionHouse.getInstance().getAuctionItemManager().removeItem(located.getKey());
|
||||
givePlayerItem(e.player, AuctionAPI.getInstance().deserializeItem(located.getRawItem()));
|
||||
sendMessages(e, located, false, 0);
|
||||
e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer));
|
||||
}
|
||||
|
||||
AuctionHouse.getInstance().getTransactionManager().getPrePurchasePlayers(auctionItem.getKey()).forEach(player -> {
|
||||
AuctionHouse.getInstance().getTransactionManager().removeAllRelatedPlayers(auctionItem.getKey());
|
||||
player.closeInventory();
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -44,7 +44,7 @@ public class GUITransactionList extends Gui {
|
||||
|
||||
private void draw() {
|
||||
reset();
|
||||
AuctionHouse.newChain().async(() -> {
|
||||
|
||||
pages = (int) Math.max(1, Math.ceil(this.transactions.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 -> e.manager.showGUI(e.player, new GUITransactionList(this.auctionPlayer)));
|
||||
@ -81,6 +81,5 @@ public class GUITransactionList extends Gui {
|
||||
put("%item_name%", AuctionAPI.getInstance().getItemName(AuctionAPI.getInstance().deserializeItem(transaction.getAuctionItem().getRawItem())));
|
||||
}}), e -> e.manager.showGUI(e.player, new GUITransactionView(this.auctionPlayer, transaction)));
|
||||
}
|
||||
}).execute();
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package ca.tweetzy.auctionhouse.helpers;
|
||||
|
||||
import ca.tweetzy.auctionhouse.AuctionHouse;
|
||||
import ca.tweetzy.core.compatibility.ServerVersion;
|
||||
import ca.tweetzy.core.utils.TextUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
|
@ -21,7 +21,6 @@ import java.util.stream.Collectors;
|
||||
* Usage of any code found within this class is prohibited unless given explicit permission otherwise
|
||||
*/
|
||||
|
||||
|
||||
public class AuctionItemManager {
|
||||
|
||||
private final ArrayList<AuctionItem> auctionItems = new ArrayList<>();
|
||||
@ -40,7 +39,7 @@ public class AuctionItemManager {
|
||||
}
|
||||
|
||||
public List<AuctionItem> getAuctionItems() {
|
||||
return Collections.unmodifiableList(auctionItems);
|
||||
return this.auctionItems;
|
||||
}
|
||||
|
||||
public List<AuctionItem> getFilteredItems(AuctionItemCategory category) {
|
||||
|
@ -6,11 +6,9 @@ import ca.tweetzy.auctionhouse.settings.Settings;
|
||||
import ca.tweetzy.auctionhouse.transaction.Transaction;
|
||||
import ca.tweetzy.core.utils.TextUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@ -22,6 +20,7 @@ import java.util.stream.Collectors;
|
||||
public class TransactionManager {
|
||||
|
||||
private final ArrayList<Transaction> transactions = new ArrayList<>();
|
||||
private final HashMap<Player, UUID> prePurchaseHolding = new HashMap<>();
|
||||
|
||||
public void addTransaction(Transaction transaction) {
|
||||
if (transaction == null) return;
|
||||
@ -40,6 +39,22 @@ public class TransactionManager {
|
||||
return Collections.unmodifiableList(this.transactions);
|
||||
}
|
||||
|
||||
public void addPrePurchase(Player player, UUID uuid) {
|
||||
this.prePurchaseHolding.put(player, uuid);
|
||||
}
|
||||
|
||||
public void removeAllRelatedPlayers(UUID uuid) {
|
||||
this.prePurchaseHolding.keySet().removeIf(p -> this.prePurchaseHolding.get(p).equals(uuid));
|
||||
}
|
||||
|
||||
public HashMap<Player, UUID> getPrePurchaseHolding() {
|
||||
return prePurchaseHolding;
|
||||
}
|
||||
|
||||
public List<Player> getPrePurchasePlayers(UUID uuid) {
|
||||
return this.prePurchaseHolding.keySet().stream().filter(p -> this.prePurchaseHolding.get(p).equals(uuid)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public void loadTransactions(boolean useDatabase) {
|
||||
if (useDatabase) {
|
||||
AuctionHouse.getInstance().getDataManager().getTransactions(all -> all.forEach(this::addTransaction));
|
||||
|
Loading…
Reference in New Issue
Block a user