[Java] setChestplate + Enchantment

Discussion in 'Plugin Development' started by Boby_Crafter, Apr 9, 2014.

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

    Boby_Crafter

    Hello,

    I have a problem .. When the player does "/ pvp" it gives him the kit (with the armor automatically threaded), but the enchantment does not apply.

    Code:java
    1. if (cmd.getName().equalsIgnoreCase("PVP")) {
    2. if (!p.hasPermission("dkits.pvp")) {
    3. p.sendMessage(ChatColor.BLUE + "dFight" + ChatColor.DARK_GRAY + " > " + ChatColor.GOLD + "C'est un kit premium, mais vous pouvez l'acheter sur notre boutique");
    4. return true;
    5. }
    6. if (usedKit.contains(p.getName())) {
    7. p.sendMessage(ChatColor.BLUE + "dFight" + ChatColor.DARK_GRAY + " > " + ChatColor.GOLD + "Un seul kit par vie");
    8. return true;
    9. }
    10. usedKit.add(p.getName());
    11. ItemStack dsword = new ItemStack(Material.DIAMOND_SWORD);
    12. dsword.addEnchantment(Enchantment.DAMAGE_ALL, 1);
    13. ItemStack ironhelmet = new ItemStack(Material.IRON_HELMET);
    14. ironhelmet.addEnchantment(Enchantment.DURABILITY, 3);
    15. ItemStack ironchestplate = new ItemStack(Material.IRON_CHESTPLATE);
    16. ironchestplate.addEnchantment(Enchantment.DURABILITY, 3);
    17. ItemStack ironleggings = new ItemStack(Material.IRON_LEGGINGS);
    18. ironleggings.addEnchantment(Enchantment.DURABILITY, 3);
    19. ItemStack ironboots = new ItemStack(Material.IRON_BOOTS);
    20. ironboots.addEnchantment(Enchantment.DURABILITY, 3);


    So, I'm obligated to do :
    Code:java
    1. p.getInventory().addItem(new ItemStack[] {ironhelmet});


    But armor is not automatically threaded.

    How to make armor enchanted and automatically threaded.

    (sorry for bad english, i'm french)
     
  2. Offline

    Dubehh

    Boby_Crafter

    This should be enough for adding items
    Code:java
    1. p.getInventory().addItem(dsword);
    2.  
    3.  


    This should add the armor:
    Code:java
    1. p.getInventory().setChestplate. ..


    something like that, if you have p.getInventory.<armorcontent>
     
  3. Offline

    Wruczek

    Code:java
    1. p.getInventory().addItem(ironhelmet (or other itemstack here));
    To put armor on player use
    Code:java
    1. p.setBoots(boots);
    2. p.setChestplate(chestplate);
    ect.
     
  4. Offline

    XvBaseballkidvX

    You should probably make a Kit Object, makes things a lot easier in the long run.

    Kit Object:
    Code:java
    1. public class Kit {
    2.  
    3. private String name;
    4. private ItemStack[] contents;
    5. private ItemStack[] armor;
    6. private String permission;
    7. private List<String> info;
    8.  
    9. public Kit(String name, ItemStack[] contents, ItemStack[] armor, String permission) {
    10. this.name = name;
    11. this.contents = contents;
    12. this.armor = armor;
    13. this.permission = permission;
    14. }
    15.  
    16. public String getName() {
    17. return this.name;
    18. }
    19.  
    20. public ItemStack[] getContents() {
    21. return this.contents;
    22. }
    23.  
    24. public ItemStack[] getArmor() {
    25. return this.armor;
    26. }
    27.  
    28. public String getPermission() {
    29. return this.permission;
    30. }
    31. }


    Then you will be able to make kits like this:
    Code:
    Kit kit = new Kit("PvP", new ItemStack[]{new ItemStack(Material.IRON_SWORD)}, new ItemStack[]{new ItemStack(Material.LEATHER_HELMET)},"kits.use.pvp");
     
  5. Offline

    Boby_Crafter

    It's okay, I used .setArmorContents
     
Thread Status:
Not open for further replies.

Share This Page