From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Sat, 8 May 2021 15:02:00 -0700 Subject: [PATCH] Improve item default attribute API diff --git a/src/main/java/org/bukkit/Material.java b/src/main/java/org/bukkit/Material.java index d0aaf145cf34e0c02d5c7b842c203d0630b04b53..5c869feaecd95dbdd658e16f5739bb41540f18bd 100644 --- a/src/main/java/org/bukkit/Material.java +++ b/src/main/java/org/bukkit/Material.java @@ -4705,6 +4705,23 @@ public enum Material implements Keyed, Translatable, net.kyori.adventure.transla } // Paper end - item rarity API + // Paper start - item default attributes API + /** + * Returns an immutable multimap of attributes for the slot. + * {@link #isItem()} must be true for this material. + * + * @param equipmentSlot the slot to get the attributes for + * @throws IllegalArgumentException if {@link #isItem()} is false + * @return an immutable multimap of attributes + * @deprecated use {@link #getDefaultAttributeModifiers(EquipmentSlot)} + */ + @NotNull + @Deprecated(forRemoval = true, since = "1.20.5") + public Multimap getItemAttributes(@NotNull EquipmentSlot equipmentSlot) { + return this.getDefaultAttributeModifiers(equipmentSlot); + } + // Paper end - item default attributes API + /** * Do not use for any reason. * @@ -5412,13 +5429,34 @@ public enum Material implements Keyed, Translatable, net.kyori.adventure.transla } } + // Paper start - improve default item attribute API + /** + * Return an immutable copy of all default {@link Attribute}s and their {@link AttributeModifier}s. + *

+ * Default attributes are those that are always preset on some items, unless + * they are specifically overridden on that {@link ItemStack}. Examples include + * the attack damage on weapons or the armor value on armor. + *

+ * Only available when {@link #isItem()} is true. + * + * @return the immutable {@link Multimap} with the respective default + * Attributes and modifiers, or an empty map if no attributes are set. + */ + public @NotNull @org.jetbrains.annotations.Unmodifiable Multimap getDefaultAttributeModifiers() { + final ItemType type = this.asItemType(); + Preconditions.checkArgument(type != null, "The Material is not an item!"); + return type.getDefaultAttributeModifiers(); + } + // Paper end - improve default item attribute API + /** * Return an immutable copy of all default {@link Attribute}s and their * {@link AttributeModifier}s for a given {@link EquipmentSlot}. - * - * Default attributes are those that are always preset on some items, such - * as the attack damage on weapons or the armor value on armor. - * + *

+ * Default attributes are those that are always preset on some items, unless + * they are specifically overridden on that {@link ItemStack}. Examples include + * the attack damage on weapons or the armor value on armor. + *

* Only available when {@link #isItem()} is true. * * @param slot the {@link EquipmentSlot} to check diff --git a/src/main/java/org/bukkit/inventory/ItemType.java b/src/main/java/org/bukkit/inventory/ItemType.java index 2b5a18fe7e885fa9b581c0afb299e31f3db2690c..a6d1dde422de98f178c0c9add99e01203a35e5cb 100644 --- a/src/main/java/org/bukkit/inventory/ItemType.java +++ b/src/main/java/org/bukkit/inventory/ItemType.java @@ -2261,6 +2261,21 @@ public interface ItemType extends Keyed, Translatable, net.kyori.adventure.trans // @NotNull // EquipmentSlot getEquipmentSlot(); + // Paper start - improve default item attribute API + /** + * Return an immutable copy of all default {@link Attribute}s and their + * {@link AttributeModifier}s. + *

+ * Default attributes are those that are always preset on some items, unless + * they are specifically overridden on that {@link ItemStack}. Examples include + * the attack damage on weapons or the armor value on armor. + * + * @return the immutable {@link Multimap} with the respective default + * Attributes and modifiers, or an empty map if no attributes are set. + */ + @NotNull @org.jetbrains.annotations.Unmodifiable Multimap getDefaultAttributeModifiers(); + // Paper end - improve default item attribute API + /** * Return an immutable copy of all default {@link Attribute}s and their * {@link AttributeModifier}s for a given {@link EquipmentSlot}.