2021-06-11 14:02:28 +02:00
|
|
|
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
|
2023-06-06 11:09:19 +02:00
|
|
|
index ac9395474e17c3a03c611c777b04a5bd18948be6..0b3b623455337c6500b9ce518ad8e6a7e5e9a17f 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/org/bukkit/Material.java
|
|
|
|
+++ b/src/main/java/org/bukkit/Material.java
|
2023-04-09 02:00:50 +02:00
|
|
|
@@ -4573,6 +4573,17 @@ public enum Material implements Keyed, Translatable, net.kyori.adventure.transla
|
2023-02-15 23:10:14 +01:00
|
|
|
return Bukkit.getUnsafe().getBlockTranslationKey(this);
|
|
|
|
}
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 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
|
2023-06-06 11:09:19 +02:00
|
|
|
index a00d93eee9710bb0fdf0fb791ef1a9262f89ef60..f79784e1823f646181a434a6dbce3bac0eaf25c9 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/org/bukkit/UnsafeValues.java
|
|
|
|
+++ b/src/main/java/org/bukkit/UnsafeValues.java
|
2023-06-06 11:09:19 +02:00
|
|
|
@@ -142,5 +142,22 @@ public interface UnsafeValues {
|
2022-05-27 17:42:36 +02:00
|
|
|
* Just don't use it.
|
2021-06-11 14:02:28 +02:00
|
|
|
*/
|
2022-05-27 17:42:36 +02:00
|
|
|
@org.jetbrains.annotations.NotNull String getMainLevelName();
|
2021-06-11 14:02:28 +02:00
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 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
|
2023-04-04 11:47:16 +02:00
|
|
|
index e4ad3a550050c4bf9cc7a2a1082bfdf668050efe..4f867ba2bc9b1a7c277e4a5f0ea8b452315f3272 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/org/bukkit/inventory/ItemStack.java
|
|
|
|
+++ b/src/main/java/org/bukkit/inventory/ItemStack.java
|
2023-02-15 23:10:14 +01:00
|
|
|
@@ -877,5 +877,15 @@ public class ItemStack implements Cloneable, ConfigurationSerializable, Translat
|
2021-08-14 06:11:12 +02:00
|
|
|
public @NotNull String translationKey() {
|
2021-06-11 14:02:28 +02:00
|
|
|
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
|
|
|
|
}
|