Find X and Y coordinate of PrimedTNT

Discussion in 'Spigot Plugin Development' started by FlamingMC, Jul 3, 2015.

  1. Hello,
    I am making a plugin that loads all chunks that PrimedTNT is in but there is a problem I can't find the X and Y coordinate of the PrimedTNT.

    Thanks in advance!
  2. @FlamingMC
    As far as I know, you'll have to do some looping (Or save EUIDs on the last server instance) to get a list of PrimedTNT's.
  3. How would I do that?
  4. sothatsit


    You would have to either save the locations of all the primed tnt in the world yourself or load all the chunks to find them. You should be able to realise which is the better solution.

    Tip: loading chunks is costly on ram and cpu
  5. How would I load all the chunks?
  6. sothatsit


  7. Okay, then how would I save the location of all the PrimedTnT in the world?
  8. sothatsit


    Pseudo code:
    Code (Text):
    //map to store primed tnt in unloaded chunks
    Map<String, List<Location>> unloadedChunks;

    //gets a unique is for the chunk. e.g. "world_5_-2"
        return chunk.getWorld.getName() + "_" + chunk.getX() + "_" + chunk.getZ();

    // when a chunk loads, remove it from the unloaded chunks list

    //when chunk unloads, add it to the unloaded chunks list
        //create a list for the locations to be stored in
        List<Location> locs = new ArrayList<Location>();

        //put the list into the unloaded chunks map
        unloadedChunks.put(getChunkId(chunk), locs);

        //loop through entities in the chunk
        foreach(entity in chunk) {
            //check if the entity is primed tnt
            if(entity is primed to tnt ) {
                //add to list

        //create list to store all locations of primed tnt
        List<Location> locs = new ArrayList<Location>();

        //loop through all loaded chunks in all worlds
        foreach(chunk in loaded chunks) {
            //loop through all entities in the chunk
            foreach(entity in chunk) {
                //check if entity is primed tnt
                if(entity is primed tnt) {
                    //add to locations list

        //loop through all locations in the unloaded chunks
        foreach(list in unloadedChunks) {
            foreach(location in list) {
                //add to locations list

        //return the list of locations
        return locs;
    Edit: added comments to explain
    #8 sothatsit, Jul 3, 2015
    Last edited: Jul 3, 2015
  9. It seems like you know what you are talking about could you make it? If not it's okay.
  10. sothatsit


    This is for helping you make it. If you want to hire someone, go to Services & Recruitment.
  11. Okay, thank you.