aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/api/0264-Item-Rarity-API.patch
blob: 5e0072532446302d77da41f34529f2d3ebb2a365 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
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 85604d2c364c41fed24257a9b02ceeb58712f6a2..8fd928cfe61ab6f06c52eb5e4561fd6860e1f8d9 100644
--- a/src/main/java/org/bukkit/Material.java
+++ b/src/main/java/org/bukkit/Material.java
@@ -4709,6 +4709,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 <b>MUST</b> 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 72a29fff4c497a2a66e2746ad42553bcb712e20d..22db1d8645a450308fe91d0cd100c926dd8c6f08 100644
--- a/src/main/java/org/bukkit/UnsafeValues.java
+++ b/src/main/java/org/bukkit/UnsafeValues.java
@@ -167,5 +167,22 @@ public interface UnsafeValues {
      * Just don't use it.
      */
     @org.jetbrains.annotations.NotNull String getMainLevelName();
+
+    /**
+     * Gets the item rarity of a material. The material <b>MUST</b> 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 1532b3e1b655a9b58588c11b80824ed4cec8c66a..569f67ee3f89d6af4fe1420cecc74811550b6507 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
 }