From 489aef2efcd442fb91b7b65fb72d4c0e48dc1bf1 Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Fri, 24 Dec 2021 12:06:21 +1100 Subject: [PATCH] #691: Add Material#getDefaultAttributeModifiers By: coll1234567 --- .../src/main/java/org/bukkit/Material.java | 23 +++++++++++++++++++ .../main/java/org/bukkit/UnsafeValues.java | 6 +++++ 2 files changed, 29 insertions(+) diff --git a/paper-api/src/main/java/org/bukkit/Material.java b/paper-api/src/main/java/org/bukkit/Material.java index 2a0773e098..89f593cd32 100644 --- a/paper-api/src/main/java/org/bukkit/Material.java +++ b/paper-api/src/main/java/org/bukkit/Material.java @@ -1,11 +1,14 @@ package org.bukkit; import com.google.common.collect.Maps; +import com.google.common.collect.Multimap; import java.lang.reflect.Constructor; import java.util.Locale; import java.util.Map; import java.util.function.Consumer; import org.apache.commons.lang.Validate; +import org.bukkit.attribute.Attribute; +import org.bukkit.attribute.AttributeModifier; import org.bukkit.block.data.Ageable; import org.bukkit.block.data.AnaloguePowerable; import org.bukkit.block.data.Bisected; @@ -9757,4 +9760,24 @@ public enum Material implements Keyed { // } } + + /** + * 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. + * + * Only available when {@link #isItem()} is true. + * + * @param slot the {@link EquipmentSlot} to check + * @return the immutable {@link Multimap} with the respective default + * Attributes and modifiers, or an empty map if no attributes are set. + */ + @NotNull + public Multimap getDefaultAttributeModifiers(@NotNull EquipmentSlot slot) { + Validate.isTrue(isItem(), "The Material is not an item!"); + + return Bukkit.getUnsafe().getDefaultAttributeModifiers(this, slot); + } } diff --git a/paper-api/src/main/java/org/bukkit/UnsafeValues.java b/paper-api/src/main/java/org/bukkit/UnsafeValues.java index 247d194f86..9ccef14c8a 100644 --- a/paper-api/src/main/java/org/bukkit/UnsafeValues.java +++ b/paper-api/src/main/java/org/bukkit/UnsafeValues.java @@ -1,7 +1,11 @@ package org.bukkit; +import com.google.common.collect.Multimap; import org.bukkit.advancement.Advancement; +import org.bukkit.attribute.Attribute; +import org.bukkit.attribute.AttributeModifier; import org.bukkit.block.data.BlockData; +import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; import org.bukkit.material.MaterialData; import org.bukkit.plugin.InvalidPluginException; @@ -69,4 +73,6 @@ public interface UnsafeValues { * @return true if a file matching this key was found and deleted */ boolean removeAdvancement(NamespacedKey key); + + Multimap getDefaultAttributeModifiers(Material material, EquipmentSlot slot); }