From f58dc02dce7a6b67050c3815ba92f7c333aa0693 Mon Sep 17 00:00:00 2001 From: Kiran Hart Date: Wed, 4 Sep 2024 13:59:55 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=8C=9F=20auction=20stack=20lore=20customi?= =?UTF-8?q?zation=20options,=20add=20translation=20for=20to=20currency=20l?= =?UTF-8?q?ore?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Took 32 minutes --- .../auctionhouse/auction/AuctionedItem.java | 95 ++++++++++--------- .../guis/selector/GUICurrencyPicker.java | 6 +- .../auctionhouse/model/MultiVarReplacer.java | 34 +++++++ .../auctionhouse/settings/Settings.java | 38 ++++++-- 4 files changed, 115 insertions(+), 58 deletions(-) create mode 100644 src/main/java/ca/tweetzy/auctionhouse/model/MultiVarReplacer.java diff --git a/src/main/java/ca/tweetzy/auctionhouse/auction/AuctionedItem.java b/src/main/java/ca/tweetzy/auctionhouse/auction/AuctionedItem.java index 2aec242..4a62fa2 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/auction/AuctionedItem.java +++ b/src/main/java/ca/tweetzy/auctionhouse/auction/AuctionedItem.java @@ -31,6 +31,7 @@ import ca.tweetzy.flight.comp.enums.ServerVersion; import ca.tweetzy.flight.nbtapi.NBT; import ca.tweetzy.flight.utils.Common; import ca.tweetzy.flight.utils.QuickItem; +import ca.tweetzy.flight.utils.Replacer; import lombok.Getter; import lombok.NonNull; import lombok.Setter; @@ -43,6 +44,8 @@ import java.util.List; import java.util.UUID; import java.util.stream.Collectors; +import static ca.tweetzy.auctionhouse.model.MultiVarReplacer.replaceVariable; + /** * The current file has been created by Kiran Hart * Date Created: July 29 2021 @@ -222,91 +225,93 @@ public class AuctionedItem { QuickItem itemStack = QuickItem.of(this.item.clone()); itemStack.amount(Math.max(this.item.getAmount(), 1)); - List lore = new ArrayList<>(); + List originalLore = this.item.getItemMeta() != null && this.item.getItemMeta().getLore() != null ? this.item.getItemMeta().getLore() : new ArrayList<>(); + List BASE_LORE = Settings.AUCTION_STACK_INFO_LAYOUT.getStringList(); + itemStack.clearLore(); if (this.serverItem) this.ownerName = AuctionHouse.getInstance().getLocale().getMessage("general.server listing").getMessage(); - lore.addAll(TextUtils.formatText(Settings.AUCTION_STACK_DETAILS_HEADER.getStringList())); - lore.addAll(TextUtils.formatText(Settings.AUCTION_STACK_DETAILS_SELLER.getStringList().stream().map(s -> s.replace("%seller%", this.ownerName)).collect(Collectors.toList()))); + final List HEADER = Common.colorize(Settings.AUCTION_STACK_DETAILS_HEADER.getStringList()); + final List CONTROLS_HEADER = Common.colorize(Settings.AUCTION_STACK_PURCHASE_CONTROL_HEADER.getStringList()); + final List CONTROLS_FOOTER = Common.colorize(Settings.AUCTION_STACK_PURCHASE_CONTROL_FOOTER.getStringList()); - if (this.basePrice != -1) { - lore.addAll(TextUtils.formatText(Settings.AUCTION_STACK_DETAILS_BUY_NOW.getStringList().stream().filter(s -> this.isBidItem ? s.length() != 0 : s.length() >= 0).map(s -> s.replace("%buynowprice%", getFormattedBasePrice())).collect(Collectors.toList()))); - } + final List SELLER = Common.colorize(Replacer.replaceVariables(Settings.AUCTION_STACK_DETAILS_SELLER.getStringList(), "seller", this.ownerName)); + final List BUY_NOW_PRICE = Replacer.replaceVariables(Settings.AUCTION_STACK_DETAILS_BUY_NOW.getStringList(), "buynowprice", getFormattedBasePrice()); + final List CURRENT_PRICE = Replacer.replaceVariables(Settings.AUCTION_STACK_DETAILS_CURRENT_PRICE.getStringList(), "currentprice", getFormattedCurrentPrice()); + final List INCREMENT_PRICE = Replacer.replaceVariables(Settings.AUCTION_STACK_DETAILS_BID_INCREMENT.getStringList(), "bidincrement", getFormattedIncrementPrice()); + final List HIGHEST_BIDDER = Replacer.replaceVariables(Settings.AUCTION_STACK_DETAILS_HIGHEST_BIDDER.getStringList(), "highestbidder", this.highestBidder.equals(this.owner) ? AuctionHouse.getInstance().getLocale().getMessage("auction.nobids").getMessage() : this.highestBidderName); - if (this.isBidItem) { - lore.addAll(TextUtils.formatText(Settings.AUCTION_STACK_DETAILS_CURRENT_PRICE.getStringList().stream().map(s -> s.replace("%currentprice%", AuctionHouse.getAPI().getFinalizedCurrencyNumber(this.currentPrice, this.currency, this.currencyItem))).collect(Collectors.toList()))); - if (!Settings.FORCE_CUSTOM_BID_AMOUNT.getBoolean()) { - lore.addAll(TextUtils.formatText(Settings.AUCTION_STACK_DETAILS_BID_INCREMENT.getStringList().stream().map(s -> s.replace("%bidincrement%", AuctionHouse.getAPI().getFinalizedCurrencyNumber(this.bidIncrementPrice, this.currency, this.currencyItem))).collect(Collectors.toList()))); - } - - if (Settings.FORCE_CUSTOM_BID_AMOUNT.getBoolean() && Settings.USE_REALISTIC_BIDDING.getBoolean()) { - lore.addAll(TextUtils.formatText(Settings.AUCTION_STACK_DETAILS_BID_INCREMENT.getStringList().stream().map(s -> s.replace("%bidincrement%", AuctionHouse.getAPI().getFinalizedCurrencyNumber(this.bidIncrementPrice, this.currency, this.currencyItem))).collect(Collectors.toList()))); - } - - lore.addAll(TextUtils.formatText(Settings.AUCTION_STACK_DETAILS_HIGHEST_BIDDER.getStringList().stream().map(s -> s.replace("%highestbidder%", this.highestBidder.equals(this.owner) ? AuctionHouse.getInstance().getLocale().getMessage("auction.nobids").getMessage() : this.highestBidderName)).collect(Collectors.toList()))); - } - - if (this.infinite) { - lore.addAll(TextUtils.formatText(Settings.AUCTION_STACK_DETAILS_INFINITE.getStringList())); - } else { + List LISTING_TIME = Settings.AUCTION_STACK_DETAILS_INFINITE.getStringList(); + if (!this.isInfinite()) { long[] times = AuctionAPI.getInstance().getRemainingTimeValues((this.expiresAt - System.currentTimeMillis()) / 1000); - lore.addAll(TextUtils.formatText(Settings.AUCTION_STACK_DETAILS_TIME_LEFT.getStringList().stream().map(s -> s - .replace("%remaining_days%", String.valueOf(times[0])) - .replace("%remaining_hours%", String.valueOf(times[1])) - .replace("%remaining_minutes%", String.valueOf(times[2])) - .replace("%remaining_seconds%", String.valueOf(times[3])) - .replace("%remaining_total_hours%", String.valueOf(((this.expiresAt - System.currentTimeMillis()) / 1000) / 3600)) - ).collect(Collectors.toList()))); + LISTING_TIME = Replacer.replaceVariables(Settings.AUCTION_STACK_DETAILS_TIME_LEFT.getStringList(), + "remaining_days", String.valueOf(times[0]), + "remaining_hours", String.valueOf(times[1]), + "remaining_minutes", String.valueOf(times[2]), + "remaining_seconds", String.valueOf(times[3]), + "remaining_total_hours", String.valueOf(((this.expiresAt - System.currentTimeMillis()) / 1000) / 3600) + ); } - if (isListingPriorityActive()) - lore.addAll(Common.colorize(Settings.AUCTION_STACK_DETAILS_PRIORITY_LISTING.getStringList())); - - lore.addAll(TextUtils.formatText(Settings.AUCTION_STACK_PURCHASE_CONTROL_HEADER.getStringList())); + final List LISTING_PRIORITY = Settings.AUCTION_STACK_DETAILS_PRIORITY_LISTING.getStringList(); + final List CONTROLS = new ArrayList<>(); if (type == AuctionStackType.MAIN_AUCTION_HOUSE) { if (this.isBidItem) { if (this.basePrice != -1) { - lore.addAll(TextUtils.formatText(Settings.AUCTION_STACK_PURCHASE_CONTROLS_BID_ON.getStringList())); + CONTROLS.addAll(Common.colorize(Settings.AUCTION_STACK_PURCHASE_CONTROLS_BID_ON.getStringList())); } else { - lore.addAll(TextUtils.formatText(Settings.AUCTION_STACK_PURCHASE_CONTROLS_BID_ON_NO_BUY_NOW.getStringList())); + CONTROLS.addAll(Common.colorize(Settings.AUCTION_STACK_PURCHASE_CONTROLS_BID_ON_NO_BUY_NOW.getStringList())); } } else { - lore.addAll(TextUtils.formatText(Settings.AUCTION_STACK_PURCHASE_CONTROLS_BID_OFF.getStringList())); + CONTROLS.addAll(Common.colorize(Settings.AUCTION_STACK_PURCHASE_CONTROLS_BID_OFF.getStringList())); if (this.isAllowPartialBuy()) { - lore.addAll(TextUtils.formatText(Settings.AUCTION_STACK_PURCHASE_CONTROLS_PARTIAL_BUY.getStringList())); + CONTROLS.addAll(Common.colorize(Settings.AUCTION_STACK_PURCHASE_CONTROLS_PARTIAL_BUY.getStringList())); } } if (BundleUtil.isBundledItem(this.item.clone()) || (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_11) && this.item.clone().getType().name().contains("SHULKER_BOX"))) { - lore.addAll(TextUtils.formatText(Settings.AUCTION_STACK_PURCHASE_CONTROLS_INSPECTION.getStringList())); + CONTROLS.addAll(Common.colorize(Settings.AUCTION_STACK_PURCHASE_CONTROLS_INSPECTION.getStringList())); } } else { if (type == AuctionStackType.HIGHEST_BID_PREVIEW) { - lore.addAll(TextUtils.formatText(Settings.AUCTION_STACK_HIGHEST_BIDDER_ITEM.getStringList())); + CONTROLS.addAll(Common.colorize(Settings.AUCTION_STACK_HIGHEST_BIDDER_ITEM.getStringList())); } else { if (type == AuctionStackType.LISTING_PREVIEW) { - lore.addAll(TextUtils.formatText(Settings.AUCTION_STACK_LISTING_PREVIEW_ITEM.getStringList())); + CONTROLS.addAll(Common.colorize(Settings.AUCTION_STACK_LISTING_PREVIEW_ITEM.getStringList())); } else { - lore.addAll(TextUtils.formatText(Settings.AUCTION_STACK_PURCHASE_CONTROLS_CANCEL_ITEM.getStringList())); + CONTROLS.addAll(Common.colorize(Settings.AUCTION_STACK_PURCHASE_CONTROLS_CANCEL_ITEM.getStringList())); if (Settings.ALLOW_PLAYERS_TO_ACCEPT_BID.getBoolean() && this.bidStartingPrice >= 1 || this.bidIncrementPrice >= 1) { if (!this.owner.equals(this.highestBidder)) { - lore.addAll(TextUtils.formatText(Settings.AUCTION_STACK_PURCHASE_CONTROLS_ACCEPT_BID.getStringList())); + CONTROLS.addAll(Common.colorize(Settings.AUCTION_STACK_PURCHASE_CONTROLS_ACCEPT_BID.getStringList())); } } if (Settings.LISTING_PRIORITY_ENABLED.getBoolean()) { - lore.addAll(Common.colorize(Settings.AUCTION_STACK_PURCHASE_CONTROLS_PRIORITY_LISTING.getStringList())); + CONTROLS.addAll(Common.colorize(Settings.AUCTION_STACK_PURCHASE_CONTROLS_PRIORITY_LISTING.getStringList())); } } } } - lore.addAll(TextUtils.formatText(Settings.AUCTION_STACK_PURCHASE_CONTROL_FOOTER.getStringList())); - itemStack.lore(player, lore); + // replace all the variables + replaceVariable(BASE_LORE, "%original_item_lore%", originalLore, false); + replaceVariable(BASE_LORE, "%header%", HEADER, false); + replaceVariable(BASE_LORE, "%seller%", SELLER, false); + replaceVariable(BASE_LORE, "%highest_bidder%", HIGHEST_BIDDER, !this.isBidItem); + replaceVariable(BASE_LORE, "%buy_now_price%", BUY_NOW_PRICE, this.basePrice == -1); + replaceVariable(BASE_LORE, "%current_price%", CURRENT_PRICE, !this.isBidItem); + replaceVariable(BASE_LORE, "%bid_increment%", INCREMENT_PRICE, !this.isBidItem || Settings.FORCE_CUSTOM_BID_AMOUNT.getBoolean()); + replaceVariable(BASE_LORE, "%listing_time%", LISTING_TIME, false); + replaceVariable(BASE_LORE, "%listing_priority%", LISTING_PRIORITY, !this.hasListingPriority); + replaceVariable(BASE_LORE, "%controls_header%", CONTROLS_HEADER, false); + replaceVariable(BASE_LORE, "%controls_footer%", CONTROLS_FOOTER, false); + replaceVariable(BASE_LORE, "%controls%", CONTROLS, false); + + itemStack.lore(player, BASE_LORE); return itemStack.make(); } diff --git a/src/main/java/ca/tweetzy/auctionhouse/guis/selector/GUICurrencyPicker.java b/src/main/java/ca/tweetzy/auctionhouse/guis/selector/GUICurrencyPicker.java index f9b7eca..fe9af53 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/guis/selector/GUICurrencyPicker.java +++ b/src/main/java/ca/tweetzy/auctionhouse/guis/selector/GUICurrencyPicker.java @@ -87,11 +87,7 @@ public final class GUICurrencyPicker extends AuctionPagedGUI { quickItem.name(currency.getCurrencyName().equalsIgnoreCase("vault") ? "&a" + Settings.CURRENCY_VAULT_SYMBOL.getString() : "&e" + currency.getCurrencyName()); } - quickItem.lore(Replacer.replaceVariables(Arrays.asList( - "&7Owning Plugin&f: &e%currency_owning_plugin%", - "", - "&a&lLeft Click &7to select this currency" - ), "currency_owning_plugin", currency.getOwningPlugin())); + quickItem.lore(Replacer.replaceVariables(Settings.GUI_CURRENCY_PICKER_ITEMS_CURRENCY_LORE .getStringList(), "currency_owning_plugin", currency.getOwningPlugin())); return quickItem.make(); } diff --git a/src/main/java/ca/tweetzy/auctionhouse/model/MultiVarReplacer.java b/src/main/java/ca/tweetzy/auctionhouse/model/MultiVarReplacer.java new file mode 100644 index 0000000..a8a8488 --- /dev/null +++ b/src/main/java/ca/tweetzy/auctionhouse/model/MultiVarReplacer.java @@ -0,0 +1,34 @@ +package ca.tweetzy.auctionhouse.model; + +import lombok.NonNull; + +import java.util.List; + +public final class MultiVarReplacer { + + public static List replaceVariable(@NonNull List originalList, final String variable, Object replacement, boolean removeVariable) { + final int varIndex = originalList.indexOf(variable); + + if (varIndex == -1) { + return originalList; + } + + if (removeVariable) { + originalList.remove(varIndex); + return originalList; + } + + if (replacement instanceof String) { + String string = (String) replacement; + originalList.set(varIndex, string); + originalList.removeIf(line -> line.equalsIgnoreCase(variable)); + } + + if (replacement instanceof List) { + originalList.addAll(varIndex, (List) replacement); + originalList.removeIf(line -> line.equalsIgnoreCase(variable)); + } + + return originalList; + } +} diff --git a/src/main/java/ca/tweetzy/auctionhouse/settings/Settings.java b/src/main/java/ca/tweetzy/auctionhouse/settings/Settings.java index 230c4db..a5e671c 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/settings/Settings.java +++ b/src/main/java/ca/tweetzy/auctionhouse/settings/Settings.java @@ -49,8 +49,7 @@ public class Settings { public static final ConfigSetting CURRENCY_FORMAT_LANGUAGE = new ConfigSetting(config, "economy.currency.format.language", "en", "An ISO 639 alpha-2 or alpha-3 language code."); public static final ConfigSetting CURRENCY_FORMAT_COUNTRY = new ConfigSetting(config, "economy.currency.format.country", "US", "An ISO 3166 alpha-2 country code or a UN M.49 numeric-3 area code."); public static final ConfigSetting CURRENCY_ABBREVIATE_NUMBERS = new ConfigSetting(config, "economy.currency.abbreviate numbers", false, "Should numbers be abbreviated?. Example: 123,000 will become 123k "); - - + public static final ConfigSetting CMD_ALIAS_MAIN = new ConfigSetting(config, "command aliases.main", Arrays.asList("ah", "auctions", "auctionhouses", "ahgui", "auctiongui"), "Command aliases for the main command"); public static final ConfigSetting CMD_ALIAS_SUB_ACTIVE = new ConfigSetting(config, "command aliases.subcommands.active", Collections.singletonList("active"), "Command aliases for the active command"); public static final ConfigSetting CMD_ALIAS_SUB_ADMIN = new ConfigSetting(config, "command aliases.subcommands.admin", Collections.singletonList("admin"), "Command aliases for the admin command"); @@ -542,6 +541,13 @@ public class Settings { ) ); + public static final ConfigSetting GUI_CURRENCY_PICKER_ITEMS_CURRENCY_LORE = new ConfigSetting(config, "gui.currency picker.items.currency.lore", + Collections.singletonList( + "&e&lClick &7to select this currency" + ), + "You can use %owning_plugin% to get the plugin name" + ); + // material picker public static final ConfigSetting GUI_MATERIAL_PICKER_TITLE = new ConfigSetting(config, "gui.material picker.title", "&7Auction House &f- &ePick an Item"); public static final ConfigSetting GUI_MATERIAL_PICKER_ITEMS_MATERIAL_LORE = new ConfigSetting(config, "gui.material picker.items.material.lore", "&7Click to select this item"); @@ -1503,8 +1509,7 @@ public class Settings { * ===============================*/ public static final ConfigSetting AUCTION_STACK_DETAILS_HEADER = new ConfigSetting(config, "auction stack.header", Collections.singletonList("&7&m-------------------------")); public static final ConfigSetting AUCTION_STACK_DETAILS_SELLER = new ConfigSetting(config, "auction stack.seller lines", Arrays.asList( - "&eSeller&f: &b%seller%", - "" + "&eSeller&f: &b%seller%" )); public static final ConfigSetting AUCTION_STACK_DETAILS_REQUESTER = new ConfigSetting(config, "auction stack.requester lines", Arrays.asList( @@ -1521,8 +1526,7 @@ public class Settings { )); public static final ConfigSetting AUCTION_STACK_DETAILS_BUY_NOW = new ConfigSetting(config, "auction stack.buy now lines", Arrays.asList( - "&eBuy Now: &a%buynowprice%", - "" + "&eBuy Now: &a%buynowprice%" )); public static final ConfigSetting AUCTION_STACK_DETAILS_CURRENT_PRICE = new ConfigSetting(config, "auction stack.current price lines", Collections.singletonList( @@ -1542,12 +1546,10 @@ public class Settings { )); public static final ConfigSetting AUCTION_STACK_DETAILS_TIME_LEFT = new ConfigSetting(config, "auction stack.time left lines", Arrays.asList( - "", "&eTime Left: &b%remaining_days%&fd &b%remaining_hours%&fh &b%remaining_minutes%&fm &b%remaining_seconds%s" )); public static final ConfigSetting AUCTION_STACK_DETAILS_INFINITE = new ConfigSetting(config, "auction stack.infinite lines", Arrays.asList( - "", "&eTime Left: &bNo Expiration" ), "this will be used instead of the time left if the item is infinite"); @@ -1583,6 +1585,26 @@ public class Settings { "&eShift Left-Click&f: &bBuy Quantity" ), "This will be appended at the end of the lore", "If the auction item allows partial buys, this will be added"); + + public static final ConfigSetting AUCTION_STACK_INFO_LAYOUT = new ConfigSetting(config, "auction stack.info layout", Arrays.asList( + "%original_item_lore%", + "%header%", + "%seller%", + "%highest_bidder%", + "", + "%buy_now_price%", + "%current_price%", + "%bid_increment%", + "", + "%listing_time%", + "%listing_priority%", + "%controls_header%", + "%controls%", + "%controls_footer%" + ), "The info order for the stacks, if a listing doesnt require one of these, Auction House will just ignore it.", "This is mainly used to just change the ordering of listing stack information"); + + + /* =============================== * AUCTION SOUNDS * ===============================*/