Solved .setArmorContents()

Discussion in 'Plugin Development' started by Impasta1000, Jun 20, 2016.

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

    Impasta1000

    Hey guys, I am having some problems with .setArmorContents()

    This is the first code i tried... No error thrown, just that the armor does not get added.
    Code:
    @Override
        public void setArmorContents(Player player) {
            player.getInventory().setArmorContents(null);
            armorContents = new ItemStack[] {
                    new ItemStack(Material.IRON_HELMET, 1),
                    new ItemStack(Material.IRON_CHESTPLATE, 1),
                    new ItemStack(Material.IRON_LEGGINGS, 1),
                    new ItemStack(Material.IRON_BOOTS, 1) };
            player.getInventory().setArmorContents(armorContents);
            player.updateInventory();
            for (ItemStack stack : player.getInventory().getArmorContents()) {
                rApi.addItemMeta(stack, "&c[Fighter]", "&eKit: " + kitName);
            }
            player.updateInventory();
            rApi.buffArmor(player, Enchantment.PROTECTION_ENVIRONMENTAL, 1);
            player.updateInventory();
        }

    Tried this too, same thing happens - no error thrown, armor not added.
    buffArmor was removed, but the same thing happens
    Code:
    @Override
        public void setArmorContents(Player player) {
            player.getInventory().setArmorContents(null);
            armorContents = new ItemStack[] {
                    rApi.createNewItem(Material.IRON_HELMET, 1, rApi.colourize("&c[Fighter] Helmet"), rApi.colourize("&eKit: " + kitName)),
                    rApi.createNewItem(Material.IRON_CHESTPLATE, 1, rApi.colourize("&c[Fighter] Chestplate"), rApi.colourize("&eKit: " + kitName)),
                    rApi.createNewItem(Material.IRON_LEGGINGS, 1, rApi.colourize("&c[Fighter] Leggings"), rApi.colourize("&eKit: " + kitName)),
                    rApi.createNewItem(Material.IRON_BOOTS, 1, rApi.colourize("&c[Fighter] Boots"), rApi.colourize("&eKit: " + kitName)) };
            player.getInventory().setArmorContents(armorContents);
            player.updateInventory();
            rApi.buffArmor(player, Enchantment.PROTECTION_ENVIRONMENTAL, 1);
            player.updateInventory();
        }
    This is where the method is called (I got the message - so this code was triggered.)
    Code:
    if (args[0].equalsIgnoreCase("kits")) {
                        if (args[1].equalsIgnoreCase("fighter")) {
                            if (!ArenaListener.playersInArena.contains(player.getName())) {
                                rApi.sendColouredMessage(player, "You need to join the Arena.");
                                return true;
                            }
                            fighterKit.setArmorContents(player);
                            fighterKit.setInventoryContents(player);
                            rApi.sendColouredMessage(player, "You have received the " + fighterKit.getKitName() + " kit.");
                        } 
                    }
    Buff armor code (if needed)
    Code:
    public void buffArmor(Player player, Enchantment ench, int level) {
            ItemStack playerHelmet = player.getInventory().getHelmet();
            playerHelmet.addEnchantment(ench, level);
            player.getInventory().setHelmet(playerHelmet);
      
            ItemStack playerChestplate = player.getInventory().getChestplate();
            playerChestplate.addEnchantment(ench, level);
            player.getInventory().setHelmet(playerChestplate);
      
            ItemStack playerLeggings = player.getInventory().getLeggings();
            playerLeggings.addEnchantment(ench, level);
            player.getInventory().setHelmet(playerLeggings);
      
            ItemStack playerBoots = player.getInventory().getBoots();
            playerBoots.addEnchantment(ench, level);
            player.getInventory().setHelmet(playerBoots);
        }
    Thanks for all the help guys!
     
  2. Offline

    Zombie_Striker

    @Impasta1000
    You should use methods like .setHelmet() and .setBoots(), to set the armor contents. Don't use .setArmorContents() for this.

    Also remember that when you get the helmet and boots, you are getting a clone of the itemstack. That means you have to re-add the item to the inventory if you make any changes to it.
     
  3. Offline

    Impasta1000

    Why would you not use .setArmorContents() in this situation though? .setArmorContents() tested and worked in my other plugin.

    Anyways, issue has been resolved. Error was on my part, where I cleared the inventory after adding the armor contents (in the setInventoryContents method)

    FYI: If anyone is using the .setArmorContents(), you have to put boots itemstack first, followed by leggings, chestplate and then helmet last.
     
Thread Status:
Not open for further replies.

Share This Page