diff options
author | Shane Freeder <[email protected]> | 2024-05-09 14:51:33 +0100 |
---|---|---|
committer | Shane Freeder <[email protected]> | 2024-05-09 14:51:33 +0100 |
commit | 3693bbdc6b65e68db10375d3eeab70f06708b729 (patch) | |
tree | 4a71a5e6e5f50b3e2937053a5d4b4196ef67665b /patches/api/0348-Add-enchantWithLevels-API.patch | |
parent | f2512b12385961f8ca1f69efebe5ed0e00c0caa8 (diff) | |
download | Paper-3693bbdc6b65e68db10375d3eeab70f06708b729.tar.gz Paper-3693bbdc6b65e68db10375d3eeab70f06708b729.zip |
Use internals for getting block/entity countstimings/use-internals
For a long time I've been meaning to move some of this logic internally
as this would allow us to avoid hitting systems like block state snapshots
which can create issues as many of the spigot implementations of this
stuff are increasingly broken, leading to unexpected crashes during ticking,
even if the API cannot properly interact with these such states/items,
it's generally more preferable to not crash the server in the course,
and just let those interactions fail more gracefully.
Diffstat (limited to 'patches/api/0348-Add-enchantWithLevels-API.patch')
-rw-r--r-- | patches/api/0348-Add-enchantWithLevels-API.patch | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/patches/api/0348-Add-enchantWithLevels-API.patch b/patches/api/0348-Add-enchantWithLevels-API.patch new file mode 100644 index 0000000000..02d301e15a --- /dev/null +++ b/patches/api/0348-Add-enchantWithLevels-API.patch @@ -0,0 +1,100 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Jason Penilla <[email protected]> +Date: Wed, 16 Mar 2022 20:35:13 -0700 +Subject: [PATCH] Add enchantWithLevels API + +Deprecate upstream's newer and poorly implemented similar +API. + +diff --git a/src/main/java/org/bukkit/inventory/ItemFactory.java b/src/main/java/org/bukkit/inventory/ItemFactory.java +index dbebaf8172ec6872f56958b9583affde4f8400a4..98a970a6582dca22e719a31559c7becea4725cb2 100644 +--- a/src/main/java/org/bukkit/inventory/ItemFactory.java ++++ b/src/main/java/org/bukkit/inventory/ItemFactory.java +@@ -185,8 +185,11 @@ public interface ItemFactory { + * @param level the level to use, which is the level in the enchantment table + * @param allowTreasures allows treasure enchants, e.g. mending, if true. + * @return a new ItemStack containing the result of the Enchantment ++ * @deprecated use {@link #enchantWithLevels(ItemStack, int, boolean, java.util.Random)}. This method's implementation is poorly ++ * designed and was originally broken. + */ + @NotNull ++ @Deprecated // Paper + ItemStack enchantItem(@NotNull final Entity entity, @NotNull final ItemStack item, final int level, final boolean allowTreasures); + + /** +@@ -199,8 +202,11 @@ public interface ItemFactory { + * @param level the level to use, which is the level in the enchantment table + * @param allowTreasures allow the treasure enchants, e.g. mending, if true. + * @return a new ItemStack containing the result of the Enchantment ++ * @deprecated use {@link #enchantWithLevels(ItemStack, int, boolean, java.util.Random)}. This method's implementation is poorly ++ * designed and was originally broken. + */ + @NotNull ++ @Deprecated // Paper + ItemStack enchantItem(@NotNull final World world, @NotNull final ItemStack item, final int level, final boolean allowTreasures); + + /** +@@ -212,8 +218,11 @@ public interface ItemFactory { + * @param level the level to use, which is the level in the enchantment table + * @param allowTreasures allow treasure enchantments, e.g. mending, if true. + * @return a new ItemStack containing the result of the Enchantment ++ * @deprecated use {@link #enchantWithLevels(ItemStack, int, boolean, java.util.Random)}. This method's implementation is poorly ++ * designed and was originally broken. + */ + @NotNull ++ @Deprecated // Paper + ItemStack enchantItem(@NotNull final ItemStack item, final int level, final boolean allowTreasures); + + // Paper start - Adventure +@@ -326,4 +335,22 @@ public interface ItemFactory { + @Deprecated + net.md_5.bungee.api.chat.hover.content.Content hoverContentOf(@NotNull org.bukkit.entity.Entity entity, @NotNull net.md_5.bungee.api.chat.BaseComponent[] customName); + // Paper end - bungee hover events ++ ++ // Paper start - enchantWithLevels API ++ /** ++ * 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); ++ // Paper end - enchantWithLevels API + } +diff --git a/src/main/java/org/bukkit/inventory/ItemStack.java b/src/main/java/org/bukkit/inventory/ItemStack.java +index 351f5c0feec38377fccf09bfc1cef2df88fc2dcd..7eb4cf0b2f162d650252d81e9d38393f69a69046 100644 +--- a/src/main/java/org/bukkit/inventory/ItemStack.java ++++ b/src/main/java/org/bukkit/inventory/ItemStack.java +@@ -670,6 +670,24 @@ public class ItemStack implements Cloneable, ConfigurationSerializable, Translat + } + + // 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) { |