Chest regeneration after X minutes and loot.

Discussion in 'Plugin Development' started by Weszzz, Feb 27, 2014.

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

    Weszzz

    Hi there!
    I want to make a plugin for my minigame where i can set loot for all chests in a world. So that it finds all the chests and then the loot i wrote down spawns in it. If a player opens the chest it dissapears and the loot falls out of it, then after X minutes i need it to respawn. I read that you can loop thru all the chunks in that world and let it search for chests and if it found a chest then put loot in it (which comes from an arraylist ?----->). I also read you can set your loot on an arraylist (which randomly spawns in the chests)
    But how to do this !? I don't know and i am already stuck on this part for like 1/2 weeks. Can someone explain with example code for example ?
    Thanks, Weszzz
     
  2. Offline

    Vandrake

    Store all the blocks where the chests are in a map, along with the time they were regenerated (System.currenttime if they're new) and every second run a check, if the time has passed X minutes, regenerate it with a set/custom item
     
    NathanWolf likes this.
  3. Offline

    Weszzz

    Vandrake Yeah, i got that but how to do that ? Can you explain with example code ? (i am not asking for a whole code)
     
  4. Offline

    Vandrake

    Run a task at the onEnable, to repeat itself every second,
    and iterate through all the blocks in the map, get their time and check if X Minutes have passed, if they have regenerate the chest, else ignore(Do nothing)
     
  5. Offline

    Weszzz

    Vandrake How does it know its a chest ? And how to add loot ?
     
  6. Offline

    Vandrake

    if block.getType() == Material.CHEST
    it's a chest
    Chest c = block.getState();
    then do shiet with c :p
     
  7. Offline

    Weszzz

    Vandrake Okay ;p But how to repeat the task to search for chest and how to iterate through all of the blocks? Sorry, i am very noob at this.
     
  8. Offline

    Vandrake

    run this task every second:

    everysecond()
    {
    everysecond();
    for(Block b: blocklist)
    {
    do something productive with b
    }
    }
     
  9. Offline

    Weszzz

    Vandrake I don't get it, what is blocklist ? And how to add loot in the chests ? Sorry again.. ;p
     
  10. Offline

    Vandrake

    the blocklist is the map,

    Block b : HashMapName.keySet()

    and you can find tutorials how to add shiet to chests online :p
     
  11. Offline

    Weszzz

    Vandrake Nope cant find if i could i already would do that ;p

    Vandrake And can u give me an example code ?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  12. Offline

    Weszzz

    BUMP.. Still need help
     
  13. Offline

    NathanWolf

  14. Offline

    Weszzz

    NathanWolf I still don't understand sorry, can u help me more please ?
     
  15. Offline

    calebbfmv

    Vandrake
    Why every second mate? Server intensive.
     
  16. Offline

    Vandrake

    Not trying to flame or anything but....

    a cpu from 1984 can run 10million Instructions per second.
    iterating through a list of at most 100 blocks, and checking if the block at such place exists, sure it may seem but whatever. Just giving out my idea
     
  17. Offline

    NathanWolf

    I can't do much better than that! You could copy and paste from there for code that fills chests, but better to try and understand the code.

    Vandrake I tend to agree, I will change (not just inspect) up to 1,000 blocks per *tick* without causing my server to blush.
     
    Vandrake likes this.
Thread Status:
Not open for further replies.

Share This Page