From 5ad08b99cdc0e0332d263e9b2f6870872def2545 Mon Sep 17 00:00:00 2001 From: Kiran Hart Date: Tue, 11 May 2021 14:57:58 -0400 Subject: [PATCH] if the current price exceeds the base price, the base price will sync to the current price. item name and lore block phrase setting, bid confirm gui is now 1 row --- .../tweetzy/auctionhouse/api/AuctionAPI.java | 22 ++++++++++- .../auctionhouse/auction/AuctionItem.java | 1 + .../auctionhouse/commands/CommandSell.java | 38 ++++++++++++++++++- .../auctionhouse/guis/GUIAuctionHouse.java | 3 ++ .../auctionhouse/guis/GUIConfirmBid.java | 4 ++ .../listeners/AuctionListeners.java | 28 +++++++------- .../auctionhouse/settings/Settings.java | 19 +++++++++- src/main/resources/en_US.lang | 3 ++ 8 files changed, 98 insertions(+), 20 deletions(-) diff --git a/src/main/java/ca/tweetzy/auctionhouse/api/AuctionAPI.java b/src/main/java/ca/tweetzy/auctionhouse/api/AuctionAPI.java index 8db167f..41b3daf 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/api/AuctionAPI.java +++ b/src/main/java/ca/tweetzy/auctionhouse/api/AuctionAPI.java @@ -5,6 +5,8 @@ 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.TextUtils; +import org.apache.commons.lang.WordUtils; import org.bukkit.OfflinePlayer; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.SkullMeta; @@ -16,8 +18,8 @@ import java.io.*; import java.text.DecimalFormat; import java.text.NumberFormat; import java.text.SimpleDateFormat; -import java.util.Base64; -import java.util.Date; +import java.util.List; +import java.util.*; import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.TimeUnit; import java.util.regex.Matcher; @@ -218,6 +220,22 @@ public class AuctionAPI { } } + public String getItemName(ItemStack stack) { + Objects.requireNonNull(stack, "Item stack cannot be null when getting name"); + return stack.getItemMeta().hasDisplayName() ? stack.getItemMeta().getDisplayName() : TextUtils.formatText("&f" + WordUtils.capitalize(stack.getType().name().toLowerCase().replace("_", " "))); + } + + public List getItemLore(ItemStack stack) { + List lore = new ArrayList<>(); + Objects.requireNonNull(stack, "Item stack cannot be null when getting lore"); + if (stack.hasItemMeta()) { + if (stack.getItemMeta().hasLore() && stack.getItemMeta().getLore() != null) { + lore.addAll(stack.getItemMeta().getLore()); + } + } + return lore; + } + public boolean match(String pattern, String sentence) { Pattern patt = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE); Matcher matcher = patt.matcher(sentence); diff --git a/src/main/java/ca/tweetzy/auctionhouse/auction/AuctionItem.java b/src/main/java/ca/tweetzy/auctionhouse/auction/AuctionItem.java index a0186e3..5cd96c6 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/auction/AuctionItem.java +++ b/src/main/java/ca/tweetzy/auctionhouse/auction/AuctionItem.java @@ -19,6 +19,7 @@ import org.bukkit.inventory.meta.ItemMeta; import java.io.Serializable; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import java.util.UUID; import java.util.stream.Collectors; diff --git a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSell.java b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSell.java index 0a253c2..4aabdb2 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSell.java +++ b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandSell.java @@ -1,6 +1,7 @@ package ca.tweetzy.auctionhouse.commands; import ca.tweetzy.auctionhouse.AuctionHouse; +import ca.tweetzy.auctionhouse.api.AuctionAPI; import ca.tweetzy.auctionhouse.api.events.AuctionStartEvent; import ca.tweetzy.auctionhouse.auction.AuctionItem; import ca.tweetzy.auctionhouse.auction.AuctionPlayer; @@ -15,6 +16,7 @@ import ca.tweetzy.core.utils.NumberUtils; import ca.tweetzy.core.utils.PlayerUtils; import org.apache.commons.lang.WordUtils; import org.bukkit.Bukkit; +import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -23,6 +25,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.UUID; +import java.util.stream.Collectors; /** * The current file has been created by Kiran Hart @@ -31,7 +34,7 @@ import java.util.UUID; * Usage of any code found within this class is prohibited unless given explicit permission otherwise */ public class CommandSell extends AbstractCommand { - + public CommandSell() { super(CommandType.PLAYER_ONLY, "sell"); } @@ -51,10 +54,36 @@ public class CommandSell extends AbstractCommand { // Check for block items if (Settings.BLOCKED_ITEMS.getStringList().contains(itemToSell.getType().name())) { - AuctionHouse.getInstance().getLocale().getMessage("general.blocked").processPlaceholder("item", itemToSell.getType().name()).sendPrefixedMessage(player); + AuctionHouse.getInstance().getLocale().getMessage("general.blockeditem").processPlaceholder("item", itemToSell.getType().name()).sendPrefixedMessage(player); return ReturnType.FAILURE; } + boolean blocked = false; + + String itemName = ChatColor.stripColor(AuctionAPI.getInstance().getItemName(itemToSell).toLowerCase()); + List itemLore = AuctionAPI.getInstance().getItemLore(itemToSell).stream().map(line -> ChatColor.stripColor(line.toLowerCase())).collect(Collectors.toList()); + + // Check for blocked names and lore + for (String s : Settings.BLOCKED_ITEM_NAMES.getStringList()) { + if (AuctionAPI.getInstance().match(s, itemName)) { + AuctionHouse.getInstance().getLocale().getMessage("general.blockedname").sendPrefixedMessage(player); + blocked = true; + } + } + + if (!itemLore.isEmpty() && !blocked) { + for (String s : Settings.BLOCKED_ITEM_LORES.getStringList()) { + for (String line : itemLore) { + if (AuctionAPI.getInstance().match(s, line)) { + AuctionHouse.getInstance().getLocale().getMessage("general.blockedlore").sendPrefixedMessage(player); + blocked = true; + } + } + } + } + + if (blocked) return ReturnType.FAILURE; + List possibleTimes = new ArrayList<>(); Settings.AUCTION_TIME.getStringList().forEach(line -> { String[] split = line.split(":"); @@ -185,6 +214,11 @@ public class CommandSell extends AbstractCommand { return ReturnType.FAILURE; } + if (Settings.BASE_PRICE_MUST_BE_HIGHER_THAN_BID_START.getBoolean() && bidStartPrice > basePrice) { + AuctionHouse.getInstance().getLocale().getMessage("pricing.basepricetoolow").sendPrefixedMessage(player); + return ReturnType.FAILURE; + } + AuctionItem item = new AuctionItem( player.getUniqueId(), player.getUniqueId(), diff --git a/src/main/java/ca/tweetzy/auctionhouse/guis/GUIAuctionHouse.java b/src/main/java/ca/tweetzy/auctionhouse/guis/GUIAuctionHouse.java index 532c331..3284df2 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/guis/GUIAuctionHouse.java +++ b/src/main/java/ca/tweetzy/auctionhouse/guis/GUIAuctionHouse.java @@ -190,6 +190,9 @@ public class GUIAuctionHouse extends Gui { } 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()); diff --git a/src/main/java/ca/tweetzy/auctionhouse/guis/GUIConfirmBid.java b/src/main/java/ca/tweetzy/auctionhouse/guis/GUIConfirmBid.java index 493fe4d..fced011 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/guis/GUIConfirmBid.java +++ b/src/main/java/ca/tweetzy/auctionhouse/guis/GUIConfirmBid.java @@ -39,6 +39,7 @@ public class GUIConfirmBid extends Gui { this.auctionItem = auctionItem; setTitle(TextUtils.formatText(Settings.GUI_CONFIRM_BID_TITLE.getString())); setAcceptsItems(false); + setRows(1); draw(); } @@ -63,6 +64,9 @@ public class GUIConfirmBid extends Gui { 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()); diff --git a/src/main/java/ca/tweetzy/auctionhouse/listeners/AuctionListeners.java b/src/main/java/ca/tweetzy/auctionhouse/listeners/AuctionListeners.java index 3dedeba..6d2800d 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/listeners/AuctionListeners.java +++ b/src/main/java/ca/tweetzy/auctionhouse/listeners/AuctionListeners.java @@ -30,20 +30,20 @@ public class AuctionListeners implements Listener { @EventHandler public void onAuctionEnd(AuctionEndEvent e) { - if (Settings.DISCORD_ENABLED.getBoolean() && Settings.DISCORD_ALERT_ON_AUCTION_FINISH.getBoolean()) { - Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(AuctionHouse.getInstance(), () -> { - if (Settings.RECORD_TRANSACTIONS.getBoolean()) { - AuctionHouse.getInstance().getTransactionManager().addTransaction(new Transaction( - UUID.randomUUID(), - e.getOriginalOwner().getUniqueId(), - e.getBuyer().getUniqueId(), - System.currentTimeMillis(), - e.getAuctionItem(), - e.getSaleType() - )); - } + Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(AuctionHouse.getInstance(), () -> { + if (Settings.RECORD_TRANSACTIONS.getBoolean()) { + AuctionHouse.getInstance().getTransactionManager().addTransaction(new Transaction( + UUID.randomUUID(), + e.getOriginalOwner().getUniqueId(), + e.getBuyer().getUniqueId(), + System.currentTimeMillis(), + e.getAuctionItem(), + e.getSaleType() + )); + } + if (Settings.DISCORD_ENABLED.getBoolean() && Settings.DISCORD_ALERT_ON_AUCTION_FINISH.getBoolean()) { Settings.DISCORD_WEBHOOKS.getStringList().forEach(hook -> AuctionAPI.getInstance().sendDiscordMessage(hook, e.getOriginalOwner(), e.getBuyer(), e.getAuctionItem(), e.getSaleType(), false, e.getSaleType() == AuctionSaleType.USED_BIDDING_SYSTEM)); - }, 1L); - } + } + }, 1L); } } diff --git a/src/main/java/ca/tweetzy/auctionhouse/settings/Settings.java b/src/main/java/ca/tweetzy/auctionhouse/settings/Settings.java index 860cd8a..bca459d 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/settings/Settings.java +++ b/src/main/java/ca/tweetzy/auctionhouse/settings/Settings.java @@ -56,6 +56,8 @@ public class Settings { 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."); /* =============================== * DATABASE OPTIONS @@ -116,9 +118,21 @@ public class Settings { public static final ConfigSetting DISCORD_MSG_FIELD_ITEM_AMOUNT_INLINE = new ConfigSetting(config, "discord.msg.item amount.inline", true); /* =============================== - * BLOCKED ITEMS + * BLACK LISTED * ===============================*/ public static final ConfigSetting BLOCKED_ITEMS = new ConfigSetting(config, "blocked items", Collections.singletonList("ENDER_CHEST"), "Materials that should be blocked (not allowed to sell)"); + public static final ConfigSetting BLOCKED_ITEM_NAMES = new ConfigSetting(config, "blocked item names", Arrays.asList( + "fuck", + "bitch", + "nigger", + "nigga", + "pussy" + ), "If an item contains any words/names specified here, it won't list."); + + public static final ConfigSetting BLOCKED_ITEM_LORES = new ConfigSetting(config, "blocked item lores", Arrays.asList( + "kill yourself", + "another random phrase" + ), "If an item lore contains any of these values, it won't list"); /* =============================== * MAX AUCTION TIME @@ -188,7 +202,8 @@ public class Settings { "&7Click here to view all of the items you", "&7are currently selling on the auction.", "", - "&e&l%active_player_auctions% Item(s)" + "&e&l%active_player_auctions% Item(s)", + "&e&lBalance &a$%player_balance%" )); public static final ConfigSetting GUI_AUCTION_HOUSE_ITEMS_COLLECTION_BIN_ITEM = new ConfigSetting(config, "gui.auction house.items.collection bin.item", "ENDER_CHEST"); diff --git a/src/main/resources/en_US.lang b/src/main/resources/en_US.lang index 97c57de..72e8e77 100644 --- a/src/main/resources/en_US.lang +++ b/src/main/resources/en_US.lang @@ -6,6 +6,8 @@ general: cantbidonown: "&cYou cannot bid on your own item!" cantbuyown: "&cYou cannot buy your own item!" blockeditem: "&cYou are not allowed to auction that item. (%item%)" + blockedname: "&cThat item contains a blocked name phrase" + blockedlore: "&cThat item contains a blocked lore phrase" air: "&cSorry, but you cannot sell air o.O" blocked: "&cSorry, you are not allowed to sell &e%item%" sellinglimit: "&cYou cannot sell more items, please remove/sell current active items" @@ -18,6 +20,7 @@ pricing: maxbaseprice: "&cThe maximum base price is &a$%price%" maxstartingprice: "&cThe maximum starting bid price is &a$%price%" maxbidincrementprice: "&cThe maximum bid increment is &a$%price%" + basepricetoolow: "&cThe buy now price must be higher than the starting bid." moneyremove: "&c&l- $%price%" moneyadd: "&a&l+ $%price%"