From 5d34619cf714948837d2a43a291a8c980e7ce7ec Mon Sep 17 00:00:00 2001 From: Tanguygab Date: Tue, 19 Nov 2024 18:01:01 +0100 Subject: [PATCH 1/3] Added hide_tooltip, enchantment_glint_override, rarity, tooltip_style and item_model --- gradle/libs.versions.toml | 2 +- .../deluxemenus/config/DeluxeMenusConfig.java | 7 +- .../deluxemenus/menu/MenuItem.java | 35 ++++++++++ .../menu/options/MenuItemOptions.java | 67 +++++++++++++++++++ .../deluxemenus/utils/VersionHelper.java | 7 ++ 5 files changed, 116 insertions(+), 2 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 68878e4..d5d5576 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,6 +1,6 @@ [versions] # Compile only -spigot = "1.21-R0.1-SNAPSHOT" +spigot = "1.21.3-R0.1-SNAPSHOT" vault = "1.7.1" authlib = "1.5.25" headdb = "1.3.1" diff --git a/src/main/java/com/extendedclip/deluxemenus/config/DeluxeMenusConfig.java b/src/main/java/com/extendedclip/deluxemenus/config/DeluxeMenusConfig.java index d7e24d7..fa04ec9 100644 --- a/src/main/java/com/extendedclip/deluxemenus/config/DeluxeMenusConfig.java +++ b/src/main/java/com/extendedclip/deluxemenus/config/DeluxeMenusConfig.java @@ -762,7 +762,12 @@ private Map> loadMenuItems(FileConfiguration .nbtInt(c.getString(currentPath + "nbt_int", null)) .nbtStrings(c.getStringList(currentPath + "nbt_strings")) .nbtInts(c.getStringList(currentPath + "nbt_ints")) - .priority(c.getInt(currentPath + "priority", 1)); + .priority(c.getInt(currentPath + "priority", 1)) + .hideTooltip(c.getString(currentPath + "hide_tooltip", null)) + .enchantmentGlintOverride(c.getString(currentPath + "enchantment_glint_override", null)) + .rarity(c.getString(currentPath + "rarity", null)) + .tooltipStyle(c.getString(currentPath + "tooltip_style", null)) + .itemModel(c.getString(currentPath + "item_model", null)); // Lore Append Mode if (c.contains(currentPath + "lore_append_mode")) { diff --git a/src/main/java/com/extendedclip/deluxemenus/menu/MenuItem.java b/src/main/java/com/extendedclip/deluxemenus/menu/MenuItem.java index be8224f..b63716e 100644 --- a/src/main/java/com/extendedclip/deluxemenus/menu/MenuItem.java +++ b/src/main/java/com/extendedclip/deluxemenus/menu/MenuItem.java @@ -14,12 +14,14 @@ import org.bukkit.FireworkEffect; import org.bukkit.Material; import org.bukkit.Registry; +import org.bukkit.NamespacedKey; import org.bukkit.block.Banner; import org.bukkit.block.data.BlockData; import org.bukkit.block.data.type.Light; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemFlag; +import org.bukkit.inventory.ItemRarity; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ArmorMeta; import org.bukkit.inventory.meta.BannerMeta; @@ -259,6 +261,39 @@ public ItemStack getItemStack(@NotNull final MenuHolder holder) { itemMeta.setUnbreakable(true); } + if (VersionHelper.HAS_DATA_COMPONENTS) { + if (this.options.hideTooltip().isPresent()) { + String hideTooltip = holder.setPlaceholdersAndArguments(this.options.hideTooltip().get()); + itemMeta.setHideTooltip(Boolean.parseBoolean(hideTooltip)); + } + if (this.options.enchantmentGlintOverride().isPresent()) { + String enchantmentGlintOverride = holder.setPlaceholdersAndArguments(this.options.enchantmentGlintOverride().get()); + itemMeta.setEnchantmentGlintOverride(Boolean.parseBoolean(enchantmentGlintOverride)); + } + if (this.options.rarity().isPresent()) { + String rarity = holder.setPlaceholdersAndArguments(this.options.rarity().get()); + try { + itemMeta.setRarity(ItemRarity.valueOf(rarity.toUpperCase())); + } catch (IllegalArgumentException e) { + DeluxeMenus.debug( + DebugLevel.HIGHEST, + Level.WARNING, + "Rarity " + rarity + " is not a valid!" + ); + } + } + } + if (VersionHelper.HAS_TOOLTIP_STYLE) { + if (this.options.tooltipStyle().isPresent()) { + NamespacedKey tooltipStyle = NamespacedKey.fromString(this.options.tooltipStyle().get()); + if (tooltipStyle != null) itemMeta.setTooltipStyle(tooltipStyle); + } + if (this.options.itemModel().isPresent()) { + NamespacedKey itemModel = NamespacedKey.fromString(this.options.itemModel().get()); + if (itemModel != null) itemMeta.setItemModel(itemModel); + } + } + if (VersionHelper.HAS_ARMOR_TRIMS && ItemUtils.hasArmorMeta(itemStack)) { final Optional trimMaterialName = this.options.trimMaterial(); final Optional trimPatternName = this.options.trimPattern(); diff --git a/src/main/java/com/extendedclip/deluxemenus/menu/options/MenuItemOptions.java b/src/main/java/com/extendedclip/deluxemenus/menu/options/MenuItemOptions.java index 3c0400e..13dc63f 100644 --- a/src/main/java/com/extendedclip/deluxemenus/menu/options/MenuItemOptions.java +++ b/src/main/java/com/extendedclip/deluxemenus/menu/options/MenuItemOptions.java @@ -37,6 +37,12 @@ public class MenuItemOptions { private final String trimMaterial; private final String trimPattern; + private final String hideTooltip; + private final String enchantmentGlintOverride; + private final String rarity; + private final String tooltipStyle; + private final String itemModel; + private final Map enchantments; private final List potionEffects; private final List bannerMeta; @@ -89,6 +95,11 @@ private MenuItemOptions(final @NotNull MenuItemOptionsBuilder builder) { this.rgb = builder.rgb; this.trimMaterial = builder.trimMaterial; this.trimPattern = builder.trimPattern; + this.hideTooltip = builder.hideTooltip; + this.enchantmentGlintOverride = builder.enchantmentGlintOverride; + this.rarity = builder.rarity; + this.tooltipStyle = builder.tooltipStyle; + this.itemModel = builder.itemModel; this.enchantments = builder.enchantments; this.potionEffects = builder.potionEffects; this.bannerMeta = builder.bannerMeta; @@ -178,6 +189,26 @@ public void headType(final @Nullable HeadType headType) { return Optional.ofNullable(trimPattern); } + public @NotNull Optional hideTooltip() { + return Optional.ofNullable(hideTooltip); + } + + public @NotNull Optional enchantmentGlintOverride() { + return Optional.ofNullable(enchantmentGlintOverride); + } + + public @NotNull Optional rarity() { + return Optional.ofNullable(rarity); + } + + public @NotNull Optional tooltipStyle() { + return Optional.ofNullable(tooltipStyle); + } + + public @NotNull Optional itemModel() { + return Optional.ofNullable(itemModel); + } + public @NotNull Map enchantments() { return enchantments; } @@ -311,6 +342,11 @@ public boolean updatePlaceholders() { .rgb(this.rgb) .trimMaterial(this.trimMaterial) .trimPattern(this.trimPattern) + .hideTooltip(this.hideTooltip) + .enchantmentGlintOverride(this.enchantmentGlintOverride) + .rarity(this.rarity) + .tooltipStyle(this.tooltipStyle) + .itemModel(this.itemModel) .enchantments(this.enchantments) .potionEffects(this.potionEffects) .bannerMeta(this.bannerMeta) @@ -355,6 +391,12 @@ public static class MenuItemOptionsBuilder { private String trimMaterial; private String trimPattern; + private String hideTooltip; + private String enchantmentGlintOverride; + private String rarity; + private String tooltipStyle; + private String itemModel; + private Map enchantments = Collections.emptyMap(); private List potionEffects = Collections.emptyList(); private List bannerMeta = Collections.emptyList(); @@ -463,6 +505,31 @@ public MenuItemOptionsBuilder trimPattern(final @Nullable String trimPattern) { return this; } + public MenuItemOptionsBuilder hideTooltip(final @Nullable String hideTooltip) { + this.hideTooltip = hideTooltip; + return this; + } + + public MenuItemOptionsBuilder enchantmentGlintOverride(final @Nullable String enchantmentGlintOverride) { + this.enchantmentGlintOverride = enchantmentGlintOverride; + return this; + } + + public MenuItemOptionsBuilder rarity(final @Nullable String rarity) { + this.rarity = rarity; + return this; + } + + public MenuItemOptionsBuilder tooltipStyle(final @Nullable String tooltipStyle) { + this.tooltipStyle = tooltipStyle; + return this; + } + + public MenuItemOptionsBuilder itemModel(final @Nullable String itemModel) { + this.itemModel = itemModel; + return this; + } + public MenuItemOptionsBuilder enchantments(final @NotNull Map enchantments) { this.enchantments = enchantments; return this; diff --git a/src/main/java/com/extendedclip/deluxemenus/utils/VersionHelper.java b/src/main/java/com/extendedclip/deluxemenus/utils/VersionHelper.java index 49b239e..a82924b 100644 --- a/src/main/java/com/extendedclip/deluxemenus/utils/VersionHelper.java +++ b/src/main/java/com/extendedclip/deluxemenus/utils/VersionHelper.java @@ -21,6 +21,8 @@ public final class VersionHelper { private static final String PACKAGE_NAME = Bukkit.getServer().getClass().getPackage().getName(); public static final String NMS_VERSION = PACKAGE_NAME.substring(PACKAGE_NAME.lastIndexOf('.') + 1); + // Tooltip Visibility, Style & Rarity + private static final int V1_21_2 = 1_21_2; // Data components private static final int V1_20_5 = 1_20_5; // ArmorTrims @@ -44,6 +46,11 @@ public final class VersionHelper { private static final boolean IS_PAPER = checkPaper(); + /** + * Checks if the current version includes the ArmorTrims API + */ + public static final boolean HAS_TOOLTIP_STYLE = CURRENT_VERSION >= V1_21_2; + /** * Checks if the current version includes the Data Components */ From 0cd983a54e3144d4607e6432390c5cc0dd169f07 Mon Sep 17 00:00:00 2001 From: Tanguygab Date: Tue, 19 Nov 2024 21:34:10 +0100 Subject: [PATCH 2/3] Updated HAS_TOOLTIP_STYLE comment --- .../com/extendedclip/deluxemenus/utils/VersionHelper.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/extendedclip/deluxemenus/utils/VersionHelper.java b/src/main/java/com/extendedclip/deluxemenus/utils/VersionHelper.java index a82924b..08e0d68 100644 --- a/src/main/java/com/extendedclip/deluxemenus/utils/VersionHelper.java +++ b/src/main/java/com/extendedclip/deluxemenus/utils/VersionHelper.java @@ -21,7 +21,7 @@ public final class VersionHelper { private static final String PACKAGE_NAME = Bukkit.getServer().getClass().getPackage().getName(); public static final String NMS_VERSION = PACKAGE_NAME.substring(PACKAGE_NAME.lastIndexOf('.') + 1); - // Tooltip Visibility, Style & Rarity + // Tooltip Style & Item Model private static final int V1_21_2 = 1_21_2; // Data components private static final int V1_20_5 = 1_20_5; @@ -47,7 +47,7 @@ public final class VersionHelper { private static final boolean IS_PAPER = checkPaper(); /** - * Checks if the current version includes the ArmorTrims API + * Checks if the current version includes the setTooltipStyle and setItemModel */ public static final boolean HAS_TOOLTIP_STYLE = CURRENT_VERSION >= V1_21_2; From 83307a6d5e8631807fa65b60f1e3f165cea6d665 Mon Sep 17 00:00:00 2001 From: Tanguygab Date: Wed, 20 Nov 2024 16:45:31 +0100 Subject: [PATCH 3/3] forgot placeholders support for tooltip_style & item_model --- src/main/java/com/extendedclip/deluxemenus/menu/MenuItem.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/extendedclip/deluxemenus/menu/MenuItem.java b/src/main/java/com/extendedclip/deluxemenus/menu/MenuItem.java index b63716e..623651e 100644 --- a/src/main/java/com/extendedclip/deluxemenus/menu/MenuItem.java +++ b/src/main/java/com/extendedclip/deluxemenus/menu/MenuItem.java @@ -285,11 +285,11 @@ public ItemStack getItemStack(@NotNull final MenuHolder holder) { } if (VersionHelper.HAS_TOOLTIP_STYLE) { if (this.options.tooltipStyle().isPresent()) { - NamespacedKey tooltipStyle = NamespacedKey.fromString(this.options.tooltipStyle().get()); + NamespacedKey tooltipStyle = NamespacedKey.fromString(holder.setPlaceholdersAndArguments(this.options.tooltipStyle().get())); if (tooltipStyle != null) itemMeta.setTooltipStyle(tooltipStyle); } if (this.options.itemModel().isPresent()) { - NamespacedKey itemModel = NamespacedKey.fromString(this.options.itemModel().get()); + NamespacedKey itemModel = NamespacedKey.fromString(holder.setPlaceholdersAndArguments(this.options.itemModel().get())); if (itemModel != null) itemMeta.setItemModel(itemModel); } }