Solved [Help] .setArmorContents()

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

  1. 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 (Text):
    @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 (Text):
    @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 (Text):
    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 (Text):
    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!
     
    #1 Impasta1000, Jun 20, 2016
    Last edited: Jun 20, 2016
  2. MiniDigger

    Supporter

    you need to update the inventory after the change IIRC.
     
  3. Tried updating player inventory (code has been updated with where I updated the inventory). Still no change.
     
  4. 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.
     
    • Informative Informative x 4