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

This commit is contained in:
Kiran Hart 2021-05-11 14:57:58 -04:00
parent 7c8194b6b9
commit 5ad08b99cd
8 changed files with 98 additions and 20 deletions

View File

@ -5,6 +5,8 @@ import ca.tweetzy.auctionhouse.auction.AuctionItem;
import ca.tweetzy.auctionhouse.auction.AuctionSaleType; import ca.tweetzy.auctionhouse.auction.AuctionSaleType;
import ca.tweetzy.auctionhouse.settings.Settings; import ca.tweetzy.auctionhouse.settings.Settings;
import ca.tweetzy.core.compatibility.XMaterial; 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.OfflinePlayer;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.inventory.meta.SkullMeta;
@ -16,8 +18,8 @@ import java.io.*;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.text.NumberFormat; import java.text.NumberFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Base64; import java.util.List;
import java.util.Date; import java.util.*;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher; 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<String> getItemLore(ItemStack stack) {
List<String> 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) { public boolean match(String pattern, String sentence) {
Pattern patt = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE); Pattern patt = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE);
Matcher matcher = patt.matcher(sentence); Matcher matcher = patt.matcher(sentence);

View File

@ -19,6 +19,7 @@ import org.bukkit.inventory.meta.ItemMeta;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;

View File

