Getting all chests in the world and fill them with random stuff

Discussion in 'Plugin Development' started by KaiTheCoder, Aug 8, 2017.

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

    KaiTheCoder

    Getting all chests in the world and fill them with random stuff

    Please Help!
     
  2. Offline

    timtower Administrator Administrator Moderator

    @KaiTheCoder When somebody clicks the chest fill it with random stuff.
    With a cooldown
     
  3. Offline

    Zombie_Striker

    @KaiTheCoder
    We are here to help you fix your problems, not write the plugin for you. We will guide you how to do this, but you will need to be the one to write the code. If you run into any problems coding, reply with the code you have written and tell us what is wrong, and we will tell you what needs to change.

    Here is what you need to do:
    1. Create a array of itemstacks that can be added to the inventory.
    2. Listen to playerInteractEvent
    3. If the chest needs to be filled (either by checking if it is empty, or if it has not been clicked before)
    4. Select a few random spots in the inventory and fill them up with a random item from the array.
     
  4. Offline

    KaiTheCoder

    Like this?
    for(Chunk c : Bukkit.getWorld("world").getLoadedChunks()) {
    for(int i = 0; i < c.getTileEntities().length; i++) {
    if(c.getTileEntities().getType() == Material.CHEST) {
    Chest chest = (Chest) c.getTileEntities();
    Inventory inv = chest.getBlockInventory();
    inv.addItem(new ItemStack(Material.ENDER_PEARL, 13));
    chest.update();
    }
    }
     
  5. Offline

    Zombie_Striker

Thread Status:
Not open for further replies.

Share This Page