Random items to a chest, help

Discussion in 'Plugin Development' started by _Zorua, May 9, 2015.

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


    So, I'm currently making a plugin and I need some help.
    I've made it so when you right click a redstone block it opens up a chest inventory.

    Is there any way I can add items too it randomly, like in a survival/hunger games plugin, where there is a random chance of getting, (e.g) a cookie, a stick, a stone sword and a leather helm. Also, if I could set the chance of getting certain items higher or lower?

    Also, when I right click it, it opens up a chest inventory, but when I put an item in there, close the inv, then open it, the item is gone, anyway I can fix that?

    If you need the code, just ask.

    ^_^, thanks.
    - Z
  2. Offline


    have a string list in the config, I would structure like this:
      - DIAMOND,10
    Then make some sort of method to add the items. In this, you will make a random variable that goes up to the same size as the string list in the config. Then you get the item at the random number and add it to the config.
  3. Offline


    Well, here's how you would do that;
    • Assosiate an ItemStack to an int.
    • Put the itemstacks into an ArrayList<ItemStacks>
    • Put them in multiple times if you want them to be more common.
    • Make a Random (Random r = new Random();)
    • Get the ArrayList<ItemStacks> and get a new Random (arraylist.get(r.nextInt(arraylist.size()));), getting a random item.
    • Then, use Inv#setItem(Slot,ItemStack) to set it so there isn't a huddle of Item in a corner.
  4. Offline


    Thanks guys ^_^, I'll try that.


    I've created my ItemStacks, what do you mean 'to an int'?
    How would I do the ArrayList?
    Sorry, I'm new at this XD
    Last edited: May 9, 2015
  5. Offline


    @_Zorua Put all your itemstack in an arraylist.
    ArayList has a method for get back infos. arraylist.get(int). (o is the first item, (arrayslit.size - 1 ) is the last one).
    Now you can apply the random method for get randomly an itemstack in your list
  6. Offline


    Yeah, I'm just confused. XD
    Can you like, spoonfeed me the code for it? lmao
  7. Offline


    List<ItemSTack> list = new ArrayList<>;
    list.add(new itemstack(Material.Caderape));

    This will return a random item
  8. Offline



    'Syntax error on token ";", . expected'
    When I change it to a '.': "Incorrect number of arguments for type ArrayList<E>; it cannot be parameterized with arguments <>"
  9. Offline


    @_Zorua you clearly don't have enough Java knowledge to get into Bukkit development. Save yourself and us some time and please learn Java first.
  10. Offline


    @_Zorua, Okay, little bit rude, but he has the right idea. You need to learn some java before you continue here. I suggest checking out thenewboston.
  11. Offline


    Yeah ik, I just didn't want to learn Java and then bukkit, but to learn Java through doing things with bukkit. But okay. ;p
Thread Status:
Not open for further replies.

Share This Page