package com.cjburkey.claimchunk.service.prereq.claim;

import org.jetbrains.annotations.NotNull;

import java.util.Optional;

public class NearChunkPrereq implements IClaimPrereq{
    @Override
    public int getWeight() {
        return 300;
    }

    @Override
    public boolean getPassed(@NotNull PrereqClaimData data) {
        System.out.println("Original " + data.chunk.getX());
        System.out.println("Original " + data.chunk.getZ());

        boolean nearClaimed = false;

        for(int x1 = -1; x1 < 2; x1++) {
            for(int z1 = -1; z1 < 2; z1++) {
                System.out.println(x1);
                System.out.println(z1);
                if(nearClaimed) break;
                nearClaimed = data.claimChunk.getChunkHandler().isClaimed(data.chunk.getWorld().getChunkAt(x1 + data.chunk.getX(), z1 + data.chunk.getZ()));
                System.out.println("Chunk " + (x1 + data.chunk.getX()));
                System.out.println("Chunk " + (z1 + data.chunk.getZ()));
                System.out.println(nearClaimed);
            }
        }
        return !nearClaimed;
    }

    @Override
    public Optional<String> getErrorMessage(@NotNull PrereqClaimData data) {
        return Optional.of("Too close to a chunk");
    }
}

@@ -48,16 +48,54 @@
 claim;%0A%0A
+import com.cjburkey.claimchunk.Utils;%0A
 import o
@@ -361,131 +361,8 @@
 ) %7B%0A
-        System.out.println(%22Original %22 + data.chunk.getX());%0A        System.out.println(%22Original %22 + data.chunk.getZ());%0A%0A
     
@@ -485,88 +485,8 @@
 ) %7B%0A
-                System.out.println(x1);%0A                System.out.println(z1);%0A
     
@@ -536,30 +536,19 @@
         
-nearClaimed = 
+if(
 data.cla
@@ -577,51 +577,41 @@
 r().
-isClaimed(data.chunk.getWorld().getChunkAt(
+getOwner(data.player.getWorld(), 
 x1 +
@@ -657,132 +657,157 @@
 Z())
-);%0A                System.out.println(%22Chunk %22 + (x1 + data.chunk.getX()));%0A                System.out.println(%22Chunk %22 + (z
+ == data.player.getUniqueId()) continue;%0A                nearClaimed = data.claimChunk.getChunkHandler().isClaimed(data.chunk.getWorld().getChunkAt(x
 1 + 
@@ -824,61 +824,36 @@
 .get
-Z()));%0A                System.out.println(nearClaimed
+X(), z1 + data.chunk.getZ())
 );%0A 
@@ -867,32 +867,33 @@
     %7D%0A        %7D%0A
+%0A
         return !

check owner