From 5e2772a5f546b2444b673a9aa329e8ba13ed9c07 Mon Sep 17 00:00:00 2001 From: Kiran Hart Date: Tue, 11 May 2021 13:44:36 -0400 Subject: [PATCH] container changes --- .../auctionhouse/auction/AuctionItem.java | 74 ++++++------------- .../auctionhouse/guis/GUIAuctionHouse.java | 2 +- .../guis/GUIContainerInspect.java | 10 +-- .../auctionhouse/settings/Settings.java | 18 +++-- 4 files changed, 37 insertions(+), 67 deletions(-) diff --git a/src/main/java/ca/tweetzy/auctionhouse/auction/AuctionItem.java b/src/main/java/ca/tweetzy/auctionhouse/auction/AuctionItem.java index 49d4907..a0186e3 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/auction/AuctionItem.java +++ b/src/main/java/ca/tweetzy/auctionhouse/auction/AuctionItem.java @@ -2,6 +2,8 @@ package ca.tweetzy.auctionhouse.auction; import ca.tweetzy.auctionhouse.api.AuctionAPI; import ca.tweetzy.auctionhouse.settings.Settings; +import ca.tweetzy.core.compatibility.ServerVersion; +import ca.tweetzy.core.compatibility.XMaterial; import ca.tweetzy.core.utils.TextUtils; import ca.tweetzy.core.utils.nms.NBTEditor; import lombok.Getter; @@ -10,6 +12,7 @@ import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.WordUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -83,63 +86,28 @@ public class AuctionItem implements Serializable { String currentPrice = (this.bidStartPrice <= 0 || this.bidIncPrice <= 0) ? "0" : Settings.USE_SHORT_NUMBERS_ON_ITEMS.getBoolean() ? AuctionAPI.getInstance().getFriendlyNumber(this.currentPrice) : String.format("%,.2f", this.currentPrice); long[] times = AuctionAPI.getInstance().getRemainingTimeValues(this.remainingTime); + List preLore = type == AuctionStackType.MAIN_AUCTION_HOUSE ? this.bidStartPrice <= 0 || this.bidIncPrice <= 0 ? Settings.AUCTION_ITEM_AUCTION_STACK.getStringList() : Settings.AUCTION_ITEM_AUCTION_STACK_WITH_BID.getStringList() : this.bidStartPrice <= 0 ? Settings.AUCTION_ITEM_LISTING_STACK.getStringList() : Settings.AUCTION_ITEM_LISTING_STACK_WITH_BID.getStringList(); + + lore.addAll(preLore.stream().map(line -> TextUtils.formatText(line + .replace("%seller%", theSeller != null ? theSeller : "&eUnknown Seller") + .replace("%buynowprice%", basePrice) + .replace("%currentprice%", currentPrice) + .replace("%bidincrement%", bidIncPrice) + .replace("%highestbidder%", highestBidder) + .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])))).collect(Collectors.toList())); if (type == AuctionStackType.MAIN_AUCTION_HOUSE) { - if (this.bidStartPrice <= 0 || this.bidIncPrice <= 0) { - Settings.AUCTION_ITEM_AUCTION_STACK.getStringList().forEach(line -> { - lore.add(TextUtils.formatText(line - .replace("%seller%", theSeller != null ? theSeller : "&eUnknown Seller") - .replace("%buynowprice%", basePrice) - .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])) - )); - }); - } else { - Settings.AUCTION_ITEM_AUCTION_STACK_WITH_BID.getStringList().forEach(line -> { - lore.add(TextUtils.formatText(line - .replace("%seller%", theSeller != null ? theSeller : "&eUnknown Seller") - .replace("%buynowprice%", basePrice) - .replace("%currentprice%", currentPrice) - .replace("%bidincrement%", bidIncPrice) - .replace("%highestbidder%", highestBidder) - .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])) - )); - }); + lore.addAll(Settings.AUCTION_PURCHASE_CONTROL_HEADER.getStringList().stream().map(TextUtils::formatText).collect(Collectors.toList())); + lore.addAll(this.bidStartPrice <= 0 || this.bidIncPrice <= 0 ? Settings.AUCTION_PURCHASE_CONTROLS_BID_OFF.getStringList().stream().map(TextUtils::formatText).collect(Collectors.toList()) : Settings.AUCTION_PURCHASE_CONTROLS_BID_ON.getStringList().stream().map(TextUtils::formatText).collect(Collectors.toList())); + + if ((ServerVersion.isServerVersionAtLeast(ServerVersion.V1_11) && itemStack.getType() == XMaterial.SHULKER_BOX.parseMaterial()) || (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_14) && itemStack.getType() == XMaterial.SHULKER_BOX.parseMaterial() || itemStack.getType() == XMaterial.BARREL.parseMaterial())) { + lore.addAll(Settings.AUCTION_PURCHASE_CONTROLS_INSPECTION.getStringList().stream().map(TextUtils::formatText).collect(Collectors.toList())); } - lore.addAll(this.bidStartPrice <= 0 || this.bidIncPrice <= 0 ? Settings.AUCTION_PURCHASE_CONTROLS_BID_OFF.getStringList().stream().map(TextUtils::formatText).collect(Collectors.toList()) : Settings.AUCTION_PURCHASE_CONTROLS_BID_ON.getStringList().stream().map(TextUtils::formatText).collect(Collectors.toList())); - } else { - if (this.bidStartPrice <= 0) { - Settings.AUCTION_ITEM_LISTING_STACK.getStringList().forEach(line -> { - lore.add(TextUtils.formatText(line - .replace("%seller%", theSeller) - .replace("%buynowprice%", basePrice) - .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])) - )); - }); - } else { - Settings.AUCTION_ITEM_LISTING_STACK_WITH_BID.getStringList().forEach(line -> { - lore.add(TextUtils.formatText(line - .replace("%seller%", theSeller) - .replace("%buynowprice%", basePrice) - .replace("%currentprice%", currentPrice) - .replace("%bidincrement%", bidIncPrice) - .replace("%highestbidder%", highestBidder) - .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])) - )); - }); - } + lore.addAll(Settings.AUCTION_PURCHASE_CONTROL_FOOTER.getStringList().stream().map(TextUtils::formatText).collect(Collectors.toList())); } meta.setLore(lore); diff --git a/src/main/java/ca/tweetzy/auctionhouse/guis/GUIAuctionHouse.java b/src/main/java/ca/tweetzy/auctionhouse/guis/GUIAuctionHouse.java index 4a6401b..532c331 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/guis/GUIAuctionHouse.java +++ b/src/main/java/ca/tweetzy/auctionhouse/guis/GUIAuctionHouse.java @@ -216,7 +216,7 @@ public class GUIAuctionHouse extends Gui { break; case SHIFT_RIGHT: if (!ServerVersion.isServerVersionAtLeast(ServerVersion.V1_11)) return; - if (e.player.isOp() || e.player.hasPermission("auctionhouse.admin") || e.player.hasPermission("auctionhouse.inspectcontainer")) { + if (e.player.isOp() || e.player.hasPermission("auctionhouse.admin") || e.player.hasPermission("auctionhouse.inspectshulker")) { ItemStack clicked = e.clickedItem; if (!(clicked.getItemMeta() instanceof BlockStateMeta)) return; diff --git a/src/main/java/ca/tweetzy/auctionhouse/guis/GUIContainerInspect.java b/src/main/java/ca/tweetzy/auctionhouse/guis/GUIContainerInspect.java index 1e834d9..9e64744 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/guis/GUIContainerInspect.java +++ b/src/main/java/ca/tweetzy/auctionhouse/guis/GUIContainerInspect.java @@ -20,15 +20,15 @@ import java.util.Arrays; public class GUIContainerInspect extends Gui { final int[] fillSlots = {0, 1, 2, 3, 4, 5, 6, 7, 8, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 46, 47, 48, 50, 51, 52, 53}; - final ItemStack container; + final ItemStack shulker; /** * Used to inspect a shulker box from it's item stack. * - * @param container is the shulker box + * @param shulker is the shulker box */ - public GUIContainerInspect(ItemStack container) { - this.container = container; + public GUIContainerInspect(ItemStack shulker) { + this.shulker = shulker; setTitle(TextUtils.formatText(Settings.GUI_SHULKER_INSPECT_TITLE.getString())); setDefaultItem(Settings.GUI_SHULKER_INSPECT_BG_ITEM.getMaterial().parseItem()); setUseLockedCells(false); @@ -45,7 +45,7 @@ public class GUIContainerInspect extends Gui { for (int i : fillSlots) setItem(i, getDefaultItem()); setButton(5, 4, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_CLOSE_BTN_ITEM.getString(), Settings.GUI_CLOSE_BTN_NAME.getString(), Settings.GUI_CLOSE_BTN_LORE.getStringList(), null), e -> e.manager.showGUI(e.player, new GUIAuctionHouse(AuctionHouse.getInstance().getAuctionPlayerManager().getPlayer(e.player.getUniqueId())))); - BlockStateMeta meta = (BlockStateMeta) this.container.getItemMeta(); + BlockStateMeta meta = (BlockStateMeta) this.shulker.getItemMeta(); ShulkerBox skulkerBox = (ShulkerBox) meta.getBlockState(); int slot = 9; diff --git a/src/main/java/ca/tweetzy/auctionhouse/settings/Settings.java b/src/main/java/ca/tweetzy/auctionhouse/settings/Settings.java index 24f67a1..2f2f1bd 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/settings/Settings.java +++ b/src/main/java/ca/tweetzy/auctionhouse/settings/Settings.java @@ -341,11 +341,12 @@ public class Settings { )); /* =============================== - * MAIN AUCTION GUI + * INSPECTION GUI * ===============================*/ public static final ConfigSetting GUI_SHULKER_INSPECT_TITLE = new ConfigSetting(config, "gui.shulker inspect.title", "&7&LInspecting Shulker Box"); public static final ConfigSetting GUI_SHULKER_INSPECT_BG_ITEM = new ConfigSetting(config, "gui.shulker inspect.bg item", XMaterial.BLACK_STAINED_GLASS_PANE.name()); + /* =============================== * AUCTION STACKS * ===============================*/ @@ -385,19 +386,20 @@ public class Settings { "&eTime Left: &b%remaining_days%&fd &b%remaining_hours%&fh &b%remaining_minutes%&fm &b%remaining_seconds%s" ), "This the item stack lore that will be appended to", "auction items in /ah listings (lore will be applied first, then these)"); + public static final ConfigSetting AUCTION_PURCHASE_CONTROL_HEADER = new ConfigSetting(config, "auction items.controls.header", Collections.singletonList("&7-------------------------")); + public static final ConfigSetting AUCTION_PURCHASE_CONTROL_FOOTER = new ConfigSetting(config, "auction items.controls.footer", Collections.singletonList("&7-------------------------")); + public static final ConfigSetting AUCTION_PURCHASE_CONTROLS_BID_ON = new ConfigSetting(config, "auction items.controls.using bid", Arrays.asList( - "&7-------------------------", "&eLeft-Click&f: &bBid", - "&eRight-Click&f: &bBuy Now", - "&7-------------------------" + "&eRight-Click&f: &bBuy Now" ), "This will be appended at the end of the lore", "If the auction item is using a bid, this will show"); - public static final ConfigSetting AUCTION_PURCHASE_CONTROLS_BID_OFF = new ConfigSetting(config, "auction items.controls.not using bid", Arrays.asList( - "&7-------------------------", - "&eLeft-Click&f: &bBuy Now", - "&7-------------------------" + public static final ConfigSetting AUCTION_PURCHASE_CONTROLS_BID_OFF = new ConfigSetting(config, "auction items.controls.not using bid", Collections.singletonList( + "&eLeft-Click&f: &bBuy Now" ), "This will be appended at the end of the lore", "If the auction item is not using a bid, this will show"); + public static final ConfigSetting AUCTION_PURCHASE_CONTROLS_INSPECTION = new ConfigSetting(config, "auction items.controls.inspection", Collections.singletonList("&eShift Right-Click to inspect"), "This will only be added to the control lore if the item can be inspected (skulker box or barrel)"); + /* =============================== * AUCTION STACKS * ===============================*/