3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-15 12:30:06 +01:00
Paper/patches/api/0277-Item-Rarity-API.patch
2022-03-11 15:24:45 +01:00

110 Zeilen
4.0 KiB
Diff

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 9f0048888a2fe40316154613a722d1c709fd3856..709ae1eaabd81ee712d7d6f353c4983f20f6dc4f 100644
--- a/src/main/java/org/bukkit/Material.java
+++ b/src/main/java/org/bukkit/Material.java
@@ -4006,6 +4006,17 @@ public enum Material implements Keyed, net.kyori.adventure.translation.Translata
public @NotNull String translationKey() {
return Bukkit.getUnsafe().getTranslationKey(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 0697214210a6e87f690b9454d9651d06ca57a524..8cbd493f695229a7dad46916087aeb3159328bfe 100644
--- a/src/main/java/org/bukkit/UnsafeValues.java
+++ b/src/main/java/org/bukkit/UnsafeValues.java
@@ -157,5 +157,22 @@ public interface UnsafeValues {
* @throws IllegalArgumentException if there isn't a registry for that type
*/
<T extends Keyed> @org.jetbrains.annotations.NotNull Registry<T> registryFor(Class<T> classOfT);
+
+ /**
+ * 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 91a228239cf2ba6d50f4489b14ee6fa9069af07f..ebc44aae46d67ae565eeafb5bb3af74bbc88dbc1 100644
--- a/src/main/java/org/bukkit/inventory/ItemStack.java
+++ b/src/main/java/org/bukkit/inventory/ItemStack.java
@@ -880,5 +880,15 @@ public class ItemStack implements Cloneable, ConfigurationSerializable, net.kyor
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
}