Update Enchantment damage increase API

The Enchantment damage increase API added previously used the
EntityCategory enum as a parameter. These values are now however
determined by tags instead of the categories themselves.

Deprecated the outdated api method, create a new overload that takes
EntityType instead and implement deprecated method by guessing an entity
type from the builtin registry based on the category passed.
This method allows
a) the tags to still be modified and the legacy
   method still respecting such.
b) potential cursed implementations of enchantments of plugins to not
   break that override the getDamageBonus method on Enchantment.
This commit is contained in:
Bjarne Koll 2024-04-25 18:42:50 +02:00
parent 653f0432b5
commit bab31b6f55
No known key found for this signature in database
GPG key ID: 27F6CCCF55D2EE62
12 changed files with 57 additions and 48 deletions

View file

@ -36,7 +36,7 @@ index 0000000000000000000000000000000000000000..e6a40c1fcea761bd66743b50e3da3d14
+ }
+}
diff --git a/src/main/java/org/bukkit/enchantments/Enchantment.java b/src/main/java/org/bukkit/enchantments/Enchantment.java
index 3375ce0f9ac50cd3f145291ceb587d4e6f72569c..d38a23dcab5312e610d7ea328b167a6105bbc0a7 100644
index 3375ce0f9ac50cd3f145291ceb587d4e6f72569c..a72202b653549b4074feb89748849fcb495ba0d4 100644
--- a/src/main/java/org/bukkit/enchantments/Enchantment.java
+++ b/src/main/java/org/bukkit/enchantments/Enchantment.java
@@ -291,11 +291,7 @@ public abstract class Enchantment implements Keyed, Translatable, net.kyori.adve
@ -51,7 +51,7 @@ index 3375ce0f9ac50cd3f145291ceb587d4e6f72569c..d38a23dcab5312e610d7ea328b167a61
public abstract boolean isCursed();
/**
@@ -329,6 +325,70 @@ public abstract class Enchantment implements Keyed, Translatable, net.kyori.adve
@@ -329,6 +325,84 @@ public abstract class Enchantment implements Keyed, Translatable, net.kyori.adve
* @return the name of the enchantment with {@code level} applied
*/
public abstract net.kyori.adventure.text.@NotNull Component displayName(int level);
@ -109,10 +109,24 @@ index 3375ce0f9ac50cd3f145291ceb587d4e6f72569c..d38a23dcab5312e610d7ea328b167a61
+ * @param level the level of enchantment
+ * @param entityCategory the category of entity
+ * @return the damage increase
+ * @deprecated Use {@link #getDamageIncrease(int, org.bukkit.entity.EntityType)} instead.
+ * Enchantment damage increase is no longer handled via {@link org.bukkit.entity.EntityCategory}s, but
+ * is instead controlled by tags, e.g. {@link org.bukkit.Tag#ENTITY_TYPES_SENSITIVE_TO_BANE_OF_ARTHROPODS}.
+ * As such, a category cannot properly represent all entities defined by the tags.
+ */
+ @Deprecated(forRemoval = true, since = "1.20.5")
+ public abstract float getDamageIncrease(int level, @NotNull org.bukkit.entity.EntityCategory entityCategory);
+
+ /**
+ * Gets the damage increase as a result of the level and entity type specified
+ *
+ * @param level the level of enchantment
+ * @param entityType the type of entity.
+ * @return the damage increase
+ */
+ public abstract float getDamageIncrease(int level, @NotNull org.bukkit.entity.EntityType entityType);
+
+ /**
+ * Gets the equipment slots where this enchantment is considered "active".
+ *
+ * @return the equipment slots