mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-29 12:27:59 +01:00
deprecate our ItemRarity API
This commit is contained in:
parent
d93d74a7d5
commit
5a55c71491
@ -11,7 +11,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+++ b/src/main/java/org/bukkit/Material.java
|
||||
@@ -0,0 +0,0 @@ public enum Material implements Keyed, Translatable, net.kyori.adventure.transla
|
||||
public io.papermc.paper.inventory.ItemRarity getItemRarity() {
|
||||
return Bukkit.getUnsafe().getItemRarity(this);
|
||||
return new org.bukkit.inventory.ItemStack(this).getRarity();
|
||||
}
|
||||
+
|
||||
+ /**
|
||||
|
@ -9,9 +9,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
--- a/src/main/java/org/bukkit/UnsafeValues.java
|
||||
+++ b/src/main/java/org/bukkit/UnsafeValues.java
|
||||
@@ -0,0 +0,0 @@ public interface UnsafeValues {
|
||||
* @return the itemstack rarity
|
||||
* Just don't use it.
|
||||
*/
|
||||
public io.papermc.paper.inventory.ItemRarity getItemStackRarity(ItemStack itemStack);
|
||||
@org.jetbrains.annotations.NotNull String getMainLevelName();
|
||||
+
|
||||
+ /**
|
||||
+ * Returns the server's protocol version.
|
||||
|
@ -9,9 +9,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
--- a/src/main/java/org/bukkit/UnsafeValues.java
|
||||
+++ b/src/main/java/org/bukkit/UnsafeValues.java
|
||||
@@ -0,0 +0,0 @@ public interface UnsafeValues {
|
||||
* @return the server's protocol version
|
||||
* @return true if valid repair, false if not
|
||||
*/
|
||||
int getProtocolVersion();
|
||||
public boolean isValidRepairItemStack(@org.jetbrains.annotations.NotNull ItemStack itemToBeRepaired, @org.jetbrains.annotations.NotNull ItemStack repairMaterial);
|
||||
+
|
||||
+ /**
|
||||
+ * Checks if the entity represented by the namespaced key has default attributes.
|
||||
|
@ -1,7 +1,7 @@
|
||||
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
|
||||
Subject: [PATCH] Improve 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
|
||||
@ -16,6 +16,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+import net.kyori.adventure.text.format.TextColor;
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+
|
||||
+/**
|
||||
+ * @deprecated use {@link org.bukkit.inventory.ItemRarity} with {@link org.bukkit.inventory.meta.ItemMeta#getRarity()}
|
||||
+ */
|
||||
+@Deprecated(forRemoval = true, since = "1.20.5")
|
||||
+public enum ItemRarity {
|
||||
+
|
||||
+ COMMON(NamedTextColor.WHITE),
|
||||
@ -52,40 +56,56 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ * Use {@link #isItem()} before this.
|
||||
+ *
|
||||
+ * @return the item rarity
|
||||
+ * @deprecated use {@link org.bukkit.inventory.meta.ItemMeta#hasRarity()} and {@link org.bukkit.inventory.meta.ItemMeta#getRarity()}
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ @Deprecated(forRemoval = true, since = "1.20.5")
|
||||
+ public io.papermc.paper.inventory.ItemRarity getItemRarity() {
|
||||
+ return Bukkit.getUnsafe().getItemRarity(this);
|
||||
+ return new org.bukkit.inventory.ItemStack(this).getRarity();
|
||||
+ }
|
||||
// Paper end
|
||||
|
||||
/**
|
||||
diff --git a/src/main/java/org/bukkit/UnsafeValues.java b/src/main/java/org/bukkit/UnsafeValues.java
|
||||
diff --git a/src/main/java/org/bukkit/inventory/ItemRarity.java b/src/main/java/org/bukkit/inventory/ItemRarity.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/org/bukkit/UnsafeValues.java
|
||||
+++ b/src/main/java/org/bukkit/UnsafeValues.java
|
||||
@@ -0,0 +0,0 @@ public interface UnsafeValues {
|
||||
* Just don't use it.
|
||||
--- a/src/main/java/org/bukkit/inventory/ItemRarity.java
|
||||
+++ b/src/main/java/org/bukkit/inventory/ItemRarity.java
|
||||
@@ -0,0 +0,0 @@ public enum ItemRarity {
|
||||
/**
|
||||
* White item name.
|
||||
*/
|
||||
@org.jetbrains.annotations.NotNull String getMainLevelName();
|
||||
- COMMON,
|
||||
+ COMMON(net.kyori.adventure.text.format.NamedTextColor.WHITE), // Paper
|
||||
/**
|
||||
* Yellow item name.
|
||||
*/
|
||||
- UNCOMMON,
|
||||
+ UNCOMMON(net.kyori.adventure.text.format.NamedTextColor.YELLOW), // Paper
|
||||
/**
|
||||
* Aqua item name.
|
||||
*/
|
||||
- RARE,
|
||||
+ RARE(net.kyori.adventure.text.format.NamedTextColor.AQUA), // Paper
|
||||
/**
|
||||
* Light purple item name.
|
||||
*/
|
||||
- EPIC;
|
||||
+ EPIC(net.kyori.adventure.text.format.NamedTextColor.LIGHT_PURPLE); // Paper
|
||||
+ // Paper start - improve ItemRarity
|
||||
+ private final net.kyori.adventure.text.format.NamedTextColor color;
|
||||
+ ItemRarity(final net.kyori.adventure.text.format.NamedTextColor color) {
|
||||
+ this.color = color;
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * Gets the item rarity of a material. The material <b>MUST</b> be an item.
|
||||
+ * Use {@link Material#isItem()} before this.
|
||||
+ * Gets the color formatting associated with this rarity.
|
||||
+ *
|
||||
+ * @param material the material to get the rarity of
|
||||
+ * @return the item rarity
|
||||
+ * @return the color
|
||||
+ */
|
||||
+ 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
|
||||
+ public net.kyori.adventure.text.format.@org.jetbrains.annotations.NotNull TextColor color() {
|
||||
+ return this.color;
|
||||
+ }
|
||||
+ // Paper end
|
||||
}
|
||||
diff --git a/src/main/java/org/bukkit/inventory/ItemStack.java b/src/main/java/org/bukkit/inventory/ItemStack.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
@ -97,13 +117,15 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
}
|
||||
+
|
||||
+ /**
|
||||
+ * Gets the item rarity of the itemstack. The rarity can change based on enchantements.
|
||||
+ * Gets the item rarity of the itemstack. The rarity can change based on enchantments.
|
||||
+ *
|
||||
+ * @return the itemstack rarity
|
||||
+ * @deprecated Use {@link ItemMeta#hasRarity()} and {@link ItemMeta#getRarity()}
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ @Deprecated(forRemoval = true, since = "1.20.5")
|
||||
+ public io.papermc.paper.inventory.ItemRarity getRarity() {
|
||||
+ return Bukkit.getUnsafe().getItemStackRarity(this);
|
||||
+ return io.papermc.paper.inventory.ItemRarity.valueOf(this.getItemMeta().getRarity().name());
|
||||
+ }
|
||||
// Paper end
|
||||
}
|
@ -9,9 +9,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
--- a/src/main/java/org/bukkit/UnsafeValues.java
|
||||
+++ b/src/main/java/org/bukkit/UnsafeValues.java
|
||||
@@ -0,0 +0,0 @@ public interface UnsafeValues {
|
||||
* @return the server's protocol version
|
||||
*/
|
||||
public io.papermc.paper.inventory.ItemRarity getItemStackRarity(ItemStack itemStack);
|
||||
|
||||
int getProtocolVersion();
|
||||
+
|
||||
+ /**
|
||||
+ * Checks if an itemstack can be repaired with another itemstack.
|
||||
+ * Returns false if either argument's type is not an item ({@link Material#isItem()}).
|
||||
@ -21,17 +22,15 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ * @return true if valid repair, false if not
|
||||
+ */
|
||||
+ public boolean isValidRepairItemStack(@org.jetbrains.annotations.NotNull ItemStack itemToBeRepaired, @org.jetbrains.annotations.NotNull ItemStack repairMaterial);
|
||||
+
|
||||
/**
|
||||
* Returns the server's protocol version.
|
||||
*
|
||||
// Paper end
|
||||
}
|
||||
diff --git a/src/main/java/org/bukkit/inventory/ItemStack.java b/src/main/java/org/bukkit/inventory/ItemStack.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/org/bukkit/inventory/ItemStack.java
|
||||
+++ b/src/main/java/org/bukkit/inventory/ItemStack.java
|
||||
@@ -0,0 +0,0 @@ public class ItemStack implements Cloneable, ConfigurationSerializable, Translat
|
||||
public io.papermc.paper.inventory.ItemRarity getRarity() {
|
||||
return Bukkit.getUnsafe().getItemStackRarity(this);
|
||||
return io.papermc.paper.inventory.ItemRarity.valueOf(this.getItemMeta().getRarity().name());
|
||||
}
|
||||
+
|
||||
+ /**
|
||||
|
@ -9,8 +9,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
||||
@@ -0,0 +0,0 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
||||
public io.papermc.paper.inventory.ItemRarity getItemStackRarity(org.bukkit.inventory.ItemStack itemStack) {
|
||||
return io.papermc.paper.inventory.ItemRarity.values()[itemStack.getRarity().ordinal()];
|
||||
public String getMainLevelName() {
|
||||
return ((net.minecraft.server.dedicated.DedicatedServer) net.minecraft.server.MinecraftServer.getServer()).getProperties().levelName;
|
||||
}
|
||||
+
|
||||
+ @Override
|
||||
|
@ -85,8 +85,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
||||
@@ -0,0 +0,0 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
||||
public int getProtocolVersion() {
|
||||
return net.minecraft.SharedConstants.getCurrentVersion().getProtocolVersion();
|
||||
}
|
||||
return CraftMagicNumbers.getItem(itemToBeRepaired.getType()).isValidRepairItem(CraftItemStack.asNMSCopy(itemToBeRepaired), CraftItemStack.asNMSCopy(repairMaterial));
|
||||
}
|
||||
+
|
||||
+ @Override
|
||||
|
@ -1,63 +0,0 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Jake Potrebic <jake.m.potrebic@gmail.com>
|
||||
Date: Fri, 12 Mar 2021 17:09:42 -0800
|
||||
Subject: [PATCH] Item Rarity API
|
||||
|
||||
== AT ==
|
||||
public net.minecraft.world.item.Item rarity
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
||||
@@ -0,0 +0,0 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
||||
public String getMainLevelName() {
|
||||
return ((net.minecraft.server.dedicated.DedicatedServer) net.minecraft.server.MinecraftServer.getServer()).getProperties().levelName;
|
||||
}
|
||||
+
|
||||
+ @Override
|
||||
+ public io.papermc.paper.inventory.ItemRarity getItemRarity(org.bukkit.Material material) {
|
||||
+ Item item = getItem(material);
|
||||
+ if (item == null) {
|
||||
+ throw new IllegalArgumentException(material + " is not an item, and rarity does not apply to blocks");
|
||||
+ }
|
||||
+ return io.papermc.paper.inventory.ItemRarity.values()[item.components().getOrDefault(net.minecraft.core.component.DataComponents.RARITY, net.minecraft.world.item.Rarity.COMMON).ordinal()];
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public io.papermc.paper.inventory.ItemRarity getItemStackRarity(org.bukkit.inventory.ItemStack itemStack) {
|
||||
+ return io.papermc.paper.inventory.ItemRarity.values()[itemStack.getRarity().ordinal()];
|
||||
+ }
|
||||
// Paper end
|
||||
|
||||
/**
|
||||
diff --git a/src/test/java/io/papermc/paper/inventory/ItemRarityTest.java b/src/test/java/io/papermc/paper/inventory/ItemRarityTest.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
|
||||
--- /dev/null
|
||||
+++ b/src/test/java/io/papermc/paper/inventory/ItemRarityTest.java
|
||||
@@ -0,0 +0,0 @@
|
||||
+package io.papermc.paper.inventory;
|
||||
+
|
||||
+import io.papermc.paper.adventure.PaperAdventure;
|
||||
+import net.minecraft.world.item.Rarity;
|
||||
+import org.junit.jupiter.api.Test;
|
||||
+
|
||||
+import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
+
|
||||
+public class ItemRarityTest {
|
||||
+
|
||||
+ @Test
|
||||
+ public void testConvertFromNmsToBukkit() {
|
||||
+ for (Rarity nmsRarity : Rarity.values()) {
|
||||
+ assertEquals(ItemRarity.values()[nmsRarity.ordinal()].name(), nmsRarity.name(), "rarity names are mis-matched");
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ @Test
|
||||
+ public void testRarityFormatting() {
|
||||
+ for (Rarity nmsRarity : Rarity.values()) {
|
||||
+ assertEquals(nmsRarity.color(), PaperAdventure.asVanilla(ItemRarity.values()[nmsRarity.ordinal()].color), "rarity formatting is mis-matched");
|
||||
+ }
|
||||
+ }
|
||||
+}
|
@ -9,9 +9,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
||||
@@ -0,0 +0,0 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
||||
return io.papermc.paper.inventory.ItemRarity.values()[itemStack.getRarity().ordinal()];
|
||||
public int getProtocolVersion() {
|
||||
return net.minecraft.SharedConstants.getCurrentVersion().getProtocolVersion();
|
||||
}
|
||||
|
||||
+
|
||||
+ @Override
|
||||
+ public boolean isValidRepairItemStack(org.bukkit.inventory.ItemStack itemToBeRepaired, org.bukkit.inventory.ItemStack repairMaterial) {
|
||||
+ if (!itemToBeRepaired.getType().isItem() || !repairMaterial.getType().isItem()) {
|
||||
@ -19,10 +20,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ }
|
||||
+ return CraftMagicNumbers.getItem(itemToBeRepaired.getType()).isValidRepairItem(CraftItemStack.asNMSCopy(itemToBeRepaired), CraftItemStack.asNMSCopy(repairMaterial));
|
||||
+ }
|
||||
+
|
||||
@Override
|
||||
public int getProtocolVersion() {
|
||||
return net.minecraft.SharedConstants.getCurrentVersion().getProtocolVersion();
|
||||
// Paper end
|
||||
|
||||
/**
|
||||
diff --git a/src/test/java/io/papermc/paper/util/ItemStackRepairCheckTest.java b/src/test/java/io/papermc/paper/util/ItemStackRepairCheckTest.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
|
||||
|
Loading…
Reference in New Issue
Block a user