setContents not working correctly | Spigot 1.8.9

Discussion in 'Plugin Development' started by Callum | NorthernH, Jun 24, 2020.

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

    The method is being used the exact same way each time, its not in a new thread, the /kit and star should work the exact same but that isn't the case as you can see from the debugger its in the PlayerInventory variable but isn't being added to the players inventory
     
  2. Offline

    timtower Moderator Moderator

    @Callum | NorthernH Did you also notice that the item is called "Defualt" and the code is checking "Default" ?
    And please post code / screenshots next time, not only a video.
     
  3. @timtower that is not the issue, as you can see in the video the code is still ran. the PlayerInventory has the pots. the code is being ran. the item its checking for is the name of the star not the kit.

    upload_2020-6-25_11-11-23.png
    upload_2020-6-25_11-11-56.png
    upload_2020-6-25_13-42-52.png


    Code:
    public static void giveKit(Player targetPlayer, give giveType, kit kitType) throws KitError{
            if(giveType != give.SELECTED && !targetPlayer.hasPermission("kit.use")) throw new KitError("Invalid Permissions", giveType, KitError.error.PERMISSION);
            if (kitSelected.containsKey(targetPlayer.getUniqueId())) throw new KitError("Kit already selected", giveType, KitError.error.ALREADY_SELECTED);
    
            switch (kitType){
                case  DEFAULT:
                    targetPlayer.getInventory().clear();
                    ItemStack[] playerInventory = new ItemStack[36];
    
                    playerInventory[0] = new ItemStack(Material.IRON_SWORD);
                    ItemMeta swordMata = playerInventory[0].getItemMeta();
                    swordMata.setDisplayName(ChatColor.GRAY + "Default Sword");
                    swordMata.addEnchant(Enchantment.DAMAGE_ALL, 1, false);
                    playerInventory[0].setItemMeta(swordMata);
    
                    playerInventory[1] = new ItemStack(Material.FISHING_ROD);
                    ItemMeta rodMata = playerInventory[1].getItemMeta();
                    rodMata.setDisplayName(ChatColor.GRAY + "Default Fishing Rod");
                    playerInventory[1].setItemMeta(rodMata);
    
                    for (int x = 0; x < playerInventory.length; x++) {
                        if (playerInventory[x] != null) continue;
                        playerInventory[x] = new Potion(PotionType.INSTANT_HEAL, 2, true).toItemStack(1);
                        ItemMeta potMeta = playerInventory[x].getItemMeta();
                        potMeta.setDisplayName(ChatColor.GRAY + "Pot");
                        potMeta.setLore(Collections.singletonList("Used to heal (Affects others)"));
                        potMeta.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS);
                        playerInventory[x].setItemMeta(potMeta);
                    }
    
                    ItemStack boots = new ItemStack(Material.IRON_BOOTS);
                    ItemMeta meta = boots.getItemMeta();
                    meta.addEnchant(Enchantment.PROTECTION_ENVIRONMENTAL, 1, true);
                    meta.setDisplayName(ChatColor.GRAY + "Default Boots");
                    meta.removeItemFlags(ItemFlag.HIDE_ATTRIBUTES);
                    boots.setItemMeta(meta);
                    ItemStack leggings = new ItemStack(Material.IRON_LEGGINGS);
                    ItemMeta Lmeta = leggings.getItemMeta();
                    Lmeta.addEnchant(Enchantment.PROTECTION_ENVIRONMENTAL, 1, true);
                    Lmeta.setDisplayName(ChatColor.GRAY + "Default Leggings");
                    Lmeta.removeItemFlags(ItemFlag.HIDE_ATTRIBUTES);
                    leggings.setItemMeta(Lmeta);
                    ItemStack chest = new ItemStack(Material.IRON_CHESTPLATE);
                    ItemMeta Cmeta = chest.getItemMeta();
                    Cmeta.addEnchant(Enchantment.PROTECTION_ENVIRONMENTAL, 1, true);
                    Cmeta.setDisplayName(ChatColor.GRAY + "Default Chestplate");
                    Cmeta.removeItemFlags(ItemFlag.HIDE_ATTRIBUTES);
                    chest.setItemMeta(Cmeta);
                    ItemStack helm = new ItemStack(Material.IRON_HELMET);
                    ItemMeta Hmeta = helm.getItemMeta();
                    Hmeta.addEnchant(Enchantment.PROTECTION_ENVIRONMENTAL, 1, true);
                    Hmeta.setDisplayName(ChatColor.GRAY + "Default Helmet");
                    Hmeta.removeItemFlags(ItemFlag.HIDE_ATTRIBUTES);
                    helm.setItemMeta(Hmeta);
                    ItemStack[] Armor = new ItemStack[4];
                    Armor[0] = boots;
                    Armor[1] = leggings;
                    Armor[2] = chest;
                    Armor[3] = helm;
                    targetPlayer.getInventory().setArmorContents(Armor);
                    targetPlayer.getInventory().setContents(playerInventory);
                    kitSelected.put(targetPlayer.getUniqueId(), "Default");
                    break;
            }
        }
     
    Last edited: Jun 25, 2020
Thread Status:
Not open for further replies.

Share This Page