package com.jaquadro.minecraft.storagedrawers.integration.thermalfoundation;

import com.jaquadro.minecraft.storagedrawers.api.security.ISecurityProvider;
import com.jaquadro.minecraft.storagedrawers.api.storage.attribute.IProtectable;
import com.jaquadro.minecraft.storagedrawers.integration.ThermalFoundation;
import com.jaquadro.minecraft.storagedrawers.security.DefaultSecurityProvider;
import com.mojang.authlib.GameProfile;
import net.minecraft.server.MinecraftServer;

public class CoFHSecurityProvider implements ISecurityProvider
{
    ThermalFoundation foundation;
    private DefaultSecurityProvider defaultProvider = new DefaultSecurityProvider();

    public CoFHSecurityProvider (ThermalFoundation foundation) {
        this.foundation = foundation;
    }

    @Override
    public String getProviderID () {
        return "cofh";
    }

    @Override
    public boolean hasOwnership (GameProfile profile, IProtectable target) {
        return defaultProvider.hasOwnership(profile, target);
    }

    @Override
    public boolean hasAccess (GameProfile profile, IProtectable target) {
        if (target.getOwner() == null)
            return true;

        GameProfile ownerProfile = MinecraftServer.getServer().func_152358_ax().func_152652_a(target.getOwner());
        if (ownerProfile == null)
            return false;

        return foundation.playerHasAccess(profile.getName(), ownerProfile);
    }
}

@@ -426,53 +426,8 @@
 ile;
-%0Aimport net.minecraft.server.MinecraftServer;
 %0A%0Apu
@@ -1152,66 +1152,31 @@
 e = 
-MinecraftServer.getServer().func_152358_ax().func_152652_a
+(profile.getId().equals
 (tar
@@ -1190,17 +1190,17 @@
 Owner())
-;
+)
 %0A       
@@ -1204,58 +1204,120 @@
     
-if (ownerProfile == null)%0A            return false
+    ? new GameProfile(profile.getId(), profile.getName())%0A            : new GameProfile(target.getOwner(), null)
 ;%0A%0A 

Fix CoFH-locked drawers crashing clients