# Get chunks around players chunk

Discussion in 'Spigot Plugin Development' started by ExtendedHorizons, Jun 21, 2015.

1. ### ExtendedHorizons

I was wondering if theres a way to get surrounding chunks of the players chunk (Example down bellow 1st comment). Then after getting those chunks do what WorldEdit does with //expand vert. Thanks!

~Extended

2. ### ExtendedHorizons

---
-+-
---
is what the surrounding chunks look like. Also + is the players chunk

bump

4. ### bo0tzz

Get the chunk's coordinates, then get some new chunks by adding to the coordinates of the original chunk.

5. ### ExtendedHorizons

I understand the concept but im wondering if theres math to do it in a better way then just
x-1, z
x+1, z
x, z-1
x, z+1

x-1, z-1
x+1, z+1
x+1, z-1
x-1, z+1
1 being 16

7. ### Creeoer Supporter

Use for loops

• Agree x 1
8. ### TimLampen

Might wanna tag @bo0tzz

9. ### ExtendedHorizons

o am dumb xD will do

This.

11. ### hamoodrex

Make a for loop that will run over coordinates, by that you can get chunks at location, just like my explosive pick plugin!

12. ### CoKoC

Code (Text):
public Collection<Chunk> getChunksAroundPlayer(Player player) {
int[] offset = {-1,0,1}

World world = player.getWorld();
int baseX = player.getLocation().getChunk().getX();
int baseZ = player.getLocation().getChunk().getZ();

Collection<Chunk> chunksAroundPlayer = new HashSet<>();
for(int x : offset) {
for(int z : offset) {
Chunk chunk = world.getChunkAt(baseX + x, baseZ + z);
chunksAroundPlayer.add(chunk);
}
} return chunksAroundPlayer;
}

• Like x 2
• Agree x 1