Modified Attributes 1.7.10 craftbukkit

Discussion in 'Plugin Development' started by maliimaloo, Jan 8, 2019.

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

    maliimaloo

    Hi;

    Hello to you;

    My problem is that when I give the item in play, it only gets the name and the Lore but not the attributes

    Version Bukkit: craftbukkit-1.7.10-R0.1-20140808.005431-8.jar


    Code:
    package com.maliimaloo.Commands;
    
    import java.util.Arrays;
    
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemStack;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    
    import net.minecraft.server.v1_7_R4.NBTTagCompound;
    import net.minecraft.server.v1_7_R4.NBTTagInt;
    import net.minecraft.server.v1_7_R4.NBTTagList;
    import net.minecraft.server.v1_7_R4.NBTTagString;
    
    public class GiveCommandeRPG implements CommandExecutor {
    
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String lebel, String[] args)
        {
            if(sender instanceof Player)
            {
                Player player = (Player)sender;
               
                if(player.isOp())
                {
                    if (args.length >= 1)
                    {
                        player.sendMessage("Test");
                        return false;
                    }
                    else
                    {
                        ItemStack item = new ItemStack(Material.DIAMOND_SWORD, 1);
                        ItemMeta itemmeta = item.getItemMeta();
                        itemmeta.setDisplayName ("Cool Sword");
                        itemmeta.setLore(Arrays.asList("Ceci est une épée cool."));
                        item.setItemMeta(itemmeta);
                       
                        net.minecraft.server.v1_7_R4.ItemStack nmsStack = CraftItemStack.asNMSCopy(item);
                       
                        NBTTagCompound compound = (nmsStack.hasTag())? nmsStack.getTag (): new NBTTagCompound();
                        NBTTagList modifiers  = new NBTTagList();
                       
                        NBTTagCompound dommage = new NBTTagCompound ();
                        dommage.set("AttributeName", new NBTTagString ("generic.attackDamage"));
                        dommage.set ("Name", new NBTTagString ("generic.attackDamage"));
                        dommage.set ("Amount", new NBTTagInt (100));
                        dommage.set ("Operation", new NBTTagInt (0));
                        dommage.set ("UUIDLeast", new NBTTagInt (894654));
                        dommage.set ("UUIDMost", new NBTTagInt (2872));
                       
                        modifiers.add (dommage);
                        compound.set ("AttributeModifiers", modifiers);
                        nmsStack.setTag (compound);
                        item = CraftItemStack.asBukkitCopy (nmsStack);
                       
                        player.getInventory().addItem(item);
                    }
                   
                }
            }
           
           
            return false;
        }
    
    }
    
     
  2. Offline

    knokko

    @maliimaloo

    Your code seems to be correct mostly, but there are a few things that may or may not cause the problem:
    -The "Amount" should be an NBTTagDouble
    -The "UUIDLeast" and "UUIDMost" should be NBTTagLong

    Does your code work for other versions of bukkit?
     
  3. Offline

    maliimaloo

    My new code


    Code:
    package com.maliimaloo.Commands;
    
    import java.util.ArrayList;
    import java.util.List;
    
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemStack;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    
    import com.maliimaloo.Main;
    import com.maliimaloo.Utils.SettingsManagerArmure;
    import com.maliimaloo.Utils.SettingsManagerMessage;
    
    import net.minecraft.server.v1_7_R4.NBTTagCompound;
    import net.minecraft.server.v1_7_R4.NBTTagDouble;
    import net.minecraft.server.v1_7_R4.NBTTagInt;
    import net.minecraft.server.v1_7_R4.NBTTagList;
    import net.minecraft.server.v1_7_R4.NBTTagLong;
    import net.minecraft.server.v1_7_R4.NBTTagString;
    
    public class GiveCommande implements CommandExecutor {
        SettingsManagerArmure settingsArmure = SettingsManagerArmure.getInstance();
        SettingsManagerMessage settingsMessage = SettingsManagerMessage.getInstance();
    
        Main main = Main.getInstance();
        public int idItemConfig;
    
        @SuppressWarnings({ "deprecation" })
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (sender instanceof Player) {
                Player player = (Player) sender;
    
                if (args.length == 0 || args.length == 1) {
                    player.sendMessage(settingsMessage.getMessageConfig().getString("Commande_GV.Invalide_Commande")
                            .replace("&", "§"));
                    return false;
                } else if (args.length >= 2) {
                    if (!(player.isOp())) {
                        player.sendMessage(settingsMessage.getMessageConfig().getString("Commande_GV.Op_Commande_Invalide")
                                .replace("&", "§"));
                        return false;
                    }
    
                    int idItem = Integer.valueOf(args[0]);
                    int quantiter = Integer.valueOf(args[1]);
    
                    List<String> getArmure = new ArrayList<String>();
                    for (String str : settingsArmure.getArmureConfig().getConfigurationSection("Armure").getKeys(false)) {
                        getArmure.add(str);
                    }
    
                    List<String> getArmure1 = new ArrayList<String>();
                    for (int a = 0; a < getArmure.size(); a++)
                    {
                        for (String str : settingsArmure.getArmureConfig().getConfigurationSection("Armure." + getArmure.get(a)).getKeys(false))
                        {
                            getArmure1.add(str);
                        }
                    }
    
                    for (int a = 0; a < getArmure.size(); a++)
                    {
                        for (int b = 0; b < getArmure1.size(); b++)
                        {
                            idItemConfig = settingsArmure.getArmureConfig().getInt("Armure." + getArmure.get(a) + "." + getArmure1.get(b) + ".ID");
    
                            if (idItem == idItemConfig)
                            {
                                List<String> getGeneric = new ArrayList<String>();
                                for (String str : settingsArmure.getArmureConfig().getConfigurationSection("Armure." + getArmure.get(a) + "." + getArmure1.get(b) + ".Generic").getKeys(false))
                                {
                                    if (str != null)
                                    {
                                        getGeneric.add(str);
                                    }
                                }
    
                                int idItemGeneric = idItemConfig;
                                ItemStack item = new ItemStack(idItemGeneric, quantiter);
                               
                                //item.setDurability(Short.valueOf(settingsArmure.getArmureConfig().getString("Armure." + getArmure.get(a) + "." + getArmure1.get(b) + ".Durabiliter")));
                                ItemMeta itemMeta = item.getItemMeta();
                                itemMeta.setDisplayName(settingsArmure.getArmureConfig().getString("Armure." + getArmure.get(a) + "." + getArmure1.get(b) + ".ItemName"));
                                itemMeta.setLore(settingsArmure.getArmureConfig().getStringList("Armure." + getArmure.get(a) + "." + getArmure1.get(b) + ".Description"));
                                item.setItemMeta(itemMeta);
    
                                net.minecraft.server.v1_7_R4.ItemStack nmsStack = CraftItemStack.asNMSCopy(item);
                                NBTTagCompound compound = nmsStack.hasTag() ? nmsStack.getTag() : new NBTTagCompound();
                                NBTTagList modifiers = new NBTTagList();
    
                                for (int c = 0; c < getGeneric.size(); c++)
                                {
                                    String generic = settingsArmure.getArmureConfig().getString("Armure." + getArmure.get(a)+ "." + getArmure1.get(b) + ".Generic." + getGeneric.get(c) + ".GenericType");
                                    Double mount = settingsArmure.getArmureConfig().getDouble("Armure." + getArmure.get(a) + "." + getArmure1.get(b) + ".Generic."+ getGeneric.get(c) + ".GenericMontant");
    
                                    NBTTagCompound genericCreate = new NBTTagCompound();
                                    genericCreate.set("AttributeName", new NBTTagString("generic." + generic));
                                    genericCreate.set("Name", new NBTTagString("generic." + generic));
                                    genericCreate.set("Amount", new NBTTagDouble(mount));
                                    genericCreate.set("Operation", new NBTTagInt(0));
                                    genericCreate.set("UUIDLeast", new NBTTagLong(894654));
                                    genericCreate.set("UUIDMost", new NBTTagLong(2872));
    
                                    modifiers.add(genericCreate);
                                }
    
                                compound.set("AttributeModifiers", modifiers);
                                nmsStack.setTag(compound);
                                item = CraftItemStack.asBukkitCopy(nmsStack);
    
                                player.getInventory().addItem(item);
                                return false;
                            }
                        }
                    }
    
                    player.sendMessage(settingsMessage.getMessageConfig().getString("Commande_GV.ItemId_Invalide").replace("&", "§").replace("%idItem%", String.valueOf(idItem)));
                    return false;
                }
            }
            return false;
        }
    }
    
     
Thread Status:
Not open for further replies.

Share This Page