package com.ForgeEssentials.permissions;

import java.util.HashMap;

import com.ForgeEssentials.core.config.FEConfig;
import com.ForgeEssentials.util.OutputHandler;

import net.minecraftforge.event.Event.Result;

/**
 * @author AbrarSyed
 */
public class Permission extends PermissionChecker
{
	private static HashMap<String, Permission>	defaults		= new HashMap<String, Permission>();

	public static final Result getPermissionDefault(String name)
	{
		Permission perm = defaults.get(name);
		if (perm != null)
			return perm.allowed;
		else
		{
			return getPermissionDefault((new PermissionChecker(name).getImmediateParent()));
		}
	}

	/**
	 * This does NOT automatically register parents.
	 * @param perm Permission to be added
	 */
	protected static void addDefaultPermission(Permission perm)
	{
		assert !defaults.containsKey(perm.name) : new IllegalArgumentException("You cannot override a default Permission");
		defaults.put(perm.name, perm);
		if (ModulePermissions.permsVerbose)
			OutputHandler.SOP("Permission Registered: " + perm);
	}

	public Result	allowed;

	public Permission(String qualifiedName, Boolean allowed)
	{
		super(qualifiedName);
		this.allowed = allowed ? Result.ALLOW : Result.DENY;
	}

	public boolean equals(Object object)
	{
		if (object instanceof Permission)
		{
			Permission perm = (Permission) object;
			return name.equals(perm.name) && this.allowed.equals(perm.allowed);
		}
		else if (object instanceof String)
		{
			return object.equals(name);
		}
		return false;
	}

	@Override
	public String toString()
	{
		return name + " : " + allowed;
	}
}

@@ -524,16 +524,21 @@
  null)%0D%0A
+%09%09%7B%0D%0A
 %09%09%09retur
@@ -554,16 +554,84 @@
 lowed;%0D%0A
+%09%09%7D%0D%0A%09%09else if (name.isEmpty())%0D%0A%09%09%7B%0D%0A%09%09%09return Result.ALLOW;%0D%0A%09%09%7D%0D%0A
 %09%09else%0D%0A

Fix to prevent infinite recursion on an empty permission string.