Check if a world contains a certain block?

Discussion in 'Plugin Development' started by Mindlessmink, Aug 11, 2016.

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


    Okay, I'm currently trying to code a plugin and I want to see if all worlds contain a certain block. I have tried several methods including getting the players world and seeing if it contains a block, But am to the point that I am now unsure. Please comment your suggestions, Thanks! Also if I can find if the block is in the world, I'd like to find the blocks location.
  2. Offline


    1. Make sure all the wolrds are loaded.
    2. Create three for int loops. They all start at -(number), and increment to (number). The ints should be X, Y, and Z.
    3. Use World.getBlockAt(x,y,z) to get the block at XYZ.
    4. If the block is equal to the one you are looking for, break and move on to the next world.
    5. If the block is not in that world after the for loop, do what you want.
  3. Offline


    Okay! Thanks a lot. Helped me out ;)

    EDIT: Thanks you for the reply @Zombie_Striker, But it turned out, I was getting confused at what you meant. This is what I got so far. Please correct me with my mistakes (Not asking for the code)
                boolean loaded = false;
                for(World w : Bukkit.getServer().getWorlds()) {
                  if(w.getName().equals("world")) {
                    loaded = true;
                    for (int x  = -10000000; x < 1000000;){
                        for (int y  = -10000000; y < 1000000;){
                            for (int z  = -10000000; z < 1000000;){
                                World w = Bukkit.getWorld("world");
                                w.getBlockAt(x, y, z);
    EDIT: Bump
    Last edited: Aug 12, 2016
  4. Offline


    Why are you looping through every world? Just use World world = Bukkit.getServer#getWorld("world");

    Useless to loop through every single one, then just use one specific one.
  5. Offline


    As @bcohen9685 pointed out, just use that method to get the world.

    As for your code, you are not increment your XYZ values. After the second semicolon for each for loop, add "X++" , "Y++", or "Z++". Also, you should really reduce those values. You are checking 20,000,000^3 blocks (or 8*10^21). This will definitely crash your server. Try changing those values to only have a range of ten thousand for the X and Z. Since the Y can only go up to 250 blocks, change the range for Y to be from '0' to '250'.
Thread Status:
Not open for further replies.

Share This Page