mirror of
https://github.com/kiranhart/Auction-House.git
synced 2024-11-29 06:35:28 +01:00
use title prompts
Took 8 minutes
This commit is contained in:
parent
a57348c1bf
commit
9af0b48e0c
@ -38,12 +38,12 @@ import ca.tweetzy.auctionhouse.guis.sell.GUISellPlaceItem;
|
||||
import ca.tweetzy.auctionhouse.guis.transaction.GUITransactionList;
|
||||
import ca.tweetzy.auctionhouse.guis.transaction.GUITransactionType;
|
||||
import ca.tweetzy.auctionhouse.helpers.ConfigurationItemHelper;
|
||||
import ca.tweetzy.auctionhouse.helpers.input.TitleInput;
|
||||
import ca.tweetzy.auctionhouse.managers.SoundManager;
|
||||
import ca.tweetzy.auctionhouse.settings.Settings;
|
||||
import ca.tweetzy.core.compatibility.ServerVersion;
|
||||
import ca.tweetzy.core.gui.events.GuiClickEvent;
|
||||
import ca.tweetzy.core.hooks.EconomyManager;
|
||||
import ca.tweetzy.core.input.PlayerChatInput;
|
||||
import ca.tweetzy.core.utils.NumberUtils;
|
||||
import ca.tweetzy.core.utils.TextUtils;
|
||||
import ca.tweetzy.core.utils.items.TItemBuilder;
|
||||
@ -52,6 +52,7 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.block.ShulkerBox;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.BlockStateMeta;
|
||||
@ -256,17 +257,28 @@ public class GUIAuctionHouse extends AbstractPlaceholderGui {
|
||||
|
||||
if (Settings.FORCE_CUSTOM_BID_AMOUNT.getBoolean()) {
|
||||
e.gui.exit();
|
||||
PlayerChatInput.PlayerChatInputBuilder<Double> builder = new PlayerChatInput.PlayerChatInputBuilder<>(AuctionHouse.getInstance(), e.player);
|
||||
builder.isValidInput((p, str) -> NumberUtils.isDouble(ChatColor.stripColor(str)) && Double.parseDouble(ChatColor.stripColor(str)) >= auctionItem.getBidIncrementPrice());
|
||||
builder.sendValueMessage(TextUtils.formatText(AuctionHouse.getInstance().getLocale().getMessage("prompts.enter bid amount").processPlaceholder("current_bid", AuctionAPI.getInstance().formatNumber(auctionItem.getCurrentPrice())).getMessage()));
|
||||
builder.invalidInputMessage(TextUtils.formatText(AuctionHouse.getInstance().getLocale().getMessage("prompts.enter valid bid amount").getMessage()));
|
||||
builder.toCancel("cancel");
|
||||
builder.onCancel(p -> e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer)));
|
||||
builder.setValue((p, value) -> Double.parseDouble(ChatColor.stripColor(value)));
|
||||
builder.onFinish((p, value) -> {
|
||||
|
||||
new TitleInput(player, AuctionHouse.getInstance().getLocale().getMessage("titles.enter bid.title").getMessage(), AuctionHouse.getInstance().getLocale().getMessage("titles.enter bid.subtitle").getMessage()) {
|
||||
|
||||
@Override
|
||||
public void onExit(Player player) {
|
||||
AuctionHouse.getInstance().getGuiManager().showGUI(player, new GUIAuctionHouse(GUIAuctionHouse.this.auctionPlayer));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onResult(String string) {
|
||||
string = ChatColor.stripColor(string);
|
||||
|
||||
if (!NumberUtils.isDouble(string)) {
|
||||
AuctionHouse.getInstance().getLocale().getMessage("general.notanumber").sendPrefixedMessage(player);
|
||||
return false;
|
||||
}
|
||||
|
||||
double value = Double.parseDouble(string);
|
||||
|
||||
if (value > Settings.MAX_AUCTION_INCREMENT_PRICE.getDouble()) {
|
||||
AuctionHouse.getInstance().getLocale().getMessage("pricing.maxbidincrementprice").processPlaceholder("price", Settings.MAX_AUCTION_INCREMENT_PRICE.getDouble()).sendPrefixedMessage(e.player);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
double newBiddingAmount = 0;
|
||||
@ -275,9 +287,9 @@ public class GUIAuctionHouse extends AbstractPlaceholderGui {
|
||||
newBiddingAmount = value;
|
||||
} else {
|
||||
if (Settings.BID_MUST_BE_HIGHER_THAN_PREVIOUS.getBoolean()) {
|
||||
e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer));
|
||||
e.manager.showGUI(e.player, new GUIAuctionHouse(GUIAuctionHouse.this.auctionPlayer));
|
||||
AuctionHouse.getInstance().getLocale().getMessage("pricing.bidmusthigherthanprevious").processPlaceholder("current_bid", AuctionAPI.getInstance().formatNumber(auctionItem.getCurrentPrice())).sendPrefixedMessage(e.player);
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
newBiddingAmount = auctionItem.getCurrentPrice() + value;
|
||||
@ -290,12 +302,12 @@ public class GUIAuctionHouse extends AbstractPlaceholderGui {
|
||||
|
||||
if (Settings.PLAYER_NEEDS_TOTAL_PRICE_TO_BID.getBoolean() && !EconomyManager.hasBalance(e.player, newBiddingAmount)) {
|
||||
AuctionHouse.getInstance().getLocale().getMessage("general.notenoughmoney").sendPrefixedMessage(e.player);
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Settings.ASK_FOR_BID_CONFIRMATION.getBoolean()) {
|
||||
e.manager.showGUI(e.player, new GUIConfirmBid(this.auctionPlayer, auctionItem, newBiddingAmount));
|
||||
return;
|
||||
e.manager.showGUI(e.player, new GUIConfirmBid(GUIAuctionHouse.this.auctionPlayer, auctionItem, newBiddingAmount));
|
||||
return true;
|
||||
}
|
||||
|
||||
ItemStack itemStack = auctionItem.getItem();
|
||||
@ -305,19 +317,18 @@ public class GUIAuctionHouse extends AbstractPlaceholderGui {
|
||||
|
||||
AuctionBidEvent auctionBidEvent = new AuctionBidEvent(e.player, auctionItem, newBiddingAmount);
|
||||
Bukkit.getServer().getPluginManager().callEvent(auctionBidEvent);
|
||||
if (auctionBidEvent.isCancelled()) return;
|
||||
if (auctionBidEvent.isCancelled()) return true;
|
||||
|
||||
// TODO implement bid tracking/money return on outbid
|
||||
if (Settings.BIDDING_TAKES_MONEY.getBoolean()) {
|
||||
final double oldBidAmount = auctionItem.getCurrentPrice();
|
||||
|
||||
if (!EconomyManager.hasBalance(e.player, newBiddingAmount)) {
|
||||
AuctionHouse.getInstance().getLocale().getMessage("general.notenoughmoney").sendPrefixedMessage(e.player);
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (e.player.getUniqueId().equals(owner.getUniqueId()) || oldBidder.getUniqueId().equals(e.player.getUniqueId())) {
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!auctionItem.getHighestBidder().equals(auctionItem.getOwner())) {
|
||||
@ -369,12 +380,11 @@ public class GUIAuctionHouse extends AbstractPlaceholderGui {
|
||||
.sendPrefixedMessage(player));
|
||||
}
|
||||
|
||||
e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer));
|
||||
});
|
||||
e.manager.showGUI(e.player, new GUIAuctionHouse(GUIAuctionHouse.this.auctionPlayer));
|
||||
|
||||
PlayerChatInput<Double> input = builder.build();
|
||||
input.start();
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
e.manager.showGUI(e.player, new GUIBid(this.auctionPlayer, auctionItem));
|
||||
|
@ -25,14 +25,15 @@ import ca.tweetzy.auctionhouse.auction.AuctionPlayer;
|
||||
import ca.tweetzy.auctionhouse.auction.AuctionedItem;
|
||||
import ca.tweetzy.auctionhouse.guis.confirmation.GUIConfirmBid;
|
||||
import ca.tweetzy.auctionhouse.helpers.ConfigurationItemHelper;
|
||||
import ca.tweetzy.auctionhouse.helpers.input.TitleInput;
|
||||
import ca.tweetzy.auctionhouse.settings.Settings;
|
||||
import ca.tweetzy.core.hooks.EconomyManager;
|
||||
import ca.tweetzy.core.input.PlayerChatInput;
|
||||
import ca.tweetzy.core.utils.NumberUtils;
|
||||
import ca.tweetzy.core.utils.TextUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
@ -73,47 +74,60 @@ public class GUIBid extends AbstractPlaceholderGui {
|
||||
e.manager.showGUI(e.player, new GUIConfirmBid(this.auctionPlayer, auctionItem));
|
||||
});
|
||||
|
||||
// TODO UPDATE BID
|
||||
setButton(1, 6, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_BIDDING_ITEMS_CUSTOM_ITEM.getString(), Settings.GUI_BIDDING_ITEMS_CUSTOM_NAME.getString(), Settings.GUI_BIDDING_ITEMS_CUSTOM_LORE.getStringList(), null), e -> {
|
||||
e.gui.exit();
|
||||
PlayerChatInput.PlayerChatInputBuilder<Double> builder = new PlayerChatInput.PlayerChatInputBuilder<>(AuctionHouse.getInstance(), e.player);
|
||||
builder.isValidInput((p, str) -> NumberUtils.isDouble(ChatColor.stripColor(str)) && Double.parseDouble(ChatColor.stripColor(str)) >= this.auctionItem.getBidIncrementPrice());
|
||||
builder.sendValueMessage(TextUtils.formatText(AuctionHouse.getInstance().getLocale().getMessage("prompts.enter bid amount").processPlaceholder("current_bid", AuctionAPI.getInstance().formatNumber(auctionItem.getCurrentPrice())).getMessage()));
|
||||
builder.toCancel("cancel");
|
||||
builder.onCancel(p -> e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer)));
|
||||
builder.setValue((p, value) -> Double.parseDouble(ChatColor.stripColor(value)));
|
||||
builder.onFinish((p, value) -> {
|
||||
|
||||
new TitleInput(player, AuctionHouse.getInstance().getLocale().getMessage("titles.enter bid.title").getMessage(), AuctionHouse.getInstance().getLocale().getMessage("titles.enter bid.subtitle").getMessage()) {
|
||||
|
||||
@Override
|
||||
public void onExit(Player player) {
|
||||
AuctionHouse.getInstance().getGuiManager().showGUI(player, new GUIAuctionHouse(GUIBid.this.auctionPlayer));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onResult(String string) {
|
||||
string = ChatColor.stripColor(string);
|
||||
|
||||
if (!NumberUtils.isDouble(string)) {
|
||||
AuctionHouse.getInstance().getLocale().getMessage("general.notanumber").sendPrefixedMessage(player);
|
||||
return false;
|
||||
}
|
||||
|
||||
double value = Double.parseDouble(string);
|
||||
|
||||
if (value > Settings.MAX_AUCTION_INCREMENT_PRICE.getDouble()) {
|
||||
AuctionHouse.getInstance().getLocale().getMessage("pricing.maxbidincrementprice").processPlaceholder("price", Settings.MAX_AUCTION_INCREMENT_PRICE.getDouble()).sendPrefixedMessage(e.player);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
double newBiddingAmount = 0;
|
||||
if (Settings.USE_REALISTIC_BIDDING.getBoolean()) {
|
||||
if (value > this.auctionItem.getCurrentPrice()) {
|
||||
if (value > GUIBid.this.auctionItem.getCurrentPrice()) {
|
||||
newBiddingAmount = value;
|
||||
} else {
|
||||
if (Settings.BID_MUST_BE_HIGHER_THAN_PREVIOUS.getBoolean()) {
|
||||
e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer));
|
||||
e.manager.showGUI(e.player, new GUIAuctionHouse(GUIBid.this.auctionPlayer));
|
||||
AuctionHouse.getInstance().getLocale().getMessage("pricing.bidmusthigherthanprevious").processPlaceholder("current_bid", AuctionAPI.getInstance().formatNumber(auctionItem.getCurrentPrice())).sendPrefixedMessage(e.player);
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
newBiddingAmount = this.auctionItem.getCurrentPrice() + value;
|
||||
newBiddingAmount = GUIBid.this.auctionItem.getCurrentPrice() + value;
|
||||
}
|
||||
} else {
|
||||
newBiddingAmount = this.auctionItem.getCurrentPrice() + value;
|
||||
newBiddingAmount = GUIBid.this.auctionItem.getCurrentPrice() + value;
|
||||
}
|
||||
|
||||
newBiddingAmount = Settings.ROUND_ALL_PRICES.getBoolean() ? Math.round(newBiddingAmount) : newBiddingAmount;
|
||||
|
||||
if (Settings.PLAYER_NEEDS_TOTAL_PRICE_TO_BID.getBoolean() && !EconomyManager.hasBalance(e.player, newBiddingAmount)) {
|
||||
AuctionHouse.getInstance().getLocale().getMessage("general.notenoughmoney").sendPrefixedMessage(e.player);
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Settings.ASK_FOR_BID_CONFIRMATION.getBoolean()) {
|
||||
e.manager.showGUI(e.player, new GUIConfirmBid(this.auctionPlayer, auctionItem, value));
|
||||
return;
|
||||
e.manager.showGUI(e.player, new GUIConfirmBid(GUIBid.this.auctionPlayer, auctionItem, value));
|
||||
return true;
|
||||
}
|
||||
|
||||
ItemStack itemStack = auctionItem.getItem();
|
||||
@ -123,19 +137,18 @@ public class GUIBid extends AbstractPlaceholderGui {
|
||||
|
||||
AuctionBidEvent auctionBidEvent = new AuctionBidEvent(e.player, auctionItem, newBiddingAmount);
|
||||
Bukkit.getServer().getPluginManager().callEvent(auctionBidEvent);
|
||||
if (auctionBidEvent.isCancelled()) return;
|
||||
if (auctionBidEvent.isCancelled()) return true;
|
||||
|
||||
// TODO implement bid tracking/money return on outbid
|
||||
if (Settings.BIDDING_TAKES_MONEY.getBoolean()) {
|
||||
final double oldBidAmount = auctionItem.getCurrentPrice();
|
||||
|
||||
if (!EconomyManager.hasBalance(e.player, newBiddingAmount)) {
|
||||
AuctionHouse.getInstance().getLocale().getMessage("general.notenoughmoney").sendPrefixedMessage(e.player);
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (e.player.getUniqueId().equals(owner.getUniqueId()) || oldBidder.getUniqueId().equals(e.player.getUniqueId())) {
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!auctionItem.getHighestBidder().equals(auctionItem.getOwner())) {
|
||||
@ -186,11 +199,11 @@ public class GUIBid extends AbstractPlaceholderGui {
|
||||
.sendPrefixedMessage(player));
|
||||
}
|
||||
|
||||
e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer));
|
||||
});
|
||||
e.manager.showGUI(e.player, new GUIAuctionHouse(GUIBid.this.auctionPlayer));
|
||||
|
||||
PlayerChatInput<Double> input = builder.build();
|
||||
input.start();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user