Dyed Armor

Discussion in 'Plugin Development' started by BlazeEyezz, Aug 8, 2014.

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

    BlazeEyezz

    Hello,
    I want to give a player dyed armor on a command, but i don't know how to make a custom itemstack, and also not how to make it dyed :S
    Can someone may help me?
     
  2. Offline

    Seadragon91

    Code:
    ItemStack item = new ItemStack(Material.LEATHER_HELMET;
    LeatherArmorMeta meta = (LeatherArmorMeta) item.getItemMeta();
    meta.setColor(Color.AQUA);
    item.setItemMeta(meta);
     
  3. Offline

    fireblast709

    Seadragon91 likes this.
  4. Offline

    BlazeEyezz

    Seadragon91
    Tried your code but won't work :l
    Got the same errors as when i tried it by my self
    Got this:
    [​IMG]

    Can someone help me ?​

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  5. Offline

    Pizza371

  6. Offline

    born2kill_

    After the LEATHER_HELMET, you forgot the closing bracket.
    After you fix that, try exporting, i'm not sure why these errors are appearing.
     
    MCMastery likes this.
  7. Offline

    BlazeEyezz

    [​IMG]

    Now got les errors, but still 4 errors :l
    First error says: Syntax error on token "setColor", Identifier expected after this token
    Second error says: Syntax error, insert "... VariableDeclaratorId" to complete FormalParameterList
    Third erros says: nothing
    Last errors says: Syntax error, insert "... VariableDeclaratorId" to complete FormalParameterList
     
  8. Offline

    Necrodoom

  9. Offline

    BlazeEyezz

  10. Euhm...
    I don't know if this can help you but this is my code and it's working. And I have a public Enum (Idk if you need it?)
    Code:java
    1. public ItemStack getChestplate(Items item) {
    2. ItemStack chestplate = new ItemStack(Material.LEATHER_CHESTPLATE, 1);
    3. LeatherArmorMeta meta = (LeatherArmorMeta)chestplate.getItemMeta();
    4. switch (item) {
    5. case Chestplateblue:
    6. meta.setDisplayName(ChatColor.GOLD + "Monster Fur");
    7. meta.setColor(Color.BLUE);
    8. meta.addEnchant(Enchantment.PROTECTION_FIRE, 1, true);
    9. chestplate.setItemMeta(meta);
    10. }
    11. return chestplate;
    12. }
     
  11. Offline

    BlazeEyezz

    get errors above item when i use that.
     
  12. That's because I used
    public enum Items {
    }
     
  13. Offline

    BlazeEyezz

    thx, got only one error under Chestplateblue :l
    DarkRangerMC
    EDIT: i tried this:
    Code:java
    1. public enum Items {
    2. Chestplateblue
    3. }
     
  14. BlazeEyezz
    Code:java
    1. public enum Items {
    2. Chestplateblue;
    3. }


    should work.
     
  15. Offline

    BlazeEyezz

    Now i want to add this itemstack as his body.
    i tried this, but got an error under chestplate
    Code:java
    1. p.getInventory().setChestplate(chestplate);
     
  16. Let me check this for you:
    Code:java
    1. p.getInventory().setChestplate
    2. (new ItemStack(getChestplate(Items.Chestplateblue)));
    3.  


    This should work
     
  17. Offline

    BlazeEyezz

    Last edited by a moderator: Jun 9, 2016
  18. It's like this:
    Code:java
    1. public enum Items {
    2. Chestplateblue, Nextitem, Nextitem;
    3. }
    4.  
    5.  
     
  19. Offline

    BlazeEyezz

    aha, i'll try that
    And I still have to set the items using
    Code:java
    1. p.getInventory().setChestplate(new ItemStack(getChestplate(Items.Chestplateblue)));
    2. p.getInventory().setChestplate(new ItemStack(getChestplate(Items.Legsblue)));

    ? Because now, i just get an normal leather chestplate in the chestplate slot :l

    DarkRangerMC
     
  20. Offline

    Necrodoom

    BlazeEyezz I'd suggest researching a bit on how enums and Java in general works, so you can understand the error you get from your IDE.
     
  21. Code:java
    1. p.getInventory().setChestplate(new ItemStack(getChestplate(Items.Chestplateblue)));
    2. p.getInventory().setChestplate(new ItemStack(getLegs(Items.Legsblue)));


    You forgot to replace getChestplate with getLegs
     
  22. Offline

    biel

    I have some code for you!
    I am now on my mobile, I'll post it here when I get home.

    Basically the function takes the material (leather armor parts) and a color (RGB).
    Hope it will help!
     
  23. Offline

    BlazeEyezz

    Thx, but i already got a solution.
     

  24. Set your tag to "Solved" please.
     
  25. Offline

    biel

    That ^^
    Will avoid wasting time around!
     
  26. Offline

    BlazeEyezz

    Got a new problem :l
    The helmet that has to be red doesn't have any color.
    Code:java
    1. public enum Items {
    2. Chestplateblue, Legsblue
    3. }
    4.  
    5. public ItemStack getHelmet(Items item) {
    6. ItemStack chestplate = new ItemStack(Material.LEATHER_HELMET, 1);
    7. LeatherArmorMeta meta = (LeatherArmorMeta)chestplate.getItemMeta();
    8. switch (item) {
    9. case Chestplateblue:
    10. meta.setDisplayName(ChatColor.GOLD + "Hat");
    11. meta.setColor(Color.GREEN);
    12. chestplate.setItemMeta(meta);
    13. }
    14. return chestplate;
    15. }
    16.  
    17. public ItemStack getHelmet2(Items item) {
    18. ItemStack legs = new ItemStack(Material.LEATHER_HELMET, 1);
    19. LeatherArmorMeta meta1 = (LeatherArmorMeta)legs.getItemMeta();
    20. switch (item) {
    21. case Legsblue:
    22. meta1.setDisplayName(ChatColor.GOLD + "Hat");
    23. meta1.setColor(Color.RED);
    24. legs.setItemMeta(meta1);
    25. }
    26. return legs;
    27. }
     
  27. Code:java
    1. Chestplateblue, Legsblue;


    I just told you how to do that.
     
  28. Offline

    BlazeEyezz

    You said I had to do this:
    Code:java
    1. public enum Items {
    2. Chestplateblue, Legsblue
    3. }

    DarkRangerMC
     
  29.  
Thread Status:
Not open for further replies.

Share This Page