From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Fri, 12 Mar 2021 17:09:40 -0800 Subject: [PATCH] Item Rarity API diff --git a/src/main/java/io/papermc/paper/inventory/ItemRarity.java b/src/main/java/io/papermc/paper/inventory/ItemRarity.java new file mode 100644 index 0000000000000000000000000000000000000000..74ef8395cc040ce488c2acaa416db20272cc2734 --- /dev/null +++ b/src/main/java/io/papermc/paper/inventory/ItemRarity.java @@ -0,0 +1,28 @@ +package io.papermc.paper.inventory; + +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.format.TextColor; +import org.jetbrains.annotations.NotNull; + +public enum ItemRarity { + + COMMON(NamedTextColor.WHITE), + UNCOMMON(NamedTextColor.YELLOW), + RARE(NamedTextColor.AQUA), + EPIC(NamedTextColor.LIGHT_PURPLE); + + TextColor color; + + ItemRarity(TextColor color) { + this.color = color; + } + + /** + * Gets the color formatting associated with the rarity. + * @return + */ + @NotNull + public TextColor getColor() { + return color; + } +} diff --git a/src/main/java/org/bukkit/Material.java b/src/main/java/org/bukkit/Material.java index 3ee36de0ee975dc300e594b17d0dc2c06edf2a16..7c14a272156cefe6d69e41fec6892891646e0985 100644 --- a/src/main/java/org/bukkit/Material.java +++ b/src/main/java/org/bukkit/Material.java @@ -4748,6 +4748,17 @@ public enum Material implements Keyed, Translatable, net.kyori.adventure.transla return Bukkit.getUnsafe().getBlockTranslationKey(this); } } + + /** + * Returns the item rarity for the item. The Material MUST be an Item not a block. + * Use {@link #isItem()} before this. + * + * @return the item rarity + */ + @NotNull + public io.papermc.paper.inventory.ItemRarity getItemRarity() { + return Bukkit.getUnsafe().getItemRarity(this); + } // Paper end /** diff --git a/src/main/java/org/bukkit/UnsafeValues.java b/src/main/java/org/bukkit/UnsafeValues.java index 5de86f8cd3cc7f7e8ebc4a22d3921273378704f2..c423204eaf3252c9fc1a3af1214ec70ed712fb80 100644 --- a/src/main/java/org/bukkit/UnsafeValues.java +++ b/src/main/java/org/bukkit/UnsafeValues.java @@ -169,5 +169,22 @@ public interface UnsafeValues { * Just don't use it. */ @org.jetbrains.annotations.NotNull String getMainLevelName(); + + /** + * Gets the item rarity of a material. The material MUST be an item. + * Use {@link Material#isItem()} before this. + * + * @param material the material to get the rarity of + * @return the item rarity + */ + public io.papermc.paper.inventory.ItemRarity getItemRarity(Material material); + + /** + * Gets the item rarity of the itemstack. The rarity can change based on enchantements. + * + * @param itemStack the itemstack to get the rarity of + * @return the itemstack rarity + */ + public io.papermc.paper.inventory.ItemRarity getItemStackRarity(ItemStack itemStack); // Paper end } diff --git a/src/main/java/org/bukkit/inventory/ItemStack.java b/src/main/java/org/bukkit/inventory/ItemStack.java index 96b6052c198454f06f877fc7cda85a98c0ddba7c..069c644f03286ba62d521754d825e81934e1e6d6 100644 --- a/src/main/java/org/bukkit/inventory/ItemStack.java +++ b/src/main/java/org/bukkit/inventory/ItemStack.java @@ -888,5 +888,15 @@ public class ItemStack implements Cloneable, ConfigurationSerializable, Translat public @NotNull String translationKey() { return Bukkit.getUnsafe().getTranslationKey(this); } + + /** + * Gets the item rarity of the itemstack. The rarity can change based on enchantements. + * + * @return the itemstack rarity + */ + @NotNull + public io.papermc.paper.inventory.ItemRarity getRarity() { + return Bukkit.getUnsafe().getItemStackRarity(this); + } // Paper end }