Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added more item tooltip stuff #152

Merged
merged 3 commits into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,12 @@ private Map<Integer, TreeMap<Integer, MenuItem>> 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")) {
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/com/extendedclip/deluxemenus/menu/MenuItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(holder.setPlaceholdersAndArguments(this.options.tooltipStyle().get()));
if (tooltipStyle != null) itemMeta.setTooltipStyle(tooltipStyle);
}
if (this.options.itemModel().isPresent()) {
NamespacedKey itemModel = NamespacedKey.fromString(holder.setPlaceholdersAndArguments(this.options.itemModel().get()));
if (itemModel != null) itemMeta.setItemModel(itemModel);
}
}

if (VersionHelper.HAS_ARMOR_TRIMS && ItemUtils.hasArmorMeta(itemStack)) {
final Optional<String> trimMaterialName = this.options.trimMaterial();
final Optional<String> trimPatternName = this.options.trimPattern();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Enchantment, Integer> enchantments;
private final List<PotionEffect> potionEffects;
private final List<Pattern> bannerMeta;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -178,6 +189,26 @@ public void headType(final @Nullable HeadType headType) {
return Optional.ofNullable(trimPattern);
}

public @NotNull Optional<String> hideTooltip() {
return Optional.ofNullable(hideTooltip);
}

public @NotNull Optional<String> enchantmentGlintOverride() {
return Optional.ofNullable(enchantmentGlintOverride);
}

public @NotNull Optional<String> rarity() {
return Optional.ofNullable(rarity);
}

public @NotNull Optional<String> tooltipStyle() {
return Optional.ofNullable(tooltipStyle);
}

public @NotNull Optional<String> itemModel() {
return Optional.ofNullable(itemModel);
}

public @NotNull Map<Enchantment, Integer> enchantments() {
return enchantments;
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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<Enchantment, Integer> enchantments = Collections.emptyMap();
private List<PotionEffect> potionEffects = Collections.emptyList();
private List<Pattern> bannerMeta = Collections.emptyList();
Expand Down Expand Up @@ -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<Enchantment, Integer> enchantments) {
this.enchantments = enchantments;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 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;
// ArmorTrims
Expand All @@ -44,6 +46,11 @@ public final class VersionHelper {

private static final boolean IS_PAPER = checkPaper();

/**
* Checks if the current version includes the setTooltipStyle and setItemModel
*/
public static final boolean HAS_TOOLTIP_STYLE = CURRENT_VERSION >= V1_21_2;

/**
* Checks if the current version includes the <a href="https://minecraft.wiki/w/Data_component_format">Data Components</a>
*/
Expand Down