package com.agricraft.agricore.plant.fertilizer;

import com.agricraft.agricore.core.AgriCore;

import java.util.Collections;
import java.util.List;

public class AgriPlantList {

    private final boolean blacklist;
    private final List<String> plant_list;

    public AgriPlantList() {
        this(true, Collections.emptyList());
    }


    public AgriPlantList(boolean blacklist, List<String> plant_list) {
        this.blacklist = blacklist;
        this.plant_list = plant_list;
    }

    public boolean isAffected(String plantId) {
        if (plant_list.contains(plantId)) {
            return !blacklist;
        }
        return blacklist;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder();
        sb.append("\nAgriPlantList:");
        sb.append("\n\t- Blacklist: ").append(blacklist);
        sb.append("\n\t- Plant List: ").append(plant_list.stream().collect(StringBuilder::new, (builder, item) -> builder.append("\n\t").append(item), StringBuilder::append).toString().replaceAll("\n", "\n\t").trim());
        return sb.toString();
    }

    public boolean validate() {
        for (String plantId : plant_list) {
            if (!AgriCore.getPlants().hasPlant(plantId)) {
                AgriCore.getCoreLogger().info("Invalid List: Invalid Plant: \"{0}\"!\n{1}", plantId, this);
                return false;
            }
        }
        return true;
    }
}

@@ -1134,24 +1134,54 @@
 alidate() %7B%0A
+        if (!blacklist) %7B%0A    
         for 
@@ -1224,21 +1224,24 @@
         
+    
 if (
-!
 AgriCore
@@ -1270,32 +1270,93 @@
 plantId)) %7B%0A    
+                return true;%0A                %7D%0A            %7D%0A
             Agri
@@ -1398,100 +1398,49 @@
 List
+ 
 : 
-Invalid Plant: %5C%22%7B0%7D%5C%22!%5Cn%7B1%7D%22, plantId, this);%0A                return false;%0A            %7D
+The list does not contains %5C%22%7B0%7D%5C%22!%22);
 %0A   

Stop unvalidating the plant list if a plant is not in the registry (#14)