Paper/patches/api/0375-Add-enchantWithLevels-API.patch

63 lines
3.4 KiB
Diff
Raw Normal View History

2022-03-17 09:51:43 +01:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jason Penilla <11360596+jpenilla@users.noreply.github.com>
Date: Wed, 16 Mar 2022 20:35:13 -0700
Subject: [PATCH] Add enchantWithLevels API
diff --git a/src/main/java/org/bukkit/inventory/ItemFactory.java b/src/main/java/org/bukkit/inventory/ItemFactory.java
index 2acafae468fcbb7213d6b6c30803a3924a3bbc30..40edff7c93b6bf75de81102326667135b9344666 100644
2022-03-17 09:51:43 +01:00
--- a/src/main/java/org/bukkit/inventory/ItemFactory.java
+++ b/src/main/java/org/bukkit/inventory/ItemFactory.java
@@ -161,6 +161,22 @@ public interface ItemFactory {
2022-03-17 09:51:43 +01:00
Material updateMaterial(@NotNull final ItemMeta meta, @NotNull final Material material) throws IllegalArgumentException;
// Paper start
+ /**
+ * Randomly enchants a copy of the provided {@link ItemStack} using the given experience levels.
+ *
+ * <p>If the provided ItemStack is already enchanted, the existing enchants will be removed before enchanting.</p>
+ *
+ * <p>Levels must be in range {@code [1, 30]}.</p>
+ *
+ * @param itemStack ItemStack to enchant
+ * @param levels levels to use for enchanting
+ * @param allowTreasure whether to allow enchantments where {@link org.bukkit.enchantments.Enchantment#isTreasure()} returns true
+ * @param random {@link java.util.Random} instance to use for enchanting
+ * @return enchanted copy of the provided ItemStack
+ * @throws IllegalArgumentException on bad arguments
+ */
+ @NotNull ItemStack enchantWithLevels(@NotNull ItemStack itemStack, @org.jetbrains.annotations.Range(from = 1, to = 30) int levels, boolean allowTreasure, @NotNull java.util.Random random);
+
/**
* Creates a hover event for the given item.
*
diff --git a/src/main/java/org/bukkit/inventory/ItemStack.java b/src/main/java/org/bukkit/inventory/ItemStack.java
2022-05-16 04:33:03 +02:00
index 66352c63bcacb9b418a3cc61d8a6219b4cdfbb32..62841846ec3e14daa46564509671cab146984cc6 100644
2022-03-17 09:51:43 +01:00
--- a/src/main/java/org/bukkit/inventory/ItemStack.java
+++ b/src/main/java/org/bukkit/inventory/ItemStack.java
2022-05-16 04:33:03 +02:00
@@ -649,6 +649,24 @@ public class ItemStack implements Cloneable, ConfigurationSerializable, net.kyor
2022-03-17 09:51:43 +01:00
}
// Paper start
+ /**
+ * Randomly enchants a copy of this {@link ItemStack} using the given experience levels.
+ *
+ * <p>If this ItemStack is already enchanted, the existing enchants will be removed before enchanting.</p>
+ *
+ * <p>Levels must be in range {@code [1, 30]}.</p>
+ *
+ * @param levels levels to use for enchanting
+ * @param allowTreasure whether to allow enchantments where {@link org.bukkit.enchantments.Enchantment#isTreasure()} returns true
+ * @param random {@link java.util.Random} instance to use for enchanting
+ * @return enchanted copy of the provided ItemStack
+ * @throws IllegalArgumentException on bad arguments
+ */
+ @NotNull
+ public ItemStack enchantWithLevels(final @org.jetbrains.annotations.Range(from = 1, to = 30) int levels, final boolean allowTreasure, final @NotNull java.util.Random random) {
+ return Bukkit.getServer().getItemFactory().enchantWithLevels(this, levels, allowTreasure, random);
+ }
+
@NotNull
@Override
public net.kyori.adventure.text.event.HoverEvent<net.kyori.adventure.text.event.HoverEvent.ShowItem> asHoverEvent(final @NotNull java.util.function.UnaryOperator<net.kyori.adventure.text.event.HoverEvent.ShowItem> op) {