Solved RandomChest Help

Discussion in 'Plugin Development' started by Binyon13, May 25, 2014.

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

    Binyon13

    I'm trying to make it so it gets all the items from the config and put one at random into the chest. Heres my code:

    Code:java
    1. public void randomChest(Chest chest) {
    2. Inventory inv = chest.getBlockInventory();
    3.  
    4. String items = SettingsManager.getInstance().getConfig()
    5. .getString("Ids");
    6.  
    7. String[] indiItems = items.split(",");
    8.  
    9. for (String s1 : indiItems) {
    10. String[] itemAmounts = s1.split("-");
    11. ItemStack item2 = new ItemStack(Integer.valueOf(itemAmounts[0]), 1);
    12.  
    13. item2.addUnsafeEnchantment(
    14. Enchantment.getById(Integer.valueOf(itemAmounts[1])), 1);
    15.  
    16. ItemStack[] s = { item2 };
    17.  
    18. int number = 1;
    19.  
    20. for (int i = 0; i < number; i++) {
    21. ItemStack material = s[this.random.nextInt(s.length)];
    22. inv.setItem(random.nextInt(27), material);
    23. }
    24.  
    25. }
    26.  
    27.  



    My config looks like this:
    Code:
    Ids: 276-16,310-0,311-0,312-0,313-0,1-0,2-0,3-0,2-0,4-0,5-0,6-0,7-0,8-0,9-0
    My problem is that its putting more that one item in the chest instead of one. All help is appreciated :D

    Edit: I have fix it :D
     
Thread Status:
Not open for further replies.

Share This Page