/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

package com.skelril.skree.service.internal.dropclear;

import com.flowpowered.math.vector.Vector3i;
import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.entity.EntityType;
import org.spongepowered.api.world.Location;
import org.spongepowered.api.world.extent.Extent;

import java.util.*;

public class CheckProfile {
    private final Collection<? extends Entity> entities;
    private final Map<Vector3i, ? extends DropClearStats> stats;

    private CheckProfile(Collection<? extends Entity> entities, Map<Vector3i, ? extends DropClearStats> stats) {
        this.entities = entities;
        this.stats = stats;
    }

    public static CheckProfile createFor(Extent extent, Collection<EntityType> checkedEntities) {
        Set<Entity> entities = new HashSet<>();
        Map<Vector3i, ChunkStats> stats = new HashMap<>();
        for (Entity entity : extent.getEntities()) {
            EntityType eType = entity.getType();
            if (checkedEntities.contains(eType)) {
                Vector3i chunkPos = getChunkPos(entity.getLocation());
                ChunkStats chunkStats = stats.merge(
                        chunkPos, new ChunkStats(chunkPos), ChunkStats::merge
                );
                chunkStats.increase(eType, 1);
                entities.add(entity);
            }
        }
        return new CheckProfile(entities, stats);
    }

    private static Vector3i getChunkPos(Location loc) {
        return new Vector3i(loc.getX() / 16, 0, loc.getZ() / 16);
    }

    public Collection<? extends Entity> getEntities() {
        return entities;
    }

    public Map<Vector3i, ? extends DropClearStats> getStats() {
        return stats;
    }
}
@@ -1102,78 +1102,13 @@
 ies(
-)) %7B%0A            EntityType eType = entity.getType();%0A            if (
+e -%3E 
 chec
@@ -1129,20 +1129,27 @@
 ntains(e
+.get
 Type
+())
 )) %7B%0A   
@@ -1157,20 +1157,16 @@
         
-   
- 
 Vector3i
@@ -1224,20 +1224,16 @@
         
-    
 ChunkSta
@@ -1277,28 +1277,24 @@
             
-   
- 
 chunkPos, ne
@@ -1347,20 +1347,16 @@
         
-    
 );%0A     
@@ -1358,28 +1358,24 @@
             
-  
-  
 chunkStats.i
@@ -1383,20 +1383,31 @@
 crease(e
+ntity.get
 Type
+()
 , 1);%0A  
@@ -1416,20 +1416,16 @@
         
-   
- 
 entities
@@ -1442,22 +1442,8 @@
 y);%0A
-            %7D%0A
     

Use the built in entity filtering system when collecting a list of entities for a drop clear profile