Find all chests on map

Discussion in 'Plugin Development' started by Simplefly, Apr 19, 2012.

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

    Simplefly

    I want to create an command that puts random items in all chests on the map. Usually the map is a custom map. So my question is how do I find all chests in a world?
     
  2. Offline

    zombieman1000

    i dont think this is the right place to post that.But there might be a plugin.If not i would try to make one for you
     
  3. Offline

    Simplefly

    What do you mean this is the right place? I need to find all chests in the world for my plugin which I'm currently writing
     
  4. Offline

    Ranzdo

    Is the goal to place an random chest and then be able to access it later?
     
  5. Offline

    messageofdeath

    He wants a chest to appear on a map. the material.
     
  6. Offline

    Ranzdo

    aha, ok, then the only thing I can think of is to go though every block on the world and check if it is a chest or not. However that is very slow and will consume alot of processing power. So you could index all chest locations in the world to a yml file and then use it to find the chests later.

    They way I would do it:
    Have the map searched once to find all current chests then register BlockPlaceEvent and ChunkPopulateEvent (if you want the netural chests too) and use them to keep your world synced with your yml file. When you use the command, go through every location in the yml file and first check if they are still chests (they could be destroyed etc). If they are not chests anymore, remove from list, else get the BlockState, cast to Chest, set the inventory and update.
     
  7. Offline

    Simplefly

    Ok, I'm trying to explain it better :p
    If the admin of the server runs the command /foo the plugin should find every chest which is placed in the world and put for example a sword in it.
    My plugin is a little game, when the game starts everyone runs around and tries to find the items and then, when the game is over, I want the admin to be able to reset the chests and add the items to it again.
     
  8. Offline

    Ranzdo

  9. Offline

    Father Of Time

    The big issue with doing this is loaded chunks... You can't get the material type of a block from a chunk that isn't loaded, so to get every chest in the world you would need to one by one load a chunk, iterate through it and identify the chest, then unload the chunk.

    Needless to say this is an insanely inefficient procedure, and frankly I strongly advise against it. Simply put, loading the entire worlds worth of chunks to search for chest will cause insane lag spikes, if not crash the server all together unless done right.

    A possible solution would be to keep a list of chest, and every time a chunk is loaded naturally (either from server start or a player walking into it, etc) do the search then... When the chunk is loaded add the chest to the master list, and when the chunk is unloaded remove them. What this will do is create a list of all chest that are currently loaded into memory and available without manually loading a chunk.

    This doesn't do exactly what you want, but it will provide you a continually adjusting list of all chest that are actively loaded into memory, just make sure to also put chest destruction checks to remove chest that are destroyed while the chunk is loaded, aka player breaking chest, tnt, etc.

    I tried what you are trying a long time ago with signs when making a shop system, I quickly found that it was easier to make list and add/remove the desired objects when they are generated into the world as appose to scanning the entire world for desired objects.

    However, this is only my opinion and not the only way to handle this.
     
    getatmedoe likes this.
  10. Offline

    geekygenius

    I would use a cache of chest locations. It would be faster, and take up a bit more hard drive space.
     
  11. Offline

    APhilosopher

    i know this thread is old but there is still great use and lack for a plugin like this, especialy with servers like mine, survival and got hit by the nodus dupe hack, which has now been patched by bukkit, but how can i find all chests in my server that contain stacks of diamondblocks?

    a plugin like this would help
     
Thread Status:
Not open for further replies.

Share This Page