Equipment

Discussion in 'Spigot Plugin Help' started by Eptix, May 22, 2016.

  1. Hey,

    my problem: i dont get the iron_chestplate

    Code (Text):
    @EventHandler
        public void onJoin(PlayerJoinEvent e) {
            Player p = e.getPlayer();
            p.setHealth(20);
            p.setFoodLevel(20);
           
            ItemStack stonesword = new ItemStack(Material.STONE_SWORD);
            ItemMeta stoneswordmeta = stonesword.getItemMeta();      
            stoneswordmeta.setDisplayName("§bKit §7- §bSchwert");
            ArrayList<String> stoneswordlore = new ArrayList<>();
            stoneswordlore.add("§8● §5FFA");
            stoneswordmeta.setLore(stoneswordlore);  
            stonesword.setItemMeta(stoneswordmeta);
            p.getInventory().setItem(0, stonesword);
           
            ItemStack bow = new ItemStack(Material.BOW);
            ItemMeta bowmeta = bow.getItemMeta();
            bowmeta.setDisplayName("§bKit §7- §bBogen");
            ArrayList<String> bowlore = new ArrayList<>();
            bowlore.add("§8● §5FFA");
            bowmeta.setLore(bowlore);
            bow.setItemMeta(bowmeta);
            p.getInventory().setItem(1, bow);
           
            ItemStack arrow = new ItemStack(Material.ARROW, 16);
            p.getInventory().setItem(2, arrow);
           
            ItemStack angel = new ItemStack(Material.FISHING_ROD);
            ItemMeta angelmeta = angel.getItemMeta();
            angelmeta.setDisplayName("§bKit §7- §bAngel");
            ArrayList<String> angellore = new ArrayList<>();
            angellore.add("§8● §5FFA");
            angelmeta.setLore(angellore);
            angel.setItemMeta(angelmeta);
            p.getInventory().setItem(4, angel);
           
            ItemStack goldapple = new ItemStack(Material.GOLDEN_APPLE, 3);
            ItemMeta goldapplemeta = goldapple.getItemMeta();
            goldapplemeta.setDisplayName("§bKit §7- §bGoldapfel");
            ArrayList<String> goldapplelore = new ArrayList<>();
            goldapplelore.add("§8● §5FFA");
            goldapplemeta.setLore(goldapplelore);
            goldapple.setItemMeta(goldapplemeta);
            p.getInventory().setItem(6, goldapple);
           
            ItemStack steak = new ItemStack(Material.COOKED_BEEF, 32);
            ItemMeta steakmeta = steak.getItemMeta();
            steakmeta.setDisplayName("§bKit §7- §bSteak");
            ArrayList<String> steaklore = new ArrayList<>();
            steaklore.add("§8● §5FFA");
            steakmeta.setLore(steaklore);
            steak.setItemMeta(steakmeta);
            p.getInventory().setItem(8, steak);
           
            ItemStack chestplate = new ItemStack(Material.IRON_CHESTPLATE);
            ItemMeta chestplatemeta = chestplate.getItemMeta();
            chestplatemeta.setDisplayName("§bKit §7- §bSteak");
            ArrayList<String> chestplatelore = new ArrayList<>();
            chestplatelore.add("§8● §5FFA");
            chestplatemeta.setLore(chestplatelore);
            chestplate.setItemMeta(chestplatemeta);
            p.getInventory().setItem(102, chestplate);
           
            // Join Message
            if(p.isOp()) {
                e.setJoinMessage("§8[§6FFA§8] §4" + p.getName() + " §3hat den Server betreten.");
            } else {
                e.setJoinMessage("§8[§6FFA§8] §e" + p.getName() + " §3hat den Server betreten.");
            }
           
        }
     
     
  2. 102 isn't a valid spot for the item.
     
  3. The number "102" isn't a valid spot.
     
  4. I looked for minecraft slot ids and found this:

    [​IMG] 102 = chestplate
     
  5. [​IMG]

    Edit: Sniped
     
  6. This is true however armor contents aren't under the normal inventory, but under Armor Contents
     
  7. okay, what must i do?
     
  8. You must set the iron chestplate in PlayerInventory#getArmorContents
     
  9. p.getInventory.getArmorSlot (or something - itll pop up) then set to 102
     
  10. p.getInventory().getArmorSlot().setItem(102, chestplate);

    .getArmorSlot().

    red underlined.
     
  11. With simple testing you can figure that out and also test others' methods before saying that
     
  12. Does your IDE not support auto-guessing what you are trying to type? Just put a . then scroll through it if you do
     
    • Like Like x 1
  13. okay thank you.

    Now i have the next problem,
    when i shot with the bow it goes from 16 arrows to 15 arrows. okay good, but when i dead, i will reset the arrows, how can i do that?
     
  14. Check for the PlayerDeathEvent get the amount of arrows in his/her inventory and fill it up to 16.
     
    • Like Like x 1