@ -1,6 +1,7 @@
package ca.tweetzy.auctionhouse.commands; package ca.tweetzy.auctionhouse.commands;
import ca.tweetzy.auctionhouse.AuctionHouse; import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.api.AuctionAPI;
import ca.tweetzy.auctionhouse.api.events.AuctionStartEvent; import ca.tweetzy.auctionhouse.api.events.AuctionStartEvent;
import ca.tweetzy.auctionhouse.auction.AuctionItem; import ca.tweetzy.auctionhouse.auction.AuctionItem;
import ca.tweetzy.auctionhouse.auction.AuctionPlayer; import ca.tweetzy.auctionhouse.auction.AuctionPlayer;
@ -15,6 +16,7 @@ import ca.tweetzy.core.utils.NumberUtils;
import ca.tweetzy.core.utils.PlayerUtils; import ca.tweetzy.core.utils.PlayerUtils;
import org.apache.commons.lang.WordUtils; import org.apache.commons.lang.WordUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -23,6 +25,7 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors;
/** /**
* The current file has been created by Kiran Hart * The current file has been created by Kiran Hart
@ -51,10 +54,36 @@ public class CommandSell extends AbstractCommand {
// Check for block items // Check for block items
if (Settings.BLOCKED_ITEMS.getStringList().contains(itemToSell.getType().name())) { 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; return ReturnType.FAILURE;
} }
boolean blocked = false;
String itemName = ChatColor.stripColor(AuctionAPI.getInstance().getItemName(itemToSell).toLowerCase());
List<String> 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<Integer> possibleTimes = new ArrayList<>(); List<Integer> possibleTimes = new ArrayList<>();
Settings.AUCTION_TIME.getStringList().forEach(line -> { Settings.AUCTION_TIME.getStringList().forEach(line -> {
String[] split = line.split(":"); String[] split = line.split(":");
@ -185,6 +214,11 @@ public class CommandSell extends AbstractCommand {
return ReturnType.FAILURE; 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( AuctionItem item = new AuctionItem(
player.getUniqueId(), player.getUniqueId(),
player.getUniqueId(), player.getUniqueId(),

View File

@ -190,6 +190,9 @@ public class GUIAuctionHouse extends Gui {
} else { } else {
auctionItem.setHighestBidder(e.player.getUniqueId()); auctionItem.setHighestBidder(e.player.getUniqueId());
auctionItem.setCurrentPrice(auctionItem.getCurrentPrice() + auctionItem.getBidIncPrice()); 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()) { if (Settings.INCREASE_TIME_ON_BID.getBoolean()) {
auctionItem.setRemainingTime(auctionItem.getRemainingTime() + Settings.TIME_TO_INCREASE_BY_ON_BID.getInt()); auctionItem.setRemainingTime(auctionItem.getRemainingTime() + Settings.TIME_TO_INCREASE_BY_ON_BID.getInt());

View File

@ -39,6 +39,7 @@ public class GUIConfirmBid extends Gui {
this.auctionItem = auctionItem; this.auctionItem = auctionItem;
setTitle(TextUtils.formatText(Settings.GUI_CONFIRM_BID_TITLE.getString())); setTitle(TextUtils.formatText(Settings.GUI_CONFIRM_BID_TITLE.getString()));
setAcceptsItems(false); setAcceptsItems(false);
setRows(1);
draw(); draw();
} }
@ -63,6 +64,9 @@ public class GUIConfirmBid extends Gui {
auctionItem.setHighestBidder(e.player.getUniqueId()); auctionItem.setHighestBidder(e.player.getUniqueId());
auctionItem.setCurrentPrice(auctionItem.getCurrentPrice() + auctionItem.getBidIncPrice()); 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()) { if (Settings.INCREASE_TIME_ON_BID.getBoolean()) {
auctionItem.setRemainingTime(auctionItem.getRemainingTime() + Settings.TIME_TO_INCREASE_BY_ON_BID.getInt()); auctionItem.setRemainingTime(auctionItem.getRemainingTime() + Settings.TIME_TO_INCREASE_BY_ON_BID.getInt());

View File

@ -30,20 +30,20 @@ public class AuctionListeners implements Listener {
@EventHandler @EventHandler
public void onAuctionEnd(AuctionEndEvent e) { public void onAuctionEnd(AuctionEndEvent e) {
if (Settings.DISCORD_ENABLED.getBoolean() && Settings.DISCORD_ALERT_ON_AUCTION_FINISH.getBoolean()) { Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(AuctionHouse.getInstance(), () -> {
Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(AuctionHouse.getInstance(), () -> { if (Settings.RECORD_TRANSACTIONS.getBoolean()) {
if (Settings.RECORD_TRANSACTIONS.getBoolean()) { AuctionHouse.getInstance().getTransactionManager().addTransaction(new Transaction(
AuctionHouse.getInstance().getTransactionManager().addTransaction(new Transaction( UUID.randomUUID(),
UUID.randomUUID(), e.getOriginalOwner().getUniqueId(),
e.getOriginalOwner().getUniqueId(), e.getBuyer().getUniqueId(),
e.getBuyer().getUniqueId(), System.currentTimeMillis(),
System.currentTimeMillis(), e.getAuctionItem(),
e.getAuctionItem(), e.getSaleType()
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)); 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);
} }
} }

View File

@ -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 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 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 * 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); 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_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 * MAX AUCTION TIME
@ -188,7 +202,8 @@ public class Settings {
"&7Click here to view all of the items you", "&7Click here to view all of the items you",
"&7are currently selling on the auction.", "&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"); public static final ConfigSetting GUI_AUCTION_HOUSE_ITEMS_COLLECTION_BIN_ITEM = new ConfigSetting(config, "gui.auction house.items.collection bin.item", "ENDER_CHEST");

View File

@ -6,6 +6,8 @@ general:
cantbidonown: "&cYou cannot bid on your own item!" cantbidonown: "&cYou cannot bid on your own item!"
cantbuyown: "&cYou cannot buy your own item!" cantbuyown: "&cYou cannot buy your own item!"
blockeditem: "&cYou are not allowed to auction that item. (%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" air: "&cSorry, but you cannot sell air o.O"
blocked: "&cSorry, you are not allowed to sell &e%item%" blocked: "&cSorry, you are not allowed to sell &e%item%"
sellinglimit: "&cYou cannot sell more items, please remove/sell current active items" 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%" maxbaseprice: "&cThe maximum base price is &a$%price%"
maxstartingprice: "&cThe maximum starting bid price is &a$%price%" maxstartingprice: "&cThe maximum starting bid price is &a$%price%"
maxbidincrementprice: "&cThe maximum bid increment 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%" moneyremove: "&c&l- $%price%"
moneyadd: "&a&l+ $%price%" moneyadd: "&a&l+ $%price%"