Solved Config.cfg trouble

Discussion in 'Plugin Development' started by nastasescu, Jun 28, 2014.

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

    nastasescu

    So, i have this line in the config.cfg
    Code:java
    1. Items: 268-1,261-1-ARROW_INFINITE-1,322-5,262-1


    And this is the code who adds enchantments
    Code:java
    1. for (String s1 : indiItems) {
    2. String[] itemAmounts = s1.split("-");
    3. ItemStack item = new ItemStack(
    4. Integer.valueOf(itemAmounts[0]),
    5. Integer.valueOf(itemAmounts[1]));
    6. if (itemAmounts[2] != null) {
    7. item.addUnsafeEnchantment(
    8. Enchantment
    9. .getByName(itemAmounts[2]),
    10. Integer.valueOf(itemAmounts[3]));
    11. }
    12. player.getInventory().addItem(item);

    If an item is not enchanted will not work, why?
     
  2. Offline

    Traks

    You aren't checking if a third element (enchantment element) exists.
    Code:java
    1. if(itemAmounts.length >= 3) {
    2. item.addUnsafeEnchantment(...); // Your stuff
    3. }
     
    nastasescu likes this.
  3. Offline

    nastasescu

    Traks it works, but now i need a thing... when a player press q to don't drop the item.
     
  4. Offline

    Traks

    Cancel PlayerDropItemEvent...
     
    nastasescu likes this.
Thread Status:
Not open for further replies.

Share This Page