2.18.1 - You can now add the item to the sell menu directly

This commit is contained in:
Kiran Hart 2021-06-29 12:05:01 -04:00
parent 2f4fda7bd2
commit 9b5a62b7d5
4 changed files with 72 additions and 26 deletions

View File

@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>ca.tweetzy</groupId>
<artifactId>auctionhouse</artifactId>
<version>2.18.0</version>
<version>2.18.1</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

View File

@ -48,6 +48,27 @@ public class CommandSell extends AbstractCommand {
ItemStack originalItem = PlayerHelper.getHeldItem(player).clone();
ItemStack itemToSell = PlayerHelper.getHeldItem(player).clone();
// check if player is at their selling limit
if (auctionPlayer.isAtSellLimit()) {
AuctionHouse.getInstance().getLocale().getMessage("general.sellinglimit").sendPrefixedMessage(player);
return ReturnType.FAILURE;
}
// open the sell menu if its 0;
if (args.length == 0) {
if (itemToSell.getType() == XMaterial.AIR.parseMaterial() && Settings.SELL_MENU_REQUIRES_USER_TO_HOLD_ITEM.getBoolean()) {
AuctionHouse.getInstance().getLocale().getMessage("general.air").sendPrefixedMessage(player);
return ReturnType.FAILURE;
} else {
AuctionHouse.getInstance().getGuiManager().showGUI(player, new GUISellItem(auctionPlayer, itemToSell));
AuctionHouse.getInstance().getAuctionPlayerManager().addItemToSellHolding(player.getUniqueId(), itemToSell);
PlayerUtils.takeActiveItem(player, CompatibleHand.MAIN_HAND, itemToSell.getAmount());
}
return ReturnType.SUCCESS;
}
if (itemToSell.getType() == XMaterial.AIR.parseMaterial()) {
AuctionHouse.getInstance().getLocale().getMessage("general.air").sendPrefixedMessage(player);
return ReturnType.FAILURE;
@ -88,20 +109,6 @@ public class CommandSell extends AbstractCommand {
// get the max allowed time for this player.
int allowedTime = auctionPlayer.getAllowedSellTime();
// check if player is at their selling limit
if (auctionPlayer.isAtSellLimit()) {
AuctionHouse.getInstance().getLocale().getMessage("general.sellinglimit").sendPrefixedMessage(player);
return ReturnType.FAILURE;
}
// open the sell menu if its 0;
if (args.length == 0) {
AuctionHouse.getInstance().getGuiManager().showGUI(player, new GUISellItem(auctionPlayer, itemToSell));
AuctionHouse.getInstance().getAuctionPlayerManager().addItemToSellHolding(player.getUniqueId(), itemToSell);
PlayerUtils.takeActiveItem(player, CompatibleHand.MAIN_HAND, itemToSell.getAmount());
return ReturnType.SUCCESS;
}
// Special command arguments
List<String> commandFlags = AuctionAPI.getInstance().getCommandFlags(args);
List<Double> listingPrices = new ArrayList<>();

View File

@ -9,6 +9,7 @@ import ca.tweetzy.auctionhouse.helpers.ConfigurationItemHelper;
import ca.tweetzy.auctionhouse.helpers.MaterialCategorizer;
import ca.tweetzy.auctionhouse.managers.SoundManager;
import ca.tweetzy.auctionhouse.settings.Settings;
import ca.tweetzy.core.compatibility.XMaterial;
import ca.tweetzy.core.gui.Gui;
import ca.tweetzy.core.gui.events.GuiClickEvent;
import ca.tweetzy.core.input.ChatPrompt;
@ -16,6 +17,7 @@ import ca.tweetzy.core.utils.NumberUtils;
import ca.tweetzy.core.utils.PlayerUtils;
import ca.tweetzy.core.utils.TextUtils;
import org.bukkit.Bukkit;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import java.util.HashMap;
@ -31,7 +33,7 @@ import java.util.UUID;
public class GUISellItem extends Gui {
private final AuctionPlayer auctionPlayer;
private final ItemStack itemToBeListed;
private ItemStack itemToBeListed;
private double buyNowPrice;
private double bidStartPrice;
@ -50,14 +52,23 @@ public class GUISellItem extends Gui {
setTitle(TextUtils.formatText(Settings.GUI_SELL_TITLE.getString()));
setDefaultItem(Settings.GUI_SELL_BG_ITEM.getMaterial().parseItem());
setUseLockedCells(true);
setAcceptsItems(false);
setAcceptsItems(true);
setRows(5);
draw();
setOnClose(close -> {
PlayerUtils.giveItem(close.player, AuctionHouse.getInstance().getAuctionPlayerManager().getSellHolding().get(close.player.getUniqueId()));
ItemStack toGiveBack = AuctionHouse.getInstance().getAuctionPlayerManager().getSellHolding().get(close.player.getUniqueId());
if (toGiveBack != null && toGiveBack.getType() != XMaterial.AIR.parseMaterial()) {
PlayerUtils.giveItem(close.player, toGiveBack);
} else {
PlayerUtils.giveItem(close.player, getItem(1, 4));
}
AuctionHouse.getInstance().getAuctionPlayerManager().getSellHolding().remove(close.player.getUniqueId());
});
setUnlocked(1, 4);
setUnlockedRange(45, 89);
}
public GUISellItem(AuctionPlayer auctionPlayer, ItemStack itemToBeListed) {
@ -68,20 +79,29 @@ public class GUISellItem extends Gui {
reset();
// the draw item that is being listed
setItem(1, 4, this.itemToBeListed);
setButton(1, 4, this.itemToBeListed, e -> {
// Is the user selling with an item in hand?
if (AuctionHouse.getInstance().getAuctionPlayerManager().getSellHolding().containsKey(e.player.getUniqueId())) {
if (AuctionHouse.getInstance().getAuctionPlayerManager().getSellHolding().get(e.player.getUniqueId()).getType() != XMaterial.AIR.parseMaterial()) {
e.event.setCancelled(true);
}
}
});
setButton(3, 1, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_SELL_ITEMS_BUY_NOW_ITEM.getString(), Settings.GUI_SELL_ITEMS_BUY_NOW_NAME.getString(), Settings.GUI_SELL_ITEMS_BUY_NOW_LORE.getStringList(), new HashMap<String, Object>() {{
put("%buy_now_price%", AuctionAPI.getInstance().formatNumber(buyNowPrice));
}}), e -> {
}}), ClickType.LEFT, e -> {
setTheItemToBeListed();
e.gui.exit();
ChatPrompt.showPrompt(AuctionHouse.getInstance(), this.auctionPlayer.getPlayer(), TextUtils.formatText(AuctionHouse.getInstance().getLocale().getMessage("prompts.enter new buy now price").getMessage()), chat -> {
String msg = chat.getMessage();
if (validateChatNumber(msg, Settings.MIN_AUCTION_PRICE.getDouble())) {
// special check
if (this.isBiddingItem && this.isAllowingBuyNow && this.buyNowPrice < this.bidStartPrice && Settings.BASE_PRICE_MUST_BE_HIGHER_THAN_BID_START.getBoolean()) {
// check if the buy now price is higher than the bid start price
if (this.isAllowingBuyNow && this.isBiddingItem && Settings.BASE_PRICE_MUST_BE_HIGHER_THAN_BID_START.getBoolean() && Double.parseDouble(msg) < this.bidStartPrice) {
reopen(e);
return;
}
this.buyNowPrice = Double.parseDouble(msg);
}
reopen(e);
@ -91,7 +111,8 @@ public class GUISellItem extends Gui {
if (this.isBiddingItem) {
setButton(3, 2, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_SELL_ITEMS_STARTING_BID_ITEM.getString(), Settings.GUI_SELL_ITEMS_STARTING_BID_NAME.getString(), Settings.GUI_SELL_ITEMS_STARTING_BID_LORE.getStringList(), new HashMap<String, Object>() {{
put("%starting_bid_price%", AuctionAPI.getInstance().formatNumber(bidStartPrice));
}}), e -> {
}}), ClickType.LEFT, e -> {
setTheItemToBeListed();
e.gui.exit();
ChatPrompt.showPrompt(AuctionHouse.getInstance(), this.auctionPlayer.getPlayer(), TextUtils.formatText(AuctionHouse.getInstance().getLocale().getMessage("prompts.enter new starting bid").getMessage()), chat -> {
String msg = chat.getMessage();
@ -104,7 +125,8 @@ public class GUISellItem extends Gui {
setButton(3, 3, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_SELL_ITEMS_BID_INC_ITEM.getString(), Settings.GUI_SELL_ITEMS_BID_INC_NAME.getString(), Settings.GUI_SELL_ITEMS_BID_INC_LORE.getStringList(), new HashMap<String, Object>() {{
put("%bid_increment_price%", AuctionAPI.getInstance().formatNumber(bidIncrementPrice));
}}), e -> {
}}), ClickType.LEFT, e -> {
setTheItemToBeListed();
e.gui.exit();
ChatPrompt.showPrompt(AuctionHouse.getInstance(), this.auctionPlayer.getPlayer(), TextUtils.formatText(AuctionHouse.getInstance().getLocale().getMessage("prompts.enter new bid increment").getMessage()), chat -> {
String msg = chat.getMessage();
@ -115,8 +137,9 @@ public class GUISellItem extends Gui {
}).setOnCancel(() -> reopen(e)).setOnClose(() -> reopen(e));
});
setButton(3, 6, ConfigurationItemHelper.createConfigurationItem(this.isAllowingBuyNow ? Settings.GUI_SELL_ITEMS_BUY_NOW_ENABLED_ITEM.getString() : Settings.GUI_SELL_ITEMS_BUY_NOW_DISABLED_ITEM.getString(), this.isAllowingBuyNow ? Settings.GUI_SELL_ITEMS_BUY_NOW_ENABLED_NAME.getString() : Settings.GUI_SELL_ITEMS_BUY_NOW_DISABLED_NAME.getString(), this.isAllowingBuyNow ? Settings.GUI_SELL_ITEMS_BUY_NOW_ENABLED_LORE.getStringList() : Settings.GUI_SELL_ITEMS_BUY_NOW_DISABLED_LORE.getStringList(), null), e -> {
setButton(3, 6, ConfigurationItemHelper.createConfigurationItem(this.isAllowingBuyNow ? Settings.GUI_SELL_ITEMS_BUY_NOW_ENABLED_ITEM.getString() : Settings.GUI_SELL_ITEMS_BUY_NOW_DISABLED_ITEM.getString(), this.isAllowingBuyNow ? Settings.GUI_SELL_ITEMS_BUY_NOW_ENABLED_NAME.getString() : Settings.GUI_SELL_ITEMS_BUY_NOW_DISABLED_NAME.getString(), this.isAllowingBuyNow ? Settings.GUI_SELL_ITEMS_BUY_NOW_ENABLED_LORE.getStringList() : Settings.GUI_SELL_ITEMS_BUY_NOW_DISABLED_LORE.getStringList(), null), ClickType.LEFT, e -> {
this.isAllowingBuyNow = !this.isAllowingBuyNow;
setTheItemToBeListed();
draw();
});
@ -124,10 +147,15 @@ public class GUISellItem extends Gui {
setButton(3, 5, ConfigurationItemHelper.createConfigurationItem(this.isBiddingItem ? Settings.GUI_SELL_ITEMS_BIDDING_ENABLED_ITEM.getString() : Settings.GUI_SELL_ITEMS_BIDDING_DISABLED_ITEM.getString(), this.isBiddingItem ? Settings.GUI_SELL_ITEMS_BIDDING_ENABLED_NAME.getString() : Settings.GUI_SELL_ITEMS_BIDDING_DISABLED_NAME.getString(), this.isBiddingItem ? Settings.GUI_SELL_ITEMS_BIDDING_ENABLED_LORE.getStringList() : Settings.GUI_SELL_ITEMS_BIDDING_DISABLED_LORE.getStringList(), null), e -> {
this.isBiddingItem = !this.isBiddingItem;
setTheItemToBeListed();
draw();
});
setButton(3, 7, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_SELL_ITEMS_CONFIRM_LISTING_ITEM.getString(), Settings.GUI_SELL_ITEMS_CONFIRM_LISTING_NAME.getString(), Settings.GUI_SELL_ITEMS_CONFIRM_LISTING_LORE.getStringList(), null), e -> {
// if the item in the sell slot is null then stop the listing
if (getItem(1, 4) == null || getItem(1, 4).getType() == XMaterial.AIR.parseMaterial()) return;
setTheItemToBeListed();
AuctionItem auctionItem = new AuctionItem(
e.player.getUniqueId(),
e.player.getUniqueId(),
@ -149,7 +177,12 @@ public class GUISellItem extends Gui {
AuctionHouse.getInstance().getAuctionItemManager().addItem(auctionItem);
SoundManager.getInstance().playSound(e.player, Settings.SOUNDS_LISTED_ITEM_ON_AUCTION_HOUSE.getString(), 1.0F, 1.0F);
AuctionHouse.getInstance().getAuctionPlayerManager().removeItemFromSellHolding(e.player.getUniqueId());
e.gui.exit();
if (Settings.OPEN_MAIN_AUCTION_HOUSE_AFTER_MENU_LIST.getBoolean()) {
e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer));
} else {
e.gui.exit();
}
// TODO FIGURE OUT WHY THE HELL THIS IS NOT WORKING
String NAX = AuctionHouse.getInstance().getLocale().getMessage("auction.biditemwithdisabledbuynow").getMessage();
@ -181,4 +214,8 @@ public class GUISellItem extends Gui {
private void reopen(GuiClickEvent e) {
e.manager.showGUI(e.player, new GUISellItem(this.auctionPlayer, this.itemToBeListed, this.buyNowPrice, this.bidStartPrice, this.bidIncrementPrice, this.isBiddingItem, this.isAllowingBuyNow));
}
private void setTheItemToBeListed() {
this.itemToBeListed = getItem(1, 4);
}
}

View File

@ -65,6 +65,8 @@ public class Settings {
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 USE_SEPARATE_FILTER_MENU = new ConfigSetting(config, "auction setting.use separate filter menu", false, "If true, rather than using a single filter item inside the auction menu", "it will open an entirely new menu to select the filter");
public static final ConfigSetting SELL_MENU_REQUIRES_USER_TO_HOLD_ITEM = new ConfigSetting(config, "auction setting.require user to hold item when using sell menu", false, "If enabled, when running just /ah sell, the user will need to hold the item in their hand, otherwise they just add it in the gui.");
public static final ConfigSetting OPEN_MAIN_AUCTION_HOUSE_AFTER_MENU_LIST = new ConfigSetting(config, "auction setting.open main auction house after listing using menu", true, "Should the main auction house be opened after the user lists an item using the sell menu?");
public static final ConfigSetting ALL_FILTER_ENABLED = new ConfigSetting(config, "auction setting.enabled filters.all", true, "Should this filter be enabled?");
public static final ConfigSetting FOOD_FILTER_ENABLED = new ConfigSetting(config, "auction setting.enabled filters.food", true, "Should this filter be enabled?");