package com.elmakers.mine.bukkit.entity;

import java.util.List;
import javax.annotation.Nullable;

import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Entity;

import com.elmakers.mine.bukkit.api.magic.MageController;
import com.elmakers.mine.bukkit.utility.ConfigurationUtils;

public class MobTargeting {
    private final MageController controller;
    private final List<String> allowedPermissions;
    private final List<String> deniedPermissions;

    private MobTargeting(MageController controller, ConfigurationSection parameters) {
        this.controller = controller;
        allowedPermissions = ConfigurationUtils.getStringList(parameters, "allowed_permissions");
        deniedPermissions = ConfigurationUtils.getStringList(parameters, "denied_permissions");
    }

    @Nullable
    public static MobTargeting getFromMobConfig(MageController controller, ConfigurationSection mobConfiguration) {
        ConfigurationSection targetingParameters = mobConfiguration.getConfigurationSection("targeting");
        if (targetingParameters == null) {
            return null;
        }
        return new MobTargeting(controller, targetingParameters);
    }

    public boolean canTarget(Entity target) {
        if (deniedPermissions != null) {
            for (String permission : deniedPermissions) {
                if (controller.hasPermission(target, permission)) {
                    return false;
                }
            }
        }
        if (allowedPermissions != null) {
            boolean hasAny = false;
            for (String permission : allowedPermissions) {
                if (controller.hasPermission(target, permission)) {
                    hasAny = true;
                    break;
                }
            }
            if (!hasAny) {
                return false;
            }
        }
        return true;
    }
}

@@ -404,33 +404,33 @@
 String%3E 
-allowedPermission
+requiredParameter
 s;%0A    p
@@ -608,33 +608,33 @@
         
-allowedPermission
+requiredParameter
 s = Conf
@@ -675,21 +675,22 @@
 eters, %22
-allow
+requir
 ed_permi
@@ -1490,33 +1490,33 @@
     if (
-allowedPermission
+requiredParameter
 s != nul
@@ -1597,25 +1597,25 @@
 n : 
-allowedPermission
+requiredParameter
 s) %7B

Change name of required_permissions parameter