How do I put enchantments and armour in my kit plugin?

Discussion in 'Plugin Development' started by Matroix7, Jan 14, 2014.

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

    Matroix7

    here is my code
    Code:java
    1. package me.Ivan.Kits;
    2.  
    3. import java.io.File;
    4. import java.io.IOException;
    5.  
    6. import org.bukkit.configuration.file.FileConfiguration;
    7. import org.bukkit.plugin.java.JavaPlugin;
    8.  
    9. public class Kits extends JavaPlugin{
    10.  
    11. public void onEnable() {
    12. saveConfig();
    13. try {
    14. setupConfig(getConfig());
    15. } catch (IOException e) {
    16. e.printStackTrace();
    17. }
    18. }
    19.  
    20. private void setupConfig(FileConfiguration config) throws IOException {
    21. if(!new File(getDataFolder(), "RESET.FILE").exists()){
    22. new File(getDataFolder(), "RESET.FILE").createNewFile();
    23.  
    24. config.set("Kits.PvP.Items", 276-1-20);
    25.  
    26. }
    27. }
    28. }
    29.  
     
  2. Offline

    Iroh

    Moved to plugin dev.
     
    Garris0n likes this.
  3. Offline

    Carnes

  4. Offline

    MrInspector

    How to add enchantments & armor ->
    Code:java
    1.  
    2. // add 1 -> 5 level enchantments
    3. ItemName.addEnchantment(Enchantment.ENCHANTMENT, Level);
    4. // add any leveled enchantment
    5. ItemName.addUnsafeEnchantment(Enchantment.ENCHANTMENT, Level);
    6.  
    7. // creating a armor piece
    8. ItemStack chestplate = new ItemStack(Material.IRON_CHESTPLATE, 1);
    9. // adding it to your chestplate inventory slot
    10. player.getEquipment().setChestplate(chestplate);
    11.  
    12. [quote="DoctorDark, post: 2179581, member: 90814387"][USER=90900748]Tupay[/USER] I believe you have to use getInventory instead of getEquipment which is used for mobs.[/quote]
    13. It'll work both ways, same thing.
    14.  
    15. EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  5. Offline

    xMrPoi

    This works
    Code:java
    1. ItemStack sword = new ItemStack(Material.DIAMOND_SWORD); //Creates a new itemstack with the material of a diamond sword assigned to it
    2. sword.addEnchantment(Enchantment.DAMAGE_ALL, 1); //Adds sharpness I to that sword that you just created
    3. player.getInventory().addItem(sword); //Adds the sword to the player's inventory (You have to define player earlier in the code)
     
  6. Offline

    Wizehh

    BcBroz :p
     
  7. Offline

    xMrPoi

    Oh and you can do the same with armor
    Code:java
    1. ItemStack helmet = new ItemStack(Material.IRON_HELMET); //Makes the iron helmet itemstack
    2. helmet.addEnchantment(Enchantment.WATER_BREATHING, 2); //Adds aqua affinity 2 to the helmet
    3. player.getInventory().setHelmet(helmet); //Sets the player's helmet to the one you just made.
     
Thread Status:
Not open for further replies.

Share This Page