package com.carpentersblocks.util.protection;

import java.util.UUID;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.MinecraftServer;
import com.carpentersblocks.util.registry.FeatureRegistry;

public class PlayerPermissions {

    /**
     * Returns true if player is operator.
     * Can only return true if called server-side.
     */
    public static boolean isOp(EntityPlayer entityPlayer)
    {
        if (!entityPlayer.worldObj.isRemote) {
            return ((EntityPlayerMP)entityPlayer).mcServer.getConfigurationManager().func_152596_g(entityPlayer.getGameProfile());
        } else {
            return false;
        }
    }

    /**
     * Whether player is an operator, owner or is in a singleplayer server.
     *
     * @param  object the {@link IProtected} block or entity
     * @param  entityPlayer the {@link EntityPlayer}
     * @return <code>true</code> if player has elevated permission
     */
    public static boolean hasElevatedPermission(IProtected object, EntityPlayer entityPlayer)
    {
        if (entityPlayer.worldObj.isRemote && Minecraft.getMinecraft().isSingleplayer()) { // Check if client is playing singleplayer
            return true;
        } else if (!entityPlayer.worldObj.isRemote && MinecraftServer.getServer().isSinglePlayer()) { // Check if server is integrated (singleplayer)
            return true;
        } else if (isOp(entityPlayer)) {
            return true;
        } else if (FeatureRegistry.enableOwnership) {
            return isOwner(object, entityPlayer);
        } else {
            return false;
        }
    }

    /**
     * Whether the player is the owner of the object.
     *
     * @param object
     * @param entityPlayer
     * @return <code>true</code> if player is owner
     */
    private static boolean isOwner(IProtected object, EntityPlayer entityPlayer)
    {
        try {
            UUID.fromString(object.getOwner());
            return object.getOwner().equals(entityPlayer.getUniqueID().toString());
        } catch (IllegalArgumentException e) {
            return object.getOwner().equals(entityPlayer.getDisplayName());
        }
    }

}

@@ -63,16 +63,77 @@
 l.UUID;%0A
+%0Aimport com.carpentersblocks.util.registry.FeatureRegistry;%0A%0A
 import n
@@ -311,67 +311,8 @@
 ver;
-%0Aimport com.carpentersblocks.util.registry.FeatureRegistry;
 %0A%0Apu
@@ -1553,48 +1553,11 @@
 else
- if (FeatureRegistry.enableOwnership)
  %7B%0A
+
     
@@ -1606,51 +1606,8 @@
 r);%0A
-        %7D else %7B%0A            return false;%0A
     
@@ -1787,16 +1787,81 @@
 is owner
+ or %7B@link FeatureRegistry#enableOwnership%7D is %3Ccode%3Efalse%3C/code%3E
 %0A     */
@@ -1934,38 +1934,115 @@
 r entityPlayer)%0A
-
     %7B%0A
+    %09if (!FeatureRegistry.enableOwnership) %7B%0A    %09%09return true;%0A    %09%7D%0A    %09%0A
         try %7B%0A  

Fix not being able to disable ownership from configuration file.