package ru.beykerykt.lightsource.items.flags.basic;

import org.bukkit.ChatColor;
import org.bukkit.entity.Entity;
import org.bukkit.inventory.ItemStack;

import ru.beykerykt.lightsource.LightSourceAPI;
import ru.beykerykt.lightsource.items.Item;
import ru.beykerykt.lightsource.items.flags.RequirementFlagExecutor;

public class PermissionCheckExecutor implements RequirementFlagExecutor {

	@Override
	public boolean onCheckRequirement(Entity entity, ItemStack itemStack, Item item, String[] args) {
		if (args.length > 0) {
			for (int i = 0; i < args.length; i++) {
				String permission = args[i];
				if (!entity.hasPermission(permission)) {
					return false;
				}
			}
		}
		return true;
	}

	@Override
	public void onCheckingSuccess(Entity entity, ItemStack itemStack, Item item, String[] args) {
	}

	@Override
	public void onCheckingFailure(Entity entity, ItemStack itemStack, Item item, String[] args) {
		if (args.length > 0) {
			for (int i = 0; i < args.length; i++) {
				String permission = args[i];
				if (!entity.hasPermission(permission)) {
					LightSourceAPI.sendMessage(entity, ChatColor.RED + "You don't have permission: " + ChatColor.WHITE + permission);
				}
			}
		}
	}
}

@@ -108,16 +108,53 @@
 Entity;%0A
+import org.bukkit.entity.EntityType;%0A
 import o
@@ -592,32 +592,82 @@
 .length; i++) %7B%0A
+%09%09%09%09if (entity.getType() == EntityType.PLAYER) %7B%0A%09
 %09%09%09%09String permi
@@ -675,32 +675,33 @@
 sion = args%5Bi%5D;%0A
+%09
 %09%09%09%09if (!entity.
@@ -725,24 +725,25 @@
 mission)) %7B%0A
+%09
 %09%09%09%09%09return 
@@ -749,16 +749,23 @@
  false;%0A
+%09%09%09%09%09%7D%0A
 %09%09%09%09%7D%0A%09%09

check permission only for player