How to copy Attribute Modifiers to another item?

Discussion in 'Plugin Development' started by SuperMegaRorro, Feb 28, 2022.

Thread Status:
Not open for further replies.
  1. Offline

    SuperMegaRorro

    My Code:
    item1.getItemMeta().setAttributeModifiers(item.getItemMeta().getAttributeModifiers());

    When i try to use this i have this error:

    java: cannot access com.google.common.collect.Multimap
    class file for com.google.common.collect.Multimap not found

    How can i fix it?
     
  2. Offline

    Strahan

    That's weird; it works fine for me. Are you sure all your imports are in order?
     
  3. Offline

    SuperMegaRorro

    i cant use
    import com.google.common.collect.Multimap;
    with only Bukkit API, do i need to add another jar to dependencies?
     
  4. Offline

    Strahan

    I didn't need that one at all. I just fired up my testbed plugin and made it copy attributes from one item to another, worked fine:
    Code:
    package com.sylvcraft;
    
    import org.bukkit.Material;
    import org.bukkit.attribute.Attribute;
    import org.bukkit.attribute.AttributeModifier;
    import org.bukkit.attribute.AttributeModifier.Operation;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Test118 extends JavaPlugin implements Listener {
      @Override
      public void onEnable() {
        saveDefaultConfig();
        PluginManager pm = getServer().getPluginManager();
        pm.registerEvents(this, this);
      }
    
      @Override
      public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
        ItemStack i1 = new ItemStack(Material.DIAMOND_SWORD);
        ItemMeta im1 = i1.getItemMeta();
        im1.addAttributeModifier(Attribute.GENERIC_ATTACK_DAMAGE, new AttributeModifier("GENERIC_ATTACK_DAMAGE", 50, Operation.ADD_NUMBER));
        i1.setItemMeta(im1);
    
        ItemStack i2 = new ItemStack(Material.DIAMOND_SWORD);
        ItemMeta im2 = i2.getItemMeta();
        im2.setAttributeModifiers(im1.getAttributeModifiers());
        i2.setItemMeta(im2);
       
        ((Player)sender).getInventory().addItem(i2);
        return true;
      }
    }
     
  5. Offline

    SuperMegaRorro

    I tried using your code, but its also not working. I'm using 1.18.2 API if it changes anything
     
    Last edited: Mar 9, 2022
Thread Status:
Not open for further replies.

Share This Page