Getting variables out of an asyncronous task

Discussion in 'Bukkit Help' started by MoldyTurtle12, Dec 15, 2020.

  1. Offline


    Hello, I'm currently having an issue with returning a variable out of this method I've created.

        public Block[] getHighestBlocksAt(final Chunk c) {
            new BukkitRunnable() {
                Block[] blocks = new Block[0];
                public void run() {
                    for(int x = 0; x < 16; x++) {
                        for(int z = 0; z < 16; z++) {
                            Block[] newArr = Arrays.copyOf(blocks, blocks.length + 1);
                            newArr[newArr.length - 1] = c.getWorld().getHighestBlockAt(c.getBlock(x, 0, z).getLocation());
                            blocks = newArr;
    The ultimate goal is to get all of the surface blocks in a chunk and return them, while still running the task asynchronously as to not cause a large amount of server lag. Of course, I cannot return any variable out of the BukkitRunnable instantiation. I obviously can't set a variable with the final modifier outside of it, I can't get a static variable out of it or create a static method in it, etc. etc. Is it even possible to accomplish this? Thanks for any help.
    Last edited by a moderator: Dec 15, 2020

Share This Page