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

import com.cjburkey.claimchunk.Config;
import com.cjburkey.claimchunk.Utils;
import com.cjburkey.claimchunk.worldguard.WorldGuardHandler;
import java.util.Optional;

public class WorldGuardPrereq implements IClaimPrereq {

    @Override
    public int getWeight() {
        return 100;
    }

    @Override
    public boolean getPassed(PrereqClaimData data) {
        boolean allowedToClaimWG = WorldGuardHandler.isAllowedClaim(data.chunk);
        boolean worldAllowsClaims = !Config.getList("chunks", "disabledWorlds").contains(data.chunk.getWorld().getName());
        boolean adminOverride = Config.getBool("worldguard", "allowAdminOverride");
        @SuppressWarnings("OptionalGetWithoutIsPresent")
        boolean hasAdmin = Utils.hasAdmin(data.player.get());

        return (worldAllowsClaims || allowedToClaimWG) && (hasAdmin && adminOverride);
    }

    @Override
    public Optional<String> getErrorMessage(PrereqClaimData data) {
        return Optional.of(data.claimChunk.getMessages().claimLocationBlock);
    }

}

@@ -816,16 +816,127 @@
 et());%0A%0A
+        // This can be simplified but it works and I'm feeling lazy%0A        // I promise I'll get around to it%0A
         
@@ -942,16 +942,19 @@
  return 
+!(!
 (worldAl
@@ -967,16 +967,50 @@
 aims %7C%7C 
+(hasAdmin && adminOverride)) %7C%7C !(
 allowedT
@@ -1021,12 +1021,11 @@
 imWG
-) &&
+ %7C%7C
  (ha
@@ -1048,16 +1048,18 @@
 verride)
+))
 ;%0A    %7D%0A

Fix players unable to claim chunks