(Help) Add "x" amount of items to player with config!

Discussion in 'Plugin Development' started by Jetsinsu, Feb 23, 2014.

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

    Jetsinsu

    Alright so i'm really new with config/giving play items with it so if anyone wold like to help me thanks. I don't know how to add the amount of items in the config file. I'm really lost on what to do. This is what I have,
    Code:java
    1. String line = getConfig().getString("kits.archer.weapon.1");
    2. String[] array = line.split("");
    3. array[0] = "262";
    4. array[1] = "64";
    5. pi.addItem(new ItemStack(Material.matchMaterial(array[0]), Integer.parseInt(array[1])));

    Config:
    Code:
    spawn:
      world: horsepvp
      x: 0
      y: 0
      z: 0
    leave:
      world: horsepvp
      x: 0
      y: 0
      z: 0
    kits:
      archer:
        armor:
          helmet: 306
          chestplate: 307
          leggings: 308
          boots: 309
        weapon:
          0: 261
          1: 262 64 
     
  2. Offline

    jordanzilla02

    You could make a for loop to repeat actively give them a specified item stack.
     
  3. Offline

    Captain Dory

    Make the weapons part of your config:
    weapons:
    0: 261
    1: 262
    1amount: <amount>

    Incorporate this in your code
    Code:java
    1. // Get '1' and save it to an integer (Example used: Foo)
    2. // get '1amount' and save it to an integer (Example used: Bar)
    3. pi.getInventory().addItem(new ItemStack (Material.getMaterial(Foo), Bar));

    This uses Item id's, not material. getMaterial is deprecated, but it works.
     
  4. Offline

    Jetsinsu

    Captain Dory
    It gives this error:
    Code:
    [20:03:01 INFO]: [Horsepvp] Enabling Horsepvp v1.2
     
    [20:03:01 ERROR]: Cannot load configuration from stream
     
    org.bukkit.configuration.InvalidConfigurationException: mapping values are not a
     
    llowed here
     
    in "<string>", line 20, column 16:
     
                amount1: 1
     
                      ^            
    This is my coding in the main:
    Code:java
    1. int item1 = this.getConfig().getInt("kits.archer.weapon.1");
    2. int amount1 = this.getConfig().getInt("kits.archer.weapon.1.amount1");
    3. pi.addItem(new ItemStack(Material.getMaterial(item1), amount1));

    This is my Config:
    Code:java
    1. kits:
    2. archer:
    3. armor:
    4. helmet: 306
    5. chestplate: 307
    6. leggings: 308
    7. boots: 309
    8. weapon:
    9. 1: 261
    10. amount1: 1
    11. 2: 262
     
Thread Status:
Not open for further replies.

Share This Page