#691: Add Material#getDefaultAttributeModifiers

By: coll1234567 <joshl5324@gmail.com>
This commit is contained in:
Bukkit/Spigot 2021-12-24 12:06:21 +11:00
parent 0503e4faed
commit 489aef2efc
2 changed files with 29 additions and 0 deletions

View File

@ -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 {
// </editor-fold>
}
}
/**
* 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<Attribute, AttributeModifier> getDefaultAttributeModifiers(@NotNull EquipmentSlot slot) {
Validate.isTrue(isItem(), "The Material is not an item!");
return Bukkit.getUnsafe().getDefaultAttributeModifiers(this, slot);
}
}

View File

@ -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<Attribute, AttributeModifier> getDefaultAttributeModifiers(Material material, EquipmentSlot slot);
}