 # Solved Help with Chunk Buy

Discussion in 'Plugin Development' started by Swissi, May 12, 2016.

Not open for further replies.
1. Offline

### Swissi

Hello Buukit.org Community I have Problems with my Chunk Buy Plugin...
i will:
1. Player buy Chunk and pays 300 -> OK and works
2. Player have 30 Chunks... and pays for the 31th Chunk 500 but next to Chunk only 300 <-- ???
But how do I do that to?

#1
2. Offline

What the...?

#2
3. Offline

### Swissi

Code:
```public Boolean isNextChunk(){
Chunk targetchunk = p.getLocation().getChunk();
if ((int)chunk.getX()+1 == (int)targetchunk.getX()){
return true;
} else if ((int)chunk.getZ()+1 == (int)targetchunk.getZ()){
return true;
} else {
if ((int)chunk.getX()-1 == (int)targetchunk.getX()){
return true;
} else if ((int)chunk.getZ()-1 == (int)targetchunk.getZ()){
return true;
} else {
return false;
}
}
}```

#3
4. Offline

### mcdorli

Why do you return a Boolean instead of boolean?

#4
5. Offline

### Zombie_Striker

This will ALWAYS return false. Lets go through each if statement:
1. If statement #1 asks if X = X+1, meaning you are testing if any number is equal to that number +1. This is like asking if 1 = 2, 2 = 3, ect.
2. Same thing as above, but for testing the Z values
3. Now you d othe reverse and as if X = X-1, which is the same problem as above. This is like asking if 2 = 1, 1 = 0, ect.
4. Same as the above but for Z.

#5
6. Offline

### Swissi

Works now for me...
Thanks for the Help Code:
Code:
```public boolean isNextChunk(){
Chunk chunk = p.getWorld().getChunkAt(p.getLocation());
for (int i = -16; i <= 16; i = i + 16) {
for (int a = -16; a <= 16; a = a + 16) {
chunk = p.getWorld().getChunkAt((p.getLocation().getBlockX() + i) >> 4,
(p.getLocation().getBlockZ() + a) >> 4);
Block b = Bukkit.getServer().getWorld("world").getHighestBlockAt((p.getLocation().getBlockX() + i), (p.getLocation().getBlockZ() + a));
ProtectedRegion region = WGBukkit.getRegionManager(chunk.getWorld()).getRegion("region_" + chunk.getX() + "_" + chunk.getZ());
Location loci = b.getLocation();
Vector v = new Vector(loci.getX(), loci.getY(), loci.getZ());
if (region == null){
} else {
if (region.contains(v)) {
if (region.getOwners().contains(p.getName())){
return true;
}
}
}
}
}
return false;
}```

#6