package io.github.aquerr.eaglefactions.listeners;

import com.flowpowered.math.vector.Vector3i;
import io.github.aquerr.eaglefactions.EagleFactions;
import io.github.aquerr.eaglefactions.PluginInfo;
import io.github.aquerr.eaglefactions.logic.FactionLogic;
import org.spongepowered.api.block.BlockSnapshot;
import org.spongepowered.api.command.CommandResult;
import org.spongepowered.api.data.Transaction;
import org.spongepowered.api.entity.Transform;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.entity.MoveEntityEvent;
import org.spongepowered.api.event.filter.cause.Root;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.format.TextColors;

public class PlayerMoveListener
{
    @Listener
    public void onPlayerMove(MoveEntityEvent event, @Root Player player)
    {
        String playerFactionName = FactionLogic.getFactionName(player.getUniqueId());

        if(EagleFactions.AutoClaimList.contains(player.getUniqueId().toString()))
        {
            Vector3i chunk = player.getLocation().getChunkPosition();

            if(!FactionLogic.getClaims(playerFactionName).isEmpty())
            {
                if(!FactionLogic.isClaimed(chunk))
                {
                    if(FactionLogic.isClaimConnected(playerFactionName, chunk))
                    {
                        FactionLogic.addClaim(playerFactionName, chunk);

                        player.sendMessage(Text.of(PluginInfo.PluginPrefix, "Land has been successfully ", TextColors.GOLD, "claimed", TextColors.WHITE, "!"));
                        return;
                    }
                }
            }
            else
            {
                FactionLogic.addClaim(playerFactionName, chunk);
                player.sendMessage(Text.of(PluginInfo.PluginPrefix, "Land has been successfully ", TextColors.GOLD, "claimed", TextColors.WHITE, "!"));
                return;
            }

        }
        return;
    }
}

@@ -250,16 +250,77 @@
 nLogic;%0A
+import io.github.aquerr.eaglefactions.services.PowerService;%0A
 import o
@@ -1338,32 +1338,221 @@
               %7B%0A
+                    if(PowerService.getFactionPower(FactionLogic.getFaction(playerFactionName)).doubleValue() %3E= FactionLogic.getClaims(playerFactionName).size())%0A                    %7B%0A    
                 
@@ -1627,32 +1627,36 @@
                 
+    
 %7B%0A              
@@ -1657,32 +1657,36 @@
                 
+ 
+   
 FactionLogic.add
@@ -1715,24 +1715,28 @@
 e, chunk);%0A%0A
+    
             
@@ -1903,32 +1903,36 @@
             
+    
 return;%0A
             
@@ -1911,32 +1911,487 @@
         return;%0A
+                        %7D%0A                        else%0A                        %7B%0A                            player.sendMessage(Text.of(PluginInfo.ErrorPrefix, TextColors.RED, %22Claims needs to be connected!%22));%0A                        %7D%0A                    %7D%0A                    else%0A                    %7B%0A                        player.sendMessage(Text.of(PluginInfo.ErrorPrefix, TextColors.RED, %22Your faction does not have power to claim more land!%22));%0A
                 

Fix claiming infinity amount of chunks in autoclaim command